mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
[spidermonkey] getLocation
Both: location = url; location.href = url; should work.
This commit is contained in:
parent
4375984708
commit
c9359669bd
@ -729,6 +729,9 @@ document_get_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
}
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||
|
||||
if (!interpreter->location_obj) {
|
||||
interpreter->location_obj = getLocation(ctx);
|
||||
}
|
||||
args.rval().setObject(*(JSObject *)(interpreter->location_obj));
|
||||
return true;
|
||||
}
|
||||
|
@ -1022,3 +1022,19 @@ location_goto_common(JSContext *ctx, struct document_view *doc_view, JS::HandleV
|
||||
mem_free(url);
|
||||
}
|
||||
}
|
||||
|
||||
JSObject *
|
||||
getLocation(JSContext *ctx)
|
||||
{
|
||||
JSObject *el = JS_NewObject(ctx, &location_class);
|
||||
|
||||
if (!el) {
|
||||
return NULL;
|
||||
}
|
||||
JS::RootedObject r_el(ctx, el);
|
||||
|
||||
JS_DefineProperties(ctx, r_el, (JSPropertySpec *) location_props);
|
||||
spidermonkey_DefineFunctions(ctx, el, location_funcs);
|
||||
|
||||
return el;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/spidermonkey/heartbeat.h"
|
||||
#include "ecmascript/spidermonkey/keyboard.h"
|
||||
#include "ecmascript/spidermonkey/location.h"
|
||||
#include "ecmascript/spidermonkey/message.h"
|
||||
#include "ecmascript/spidermonkey/window.h"
|
||||
#include "ecmascript/timer.h"
|
||||
@ -53,6 +54,8 @@
|
||||
|
||||
static bool window_get_property_closed(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||
static bool window_get_property_event(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||
static bool window_get_property_location(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||
static bool window_set_property_location(JSContext *cx, unsigned int argc, JS::Value *vp);
|
||||
static bool window_get_property_parent(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool window_get_property_self(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
static bool window_get_property_status(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
@ -117,18 +120,6 @@ JSClass window_class = {
|
||||
&window_ops
|
||||
};
|
||||
|
||||
|
||||
/* Tinyids of properties. Use negative values to distinguish these
|
||||
* from array indexes (even though this object has no array elements).
|
||||
* ECMAScript code should not use these directly as in window[-1];
|
||||
* future versions of ELinks may change the numbers. */
|
||||
enum window_prop {
|
||||
JSP_WIN_CLOSED = -1,
|
||||
JSP_WIN_PARENT = -2,
|
||||
JSP_WIN_SELF = -3,
|
||||
JSP_WIN_STATUS = -4,
|
||||
JSP_WIN_TOP = -5,
|
||||
};
|
||||
/* "location" is special because we need to simulate "location.href"
|
||||
* when the code is asking directly for "location". We do not register
|
||||
* it as a "known" property since that was yielding strange bugs
|
||||
@ -138,6 +129,7 @@ enum window_prop {
|
||||
JSPropertySpec window_props[] = {
|
||||
JS_PSG("closed", window_get_property_closed, JSPROP_ENUMERATE),
|
||||
JS_PSG("event", window_get_property_event, JSPROP_ENUMERATE),
|
||||
JS_PSGS("location", window_get_property_location, window_set_property_location, JSPROP_ENUMERATE),
|
||||
JS_PSG("parent", window_get_property_parent, JSPROP_ENUMERATE),
|
||||
JS_PSG("self", window_get_property_self, JSPROP_ENUMERATE),
|
||||
JS_PSGS("status", window_get_property_status, window_set_property_status, 0),
|
||||
@ -703,6 +695,73 @@ window_get_property_event(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
window_get_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||
|
||||
if (!comp) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||
|
||||
if (!interpreter->location_obj) {
|
||||
interpreter->location_obj = getLocation(ctx);
|
||||
}
|
||||
args.rval().setObject(*(JSObject *)(interpreter->location_obj));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
window_set_property_location(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
JS::CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||
|
||||
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||
|
||||
if (!comp) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS::GetRealmPrivate(comp);
|
||||
|
||||
struct view_state *vs;
|
||||
struct document_view *doc_view;
|
||||
|
||||
vs = interpreter->vs;
|
||||
|
||||
if (!vs) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
doc_view = vs->doc_view;
|
||||
char *url = jsval_to_string(ctx, args[0]);
|
||||
|
||||
if (url) {
|
||||
location_goto(doc_view, url);
|
||||
mem_free(url);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
window_get_property_parent(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
|
@ -144,7 +144,7 @@ void *
|
||||
spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
{
|
||||
JSContext *ctx;
|
||||
JSObject *console_obj, *document_obj, /* *forms_obj,*/ *history_obj, *location_obj,
|
||||
JSObject *console_obj, *document_obj, /* *forms_obj,*/ *history_obj,
|
||||
*statusbar_obj, *menubar_obj, *navigator_obj, *localstorage_obj, *screen_obj,
|
||||
*xhr_obj;
|
||||
|
||||
@ -221,18 +221,6 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
if (!history_obj) {
|
||||
goto release_and_fail;
|
||||
}
|
||||
|
||||
location_obj = spidermonkey_InitClass(ctx, global, NULL,
|
||||
&location_class, NULL, 0,
|
||||
location_props,
|
||||
location_funcs,
|
||||
NULL, NULL);
|
||||
if (!location_obj) {
|
||||
goto release_and_fail;
|
||||
}
|
||||
|
||||
interpreter->location_obj = location_obj;
|
||||
|
||||
screen_obj = spidermonkey_InitClass(ctx, global, NULL,
|
||||
&screen_class, NULL, 0,
|
||||
screen_props,
|
||||
|
@ -7,5 +7,7 @@
|
||||
extern JSClass location_class;
|
||||
extern const spidermonkeyFunctionSpec location_funcs[];
|
||||
extern JSPropertySpec location_props[];
|
||||
JSObject *getLocation(JSContext *ctx);
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user