1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[spidermonkey] location.assign

This commit is contained in:
Witold Filipczyk 2024-01-16 17:38:26 +01:00
parent 103669e825
commit ebaceedab2

View File

@ -940,16 +940,75 @@ location_set_property_search(JSContext *ctx, unsigned int argc, JS::Value *vp)
return true;
}
static bool location_assign(JSContext *ctx, unsigned int argc, JS::Value *rval);
static bool location_reload(JSContext *ctx, unsigned int argc, JS::Value *rval);
static bool location_toString(JSContext *ctx, unsigned int argc, JS::Value *rval);
const spidermonkeyFunctionSpec location_funcs[] = {
{ "assign", location_assign, 1 },
{ "reload", location_reload, 0 },
{ "toString", location_toString, 0 },
{ "toLocaleString", location_toString, 0 },
{ NULL }
};
static bool
location_assign(JSContext *ctx, unsigned int argc, JS::Value *rval)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
JS::CallArgs args = CallArgsFromVp(argc, rval);
if (argc != 1) {
args.rval().setBoolean(false);
return true;
}
JS::RootedObject hobj(ctx, &args.thisv().toObject());
struct view_state *vs;
struct document_view *doc_view;
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);
/* This can be called if @obj if not itself an instance of the
* appropriate class but has one in its prototype chain. Fail
* such calls. */
if (!JS_InstanceOf(ctx, hobj, &location_class, NULL)) {
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
#endif
return false;
}
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) {
return false;
}
location_goto(doc_view, url);
mem_free(url);
return true;
}
static bool
location_reload(JSContext *ctx, unsigned int argc, JS::Value *rval)
{