1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-27 02:56:18 -04:00

[mujs] Define location in window.c

This commit is contained in:
Witold Filipczyk 2023-10-19 18:03:53 +02:00
parent ba33d709de
commit b931536fc3
2 changed files with 41 additions and 1 deletions

View File

@ -550,7 +550,6 @@ mjs_location_init(js_State *J)
addproperty(J, "protocol", mjs_location_get_property_protocol, mjs_location_set_property_protocol);
addproperty(J, "search", mjs_location_get_property_search, mjs_location_set_property_search);
}
js_defglobal(J, "location", JS_DONTENUM);
return 0;
}

View File

@ -22,6 +22,7 @@
#include "ecmascript/ecmascript.h"
#include "ecmascript/mujs.h"
#include "ecmascript/mujs/keyboard.h"
#include "ecmascript/mujs/location.h"
#include "ecmascript/mujs/message.h"
#include "ecmascript/mujs/window.h"
#include "ecmascript/timer.h"
@ -101,6 +102,45 @@ mjs_window_get_property_event(js_State *J)
mjs_push_keyboardEvent(J, NULL);
}
static void
mjs_window_get_property_location(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
mjs_push_location(J);
}
static void
mjs_window_set_property_location(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs;
struct document_view *doc_view;
vs = interpreter->vs;
const char *url;
if (!vs) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
js_pushnull(J);
return;
}
doc_view = vs->doc_view;;
url = js_tostring(J, 1);
if (!url) {
js_pushnull(J);
return;
}
location_goto_const(doc_view, url);
js_pushundefined(J);
}
static void
mjs_window_get_property_parent(js_State *J)
{
@ -642,6 +682,7 @@ mjs_window_init(js_State *J)
addproperty(J, "window.closed", mjs_window_get_property_closed, NULL);
addproperty(J, "window.event", mjs_window_get_property_event, NULL);
addproperty(J, "window.location", mjs_window_get_property_location, mjs_window_set_property_location);
addproperty(J, "window.parent", mjs_window_get_property_parent, NULL);
addproperty(J, "window.self", mjs_window_get_property_self, NULL);
addproperty(J, "window.status", mjs_window_get_property_status, mjs_window_set_property_status);