diff --git a/configure.ac b/configure.ac index e1b5dd444..d832f8748 100644 --- a/configure.ac +++ b/configure.ac @@ -612,11 +612,11 @@ case "$with_spidermonkey" in ;; esac -for package in mozjs-24; do +for package in mozjs-31; do if test -n "$CONFIG_SPIDERMONKEY"; then break else - AC_MSG_CHECKING([for SpiderMonkey (mozjs-24) in pkg-config $package]) + AC_MSG_CHECKING([for SpiderMonkey (mozjs-31) in pkg-config $package]) if $PKG_CONFIG --cflags --libs $package > /dev/null 2>&AS_MESSAGE_LOG_FD; then SPIDERMONKEY_LIBS="$($PKG_CONFIG --libs $package)" SPIDERMONKEY_CFLAGS="$($PKG_CONFIG --cflags $package)" diff --git a/src/ecmascript/spidermonkey-shared.c b/src/ecmascript/spidermonkey-shared.c index d23922dd4..3793865b6 100644 --- a/src/ecmascript/spidermonkey-shared.c +++ b/src/ecmascript/spidermonkey-shared.c @@ -44,6 +44,10 @@ spidermonkey_runtime_addref(void) assert(spidermonkey_empty_context == NULL); if_assert_failed return 0; + if (!JS_Init()) { + return 0; + } + spidermonkey_runtime = JS_NewRuntime(4L * 1024L * 1024L, JS_USE_HELPER_THREADS); if (!spidermonkey_runtime) return 0; @@ -92,16 +96,17 @@ spidermonkey_runtime_release(void) /** An ELinks-specific replacement for JS_DefineFunctions(). * * @relates spidermonkeyFunctionSpec */ -JSBool +bool spidermonkey_DefineFunctions(JSContext *cx, JSObject *obj, const spidermonkeyFunctionSpec *fs) { + JS::RootedObject hobj(cx, obj); for (; fs->name; fs++) { - if (!JS_DefineFunction(cx, obj, fs->name, fs->call, + if (!JS_DefineFunction(cx, hobj, fs->name, fs->call, fs->nargs, 0)) - return JS_FALSE; + return false; } - return JS_TRUE; + return true; } /** An ELinks-specific replacement for JS_InitClass(). @@ -116,7 +121,9 @@ spidermonkey_InitClass(JSContext *cx, JSObject *obj, JSPropertySpec *static_ps, const spidermonkeyFunctionSpec *static_fs) { - JSObject *proto = JS_InitClass(cx, obj, parent_proto, clasp, + JS::RootedObject hobj(cx, obj); + JS::RootedObject r_parent_proto(cx, parent_proto); + JSObject *proto = JS_InitClass(cx, hobj, r_parent_proto, clasp, constructor, nargs, ps, NULL, static_ps, NULL); @@ -129,7 +136,8 @@ spidermonkey_InitClass(JSContext *cx, JSObject *obj, } if (static_fs) { - JSObject *cons_obj = JS_GetConstructor(cx, proto); + JS::RootedObject r_proto(cx, proto); + JSObject *cons_obj = JS_GetConstructor(cx, r_proto); if (cons_obj == NULL) return NULL; diff --git a/src/ecmascript/spidermonkey-shared.h b/src/ecmascript/spidermonkey-shared.h index 74e709add..84174f6e8 100644 --- a/src/ecmascript/spidermonkey-shared.h +++ b/src/ecmascript/spidermonkey-shared.h @@ -43,7 +43,7 @@ typedef struct spidermonkeyFunctionSpec { /* ELinks does not use "flags" and "extra" so omit them here. */ } spidermonkeyFunctionSpec; -JSBool spidermonkey_DefineFunctions(JSContext *cx, JSObject *obj, +bool spidermonkey_DefineFunctions(JSContext *cx, JSObject *obj, const spidermonkeyFunctionSpec *fs); JSObject *spidermonkey_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto, JSClass *clasp, @@ -68,23 +68,20 @@ undef_to_jsval(JSContext *ctx, jsval *vp) static inline unsigned char * jsval_to_string(JSContext *ctx, jsval *vp) { - jsval val; + JS::RootedValue r_vp(ctx, *vp); + JSString *str = JS::ToString(ctx, r_vp); - if (JS_ConvertValue(ctx, *vp, JSTYPE_STRING, &val) == JS_FALSE) { - return ""; - } - - return empty_string_or_(JS_EncodeString(ctx, JS_ValueToString(ctx, val))); + return empty_string_or_(JS_EncodeString(ctx, str)); } static inline unsigned char * jsid_to_string(JSContext *ctx, jsid *id) { - jsval v; + JS::RootedValue v(ctx); /* TODO: check returned value */ JS_IdToValue(ctx, *id, &v); - return jsval_to_string(ctx, &v); + return jsval_to_string(ctx, v.address()); } #define ELINKS_CAST_PROP_PARAMS JSObject *obj = (hobj.get()); \ diff --git a/src/ecmascript/spidermonkey.c b/src/ecmascript/spidermonkey.c index 6555bbcef..e6a75ba34 100644 --- a/src/ecmascript/spidermonkey.c +++ b/src/ecmascript/spidermonkey.c @@ -50,8 +50,6 @@ #include "viewer/text/link.h" #include "viewer/text/vs.h" -using namespace JS; - /*** Global methods */ @@ -143,11 +141,10 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter) interpreter->backend_data = ctx; JSAutoRequest ar(ctx); JS_SetContextPrivate(ctx, interpreter); - JS_SetOptions(ctx, JSOPTION_VAROBJFIX | JS_METHODJIT); + //JS_SetOptions(ctx, JSOPTION_VAROBJFIX | JS_METHODJIT); JS_SetErrorReporter(ctx, error_reporter); - JS_SetOperationCallback(ctx, heartbeat_callback); - RootedObject window_obj(ctx); - window_obj = JS_NewGlobalObject(ctx, &window_class, NULL); + JS_SetInterruptCallback(spidermonkey_runtime, heartbeat_callback); + JS::RootedObject window_obj(ctx, JS_NewGlobalObject(ctx, &window_class, NULL, JS::DontFireOnNewGlobalHook)); if (window_obj) { ac = new JSAutoCompartment(ctx, window_obj); @@ -204,7 +201,7 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter) goto release_and_fail; } - menubar_obj = JS_InitClass(ctx, window_obj, NULL, + menubar_obj = JS_InitClass(ctx, window_obj, JS::NullPtr(), &menubar_class, NULL, 0, unibar_props, NULL, NULL, NULL); @@ -213,7 +210,7 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter) } JS_SetPrivate(menubar_obj, "t"); /* to @menubar_class */ - statusbar_obj = JS_InitClass(ctx, window_obj, NULL, + statusbar_obj = JS_InitClass(ctx, window_obj, JS::NullPtr(), &statusbar_class, NULL, 0, unibar_props, NULL, NULL, NULL); @@ -222,7 +219,7 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter) } JS_SetPrivate(statusbar_obj, "s"); /* to @statusbar_class */ - navigator_obj = JS_InitClass(ctx, window_obj, NULL, + navigator_obj = JS_InitClass(ctx, window_obj, JS::NullPtr(), &navigator_class, NULL, 0, navigator_props, NULL, NULL, NULL); @@ -266,8 +263,10 @@ spidermonkey_eval(struct ecmascript_interpreter *interpreter, interpreter->heartbeat = add_heartbeat(interpreter); interpreter->ret = ret; - JS_EvaluateScript(ctx, JS_GetGlobalForScopeChain(ctx), - code->source, code->length, "", 0, &rval); + JS::RootedObject cg(ctx, JS::CurrentGlobalOrNull(ctx)); + JS::RootedValue r_val(ctx, rval); + + JS_EvaluateScript(ctx, cg, code->source, code->length, "", 0, &r_val); done_heartbeat(interpreter->heartbeat); } @@ -276,7 +275,7 @@ unsigned char * spidermonkey_eval_stringback(struct ecmascript_interpreter *interpreter, struct string *code) { - JSBool ret; + bool ret; JSContext *ctx; jsval rval; @@ -286,19 +285,20 @@ spidermonkey_eval_stringback(struct ecmascript_interpreter *interpreter, interpreter->ret = NULL; interpreter->heartbeat = add_heartbeat(interpreter); - ret = JS_EvaluateScript(ctx, JS_GetGlobalForScopeChain(ctx), - code->source, code->length, "", 0, &rval); + JS::RootedObject cg(ctx, JS::CurrentGlobalOrNull(ctx)); + JS::RootedValue r_rval(ctx, rval); + ret = JS_EvaluateScript(ctx, cg, code->source, code->length, "", 0, &r_rval); done_heartbeat(interpreter->heartbeat); - if (ret == JS_FALSE) { + if (ret == false) { return NULL; } - if (JSVAL_IS_VOID(rval) || JSVAL_IS_NULL(rval)) { + if (r_rval.isNullOrUndefined()) { /* Undefined value. */ return NULL; } - return stracpy(jsval_to_string(ctx, &rval)); + return stracpy(JS_EncodeString(ctx, JS::ToString(ctx, r_rval))); } @@ -316,19 +316,23 @@ spidermonkey_eval_boolback(struct ecmascript_interpreter *interpreter, ctx = interpreter->backend_data; interpreter->ret = NULL; - fun = JS_CompileFunction(ctx, JS_GetGlobalForScopeChain(ctx), "", 0, NULL, code->source, - code->length, "", 0); + JS::CompileOptions options(ctx); + JS::RootedObject cg(ctx, JS::CurrentGlobalOrNull(ctx)); + fun = JS_CompileFunction(ctx, cg, "", 0, NULL, code->source, + code->length, options); if (!fun) return -1; interpreter->heartbeat = add_heartbeat(interpreter); - ret = JS_CallFunction(ctx, JS_GetGlobalForScopeChain(ctx), fun, 0, NULL, &rval); + JS::RootedFunction r_fun(ctx, fun); + JS::RootedValue r_val(ctx, rval); + ret = JS_CallFunction(ctx, cg, r_fun, JS::HandleValueArray::empty(), &r_val); done_heartbeat(interpreter->heartbeat); if (ret == 2) { /* onClick="history.back()" */ return 0; } - if (ret == JS_FALSE) { + if (ret == false) { return -1; } if (JSVAL_IS_VOID(rval)) { diff --git a/src/ecmascript/spidermonkey/document.c b/src/ecmascript/spidermonkey/document.c index 72f084eb8..e4bc3d8a2 100644 --- a/src/ecmascript/spidermonkey/document.c +++ b/src/ecmascript/spidermonkey/document.c @@ -47,7 +47,7 @@ #include "viewer/text/vs.h" -static JSBool document_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); +static bool document_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); /* Each @document_class object must have a @window_class parent. */ JSClass document_class = { @@ -59,25 +59,23 @@ JSClass document_class = { }; #ifdef CONFIG_COOKIES -static JSBool -document_get_property_cookie(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +document_get_property_cookie(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - - JSObject *parent_win; /* instance of @window_class */ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + JS::RootedObject parent_win(ctx, JS_GetParent(hobj)); struct view_state *vs; struct string *cookies; - JSClass* classPtr = JS_GetClass(obj); - if (classPtr != &document_class) - return JS_FALSE; - - parent_win = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } cookies = send_cookies_js(vs->uri); if (cookies) { @@ -85,110 +83,98 @@ document_get_property_cookie(JSContext *ctx, JS::HandleObject hobj, JS::HandleId strncpy(cookiestr, cookies->source, 1023); done_string(cookies); - string_to_jsval(ctx, vp, cookiestr); + args.rval().setString(JS_NewStringCopyZ(ctx, cookiestr)); } else { - string_to_jsval(ctx, vp, ""); + args.rval().setString(JS_NewStringCopyZ(ctx, "")); } - return JS_TRUE; + return true; } -static JSBool -document_set_property_cookie(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +document_set_property_cookie(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - - JSObject *parent_win; /* instance of @window_class */ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + JS::RootedObject parent_win(ctx, JS_GetParent(hobj)); struct view_state *vs; + struct string *cookies; - /* 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, obj, &document_class, NULL)) - return JS_FALSE; - - parent_win = JS_GetParent(obj); + parent_win = JS_GetParent(hobj); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); - set_cookie(vs->uri, jsval_to_string(ctx, vp)); + if (!vs) { + return false; + } + set_cookie(vs->uri, JS_EncodeString(ctx, args[0].toString())); - return JS_TRUE; + return true; } #endif -static JSBool -document_get_property_location(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +document_get_property_location(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + JS::RootedObject parent_win(ctx, JS_GetParent(hobj)); - JSObject *parent_win; /* instance of @window_class */ - JSClass* classPtr = JS_GetClass(obj); - - if (classPtr != &document_class) - return JS_FALSE; - - parent_win = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - JS_GetProperty(ctx, parent_win, "location", vp); + JS_GetProperty(ctx, parent_win, "location", args.rval()); - return JS_TRUE; + return true; } -static JSBool -document_set_property_location(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +document_set_property_location(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - - JSObject *parent_win; /* instance of @window_class */ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + JS::RootedObject parent_win(ctx, JS_GetParent(hobj)); struct view_state *vs; struct document_view *doc_view; - /* 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, obj, &document_class, NULL)) - return JS_FALSE; - - parent_win = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; - location_goto(doc_view, jsval_to_string(ctx, vp)); + location_goto(doc_view, JS_EncodeString(ctx, args[0].toString())); - return JS_TRUE; + return true; } -static JSBool -document_get_property_referrer(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +document_get_property_referrer(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - - JSObject *parent_win; /* instance of @window_class */ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + JS::RootedObject parent_win(ctx, JS_GetParent(hobj)); struct view_state *vs; struct document_view *doc_view; struct document *document; struct session *ses; - JSClass* classPtr = JS_GetClass(obj); - if (classPtr != &document_class) - return JS_FALSE; - - parent_win = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; ses = doc_view->session; @@ -196,138 +182,148 @@ document_get_property_referrer(JSContext *ctx, JS::HandleObject hobj, JS::Handle switch (get_opt_int("protocol.http.referer.policy", NULL)) { case REFERER_NONE: /* oh well */ - undef_to_jsval(ctx, vp); + args.rval().setUndefined(); break; case REFERER_FAKE: - string_to_jsval(ctx, vp, get_opt_str("protocol.http.referer.fake", NULL)); + args.rval().setString(JS_NewStringCopyZ(ctx, get_opt_str("protocol.http.referer.fake", NULL))); break; case REFERER_TRUE: /* XXX: Encode as in add_url_to_httset_prop_string(&prop, ) ? --pasky */ if (ses->referrer) { - astring_to_jsval(ctx, vp, get_uri_string(ses->referrer, URI_HTTP_REFERRER)); + unsigned char *str = get_uri_string(ses->referrer, URI_HTTP_REFERRER); + + if (str) { + args.rval().setString(JS_NewStringCopyZ(ctx, str)); + mem_free(str); + } else { + args.rval().setUndefined(); + } } break; case REFERER_SAME_URL: - astring_to_jsval(ctx, vp, get_uri_string(document->uri, URI_HTTP_REFERRER)); + unsigned char *str = get_uri_string(document->uri, URI_HTTP_REFERRER); + + if (str) { + args.rval().setString(JS_NewStringCopyZ(ctx, str)); + mem_free(str); + } else { + args.rval().setUndefined(); + } break; } - return JS_TRUE; + return true; } -static JSBool -document_get_property_title(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +document_get_property_title(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - - JSObject *parent_win; /* instance of @window_class */ - struct view_state *vs; - struct document_view *doc_view; - struct document *document; - JSClass* classPtr = JS_GetClass(obj); - - if (classPtr != &document_class) - return JS_FALSE; - - parent_win = JS_GetParent(obj); - assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; - - vs = JS_GetInstancePrivate(ctx, parent_win, - &window_class, NULL); - doc_view = vs->doc_view; - document = doc_view->document; - string_to_jsval(ctx, vp, document->title); - - return JS_TRUE; -} - -static JSBool -document_set_property_title(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) -{ - ELINKS_CAST_PROP_PARAMS - - JSObject *parent_win; /* instance of @window_class */ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + JS::RootedObject parent_win(ctx, JS_GetParent(hobj)); struct view_state *vs; struct document_view *doc_view; struct document *document; - /* 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, obj, &document_class, NULL)) - return JS_FALSE; - - parent_win = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - mem_free_set(&document->title, stracpy(jsval_to_string(ctx, vp))); + args.rval().setString(JS_NewStringCopyZ(ctx, document->title)); + + return true; +} + +static bool +document_set_property_title(JSContext *ctx, int argc, jsval *vp) +{ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + JS::RootedObject parent_win(ctx, JS_GetParent(hobj)); + struct view_state *vs; + struct document_view *doc_view; + struct document *document; + + assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); + if_assert_failed return false; + + vs = JS_GetInstancePrivate(ctx, parent_win, + &window_class, NULL); + if (!vs) { + return false; + } + doc_view = vs->doc_view; + document = doc_view->document; + mem_free_set(&document->title, stracpy(JS_EncodeString(ctx, args[0].toString()))); print_screen_status(doc_view->session); - return JS_TRUE; + return true; } -static JSBool -document_get_property_url(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +document_get_property_url(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - - JSObject *parent_win; /* instance of @window_class */ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + JS::RootedObject parent_win(ctx, JS_GetParent(hobj)); struct view_state *vs; struct document_view *doc_view; struct document *document; - JSClass* classPtr = JS_GetClass(obj); - if (classPtr != &document_class) - return JS_FALSE; - - parent_win = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - astring_to_jsval(ctx, vp, get_uri_string(document->uri, URI_ORIGINAL)); + unsigned char *str = get_uri_string(document->uri, URI_ORIGINAL); - return JS_TRUE; + if (str) { + args.rval().setString(JS_NewStringCopyZ(ctx, str)); + mem_free(str); + } else { + args.rval().setUndefined(); + } + + return true; } -static JSBool -document_set_property_url(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +document_set_property_url(JSContext *ctx, int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - - JSObject *parent_win; /* instance of @window_class */ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + JS::RootedObject parent_win(ctx, JS_GetParent(hobj)); struct view_state *vs; struct document_view *doc_view; + struct document *document; - /* 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, obj, &document_class, NULL)) - return JS_FALSE; - - parent_win = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; - location_goto(doc_view, jsval_to_string(ctx, vp)); + location_goto(doc_view, JS_EncodeString(ctx, args[0].toString())); - return JS_TRUE; + return true; } @@ -335,24 +331,24 @@ document_set_property_url(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hi * cookie-module. XXX: Would it work if "cookie" was defined in this array? */ JSPropertySpec document_props[] = { #ifdef CONFIG_COOKIES - { "cookie", 0, JSPROP_ENUMERATE | JSPROP_SHARED, JSOP_WRAPPER(document_get_property_cookie), JSOP_WRAPPER(document_set_property_cookie) }, + JS_PSGS("cookie", document_get_property_cookie, document_set_property_cookie, JSPROP_ENUMERATE), #endif - { "location", 0, JSPROP_ENUMERATE | JSPROP_SHARED, JSOP_WRAPPER(document_get_property_location), JSOP_WRAPPER(document_set_property_location) }, - { "referrer", 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED, JSOP_WRAPPER(document_get_property_referrer), JSOP_NULLWRAPPER }, - { "title", 0, JSPROP_ENUMERATE | JSPROP_SHARED, JSOP_WRAPPER(document_get_property_title), JSOP_WRAPPER(document_set_property_title) }, /* TODO: Charset? */ - { "url", 0, JSPROP_ENUMERATE | JSPROP_SHARED, JSOP_WRAPPER(document_get_property_url), JSOP_WRAPPER(document_set_property_url) }, + JS_PSGS("location", document_get_property_location, document_set_property_location, JSPROP_ENUMERATE), + JS_PSG("referrer", document_get_property_referrer, JSPROP_ENUMERATE), + JS_PSGS("title", document_get_property_title, document_set_property_title, JSPROP_ENUMERATE), /* TODO: Charset? */ + JS_PSGS("url", document_get_property_url, document_set_property_url, JSPROP_ENUMERATE), { NULL } }; /* @document_class.getProperty */ -static JSBool +static bool document_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) { ELINKS_CAST_PROP_PARAMS jsid id = hid.get(); - JSObject *parent_win; /* instance of @window_class */ + JS::RootedObject parent_win(ctx); /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -362,11 +358,11 @@ document_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, J JSClass* classPtr = JS_GetClass(obj); if (classPtr != &document_class) - return JS_FALSE; + return false; parent_win = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); @@ -382,11 +378,11 @@ document_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, J break; } - return JS_TRUE; + return true; } -static JSBool document_write(JSContext *ctx, unsigned int argc, jsval *rval); -static JSBool document_writeln(JSContext *ctx, unsigned int argc, jsval *rval); +static bool document_write(JSContext *ctx, unsigned int argc, jsval *rval); +static bool document_writeln(JSContext *ctx, unsigned int argc, jsval *rval); const spidermonkeyFunctionSpec document_funcs[] = { { "write", document_write, 1 }, @@ -394,19 +390,19 @@ const spidermonkeyFunctionSpec document_funcs[] = { { NULL } }; -static JSBool +static bool document_write_do(JSContext *ctx, unsigned int argc, jsval *rval, int newline) { jsval val; struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx); struct string *ret = interpreter->ret; - jsval *argv = JS_ARGV(ctx, rval); + JS::CallArgs args = JS::CallArgsFromVp(argc, rval); if (argc >= 1 && ret) { int i = 0; for (; i < argc; ++i) { - unsigned char *code = jsval_to_string(ctx, &argv[i]); + unsigned char *code = jsval_to_string(ctx, args[i].address()); add_to_string(ret, code); } @@ -425,14 +421,13 @@ document_write_do(JSContext *ctx, unsigned int argc, jsval *rval, int newline) set_led_value(interpreter->vs->doc_view->session->status.ecmascript_led, 'J'); #endif - boolean_to_jsval(ctx, &val, 0); - JS_SET_RVAL(ctx, rval, val); + args.rval().setBoolean(false); - return JS_TRUE; + return true; } /* @document_funcs{"write"} */ -static JSBool +static bool document_write(JSContext *ctx, unsigned int argc, jsval *rval) { @@ -440,7 +435,7 @@ document_write(JSContext *ctx, unsigned int argc, jsval *rval) } /* @document_funcs{"writeln"} */ -static JSBool +static bool document_writeln(JSContext *ctx, unsigned int argc, jsval *rval) { return document_write_do(ctx, argc, rval, 1); diff --git a/src/ecmascript/spidermonkey/form.c b/src/ecmascript/spidermonkey/form.c index 64c53ad32..8f8c003a8 100644 --- a/src/ecmascript/spidermonkey/form.c +++ b/src/ecmascript/spidermonkey/form.c @@ -49,19 +49,19 @@ //static JSClass form_class; /* defined below */ -static JSBool form_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool form_get_property_action(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool form_set_property_action(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp); -static JSBool form_get_property_elements(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool form_get_property_encoding(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool form_set_property_encoding(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp); -static JSBool form_get_property_length(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool form_get_property_method(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool form_set_property_method(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp); -static JSBool form_get_property_name(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool form_set_property_name(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp); -static JSBool form_get_property_target(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool form_set_property_target(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp); +static bool form_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); +static bool form_get_property_action(JSContext *ctx, unsigned int argc, jsval *vp); +static bool form_set_property_action(JSContext *ctx, unsigned int argc, jsval *vp); +static bool form_get_property_elements(JSContext *ctx, unsigned int argc, jsval *vp); +static bool form_get_property_encoding(JSContext *ctx, unsigned int argc, jsval *vp); +static bool form_set_property_encoding(JSContext *ctx, unsigned int argc, jsval *vp); +static bool form_get_property_length(JSContext *ctx, unsigned int argc, jsval *vp); +static bool form_get_property_method(JSContext *ctx, unsigned int argc, jsval *vp); +static bool form_set_property_method(JSContext *ctx, unsigned int argc, jsval *vp); +static bool form_get_property_name(JSContext *ctx, unsigned int argc, jsval *vp); +static bool form_set_property_name(JSContext *ctx, unsigned int argc, jsval *vp); +static bool form_get_property_target(JSContext *ctx, unsigned int argc, jsval *vp); +static bool form_set_property_target(JSContext *ctx, unsigned int argc, jsval *vp); static void form_finalize(JSFreeOp *op, JSObject *obj); @@ -81,8 +81,8 @@ static JSClass form_class = { * HTMLInputElement. The difference could be spotted only by some clever tricky * JS code, but I hope it doesn't matter anywhere. --pasky */ -static JSBool input_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool input_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp); +static bool input_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); +static bool input_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, bool strict, JS::MutableHandleValue hvp); static void input_finalize(JSFreeOp *op, JSObject *obj); /* Each @input_class object must have a @form_class parent. */ @@ -118,18 +118,16 @@ enum input_prop { }; static JSString *unicode_to_jsstring(JSContext *ctx, unicode_val_T u); -static unicode_val_T jsval_to_accesskey(JSContext *ctx, jsval *vp); +static unicode_val_T jsval_to_accesskey(JSContext *ctx, JS::MutableHandleValue hvp); static struct form_state *input_get_form_state(JSContext *ctx, JSObject *jsinput); -static JSBool -input_get_property_accessKey(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +input_get_property_accessKey(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -139,30 +137,27 @@ input_get_property_accessKey(JSContext *ctx, JS::HandleObject hobj, JS::HandleId struct link *link = NULL; JSString *keystr; - /* 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, obj, &input_class, NULL)) - return JS_FALSE; - - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_doc = JS_GetParent(parent_form); + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_win = JS_GetParent(parent_doc); + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); @@ -172,30 +167,30 @@ input_get_property_accessKey(JSContext *ctx, JS::HandleObject hobj, JS::HandleId /* Hiddens have no link. */ if (linknum >= 0) link = &document->links[linknum]; - undef_to_jsval(ctx, vp); - - if (!link) return JS_TRUE; + if (!link) { + args.rval().setUndefined(); + return true; + } if (!link->accesskey) { - *vp = JS_GetEmptyStringValue(ctx); + args.rval().set(JS_GetEmptyStringValue(ctx)); } else { keystr = unicode_to_jsstring(ctx, link->accesskey); - if (keystr) - *vp = STRING_TO_JSVAL(keystr); + if (keystr) { + args.rval().setString(keystr); + } else - return JS_FALSE; + return false; } - return JS_TRUE; + return true; } -static JSBool -input_set_property_accessKey(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +input_set_property_accessKey(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -205,27 +200,25 @@ input_set_property_accessKey(JSContext *ctx, JS::HandleObject hobj, JS::HandleId struct link *link = NULL; unicode_val_T accesskey; - /* 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, obj, &input_class, NULL)) - return JS_FALSE; - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; - parent_doc = JS_GetParent(parent_form); + if_assert_failed return false; + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); @@ -235,544 +228,482 @@ input_set_property_accessKey(JSContext *ctx, JS::HandleObject hobj, JS::HandleId /* Hiddens have no link. */ if (linknum >= 0) link = &document->links[linknum]; - accesskey = jsval_to_accesskey(ctx, vp); + accesskey = jsval_to_accesskey(ctx, args[0]); if (accesskey == UCS_NO_CHAR) - return JS_FALSE; + return false; else if (link) link->accesskey = accesskey; - return JS_TRUE; + return true; } -static JSBool -input_get_property_alt(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +input_get_property_alt(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; struct form_state *fs; struct el_form_control *fc; - /* 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, obj, &input_class, NULL)) - return JS_FALSE; - - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_doc = JS_GetParent(parent_form); + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_win = JS_GetParent(parent_doc); + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); - string_to_jsval(ctx, vp, fc->alt); + args.rval().setString(JS_NewStringCopyZ(ctx, fc->alt)); - return JS_TRUE; + return true; } -static JSBool -input_set_property_alt(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +input_set_property_alt(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); struct view_state *vs; struct document_view *doc_view; struct document *document; struct form_state *fs; struct el_form_control *fc; - /* 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, obj, &input_class, NULL)) - return JS_FALSE; - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; - parent_doc = JS_GetParent(parent_form); + if_assert_failed return false; + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); - mem_free_set(&fc->alt, stracpy(jsval_to_string(ctx, vp))); + mem_free_set(&fc->alt, stracpy(JS_EncodeString(ctx, args[0].toString()))); - return JS_TRUE; + return true; } -static JSBool -input_get_property_checked(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +input_get_property_checked(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); struct form_state *fs; - /* 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, obj, &input_class, NULL)) - return JS_FALSE; + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + args.rval().setBoolean(fs->state); - boolean_to_jsval(ctx, vp, fs->state); - - return JS_TRUE; + return true; } -static JSBool -input_set_property_checked(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +input_set_property_checked(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; struct form_state *fs; struct el_form_control *fc; - /* 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, obj, &input_class, NULL)) - return JS_FALSE; - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; - parent_doc = JS_GetParent(parent_form); + if_assert_failed return false; + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); if (fc->type != FC_CHECKBOX && fc->type != FC_RADIO) - return JS_TRUE; - fs->state = jsval_to_boolean(ctx, vp); + return true; + fs->state = args[0].toBoolean(); - return JS_TRUE; + return true; } -static JSBool -input_get_property_defaultChecked(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +input_get_property_defaultChecked(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; struct form_state *fs; struct el_form_control *fc; - /* 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, obj, &input_class, NULL)) - return JS_FALSE; - - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_doc = JS_GetParent(parent_form); + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_win = JS_GetParent(parent_doc); + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); - boolean_to_jsval(ctx, vp, fc->default_state); + args.rval().setBoolean(fc->default_state); - return JS_TRUE; + return true; } -static JSBool -input_get_property_defaultValue(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +input_get_property_defaultValue(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; struct form_state *fs; struct el_form_control *fc; - /* 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, obj, &input_class, NULL)) - return JS_FALSE; - - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_doc = JS_GetParent(parent_form); + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_win = JS_GetParent(parent_doc); + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); /* FIXME (bug 805): convert from the charset of the document */ - string_to_jsval(ctx, vp, fc->default_value); + args.rval().setString(JS_NewStringCopyZ(ctx, fc->default_value)); - return JS_TRUE; + return true; } -static JSBool -input_get_property_disabled(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +input_get_property_disabled(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; struct form_state *fs; struct el_form_control *fc; - /* 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, obj, &input_class, NULL)) - return JS_FALSE; - - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_doc = JS_GetParent(parent_form); + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_win = JS_GetParent(parent_doc); + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); /* FIXME: --pasky */ - boolean_to_jsval(ctx, vp, fc->mode == FORM_MODE_DISABLED); + args.rval().setBoolean(fc->mode == FORM_MODE_DISABLED); - return JS_TRUE; + return true; } -static JSBool -input_set_property_disabled(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +input_set_property_disabled(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; struct form_state *fs; struct el_form_control *fc; - /* 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, obj, &input_class, NULL)) - return JS_FALSE; - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; - parent_doc = JS_GetParent(parent_form); + if_assert_failed return false; + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); /* FIXME: --pasky */ - fc->mode = (jsval_to_boolean(ctx, vp) ? FORM_MODE_DISABLED + fc->mode = (args[0].toBoolean() ? FORM_MODE_DISABLED : fc->mode == FORM_MODE_READONLY ? FORM_MODE_READONLY : FORM_MODE_NORMAL); - return JS_TRUE; + return true; } -static JSBool -input_get_property_form(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +input_get_property_form(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - - /* 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, obj, &input_class, NULL)) - return JS_FALSE; - - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - object_to_jsval(ctx, vp, parent_form); + args.rval().setObject(*parent_form); - return JS_TRUE; + return true; } -static JSBool -input_get_property_maxLength(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +input_get_property_maxLength(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; struct form_state *fs; struct el_form_control *fc; - /* 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, obj, &input_class, NULL)) - return JS_FALSE; - - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_doc = JS_GetParent(parent_form); + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_win = JS_GetParent(parent_doc); + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); - int_to_jsval(ctx, vp, fc->maxlength); + args.rval().setInt32(fc->maxlength); - return JS_TRUE; + return true; } -static JSBool -input_set_property_maxLength(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +input_set_property_maxLength(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; struct form_state *fs; struct el_form_control *fc; - /* 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, obj, &input_class, NULL)) - return JS_FALSE; - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; - parent_doc = JS_GetParent(parent_form); + if_assert_failed return false; + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); - if (!JS_ValueToInt32(ctx, *vp, &fc->maxlength)) - return JS_FALSE; + fc->maxlength = args[0].toInt32(); - return JS_TRUE; + return true; } -static JSBool -input_get_property_name(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +input_get_property_name(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; struct form_state *fs; struct el_form_control *fc; - /* 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, obj, &input_class, NULL)) - return JS_FALSE; - - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_doc = JS_GetParent(parent_form); + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_win = JS_GetParent(parent_doc); + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); - string_to_jsval(ctx, vp, fc->name); + args.rval().setString(JS_NewStringCopyZ(ctx, fc->name)); - return JS_TRUE; + return true; } /* @input_class.setProperty */ -static JSBool -input_set_property_name(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +input_set_property_name(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -782,42 +713,44 @@ input_set_property_name(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, /* 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, obj, &input_class, NULL)) - return JS_FALSE; - parent_form = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &input_class, NULL)) + return false; + + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; - parent_doc = JS_GetParent(parent_form); + if_assert_failed return false; + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); - mem_free_set(&fc->name, stracpy(jsval_to_string(ctx, vp))); + mem_free_set(&fc->name, stracpy(JS_EncodeString(ctx, args[0].toString()))); - return JS_TRUE; + return true; } -static JSBool -input_get_property_readonly(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +input_get_property_readonly(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -827,47 +760,48 @@ input_get_property_readonly(JSContext *ctx, JS::HandleObject hobj, JS::HandleId /* 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, obj, &input_class, NULL)) - return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &input_class, NULL)) + return false; - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_doc = JS_GetParent(parent_form); + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_win = JS_GetParent(parent_doc); + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); /* FIXME: --pasky */ - boolean_to_jsval(ctx, vp, fc->mode == FORM_MODE_READONLY); + args.rval().setBoolean(fc->mode == FORM_MODE_READONLY); - return JS_TRUE; + return true; } /* @input_class.setProperty */ -static JSBool -input_set_property_readonly(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +input_set_property_readonly(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -877,45 +811,46 @@ input_set_property_readonly(JSContext *ctx, JS::HandleObject hobj, JS::HandleId /* 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, obj, &input_class, NULL)) - return JS_FALSE; - parent_form = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &input_class, NULL)) + return false; + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; - parent_doc = JS_GetParent(parent_form); + if_assert_failed return false; + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); /* FIXME: --pasky */ - fc->mode = (jsval_to_boolean(ctx, vp) ? FORM_MODE_READONLY + fc->mode = (args[0].toBoolean() ? FORM_MODE_READONLY : fc->mode == FORM_MODE_DISABLED ? FORM_MODE_DISABLED : FORM_MODE_NORMAL); - return JS_TRUE; + return true; } -static JSBool -input_get_property_selectedIndex(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +input_get_property_selectedIndex(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -925,85 +860,89 @@ input_get_property_selectedIndex(JSContext *ctx, JS::HandleObject hobj, JS::Hand /* 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, obj, &input_class, NULL)) - return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &input_class, NULL)) + return false; - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_doc = JS_GetParent(parent_form); + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_win = JS_GetParent(parent_doc); + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ - fc = find_form_control(document, fs); - - assert(fc); - assert(fc->form && fs); - - undef_to_jsval(ctx, vp); - - if (fc->type == FC_SELECT) int_to_jsval(ctx, vp, fs->state); - - return JS_TRUE; -} - -/* @input_class.setProperty */ -static JSBool -input_set_property_selectedIndex(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) -{ - ELINKS_CAST_PROP_PARAMS - - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ - struct view_state *vs; - struct document_view *doc_view; - struct document *document; - struct form_state *fs; - struct el_form_control *fc; - - /* 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, obj, &input_class, NULL)) - return JS_FALSE; - parent_form = JS_GetParent(obj); - assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; - parent_doc = JS_GetParent(parent_form); - assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); - assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; - - vs = JS_GetInstancePrivate(ctx, parent_win, - &window_class, NULL); - doc_view = vs->doc_view; - document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); if (fc->type == FC_SELECT) { - int item; + args.rval().setInt32(fs->state); + } + else { + args.rval().setUndefined(); + } - if (!JS_ValueToInt32(ctx, *vp, &item)) - return JS_FALSE; + return true; +} + +/* @input_class.setProperty */ +static bool +input_set_property_selectedIndex(JSContext *ctx, unsigned int argc, jsval *vp) +{ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + + struct view_state *vs; + struct document_view *doc_view; + struct document *document; + struct form_state *fs; + struct el_form_control *fc; + + /* 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, &input_class, NULL)) + return false; + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); + assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); + if_assert_failed return false; + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); + assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); + if_assert_failed return false; + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); + assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); + if_assert_failed return false; + + vs = JS_GetInstancePrivate(ctx, parent_win, + &window_class, NULL); + if (!vs) { + return false; + } + doc_view = vs->doc_view; + document = doc_view->document; + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ + fc = find_form_control(document, fs); + + assert(fc); + assert(fc->form && fs); + + if (fc->type == FC_SELECT) { + int item = args[0].toInt32(); if (item >= 0 && item < fc->nvalues) { fs->state = item; @@ -1011,17 +950,15 @@ input_set_property_selectedIndex(JSContext *ctx, JS::HandleObject hobj, JS::Hand } } - return JS_TRUE; + return true; } -static JSBool -input_get_property_size(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +input_get_property_size(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -1031,45 +968,46 @@ input_get_property_size(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, /* 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, obj, &input_class, NULL)) - return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &input_class, NULL)) + return false; - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_doc = JS_GetParent(parent_form); + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_win = JS_GetParent(parent_doc); + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); - int_to_jsval(ctx, vp, fc->size); + args.rval().setInt32(fc->size); - return JS_TRUE; + return true; } -static JSBool -input_get_property_src(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +input_get_property_src(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -1081,27 +1019,30 @@ input_get_property_src(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, /* 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, obj, &input_class, NULL)) - return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &input_class, NULL)) + return false; - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_doc = JS_GetParent(parent_form); + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_win = JS_GetParent(parent_doc); + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); @@ -1110,22 +1051,21 @@ input_get_property_src(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, /* Hiddens have no link. */ if (linknum >= 0) link = &document->links[linknum]; - undef_to_jsval(ctx, vp); + if (link && link->where_img) { + args.rval().setString(JS_NewStringCopyZ(ctx, link->where_img)); + } else { + args.rval().setUndefined(); + } - if (link && link->where_img) - string_to_jsval(ctx, vp, link->where_img); - - return JS_TRUE; + return true; } -static JSBool -input_set_property_src(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +input_set_property_src(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -1137,24 +1077,30 @@ input_set_property_src(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, /* 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, obj, &input_class, NULL)) - return JS_FALSE; - parent_form = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &input_class, NULL)) + return false; + + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; - parent_doc = JS_GetParent(parent_form); + if_assert_failed return false; + + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); @@ -1165,20 +1111,18 @@ input_set_property_src(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, if (linknum >= 0) link = &document->links[linknum]; if (link) { - mem_free_set(&link->where_img, stracpy(jsval_to_string(ctx, vp))); + mem_free_set(&link->where_img, stracpy(JS_EncodeString(ctx, args[0].toString()))); } - return JS_TRUE; + return true; } -static JSBool -input_get_property_tabIndex(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +input_get_property_tabIndex(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -1190,27 +1134,30 @@ input_get_property_tabIndex(JSContext *ctx, JS::HandleObject hobj, JS::HandleId /* 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, obj, &input_class, NULL)) - return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &input_class, NULL)) + return false; - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_doc = JS_GetParent(parent_form); + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_win = JS_GetParent(parent_doc); + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); @@ -1220,23 +1167,22 @@ input_get_property_tabIndex(JSContext *ctx, JS::HandleObject hobj, JS::HandleId /* Hiddens have no link. */ if (linknum >= 0) link = &document->links[linknum]; - undef_to_jsval(ctx, vp); - - if (link) + if (link) { /* FIXME: This is WRONG. --pasky */ - int_to_jsval(ctx, vp, link->number); + args.rval().setInt32(link->number); + } else { + args.rval().setUndefined(); + } - return JS_TRUE; + return true; } -static JSBool -input_get_property_type(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +input_get_property_type(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -1247,27 +1193,30 @@ input_get_property_type(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, /* 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, obj, &input_class, NULL)) - return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &input_class, NULL)) + return false; - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_doc = JS_GetParent(parent_form); + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_win = JS_GetParent(parent_doc); + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); @@ -1287,39 +1236,38 @@ input_get_property_type(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, case FC_SELECT: s = "select"; break; default: INTERNAL("input_get_property() upon a non-input item."); break; } - string_to_jsval(ctx, vp, s); + args.rval().setString(JS_NewStringCopyZ(ctx, s)); - return JS_TRUE; + return true; } -static JSBool -input_get_property_value(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +input_get_property_value(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); struct form_state *fs; /* 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, obj, &input_class, NULL)) - return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &input_class, NULL)) + return false; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ - string_to_jsval(ctx, vp, fs->value); + args.rval().setString(JS_NewStringCopyZ(ctx, fs->value)); - return JS_TRUE; + return true; } -static JSBool -input_set_property_value(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +input_set_property_value(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -1329,36 +1277,42 @@ input_set_property_value(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid /* 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, obj, &input_class, NULL)) - return JS_FALSE; - parent_form = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &input_class, NULL)) + return false; + + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; - parent_doc = JS_GetParent(parent_form); + if_assert_failed return false; + + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); if (fc->type != FC_FILE) { - mem_free_set(&fs->value, stracpy(jsval_to_string(ctx, vp))); + mem_free_set(&fs->value, stracpy(JS_EncodeString(ctx, args[0].toString()))); if (fc->type == FC_TEXT || fc->type == FC_PASSWORD) fs->state = strlen(fs->value); } - return JS_TRUE; + return true; } /* XXX: Some of those are marked readonly just because we can't change them @@ -1367,29 +1321,29 @@ input_set_property_value(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid * require re-rendering the document (TODO), tabindex would require renumbering * of all links and whatnot. --pasky */ static JSPropertySpec input_props[] = { - { "accessKey", 0, JSPROP_ENUMERATE | JSPROP_SHARED, JSOP_WRAPPER(input_get_property_accessKey), JSOP_WRAPPER(input_set_property_accessKey) }, - { "alt", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(input_get_property_alt), JSOP_WRAPPER(input_set_property_alt) }, - { "checked", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(input_get_property_checked), JSOP_WRAPPER(input_set_property_checked) }, - { "defaultChecked",0,JSPROP_ENUMERATE|JSPROP_SHARED|JSPROP_READONLY, JSOP_WRAPPER(input_get_property_defaultChecked), JSOP_NULLWRAPPER }, - { "defaultValue",0,JSPROP_ENUMERATE|JSPROP_SHARED|JSPROP_READONLY, JSOP_WRAPPER(input_get_property_defaultValue), JSOP_NULLWRAPPER }, - { "disabled", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(input_get_property_disabled), JSOP_WRAPPER(input_set_property_disabled) }, - { "form", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(input_get_property_form), JSOP_NULLWRAPPER }, - { "maxLength", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(input_get_property_maxLength), JSOP_WRAPPER(input_set_property_maxLength) }, - { "name", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(input_get_property_name), JSOP_WRAPPER(input_set_property_name) }, - { "readonly", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(input_get_property_readonly), JSOP_WRAPPER(input_set_property_readonly) }, - { "selectedIndex", 0,JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(input_get_property_selectedIndex), JSOP_WRAPPER(input_set_property_selectedIndex) }, - { "size", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(input_get_property_size), JSOP_NULLWRAPPER }, - { "src", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(input_get_property_src), JSOP_WRAPPER(input_set_property_src) }, - { "tabindex", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(input_get_property_tabIndex), JSOP_NULLWRAPPER }, - { "type", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(input_get_property_type), JSOP_NULLWRAPPER }, - { "value", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(input_get_property_value), JSOP_WRAPPER(input_set_property_value)}, + JS_PSGS("accessKey", input_get_property_accessKey, input_set_property_accessKey, JSPROP_ENUMERATE), + JS_PSGS("alt", input_get_property_alt, input_set_property_alt, JSPROP_ENUMERATE), + JS_PSGS("checked", input_get_property_checked, input_set_property_checked, JSPROP_ENUMERATE), + JS_PSG("defaultChecked", input_get_property_defaultChecked, JSPROP_ENUMERATE), + JS_PSG("defaultValue",input_get_property_defaultValue, JSPROP_ENUMERATE), + JS_PSGS("disabled", input_get_property_disabled, input_set_property_disabled, JSPROP_ENUMERATE), + JS_PSG("form", input_get_property_form, JSPROP_ENUMERATE), + JS_PSGS("maxLength", input_get_property_maxLength, input_set_property_maxLength, JSPROP_ENUMERATE), + JS_PSGS("name", input_get_property_name, input_set_property_name, JSPROP_ENUMERATE), + JS_PSGS("readonly", input_get_property_readonly, input_set_property_readonly, JSPROP_ENUMERATE), + JS_PSGS("selectedIndex", input_get_property_selectedIndex, input_set_property_selectedIndex, JSPROP_ENUMERATE), + JS_PSG("size", input_get_property_size, JSPROP_ENUMERATE), + JS_PSGS("src", input_get_property_src, input_set_property_src,JSPROP_ENUMERATE), + JS_PSG("tabindex", input_get_property_tabIndex, JSPROP_ENUMERATE), + JS_PSG("type", input_get_property_type, JSPROP_ENUMERATE), + JS_PSGS("value", input_get_property_value, input_set_property_value, JSPROP_ENUMERATE), { NULL } }; -static JSBool input_blur(JSContext *ctx, unsigned int argc, jsval *rval); -static JSBool input_click(JSContext *ctx, unsigned int argc, jsval *rval); -static JSBool input_focus(JSContext *ctx, unsigned int argc, jsval *rval); -static JSBool input_select(JSContext *ctx, unsigned int argc, jsval *rval); +static bool input_blur(JSContext *ctx, unsigned int argc, jsval *rval); +static bool input_click(JSContext *ctx, unsigned int argc, jsval *rval); +static bool input_focus(JSContext *ctx, unsigned int argc, jsval *rval); +static bool input_select(JSContext *ctx, unsigned int argc, jsval *rval); static const spidermonkeyFunctionSpec input_funcs[] = { { "blur", input_blur, 0 }, @@ -1402,7 +1356,8 @@ static const spidermonkeyFunctionSpec input_funcs[] = { static struct form_state * input_get_form_state(JSContext *ctx, JSObject *jsinput) { - struct form_state *fs = JS_GetInstancePrivate(ctx, jsinput, + JS::RootedObject r_jsinput(ctx, jsinput); + struct form_state *fs = JS_GetInstancePrivate(ctx, r_jsinput, &input_class, NULL); @@ -1415,15 +1370,15 @@ input_get_form_state(JSContext *ctx, JSObject *jsinput) } /* @input_class.getProperty */ -static JSBool +static bool input_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) { ELINKS_CAST_PROP_PARAMS jsid id = hid.get(); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::RootedObject parent_form(ctx); /* instance of @form_class */ + JS::RootedObject parent_doc(ctx); /* instance of @document_class */ + JS::RootedObject parent_win(ctx); /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -1435,34 +1390,34 @@ input_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:: /* 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, obj, &input_class, NULL)) - return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &input_class, NULL)) + return false; parent_form = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_doc = JS_GetParent(parent_form); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_win = JS_GetParent(parent_doc); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); if (!JSID_IS_INT(id)) - return JS_TRUE; + return true; linknum = get_form_control_link(document, fc); /* Hiddens have no link. */ @@ -1484,7 +1439,7 @@ input_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:: if (keystr) *vp = STRING_TO_JSVAL(keystr); else - return JS_FALSE; + return false; } break; } @@ -1561,26 +1516,26 @@ input_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:: default: /* Unrecognized integer property ID; someone is using * the object as an array. SMJS builtin classes (e.g. - * js_RegExpClass) just return JS_TRUE in this case + * js_RegExpClass) just return true in this case * and leave *@vp unchanged. Do the same here. * (Actually not quite the same, as we already used * @undef_to_jsval.) */ break; } - return JS_TRUE; + return true; } /* @input_class.setProperty */ -static JSBool -input_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +input_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, bool strict, JS::MutableHandleValue hvp) { ELINKS_CAST_PROP_PARAMS jsid id = hid.get(); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::RootedObject parent_form(ctx); /* instance of @form_class */ + JS::RootedObject parent_doc(ctx); /* instance of @document_class */ + JS::RootedObject parent_win(ctx); /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -1593,31 +1548,31 @@ input_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBo /* 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, obj, &input_class, NULL)) - return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &input_class, NULL)) + return false; parent_form = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_doc = JS_GetParent(parent_form); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_win = JS_GetParent(parent_doc); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); doc_view = vs->doc_view; document = doc_view->document; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ fc = find_form_control(document, fs); assert(fc); assert(fc->form && fs); if (!JSID_IS_INT(id)) - return JS_TRUE; + return true; linknum = get_form_control_link(document, fc); /* Hiddens have no link. */ @@ -1625,9 +1580,9 @@ input_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBo switch (JSID_TO_INT(id)) { case JSP_INPUT_ACCESSKEY: - accesskey = jsval_to_accesskey(ctx, vp); + accesskey = jsval_to_accesskey(ctx, hvp); if (accesskey == UCS_NO_CHAR) - return JS_FALSE; + return false; else if (link) link->accesskey = accesskey; break; @@ -1646,8 +1601,8 @@ input_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBo : FORM_MODE_NORMAL); break; case JSP_INPUT_MAX_LENGTH: - if (!JS_ValueToInt32(ctx, *vp, &fc->maxlength)) - return JS_FALSE; + if (!JS::ToInt32(ctx, hvp, &fc->maxlength)) + return false; break; case JSP_INPUT_NAME: mem_free_set(&fc->name, stracpy(jsval_to_string(ctx, vp))); @@ -1674,8 +1629,8 @@ input_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBo if (fc->type == FC_SELECT) { int item; - if (!JS_ValueToInt32(ctx, *vp, &item)) - return JS_FALSE; + if (!JS::ToInt32(ctx, hvp, &item)) + return false; if (item >= 0 && item < fc->nvalues) { fs->state = item; @@ -1687,33 +1642,33 @@ input_set_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBo default: /* Unrecognized integer property ID; someone is using * the object as an array. SMJS builtin classes (e.g. - * js_RegExpClass) just return JS_TRUE in this case. + * js_RegExpClass) just return true in this case. * Do the same here. */ - return JS_TRUE; + return true; } - return JS_TRUE; + return true; } /* @input_funcs{"blur"} */ -static JSBool +static bool input_blur(JSContext *ctx, unsigned int argc, jsval *rval) { /* We are a text-mode browser and there *always* has to be something * selected. So we do nothing for now. (That was easy.) */ - return JS_TRUE; + return true; } /* @input_funcs{"click"} */ -static JSBool +static bool input_click(JSContext *ctx, unsigned int argc, jsval *rval) { jsval val; - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ - JSObject *obj = JS_THIS_OBJECT(ctx, rval); - jsval *argv = JS_ARGV(ctx, rval); + JS::RootedObject parent_form(ctx); /* instance of @form_class */ + JS::RootedObject parent_doc(ctx); /* instance of @document_class */ + JS::RootedObject parent_win(ctx); /* instance of @window_class */ + JS::RootedObject hobj(ctx, JS_THIS_OBJECT(ctx, rval)); + JS::CallArgs args = JS::CallArgsFromVp(argc, rval); struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -1722,24 +1677,24 @@ input_click(JSContext *ctx, unsigned int argc, jsval *rval) struct el_form_control *fc; int linknum; - if (!JS_InstanceOf(ctx, obj, &input_class, argv)) return JS_FALSE; - parent_form = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &input_class, &args)) return false; + parent_form = JS_GetParent(hobj); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_doc = JS_GetParent(parent_form); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_win = JS_GetParent(parent_doc); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); doc_view = vs->doc_view; document = doc_view->document; ses = doc_view->session; - fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + fs = input_get_form_state(ctx, hobj); + if (!fs) return false; /* detached */ assert(fs); fc = find_form_control(document, fs); @@ -1748,7 +1703,7 @@ input_click(JSContext *ctx, unsigned int argc, jsval *rval) linknum = get_form_control_link(document, fc); /* Hiddens have no link. */ if (linknum < 0) - return JS_TRUE; + return true; /* Restore old current_link afterwards? */ jump_to_link_number(ses, doc_view, linknum); @@ -1757,21 +1712,21 @@ input_click(JSContext *ctx, unsigned int argc, jsval *rval) else print_screen_status(ses); - boolean_to_jsval(ctx, &val, 0); - JS_SET_RVAL(ctx, rval, val); - return JS_TRUE; + args.rval().setBoolean(false); + + return true; } /* @input_funcs{"focus"} */ -static JSBool +static bool input_focus(JSContext *ctx, unsigned int argc, jsval *rval) { jsval val; - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ - JSObject *obj = JS_THIS_OBJECT(ctx, rval); - jsval *argv = JS_ARGV(ctx, rval); + JS::RootedObject parent_form(ctx); /* instance of @form_class */ + JS::RootedObject parent_doc(ctx); /* instance of @document_class */ + JS::RootedObject parent_win(ctx); /* instance of @window_class */ + JS::RootedObject obj(ctx, JS_THIS_OBJECT(ctx, rval)); + JS::CallArgs args = JS::CallArgsFromVp(argc, rval); struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -1780,16 +1735,16 @@ input_focus(JSContext *ctx, unsigned int argc, jsval *rval) struct el_form_control *fc; int linknum; - if (!JS_InstanceOf(ctx, obj, &input_class, argv)) return JS_FALSE; + if (!JS_InstanceOf(ctx, obj, &input_class, &args)) return false; parent_form = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_doc = JS_GetParent(parent_form); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_win = JS_GetParent(parent_doc); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); @@ -1797,7 +1752,7 @@ input_focus(JSContext *ctx, unsigned int argc, jsval *rval) document = doc_view->document; ses = doc_view->session; fs = input_get_form_state(ctx, obj); - if (!fs) return JS_FALSE; /* detached */ + if (!fs) return false; /* detached */ assert(fs); fc = find_form_control(document, fs); @@ -1806,22 +1761,21 @@ input_focus(JSContext *ctx, unsigned int argc, jsval *rval) linknum = get_form_control_link(document, fc); /* Hiddens have no link. */ if (linknum < 0) - return JS_TRUE; + return true; jump_to_link_number(ses, doc_view, linknum); - boolean_to_jsval(ctx, &val, 0); - JS_SET_RVAL(ctx, rval, val); - return JS_TRUE; + args.rval().setBoolean(false); + return true; } /* @input_funcs{"select"} */ -static JSBool +static bool input_select(JSContext *ctx, unsigned int argc, jsval *rval) { /* We support no text selecting yet. So we do nothing for now. * (That was easy, too.) */ - return JS_TRUE; + return true; } static JSObject * @@ -1830,8 +1784,9 @@ get_input_object(JSContext *ctx, JSObject *jsform, struct form_state *fs) JSObject *jsinput = fs->ecmascript_obj; if (jsinput) { + JS::RootedObject r_jsinput(ctx, jsinput); /* This assumes JS_GetInstancePrivate cannot GC. */ - assert(JS_GetInstancePrivate(ctx, jsinput, + assert(JS_GetInstancePrivate(ctx, r_jsinput, &input_class, NULL) == fs); if_assert_failed return NULL; @@ -1839,13 +1794,17 @@ get_input_object(JSContext *ctx, JSObject *jsform, struct form_state *fs) return jsinput; } + JS::RootedObject r_jsform(ctx, jsform); /* jsform ('form') is input's parent */ /* FIXME: That is NOT correct since the real containing element * should be its parent, but gimme DOM first. --pasky */ - jsinput = JS_NewObject(ctx, &input_class, NULL, jsform); + jsinput = JS_NewObject(ctx, &input_class, JS::NullPtr(), r_jsform); if (!jsinput) return NULL; - JS_DefineProperties(ctx, jsinput, (JSPropertySpec *) input_props); + + JS::RootedObject r_jsinput(ctx, jsinput); + + JS_DefineProperties(ctx, r_jsinput, (JSPropertySpec *) input_props); spidermonkey_DefineFunctions(ctx, jsinput, input_funcs); JS_SetPrivate(jsinput, fs); /* to @input_class */ @@ -1878,6 +1837,7 @@ spidermonkey_detach_form_state(struct form_state *fs) JSObject *jsinput = fs->ecmascript_obj; if (jsinput) { + JS::RootedObject r_jsinput(spidermonkey_empty_context, jsinput); /* This assumes JS_GetInstancePrivate and JS_SetPrivate * cannot GC. */ @@ -1886,7 +1846,7 @@ spidermonkey_detach_form_state(struct form_state *fs) * crashes seem possible either way. Resetting it is * easiest. */ assert(JS_GetInstancePrivate(spidermonkey_empty_context, - jsinput, + r_jsinput, &input_class, NULL) == fs); if_assert_failed {} @@ -1942,7 +1902,7 @@ get_form_control_object(JSContext *ctx, JSObject *jsform, static struct form_view *form_get_form_view(JSContext *ctx, JSObject *jsform, jsval *argv); -static JSBool form_elements_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); +static bool form_elements_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); /* Each @form_elements_class object must have a @form_class parent. */ static JSClass form_elements_class = { @@ -1953,10 +1913,10 @@ static JSClass form_elements_class = { JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL }; -static JSBool form_elements_item2(JSContext *ctx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); -static JSBool form_elements_namedItem2(JSContext *ctx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); -static JSBool form_elements_item(JSContext *ctx, unsigned int argc, jsval *rval); -static JSBool form_elements_namedItem(JSContext *ctx, unsigned int argc, jsval *rval); +static bool form_elements_item2(JSContext *ctx, JSObject *obj, int index, jsval *rval); +static bool form_elements_namedItem2(JSContext *ctx, JSObject *obj, unsigned char *string, jsval *rval); +static bool form_elements_item(JSContext *ctx, unsigned int argc, jsval *rval); +static bool form_elements_namedItem(JSContext *ctx, unsigned int argc, jsval *rval); static const spidermonkeyFunctionSpec form_elements_funcs[] = { @@ -1965,7 +1925,7 @@ static const spidermonkeyFunctionSpec form_elements_funcs[] = { { NULL } }; -static JSBool form_elements_get_property_length(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); +static bool form_elements_get_property_length(JSContext *ctx, unsigned int argc, jsval *vp); /* Tinyids of properties. Use negative values to distinguish these * from array indexes (elements[INT] for INT>=0 is equivalent to @@ -1975,57 +1935,62 @@ enum form_elements_prop { JSP_FORM_ELEMENTS_LENGTH = -1, }; static JSPropertySpec form_elements_props[] = { - { "length", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(form_elements_get_property_length), JSOP_NULLWRAPPER}, + JS_PSG("length", form_elements_get_property_length, JSPROP_ENUMERATE), { NULL } }; -static JSBool +static bool form_elements_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) { ELINKS_CAST_PROP_PARAMS jsid id = hid.get(); jsval idval; - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::RootedObject parent_form(ctx); /* instance of @form_class */ + JS::RootedObject parent_doc(ctx); /* instance of @document_class */ + JS::RootedObject parent_win(ctx); /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; struct form_view *form_view; struct form *form; + /* 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, obj, &form_elements_class, NULL)) - return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &form_elements_class, NULL)) { + return false; + } parent_form = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_doc = JS_GetParent(parent_form); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_win = JS_GetParent(parent_doc); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); doc_view = vs->doc_view; document = doc_view->document; form_view = form_get_form_view(ctx, parent_form, NULL); - if (!form_view) return JS_FALSE; /* detached */ + if (!form_view) return false; /* detached */ form = find_form_by_form_view(document, form_view); if (JSID_IS_STRING(id)) { - JS_IdToValue(ctx, id, &idval); - form_elements_namedItem2(ctx, obj, 1, &idval, vp); - return JS_TRUE; + JS::RootedValue r_idval(ctx, idval); + JS_IdToValue(ctx, id, &r_idval); + unsigned char *string = JS_EncodeString(ctx, JS::ToString(ctx, r_idval)); + form_elements_namedItem2(ctx, obj, string, vp); + return true; } - if (!JSID_IS_INT(id)) - return JS_TRUE; + if (!JSID_IS_INT(id)) { + return true; + } undef_to_jsval(ctx, vp); @@ -2035,76 +2000,84 @@ form_elements_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h break; default: /* Array index. */ - JS_IdToValue(ctx, id, &idval); - form_elements_item2(ctx, obj, 1, &idval, vp); + int index; + JS::RootedValue r_idval(ctx, idval); + JS_IdToValue(ctx, id, &r_idval); + JS::ToInt32(ctx, r_idval, &index); + form_elements_item2(ctx, obj, index, vp); break; } - return JS_TRUE; + return true; } -static JSBool -form_elements_get_property_length(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +form_elements_get_property_length(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; struct form_view *form_view; struct form *form; - /* 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, obj, &form_elements_class, NULL)) - return JS_FALSE; - parent_form = JS_GetParent(obj); + JS::RootedObject parent_form(ctx, JS_GetParent(hobj)); + assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; - parent_doc = JS_GetParent(parent_form); + if_assert_failed return false; + + JS::RootedObject parent_doc(ctx, JS_GetParent(parent_form)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; form_view = form_get_form_view(ctx, parent_form, NULL); - if (!form_view) return JS_FALSE; /* detached */ + if (!form_view) return false; /* detached */ + form = find_form_by_form_view(document, form_view); + args.rval().setInt32(list_size(&form->items)); - int_to_jsval(ctx, vp, list_size(&form->items)); - - return JS_TRUE; + return true; } /* @form_elements_funcs{"item"} */ -static JSBool +static bool form_elements_item(JSContext *ctx, unsigned int argc, jsval *rval) { jsval val = JSVAL_VOID; JSObject *obj = JS_THIS_OBJECT(ctx, rval); - jsval *argv = JS_ARGV(ctx, rval); - JSBool ret = form_elements_item2(ctx, obj, argc, argv, &val); + JS::CallArgs args = JS::CallArgsFromVp(argc, rval); - JS_SET_RVAL(ctx, rval, val); + int index; + JS::ToInt32(ctx, args[0], &index); + + bool ret = form_elements_item2(ctx, obj, index, &val); + + args.rval().set(val); +// JS_SET_RVAL(ctx, rval, val); return ret; } -static JSBool -form_elements_item2(JSContext *ctx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval) +static bool +form_elements_item2(JSContext *ctx, JSObject *obj, int index, jsval *rval) { - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::RootedObject parent_form(ctx); /* instance of @form_class */ + JS::RootedObject parent_doc(ctx); /* instance of @document_class */ + JS::RootedObject parent_win(ctx); /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -2112,32 +2085,28 @@ form_elements_item2(JSContext *ctx, JSObject *obj, unsigned int argc, jsval *arg struct form *form; struct el_form_control *fc; int counter = -1; - int index; - if (!JS_InstanceOf(ctx, obj, &form_elements_class, argv)) return JS_FALSE; + JS::RootedObject hobj(ctx, obj); + + if (!JS_InstanceOf(ctx, hobj, &form_elements_class, NULL)) return false; parent_form = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_doc = JS_GetParent(parent_form); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_win = JS_GetParent(parent_doc); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); doc_view = vs->doc_view; document = doc_view->document; form_view = form_get_form_view(ctx, parent_form, NULL); - if (!form_view) return JS_FALSE; /* detached */ + if (!form_view) return false; /* detached */ form = find_form_by_form_view(document, form_view); - if (argc != 1) - return JS_TRUE; - - if (!JS_ValueToInt32(ctx, argv[0], &index)) - return JS_FALSE; undef_to_jsval(ctx, rval); foreach (fc, form->items) { @@ -2155,61 +2124,62 @@ form_elements_item2(JSContext *ctx, JSObject *obj, unsigned int argc, jsval *arg } } - return JS_TRUE; + return true; } /* @form_elements_funcs{"namedItem"} */ -static JSBool +static bool form_elements_namedItem(JSContext *ctx, unsigned int argc, jsval *rval) { jsval val = JSVAL_VOID; JSObject *obj = JS_THIS_OBJECT(ctx, rval); - jsval *argv = JS_ARGV(ctx, rval); - JSBool ret = form_elements_namedItem2(ctx, obj, argc, argv, &val); - JS_SET_RVAL(ctx, rval, val); + JS::CallArgs args = JS::CallArgsFromVp(argc, rval); +// jsval *argv = JS_ARGV(ctx, rval); + unsigned char *string = JS_EncodeString(ctx, JS::ToString(ctx, args[0])); + bool ret = form_elements_namedItem2(ctx, obj, string, &val); + args.rval().set(val); +// JS_SET_RVAL(ctx, rval, val); return ret; } -static JSBool -form_elements_namedItem2(JSContext *ctx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval) +static bool +form_elements_namedItem2(JSContext *ctx, JSObject *obj, unsigned char *string, jsval *rval) { - JSObject *parent_form; /* instance of @form_class */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::RootedObject parent_form(ctx); /* instance of @form_class */ + JS::RootedObject parent_doc(ctx); /* instance of @document_class */ + JS::RootedObject parent_win(ctx); /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; struct form_view *form_view; struct form *form; struct el_form_control *fc; - unsigned char *string; - if (!JS_InstanceOf(ctx, obj, &form_elements_class, argv)) return JS_FALSE; + if (!*string) { + return true; + } + + JS::RootedObject hobj(ctx, obj); + + if (!JS_InstanceOf(ctx, hobj, &form_elements_class, NULL)) return false; parent_form = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_form, &form_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_doc = JS_GetParent(parent_form); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_win = JS_GetParent(parent_doc); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); doc_view = vs->doc_view; document = doc_view->document; form_view = form_get_form_view(ctx, parent_form, NULL); - if (!form_view) return JS_FALSE; /* detached */ + if (!form_view) return false; /* detached */ form = find_form_by_form_view(document, form_view); - if (argc != 1) - return JS_TRUE; - - string = jsval_to_string(ctx, &argv[0]); - if (!*string) - return JS_TRUE; - undef_to_jsval(ctx, rval); foreach (fc, form->items) { @@ -2227,7 +2197,7 @@ form_elements_namedItem2(JSContext *ctx, JSObject *obj, unsigned int argc, jsval } } - return JS_TRUE; + return true; } @@ -2247,18 +2217,18 @@ enum form_prop { }; static JSPropertySpec form_props[] = { - { "action", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(form_get_property_action), JSOP_WRAPPER(form_set_property_action) }, - { "elements", 0, JSPROP_ENUMERATE|JSPROP_SHARED|JSPROP_READONLY, JSOP_WRAPPER(form_get_property_elements), JSOP_NULLWRAPPER }, - { "encoding", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(form_get_property_encoding), JSOP_WRAPPER(form_set_property_encoding) }, - { "length", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(form_get_property_length), JSOP_NULLWRAPPER }, - { "method", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(form_get_property_method), JSOP_WRAPPER(form_set_property_method) }, - { "name", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(form_get_property_name), JSOP_WRAPPER(form_set_property_name) }, - { "target", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(form_get_property_target), JSOP_WRAPPER(form_set_property_target) }, + JS_PSGS("action", form_get_property_action, form_set_property_action, JSPROP_ENUMERATE), + JS_PSG("elements", form_get_property_elements, JSPROP_ENUMERATE), + JS_PSGS("encoding", form_get_property_encoding, form_set_property_encoding, JSPROP_ENUMERATE), + JS_PSG("length", form_get_property_length, JSPROP_ENUMERATE), + JS_PSGS("method", form_get_property_method, form_set_property_method, JSPROP_ENUMERATE), + JS_PSGS("name", form_get_property_name, form_set_property_name, JSPROP_ENUMERATE), + JS_PSGS("target", form_get_property_target, form_set_property_target, JSPROP_ENUMERATE), { NULL } }; -static JSBool form_reset(JSContext *ctx, unsigned int argc, jsval *rval); -static JSBool form_submit(JSContext *ctx, unsigned int argc, jsval *rval); +static bool form_reset(JSContext *ctx, unsigned int argc, jsval *rval); +static bool form_submit(JSContext *ctx, unsigned int argc, jsval *rval); static const spidermonkeyFunctionSpec form_funcs[] = { { "reset", form_reset, 0 }, @@ -2269,9 +2239,11 @@ static const spidermonkeyFunctionSpec form_funcs[] = { static struct form_view * form_get_form_view(JSContext *ctx, JSObject *jsform, jsval *argv) { - struct form_view *fv = JS_GetInstancePrivate(ctx, jsform, + JS::RootedObject r_jsform(ctx, jsform); + JS::CallArgs args = JS::CallArgsFromVp(1, argv); + struct form_view *fv = JS_GetInstancePrivate(ctx, r_jsform, &form_class, - argv); + &args); if (!fv) return NULL; /* detached */ @@ -2282,14 +2254,14 @@ form_get_form_view(JSContext *ctx, JSObject *jsform, jsval *argv) } /* @form_class.getProperty */ -static JSBool +static bool form_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) { ELINKS_CAST_PROP_PARAMS jsid id = hid.get(); /* DBG("doc %p %s\n", parent_doc, JS_GetStringBytes(JS_ValueToString(ctx, OBJECT_TO_JSVAL(parent_doc)))); */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::RootedObject parent_doc(ctx); /* instance of @document_class */ + JS::RootedObject parent_win(ctx); /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct form_view *fv; @@ -2298,20 +2270,20 @@ form_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::M /* 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, obj, &form_class, NULL)) - return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &form_class, NULL)) + return false; parent_doc = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_win = JS_GetParent(parent_doc); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); doc_view = vs->doc_view; fv = form_get_form_view(ctx, obj, NULL); - if (!fv) return JS_FALSE; /* detached */ + if (!fv) return false; /* detached */ form = find_form_by_form_view(doc_view->document, fv); assert(form); @@ -2337,11 +2309,11 @@ form_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::M } break; } - return JS_TRUE; + return true; } if (!JSID_IS_INT(id)) - return JS_TRUE; + return true; undef_to_jsval(ctx, vp); @@ -2353,9 +2325,11 @@ form_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::M case JSP_FORM_ELEMENTS: { /* jsform ('form') is form_elements' parent; who knows is that's correct */ - JSObject *jsform_elems = JS_NewObject(ctx, &form_elements_class, NULL, obj); + JSObject *jsform_elems = JS_NewObject(ctx, &form_elements_class, JS::NullPtr(), hobj); - JS_DefineProperties(ctx, jsform_elems, (JSPropertySpec *) form_elements_props); + JS::RootedObject r_jsform_elems(ctx, jsform_elems); + + JS_DefineProperties(ctx, r_jsform_elems, (JSPropertySpec *) form_elements_props); spidermonkey_DefineFunctions(ctx, jsform_elems, form_elements_funcs); object_to_jsval(ctx, vp, jsform_elems); @@ -2408,24 +2382,23 @@ form_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::M default: /* Unrecognized integer property ID; someone is using * the object as an array. SMJS builtin classes (e.g. - * js_RegExpClass) just return JS_TRUE in this case + * js_RegExpClass) just return true in this case * and leave *@vp unchanged. Do the same here. * (Actually not quite the same, as we already used * @undef_to_jsval.) */ break; } - return JS_TRUE; + return true; } -static JSBool -form_get_property_action(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +form_get_property_action(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - /* DBG("doc %p %s\n", parent_doc, JS_GetStringBytes(JS_ValueToString(ctx, OBJECT_TO_JSVAL(parent_doc)))); */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + struct view_state *vs; struct document_view *doc_view; struct form_view *fv; @@ -2434,35 +2407,39 @@ form_get_property_action(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid /* 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, obj, &form_class, NULL)) - return JS_FALSE; - parent_doc = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &form_class, NULL)) + return false; + + JS::RootedObject parent_doc(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; - fv = form_get_form_view(ctx, obj, NULL); - if (!fv) return JS_FALSE; /* detached */ + fv = form_get_form_view(ctx, hobj, NULL); + if (!fv) return false; /* detached */ form = find_form_by_form_view(doc_view->document, fv); assert(form); - string_to_jsval(ctx, vp, form->action); + args.rval().setString(JS_NewStringCopyZ(ctx, form->action)); - return JS_TRUE; + return true; } -static JSBool -form_set_property_action(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +form_set_property_action(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct form_view *fv; @@ -2472,71 +2449,74 @@ form_set_property_action(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid /* 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, obj, &form_class, NULL)) - return JS_FALSE; - parent_doc = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &form_class, NULL)) + return false; + + JS::RootedObject parent_doc(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; - fv = form_get_form_view(ctx, obj, NULL); - if (!fv) return JS_FALSE; /* detached */ + fv = form_get_form_view(ctx, hobj, NULL); + if (!fv) return false; /* detached */ form = find_form_by_form_view(doc_view->document, fv); assert(form); - string = stracpy(jsval_to_string(ctx, vp)); + string = stracpy(JS_EncodeString(ctx, args[0].toString())); if (form->action) { ecmascript_set_action(&form->action, string); } else { mem_free_set(&form->action, string); } - return JS_TRUE; + return true; } -static JSBool -form_get_property_elements(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +form_get_property_elements(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - /* DBG("doc %p %s\n", parent_doc, JS_GetStringBytes(JS_ValueToString(ctx, OBJECT_TO_JSVAL(parent_doc)))); */ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + struct form_view *fv; - JSObject *jsform_elems; /* 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, obj, &form_class, NULL)) - return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &form_class, NULL)) + return false; - fv = form_get_form_view(ctx, obj, NULL); - if (!fv) return JS_FALSE; /* detached */ + fv = form_get_form_view(ctx, hobj, NULL); + if (!fv) return false; /* detached */ /* jsform ('form') is form_elements' parent; who knows is that's correct */ - jsform_elems = JS_NewObject(ctx, &form_elements_class, NULL, obj); + JSObject *jsform_elems = JS_NewObject(ctx, &form_elements_class, JS::NullPtr(), hobj); + JS::RootedObject r_jsform_elems(ctx, jsform_elems); - JS_DefineProperties(ctx, jsform_elems, (JSPropertySpec *) form_elements_props); + JS_DefineProperties(ctx, r_jsform_elems, (JSPropertySpec *) form_elements_props); spidermonkey_DefineFunctions(ctx, jsform_elems, form_elements_funcs); - object_to_jsval(ctx, vp, jsform_elems); - /* SM will cache this property value for us so we create this - * just once per form. */ + args.rval().setObject(*jsform_elems); - return JS_TRUE; + return true; } -static JSBool -form_get_property_encoding(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +form_get_property_encoding(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - /* DBG("doc %p %s\n", parent_doc, JS_GetStringBytes(JS_ValueToString(ctx, OBJECT_TO_JSVAL(parent_doc)))); */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + struct view_state *vs; struct document_view *doc_view; struct form_view *fv; @@ -2545,20 +2525,25 @@ form_get_property_encoding(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h /* 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, obj, &form_class, NULL)) - return JS_FALSE; - parent_doc = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &form_class, NULL)) + return false; + + JS::RootedObject parent_doc(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; - fv = form_get_form_view(ctx, obj, NULL); - if (!fv) return JS_FALSE; /* detached */ + fv = form_get_form_view(ctx, hobj, NULL); + if (!fv) return false; /* detached */ form = find_form_by_form_view(doc_view->document, fv); assert(form); @@ -2566,27 +2551,26 @@ form_get_property_encoding(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h switch (form->method) { case FORM_METHOD_GET: case FORM_METHOD_POST: - string_to_jsval(ctx, vp, "application/x-www-form-urlencoded"); + args.rval().setString(JS_NewStringCopyZ(ctx, "application/x-www-form-urlencoded")); break; case FORM_METHOD_POST_MP: - string_to_jsval(ctx, vp, "multipart/form-data"); + args.rval().setString(JS_NewStringCopyZ(ctx, "multipart/form-data")); break; case FORM_METHOD_POST_TEXT_PLAIN: - string_to_jsval(ctx, vp, "text/plain"); + args.rval().setString(JS_NewStringCopyZ(ctx, "text/plain")); break; } - return JS_TRUE; + return true; } /* @form_class.setProperty */ -static JSBool -form_set_property_encoding(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +form_set_property_encoding(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct form_view *fv; @@ -2596,25 +2580,30 @@ form_set_property_encoding(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h /* 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, obj, &form_class, NULL)) - return JS_FALSE; - parent_doc = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &form_class, NULL)) + return false; + + JS::RootedObject parent_doc(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; - fv = form_get_form_view(ctx, obj, NULL); - if (!fv) return JS_FALSE; /* detached */ + fv = form_get_form_view(ctx, hobj, NULL); + if (!fv) return false; /* detached */ form = find_form_by_form_view(doc_view->document, fv); assert(form); - string = jsval_to_string(ctx, vp); + string = JS_EncodeString(ctx, args[0].toString()); if (!c_strcasecmp(string, "application/x-www-form-urlencoded")) { form->method = form->method == FORM_METHOD_GET ? FORM_METHOD_GET : FORM_METHOD_POST; @@ -2624,16 +2613,15 @@ form_set_property_encoding(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h form->method = FORM_METHOD_POST_TEXT_PLAIN; } - return JS_TRUE; + return true; } -static JSBool -form_get_property_length(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +form_get_property_length(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - /* DBG("doc %p %s\n", parent_doc, JS_GetStringBytes(JS_ValueToString(ctx, OBJECT_TO_JSVAL(parent_doc)))); */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + struct view_state *vs; struct document_view *doc_view; struct form_view *fv; @@ -2642,36 +2630,40 @@ form_get_property_length(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid /* 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, obj, &form_class, NULL)) - return JS_FALSE; - parent_doc = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &form_class, NULL)) + return false; + + JS::RootedObject parent_doc(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; - fv = form_get_form_view(ctx, obj, NULL); - if (!fv) return JS_FALSE; /* detached */ + fv = form_get_form_view(ctx, hobj, NULL); + if (!fv) return false; /* detached */ form = find_form_by_form_view(doc_view->document, fv); assert(form); - int_to_jsval(ctx, vp, list_size(&form->items)); + args.rval().setInt32(list_size(&form->items)); - return JS_TRUE; + return true; } -static JSBool -form_get_property_method(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +form_get_property_method(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - /* DBG("doc %p %s\n", parent_doc, JS_GetStringBytes(JS_ValueToString(ctx, OBJECT_TO_JSVAL(parent_doc)))); */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + struct view_state *vs; struct document_view *doc_view; struct form_view *fv; @@ -2680,47 +2672,51 @@ form_get_property_method(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid /* 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, obj, &form_class, NULL)) - return JS_FALSE; - parent_doc = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &form_class, NULL)) + return false; + + JS::RootedObject parent_doc(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; - fv = form_get_form_view(ctx, obj, NULL); - if (!fv) return JS_FALSE; /* detached */ + fv = form_get_form_view(ctx, hobj, NULL); + if (!fv) return false; /* detached */ form = find_form_by_form_view(doc_view->document, fv); assert(form); switch (form->method) { case FORM_METHOD_GET: - string_to_jsval(ctx, vp, "GET"); + args.rval().setString(JS_NewStringCopyZ(ctx, "GET")); break; case FORM_METHOD_POST: case FORM_METHOD_POST_MP: case FORM_METHOD_POST_TEXT_PLAIN: - string_to_jsval(ctx, vp, "POST"); + args.rval().setString(JS_NewStringCopyZ(ctx, "POST")); break; } - return JS_TRUE; + return true; } /* @form_class.setProperty */ -static JSBool -form_set_property_method(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +form_set_property_method(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct form_view *fv; @@ -2730,41 +2726,45 @@ form_set_property_method(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid /* 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, obj, &form_class, NULL)) - return JS_FALSE; - parent_doc = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &form_class, NULL)) + return false; + + JS::RootedObject parent_doc(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; - fv = form_get_form_view(ctx, obj, NULL); - if (!fv) return JS_FALSE; /* detached */ + fv = form_get_form_view(ctx, hobj, NULL); + if (!fv) return false; /* detached */ form = find_form_by_form_view(doc_view->document, fv); assert(form); - string = jsval_to_string(ctx, vp); + string = JS_EncodeString(ctx, args[0].toString()); if (!c_strcasecmp(string, "GET")) { form->method = FORM_METHOD_GET; } else if (!c_strcasecmp(string, "POST")) { form->method = FORM_METHOD_POST; } - return JS_TRUE; + return true; } -static JSBool -form_get_property_name(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +form_get_property_name(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - /* DBG("doc %p %s\n", parent_doc, JS_GetStringBytes(JS_ValueToString(ctx, OBJECT_TO_JSVAL(parent_doc)))); */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + struct view_state *vs; struct document_view *doc_view; struct form_view *fv; @@ -2773,37 +2773,41 @@ form_get_property_name(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, /* 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, obj, &form_class, NULL)) - return JS_FALSE; - parent_doc = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &form_class, NULL)) + return false; + + JS::RootedObject parent_doc(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; - fv = form_get_form_view(ctx, obj, NULL); - if (!fv) return JS_FALSE; /* detached */ + fv = form_get_form_view(ctx, hobj, NULL); + if (!fv) return false; /* detached */ form = find_form_by_form_view(doc_view->document, fv); assert(form); - string_to_jsval(ctx, vp, form->name); + args.rval().setString(JS_NewStringCopyZ(ctx, form->name)); - return JS_TRUE; + return true; } /* @form_class.setProperty */ -static JSBool -form_set_property_name(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +form_set_property_name(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct form_view *fv; @@ -2812,35 +2816,39 @@ form_set_property_name(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, /* 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, obj, &form_class, NULL)) - return JS_FALSE; - parent_doc = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &form_class, NULL)) + return false; + + JS::RootedObject parent_doc(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; - fv = form_get_form_view(ctx, obj, NULL); - if (!fv) return JS_FALSE; /* detached */ + fv = form_get_form_view(ctx, hobj, NULL); + if (!fv) return false; /* detached */ form = find_form_by_form_view(doc_view->document, fv); assert(form); - mem_free_set(&form->name, stracpy(jsval_to_string(ctx, vp))); + mem_free_set(&form->name, stracpy(JS_EncodeString(ctx, args[0].toString()))); - return JS_TRUE; + return true; } -static JSBool -form_get_property_target(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +form_get_property_target(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - /* DBG("doc %p %s\n", parent_doc, JS_GetStringBytes(JS_ValueToString(ctx, OBJECT_TO_JSVAL(parent_doc)))); */ - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + struct view_state *vs; struct document_view *doc_view; struct form_view *fv; @@ -2849,35 +2857,39 @@ form_get_property_target(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid /* 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, obj, &form_class, NULL)) - return JS_FALSE; - parent_doc = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &form_class, NULL)) + return false; + + JS::RootedObject parent_doc(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; - fv = form_get_form_view(ctx, obj, NULL); - if (!fv) return JS_FALSE; /* detached */ + fv = form_get_form_view(ctx, hobj, NULL); + if (!fv) return false; /* detached */ form = find_form_by_form_view(doc_view->document, fv); assert(form); - string_to_jsval(ctx, vp, form->target); + args.rval().setString(JS_NewStringCopyZ(ctx, form->target)); - return JS_TRUE; + return true; } -static JSBool -form_set_property_target(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +form_set_property_target(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct form_view *fv; @@ -2886,56 +2898,64 @@ form_set_property_target(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid /* 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, obj, &form_class, NULL)) - return JS_FALSE; - parent_doc = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &form_class, NULL)) + return false; + + JS::RootedObject parent_doc(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; - parent_win = JS_GetParent(parent_doc); + if_assert_failed return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; - fv = form_get_form_view(ctx, obj, NULL); - if (!fv) return JS_FALSE; /* detached */ + fv = form_get_form_view(ctx, hobj, NULL); + if (!fv) return false; /* detached */ form = find_form_by_form_view(doc_view->document, fv); assert(form); - mem_free_set(&form->target, stracpy(jsval_to_string(ctx, vp))); + mem_free_set(&form->target, stracpy(JS_EncodeString(ctx, args[0].toString()))); - return JS_TRUE; + return true; } /* @form_funcs{"reset"} */ -static JSBool +static bool form_reset(JSContext *ctx, unsigned int argc, jsval *rval) { jsval val; - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::RootedObject parent_doc(ctx); /* instance of @document_class */ + JS::RootedObject parent_win(ctx); /* instance of @window_class */ JSObject *obj = JS_THIS_OBJECT(ctx, rval); - jsval *argv = JS_ARGV(ctx, rval); + JS::RootedObject hobj(ctx, obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, rval); +// jsval *argv = JS_ARGV(ctx, rval); struct view_state *vs; struct document_view *doc_view; struct form_view *fv; struct form *form; - if (!JS_InstanceOf(ctx, obj, &form_class, argv)) return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &form_class, &args)) return false; parent_doc = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_win = JS_GetParent(parent_doc); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); doc_view = vs->doc_view; - fv = form_get_form_view(ctx, obj, argv); - if (!fv) return JS_FALSE; /* detached */ +/// fv = form_get_form_view(ctx, obj, argv); + fv = form_get_form_view(ctx, obj, rval); + if (!fv) return false; /* detached */ form = find_form_by_form_view(doc_view->document, fv); assert(form); @@ -2943,50 +2963,51 @@ form_reset(JSContext *ctx, unsigned int argc, jsval *rval) do_reset_form(doc_view, form); draw_forms(doc_view->session->tab->term, doc_view); - boolean_to_jsval(ctx, &val, 0); - JS_SET_RVAL(ctx, rval, val); + args.rval().setBoolean(false); - return JS_TRUE; + return true; } /* @form_funcs{"submit"} */ -static JSBool +static bool form_submit(JSContext *ctx, unsigned int argc, jsval *rval) { jsval val; - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::RootedObject parent_doc(ctx); /* instance of @document_class */ + JS::RootedObject parent_win(ctx); /* instance of @window_class */ JSObject *obj = JS_THIS_OBJECT(ctx, rval); - jsval *argv = JS_ARGV(ctx, rval); + JS::RootedObject hobj(ctx, obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, rval); +// jsval *argv = JS_ARGV(ctx, rval); struct view_state *vs; struct document_view *doc_view; struct session *ses; struct form_view *fv; struct form *form; - if (!JS_InstanceOf(ctx, obj, &form_class, argv)) return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &form_class, &args)) return false; parent_doc = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_win = JS_GetParent(parent_doc); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); doc_view = vs->doc_view; ses = doc_view->session; - fv = form_get_form_view(ctx, obj, argv); - if (!fv) return JS_FALSE; /* detached */ +// fv = form_get_form_view(ctx, obj, argv); + fv = form_get_form_view(ctx, obj, rval); + if (!fv) return false; /* detached */ form = find_form_by_form_view(doc_view->document, fv); assert(form); submit_given_form(ses, doc_view, form, 0); - boolean_to_jsval(ctx, &val, 0); - JS_SET_RVAL(ctx, rval, val); + args.rval().setBoolean(false); - return JS_TRUE; + return true; } JSObject * @@ -2995,8 +3016,9 @@ get_form_object(JSContext *ctx, JSObject *jsdoc, struct form_view *fv) JSObject *jsform = fv->ecmascript_obj; if (jsform) { + JS::RootedObject r_jsform(ctx, jsform); /* This assumes JS_GetInstancePrivate cannot GC. */ - assert(JS_GetInstancePrivate(ctx, jsform, + assert(JS_GetInstancePrivate(ctx, r_jsform, &form_class, NULL) == fv); if_assert_failed return NULL; @@ -3004,13 +3026,15 @@ get_form_object(JSContext *ctx, JSObject *jsdoc, struct form_view *fv) return jsform; } + JS::RootedObject r_jsdoc(ctx, jsdoc); /* jsdoc ('document') is fv's parent */ /* FIXME: That is NOT correct since the real containing element * should be its parent, but gimme DOM first. --pasky */ - jsform = JS_NewObject(ctx, &form_class, NULL, jsdoc); + jsform = JS_NewObject(ctx, &form_class, JS::NullPtr(), r_jsdoc); if (jsform == NULL) return NULL; - JS_DefineProperties(ctx, jsform, form_props); + JS::RootedObject r_jsform(ctx, jsform); + JS_DefineProperties(ctx, r_jsform, form_props); spidermonkey_DefineFunctions(ctx, jsform, form_funcs); JS_SetPrivate(jsform, fv); /* to @form_class */ @@ -3044,6 +3068,7 @@ spidermonkey_detach_form_view(struct form_view *fv) JSObject *jsform = fv->ecmascript_obj; if (jsform) { + JS::RootedObject r_jsform(spidermonkey_empty_context, jsform); /* This assumes JS_GetInstancePrivate and JS_SetPrivate * cannot GC. */ @@ -3052,7 +3077,7 @@ spidermonkey_detach_form_view(struct form_view *fv) * crashes seem possible either way. Resetting it is * easiest. */ assert(JS_GetInstancePrivate(spidermonkey_empty_context, - jsform, + r_jsform, &form_class, NULL) == fv); if_assert_failed {} @@ -3063,8 +3088,8 @@ spidermonkey_detach_form_view(struct form_view *fv) } -static JSBool forms_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool forms_get_property_length(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); +static bool forms_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); +static bool forms_get_property_length(JSContext *ctx, unsigned int argc, jsval *vp); /* Each @forms_class object must have a @document_class parent. */ JSClass forms_class = { @@ -3075,9 +3100,9 @@ JSClass forms_class = { JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL }; -static JSBool forms_item(JSContext *ctx, unsigned int argc, jsval *rval); -static JSBool forms_item2(JSContext *ctx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); -static JSBool forms_namedItem(JSContext *ctx, unsigned int argc, jsval *rval); +static bool forms_item(JSContext *ctx, unsigned int argc, jsval *rval); +static bool forms_item2(JSContext *ctx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval); +static bool forms_namedItem(JSContext *ctx, unsigned int argc, jsval *rval); const spidermonkeyFunctionSpec forms_funcs[] = { { "item", forms_item, 1 }, @@ -3093,7 +3118,7 @@ enum forms_prop { JSP_FORMS_LENGTH = -1, }; JSPropertySpec forms_props[] = { - { "length", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(forms_get_property_length), JSOP_NULLWRAPPER}, + JS_PSG("length", forms_get_property_length, JSPROP_ENUMERATE), { NULL } }; @@ -3103,9 +3128,8 @@ JSPropertySpec forms_props[] = { static void find_form_by_name(JSContext *ctx, JSObject *jsdoc, struct document_view *doc_view, - jsval name, jsval *rval) + unsigned char *string, jsval *rval) { - unsigned char *string = jsval_to_string(ctx, &name); struct form *form; if (!*string) @@ -3121,31 +3145,31 @@ find_form_by_name(JSContext *ctx, JSObject *jsdoc, } /* @forms_class.getProperty */ -static JSBool +static bool forms_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) { ELINKS_CAST_PROP_PARAMS jsid id = hid.get(); jsval idval; - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::RootedObject parent_doc(ctx); /* instance of @document_class */ + JS::RootedObject parent_win(ctx); /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; /* 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, obj, &forms_class, NULL)) - return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &forms_class, NULL)) + return false; parent_doc = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_win = JS_GetParent(parent_doc); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); @@ -3158,32 +3182,34 @@ forms_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS:: strtoll(string, &end, 10); if (end) { + JS::RootedValue r_idval(ctx, idval); /* When SMJS evaluates forms.namedItem("foo"), it first * calls forms_get_property with id = JSString "namedItem" * and *vp = JSObject JSFunction forms_namedItem. * If we don't find a form whose name is id, * we must leave *vp unchanged here, to avoid * "TypeError: forms.namedItem is not a function". */ - JS_IdToValue(ctx, id, &idval); - find_form_by_name(ctx, parent_doc, doc_view, idval, vp); + JS_IdToValue(ctx, id, &r_idval); + unsigned char *string = JS_EncodeString(ctx, JS::ToString(ctx, r_idval)); + find_form_by_name(ctx, parent_doc, doc_view, string, vp); - return JS_TRUE; + return true; } } /* Array index. */ - JS_IdToValue(ctx, id, &idval); + JS::RootedValue r_idval(ctx, idval); + JS_IdToValue(ctx, id, &r_idval); forms_item2(ctx, obj, 1, &idval, vp); - return JS_TRUE; + return true; } -static JSBool -forms_get_property_length(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +forms_get_property_length(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct document *document; @@ -3191,68 +3217,76 @@ forms_get_property_length(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hi /* 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, obj, &forms_class, NULL)) - return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &forms_class, NULL)) + return false; - parent_doc = JS_GetParent(obj); + JS::RootedObject parent_doc(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; - parent_win = JS_GetParent(parent_doc); + JS::RootedObject parent_win(ctx, JS_GetParent(parent_doc)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; document = doc_view->document; - int_to_jsval(ctx, vp, list_size(&document->forms)); + args.rval().setInt32(list_size(&document->forms)); - return JS_TRUE; + return true; } /* @forms_funcs{"item"} */ -static JSBool +static bool forms_item(JSContext *ctx, unsigned int argc, jsval *rval) { jsval val = JSVAL_VOID; JSObject *obj = JS_THIS_OBJECT(ctx, rval); - jsval *argv = JS_ARGV(ctx, rval); - JSBool ret = forms_item2(ctx, obj, argc, argv, &val); + JS::CallArgs args = JS::CallArgsFromVp(argc, rval); +// jsval *argv = JS_ARGV(ctx, rval); + bool ret = forms_item2(ctx, obj, argc, rval, &val); + + args.rval().set(val); - JS_SET_RVAL(ctx, rval, val); return ret; } -static JSBool +static bool forms_item2(JSContext *ctx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval) { - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::RootedObject parent_doc(ctx); /* instance of @document_class */ + JS::RootedObject parent_win(ctx); /* instance of @window_class */ struct view_state *vs; struct form_view *fv; int counter = -1; int index; - if (!JS_InstanceOf(ctx, obj, &forms_class, argv)) - return JS_FALSE; + JS::RootedObject hobj(ctx, obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, argv); + + if (!JS_InstanceOf(ctx, hobj, &forms_class, &args)) + return false; parent_doc = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_win = JS_GetParent(parent_doc); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); if (argc != 1) - return JS_TRUE; + return true; - if (!JS_ValueToInt32(ctx, argv[0], &index)) - return JS_FALSE; + if (!JS::ToInt32(ctx, args[0], &index)) + return false; undef_to_jsval(ctx, rval); @@ -3264,40 +3298,46 @@ forms_item2(JSContext *ctx, JSObject *obj, unsigned int argc, jsval *argv, jsval } } - return JS_TRUE; + return true; } /* @forms_funcs{"namedItem"} */ -static JSBool +static bool forms_namedItem(JSContext *ctx, unsigned int argc, jsval *rval) { jsval val; - JSObject *parent_doc; /* instance of @document_class */ - JSObject *parent_win; /* instance of @window_class */ + JS::RootedObject parent_doc(ctx); /* instance of @document_class */ + JS::RootedObject parent_win(ctx); /* instance of @window_class */ JSObject *obj = JS_THIS_OBJECT(ctx, rval); - jsval *argv = JS_ARGV(ctx, rval); + JS::CallArgs args = JS::CallArgsFromVp(argc, rval); +// jsval *argv = JS_ARGV(ctx, rval); struct view_state *vs; struct document_view *doc_view; - if (!JS_InstanceOf(ctx, obj, &forms_class, argv)) return JS_FALSE; + JS::RootedObject hobj(ctx, obj); + + if (!JS_InstanceOf(ctx, hobj, &forms_class, &args)) return false; parent_doc = JS_GetParent(obj); assert(JS_InstanceOf(ctx, parent_doc, &document_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; parent_win = JS_GetParent(parent_doc); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); doc_view = vs->doc_view; if (argc != 1) - return JS_TRUE; + return true; undef_to_jsval(ctx, &val); - find_form_by_name(ctx, parent_doc, doc_view, argv[0], &val); - JS_SET_RVAL(ctx, rval, val); - return JS_TRUE; + unsigned char *string = JS_EncodeString(ctx, args[0].toString()); + + find_form_by_name(ctx, parent_doc, doc_view, string, &val); + args.rval().set(val); + + return true; } @@ -3330,26 +3370,27 @@ unicode_to_jsstring(JSContext *ctx, unicode_val_T u) /* Convert the string *@vp to an access key. Return 0 for no access * key, UCS_NO_CHAR on error, or the access key otherwise. */ static unicode_val_T -jsval_to_accesskey(JSContext *ctx, jsval *vp) +jsval_to_accesskey(JSContext *ctx, JS::MutableHandleValue hvp) { size_t len; - const char *chr; + const jschar *chr; - /* Convert the value in place, to protect the result from GC. */ - if (JS_ConvertValue(ctx, *vp, JSTYPE_STRING, vp) == JS_FALSE) - return UCS_NO_CHAR; - len = JS_GetStringEncodingLength(ctx, JSVAL_TO_STRING(*vp)); - chr = JS_EncodeString(ctx, JSVAL_TO_STRING(*vp)); + JSString *str = JS::ToString(ctx, hvp); + + len = JS_GetStringLength(str); + chr = JS_GetStringCharsZ(ctx, str); /* This implementation ignores extra characters in the string. */ if (len < 1) return 0; /* which means no access key */ - if (!is_utf16_surrogate(chr[0])) + if (!is_utf16_surrogate(chr[0])) { return chr[0]; + } if (len >= 2 && is_utf16_high_surrogate(chr[0]) - && is_utf16_low_surrogate(chr[1])) + && is_utf16_low_surrogate(chr[1])) { return join_utf16_surrogates(chr[0], chr[1]); + } JS_ReportError(ctx, "Invalid UTF-16 sequence"); return UCS_NO_CHAR; /* which the caller will reject */ } diff --git a/src/ecmascript/spidermonkey/heartbeat.c b/src/ecmascript/spidermonkey/heartbeat.c index 5eb2830b7..e66d0f496 100644 --- a/src/ecmascript/spidermonkey/heartbeat.c +++ b/src/ecmascript/spidermonkey/heartbeat.c @@ -30,17 +30,17 @@ static INIT_LIST_OF(struct heartbeat, heartbeats); static struct itimerval heartbeat_timer = { { 1, 0 }, { 1, 0 } }; -/* This callback is installed by JS_SetOperationCallback and triggered - * by JS_TriggerOperationCallback in the heartbeat code below. Returning - * JS_FALSE terminates script execution immediately. */ -JSBool +/* This callback is installed by JS_SetInterruptCallback and triggered + * by JS_RequestInterruptCallback in the heartbeat code below. Returning + * false terminates script execution immediately. */ +bool heartbeat_callback(JSContext *ctx) { - return JS_FALSE; + return false; } /* Callback for SIGVTALRM. Go through all heartbeats, decrease each - * one's TTL, and call JS_TriggerOperationCallback if a heartbeat's TTL + * one's TTL, and call JS_RequestInterruptCallback if a heartbeat's TTL * goes to 0. */ static void check_heartbeats(void *data) @@ -63,7 +63,7 @@ check_heartbeats(void *data) ecmascript_timeout_dialog(term, max_exec_time); } - JS_TriggerOperationCallback(JS_GetRuntime(hb->interpreter->backend_data)); + JS_RequestInterruptCallback(JS_GetRuntime(hb->interpreter->backend_data)); } } install_signal_handler(SIGVTALRM, check_heartbeats, NULL, 1); diff --git a/src/ecmascript/spidermonkey/heartbeat.h b/src/ecmascript/spidermonkey/heartbeat.h index f7c8b127e..079e0498b 100644 --- a/src/ecmascript/spidermonkey/heartbeat.h +++ b/src/ecmascript/spidermonkey/heartbeat.h @@ -19,6 +19,6 @@ struct heartbeat { struct heartbeat *add_heartbeat(struct ecmascript_interpreter *interpreter); void done_heartbeat(struct heartbeat *hb); -JSBool heartbeat_callback(JSContext *ctx); +bool heartbeat_callback(JSContext *ctx); #endif diff --git a/src/ecmascript/spidermonkey/location.c b/src/ecmascript/spidermonkey/location.c index 33cc6b1d1..7e1cbc5bb 100644 --- a/src/ecmascript/spidermonkey/location.c +++ b/src/ecmascript/spidermonkey/location.c @@ -45,9 +45,9 @@ #include "viewer/text/vs.h" -static JSBool history_back(JSContext *ctx, unsigned int argc, jsval *rval); -static JSBool history_forward(JSContext *ctx, unsigned int argc, jsval *rval); -static JSBool history_go(JSContext *ctx, unsigned int argc, jsval *rval); +static bool history_back(JSContext *ctx, unsigned int argc, jsval *rval); +static bool history_forward(JSContext *ctx, unsigned int argc, jsval *rval); +static bool history_go(JSContext *ctx, unsigned int argc, jsval *rval); JSClass history_class = { "history", @@ -65,12 +65,13 @@ const spidermonkeyFunctionSpec history_funcs[] = { }; /* @history_funcs{"back"} */ -static JSBool +static bool history_back(JSContext *ctx, unsigned int argc, jsval *rval) { struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx); struct document_view *doc_view = interpreter->vs->doc_view; struct session *ses = doc_view->session; + JS::CallArgs args = JS::CallArgsFromVp(argc, rval); go_back(ses); @@ -78,39 +79,42 @@ history_back(JSContext *ctx, unsigned int argc, jsval *rval) * and return non zero for to prevent * "calculating" new link. Returned value 2 is changed to 0 in function * spidermonkey_eval_boolback */ - JS_SET_RVAL(ctx, rval, JSVAL_NULL); + args.rval().setNull(); return 2; } /* @history_funcs{"forward"} */ -static JSBool +static bool history_forward(JSContext *ctx, unsigned int argc, jsval *rval) { struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx); struct document_view *doc_view = interpreter->vs->doc_view; struct session *ses = doc_view->session; + JS::CallArgs args = JS::CallArgsFromVp(argc, rval); go_unback(ses); - JS_SET_RVAL(ctx, rval, JSVAL_NULL); + args.rval().setNull(); return 2; } /* @history_funcs{"go"} */ -static JSBool +static bool history_go(JSContext *ctx, unsigned int argc, jsval *rval) { struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx); struct document_view *doc_view = interpreter->vs->doc_view; struct session *ses = doc_view->session; - jsval *argv = JS_ARGV(ctx, rval); + JS::CallArgs args = JS::CallArgsFromVp(argc, rval); + +// jsval *argv = JS_ARGV(ctx, rval); int index; struct location *loc; if (argc != 1) - return JS_TRUE; + return true; - index = atol(jsval_to_string(ctx, &argv[0])); + index = atol(jsval_to_string(ctx, args[0].address())); for (loc = cur_loc(ses); loc != (struct location *) &ses->history.history; @@ -123,13 +127,13 @@ history_go(JSContext *ctx, unsigned int argc, jsval *rval) index += index > 0 ? -1 : 1; } - JS_SET_RVAL(ctx, rval, JSVAL_NULL); + args.rval().setNull(); return 2; } -static JSBool location_get_property_href(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool location_set_property_href(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp); +static bool location_get_property_href(JSContext *ctx, unsigned int argc, jsval *vp); +static bool location_set_property_href(JSContext *ctx, unsigned int argc, jsval *vp); /* Each @location_class object must have a @window_class parent. */ JSClass location_class = { @@ -148,63 +152,79 @@ enum location_prop { JSP_LOC_HREF = -1, }; JSPropertySpec location_props[] = { - { "href", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(location_get_property_href), JSOP_WRAPPER(location_set_property_href) }, + JS_PSGS("href", location_get_property_href, location_set_property_href, JSPROP_ENUMERATE), { NULL } }; -static JSBool -location_get_property_href(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +location_get_property_href(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; /* 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, obj, &location_class, NULL)) - return JS_FALSE; - parent_win = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &location_class, NULL)) + return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } - astring_to_jsval(ctx, vp, get_uri_string(vs->uri, URI_ORIGINAL)); + unsigned char *str = get_uri_string(vs->uri, URI_ORIGINAL); - return JS_TRUE; + if (!str) { + return false; + } + + args.rval().setString(JS_NewStringCopyZ(ctx, str)); + mem_free(str); + + return true; } -static JSBool -location_set_property_href(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +location_set_property_href(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - JSObject *parent_win; /* instance of @window_class */ + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); + struct view_state *vs; struct document_view *doc_view; /* 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, obj, &location_class, NULL)) - return JS_FALSE; - parent_win = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &location_class, NULL)) + return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return; + } doc_view = vs->doc_view; - location_goto(doc_view, jsval_to_string(ctx, vp)); + location_goto(doc_view, JS_EncodeString(ctx, args[0].toString())); - return JS_TRUE; + return true; } -static JSBool location_toString(JSContext *ctx, unsigned int argc, jsval *rval); +static bool location_toString(JSContext *ctx, unsigned int argc, jsval *rval); const spidermonkeyFunctionSpec location_funcs[] = { { "toString", location_toString, 0 }, @@ -213,14 +233,17 @@ const spidermonkeyFunctionSpec location_funcs[] = { }; /* @location_funcs{"toString"}, @location_funcs{"toLocaleString"} */ -static JSBool +static bool location_toString(JSContext *ctx, unsigned int argc, jsval *rval) { jsval val; JSObject *obj = JS_THIS_OBJECT(ctx, rval); - JSBool ret = JS_GetProperty(ctx, obj, "href", &val); + JS::CallArgs args = JS::CallArgsFromVp(argc, rval); + JS::RootedObject hobj(ctx, obj); + JS::RootedValue r_val(ctx, val); + bool ret = JS_GetProperty(ctx, hobj, "href", &r_val); - JS_SET_RVAL(ctx, rval, val); + args.rval().set(val); return ret; } diff --git a/src/ecmascript/spidermonkey/navigator.c b/src/ecmascript/spidermonkey/navigator.c index 57f2dccee..e6bd4b12e 100644 --- a/src/ecmascript/spidermonkey/navigator.c +++ b/src/ecmascript/spidermonkey/navigator.c @@ -44,12 +44,12 @@ #include "viewer/text/vs.h" -static JSBool navigator_get_property_appCodeName(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool navigator_get_property_appName(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool navigator_get_property_appVersion(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool navigator_get_property_language(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool navigator_get_property_platform(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool navigator_get_property_userAgent(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); +static bool navigator_get_property_appCodeName(JSContext *ctx, unsigned int argc, jsval *vp); +static bool navigator_get_property_appName(JSContext *ctx, unsigned int argc, jsval *vp); +static bool navigator_get_property_appVersion(JSContext *ctx, unsigned int argc, jsval *vp); +static bool navigator_get_property_language(JSContext *ctx, unsigned int argc, jsval *vp); +static bool navigator_get_property_platform(JSContext *ctx, unsigned int argc, jsval *vp); +static bool navigator_get_property_userAgent(JSContext *ctx, unsigned int argc, jsval *vp); JSClass navigator_class = { "navigator", @@ -74,83 +74,76 @@ enum navigator_prop { JSP_NAVIGATOR_USER_AGENT = -8, }; JSPropertySpec navigator_props[] = { - { "appCodeName",0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(navigator_get_property_appCodeName), JSOP_NULLWRAPPER }, - { "appName", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(navigator_get_property_appName), JSOP_NULLWRAPPER }, - { "appVersion", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(navigator_get_property_appVersion), JSOP_NULLWRAPPER }, - { "language", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(navigator_get_property_language), JSOP_NULLWRAPPER }, - { "platform", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(navigator_get_property_platform), JSOP_NULLWRAPPER }, - { "userAgent", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(navigator_get_property_userAgent), JSOP_NULLWRAPPER }, + JS_PSG("appCodeName", navigator_get_property_appCodeName, JSPROP_ENUMERATE), + JS_PSG("appName", navigator_get_property_appName, JSPROP_ENUMERATE), + JS_PSG("appVersion", navigator_get_property_appVersion, JSPROP_ENUMERATE), + JS_PSG("language", navigator_get_property_language, JSPROP_ENUMERATE), + JS_PSG("platform", navigator_get_property_platform, JSPROP_ENUMERATE), + JS_PSG("userAgent", navigator_get_property_userAgent, JSPROP_ENUMERATE), { NULL } }; /* @navigator_class.getProperty */ -static JSBool -navigator_get_property_appCodeName(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +navigator_get_property_appCodeName(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - (void)obj; + JS::CallArgs args = CallArgsFromVp(argc, vp); + args.rval().setString(JS_NewStringCopyZ(ctx, "Mozilla")); /* More like a constant nowadays. */ - string_to_jsval(ctx, vp, "Mozilla"); /* More like a constant nowadays. */ - - return JS_TRUE; + return true; } -static JSBool -navigator_get_property_appName(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +navigator_get_property_appName(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - (void)obj; + JS::CallArgs args = CallArgsFromVp(argc, vp); + args.rval().setString(JS_NewStringCopyZ(ctx, + "ELinks (roughly compatible with Netscape Navigator, Mozilla and Microsoft Internet Explorer)")); - string_to_jsval(ctx, vp, "ELinks (roughly compatible with Netscape Navigator, Mozilla and Microsoft Internet Explorer)"); - - return JS_TRUE; + return true; } -static JSBool -navigator_get_property_appVersion(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +navigator_get_property_appVersion(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - (void)obj; + JS::CallArgs args = CallArgsFromVp(argc, vp); + args.rval().setString(JS_NewStringCopyZ(ctx, VERSION)); - string_to_jsval(ctx, vp, VERSION); - - return JS_TRUE; + return true; } -static JSBool -navigator_get_property_language(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +navigator_get_property_language(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - (void)obj; + JS::CallArgs args = CallArgsFromVp(argc, vp); - undef_to_jsval(ctx, vp); #ifdef CONFIG_NLS - if (get_opt_bool("protocol.http.accept_ui_language", NULL)) - string_to_jsval(ctx, vp, language_to_iso639(current_language)); - + if (get_opt_bool("protocol.http.accept_ui_language", NULL)) { + args.rval().setString(JS_NewStringCopyZ(ctx, language_to_iso639(current_language))); + return true; + } #endif - return JS_TRUE; + args.rval().setUndefined(); + + return true; } -static JSBool -navigator_get_property_platform(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +navigator_get_property_platform(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - (void)obj; + JS::CallArgs args = CallArgsFromVp(argc, vp); + args.rval().setString(JS_NewStringCopyZ(ctx, system_name)); - string_to_jsval(ctx, vp, system_name); - - return JS_TRUE; + return true; } -static JSBool -navigator_get_property_userAgent(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +navigator_get_property_userAgent(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); unsigned char *optstr; - (void)obj; optstr = get_opt_str("protocol.http.user_agent", NULL); @@ -173,12 +166,12 @@ navigator_get_property_userAgent(JSContext *ctx, JS::HandleObject hobj, JS::Hand if (ustr) { safe_strncpy(custr, ustr, 256); mem_free(ustr); - string_to_jsval(ctx, vp, custr); + args.rval().setString(JS_NewStringCopyZ(ctx, custr)); - return JS_TRUE; + return true; } } - string_to_jsval(ctx, vp, system_name); + args.rval().setString(JS_NewStringCopyZ(ctx, system_name)); - return JS_TRUE; + return true; } diff --git a/src/ecmascript/spidermonkey/unibar.c b/src/ecmascript/spidermonkey/unibar.c index 2a12829f2..a9f1b2176 100644 --- a/src/ecmascript/spidermonkey/unibar.c +++ b/src/ecmascript/spidermonkey/unibar.c @@ -44,8 +44,8 @@ #include "viewer/text/link.h" #include "viewer/text/vs.h" -static JSBool unibar_get_property_visible(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool unibar_set_property_visible(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp); +static bool unibar_get_property_visible(JSContext *ctx, unsigned int argc, jsval *vp); +static bool unibar_set_property_visible(JSContext *ctx, unsigned int argc, jsval *vp); /* Each @menubar_class object must have a @window_class parent. */ JSClass menubar_class = { @@ -72,18 +72,18 @@ enum unibar_prop { JSP_UNIBAR_VISIBLE = -1, }; JSPropertySpec unibar_props[] = { - { "visible", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(unibar_get_property_visible), JSOP_WRAPPER(unibar_set_property_visible) }, + JS_PSGS("visible", unibar_get_property_visible, unibar_set_property_visible, JSPROP_ENUMERATE), { NULL } }; -static JSBool -unibar_get_property_visible(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +unibar_get_property_visible(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct session_status *status; @@ -92,45 +92,49 @@ unibar_get_property_visible(JSContext *ctx, JS::HandleObject hobj, JS::HandleId /* This can be called if @obj if not itself an instance of either * appropriate class but has one in its prototype chain. Fail * such calls. */ - if (!JS_InstanceOf(ctx, obj, &menubar_class, NULL) - && !JS_InstanceOf(ctx, obj, &statusbar_class, NULL)) - return JS_FALSE; - parent_win = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &menubar_class, NULL) + && !JS_InstanceOf(ctx, hobj, &statusbar_class, NULL)) + return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; status = &doc_view->session->status; - bar = JS_GetPrivate(obj); /* from @menubar_class or @statusbar_class */ + bar = JS_GetPrivate(hobj); /* from @menubar_class or @statusbar_class */ #define unibar_fetch(bar) \ - boolean_to_jsval(ctx, vp, status->force_show_##bar##_bar >= 0 \ + status->force_show_##bar##_bar >= 0 \ ? status->force_show_##bar##_bar \ - : status->show_##bar##_bar) + : status->show_##bar##_bar switch (*bar) { case 's': - unibar_fetch(status); + args.rval().setBoolean(unibar_fetch(status)); break; case 't': - unibar_fetch(title); + args.rval().setBoolean(unibar_fetch(title)); break; default: - boolean_to_jsval(ctx, vp, 0); + args.rval().setBoolean(false); break; } #undef unibar_fetch - return JS_TRUE; + return true; } -static JSBool -unibar_set_property_visible(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +unibar_set_property_visible(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - JSObject *parent_win; /* instance of @window_class */ struct view_state *vs; struct document_view *doc_view; struct session_status *status; @@ -139,30 +143,34 @@ unibar_set_property_visible(JSContext *ctx, JS::HandleObject hobj, JS::HandleId /* This can be called if @obj if not itself an instance of either * appropriate class but has one in its prototype chain. Fail * such calls. */ - if (!JS_InstanceOf(ctx, obj, &menubar_class, NULL) - && !JS_InstanceOf(ctx, obj, &statusbar_class, NULL)) - return JS_FALSE; - parent_win = JS_GetParent(obj); + if (!JS_InstanceOf(ctx, hobj, &menubar_class, NULL) + && !JS_InstanceOf(ctx, hobj, &statusbar_class, NULL)) + return false; + + JS::RootedObject parent_win(ctx, JS_GetParent(hobj)); assert(JS_InstanceOf(ctx, parent_win, &window_class, NULL)); - if_assert_failed return JS_FALSE; + if_assert_failed return false; vs = JS_GetInstancePrivate(ctx, parent_win, &window_class, NULL); + if (!vs) { + return false; + } doc_view = vs->doc_view; status = &doc_view->session->status; - bar = JS_GetPrivate(obj); /* from @menubar_class or @statusbar_class */ + bar = JS_GetPrivate(hobj); /* from @menubar_class or @statusbar_class */ switch (*bar) { case 's': - status->force_show_status_bar = jsval_to_boolean(ctx, vp); + status->force_show_status_bar = args[0].toBoolean(); break; case 't': - status->force_show_title_bar = jsval_to_boolean(ctx, vp); + status->force_show_title_bar = args[0].toBoolean(); break; default: break; } register_bottom_half(update_status, NULL); - return JS_TRUE; + return true; } diff --git a/src/ecmascript/spidermonkey/util.h b/src/ecmascript/spidermonkey/util.h index b02bc20b1..19ea364b2 100644 --- a/src/ecmascript/spidermonkey/util.h +++ b/src/ecmascript/spidermonkey/util.h @@ -56,25 +56,8 @@ boolean_to_jsval(JSContext *ctx, jsval *vp, int boolean) static inline int jsval_to_boolean(JSContext *ctx, jsval *vp) { - jsval val; - - if (JS_ConvertValue(ctx, *vp, JSTYPE_BOOLEAN, &val) == JS_FALSE) { - return JS_FALSE; - } - - return JSVAL_TO_BOOLEAN(val); -} - -static inline JSObject * -jsval_to_object(JSContext *ctx, jsval *vp) -{ - jsval val; - - if (JS_ConvertValue(ctx, *vp, JSTYPE_OBJECT, &val) == JS_FALSE) { - return NULL; - } - - return JSVAL_TO_OBJECT(val); + JS::RootedValue r_vp(ctx, *vp); + return (int)JS::ToBoolean(r_vp); } #endif diff --git a/src/ecmascript/spidermonkey/window.c b/src/ecmascript/spidermonkey/window.c index 517ab4b8d..fffb074fa 100644 --- a/src/ecmascript/spidermonkey/window.c +++ b/src/ecmascript/spidermonkey/window.c @@ -44,14 +44,13 @@ #include "viewer/text/vs.h" -static JSBool window_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool window_get_property_closed(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool window_get_property_parent(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool window_get_property_self(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool window_get_property_status(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool window_set_property_status(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp); -static JSBool window_get_property_top(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); -static JSBool window_get_property_window(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); +static bool window_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp); +static bool window_get_property_closed(JSContext *cx, unsigned int argc, jsval *vp); +static bool window_get_property_parent(JSContext *ctx, unsigned int argc, jsval *vp); +static bool window_get_property_self(JSContext *ctx, unsigned int argc, jsval *vp); +static bool window_get_property_status(JSContext *ctx, unsigned int argc, jsval *vp); +static bool window_set_property_status(JSContext *ctx, unsigned int argc, jsval *vp); +static bool window_get_property_top(JSContext *ctx, unsigned int argc, jsval *vp); JSClass window_class = { "window", @@ -80,12 +79,12 @@ enum window_prop { * assigning to it once), instead we do just a little string * comparing. */ JSPropertySpec window_props[] = { - { "closed", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(window_get_property_closed), JSOP_NULLWRAPPER }, - { "parent", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(window_get_property_parent), JSOP_NULLWRAPPER }, - { "self", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(window_get_property_self), JSOP_NULLWRAPPER }, - { "status", 0, JSPROP_ENUMERATE|JSPROP_SHARED, JSOP_WRAPPER(window_get_property_status), JSOP_WRAPPER(window_set_property_status) }, - { "top", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(window_get_property_top), JSOP_NULLWRAPPER }, - { "window", 0, JSPROP_ENUMERATE | JSPROP_READONLY|JSPROP_SHARED, JSOP_WRAPPER(window_get_property_window), JSOP_NULLWRAPPER }, + JS_PSG("closed", window_get_property_closed, 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), + JS_PSG("top", window_get_property_top, JSPROP_ENUMERATE), + JS_PSG("window", window_get_property_self, JSPROP_ENUMERATE), { NULL } }; @@ -102,7 +101,7 @@ try_resolve_frame(struct document_view *doc_view, unsigned char *id) if (target->vs.ecmascript_fragile) ecmascript_reset_state(&target->vs); if (!target->vs.ecmascript) return NULL; - return JS_GetGlobalForScopeChain(target->vs.ecmascript->backend_data); + return JS::CurrentGlobalOrNull(target->vs.ecmascript->backend_data); } #if 0 @@ -127,7 +126,7 @@ find_child_frame(struct document_view *doc_view, struct frame_desc *tframe) #endif /* @window_class.getProperty */ -static JSBool +static bool window_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) { ELINKS_CAST_PROP_PARAMS @@ -138,10 +137,10 @@ window_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS: /* 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, obj, &window_class, NULL)) - return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &window_class, NULL)) + return false; - vs = JS_GetInstancePrivate(ctx, obj, &window_class, NULL); + vs = JS_GetInstancePrivate(ctx, hobj, &window_class, NULL); /* No need for special window.location measurements - when * location is then evaluated in string context, toString() @@ -155,11 +154,11 @@ window_get_property(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS: if (obj) { object_to_jsval(ctx, vp, obj); } - return JS_TRUE; + return true; } if (!JSID_IS_INT(id)) - return JS_TRUE; + return true; undef_to_jsval(ctx, vp); @@ -216,7 +215,7 @@ found_parent: } #endif case JSP_WIN_STATUS: - return JS_FALSE; + return false; case JSP_WIN_TOP: { struct document_view *doc_view = vs->doc_view; @@ -228,7 +227,7 @@ found_parent: ecmascript_reset_state(top_view->vs); if (!top_view->vs->ecmascript) break; - newjsframe = JS_GetGlobalForScopeChain(top_view->vs->ecmascript->backend_data); + newjsframe = JS::CurrentGlobalOrNull(top_view->vs->ecmascript->backend_data); /* Keep this unrolled this way. Will have to check document.domain * JS property. */ @@ -247,21 +246,21 @@ found_parent: default: /* Unrecognized integer property ID; someone is using * the object as an array. SMJS builtin classes (e.g. - * js_RegExpClass) just return JS_TRUE in this case + * js_RegExpClass) just return true in this case * and leave *@vp unchanged. Do the same here. * (Actually not quite the same, as we already used * @undef_to_jsval.) */ break; } - return JS_TRUE; + return true; } void location_goto(struct document_view *doc_view, unsigned char *url); -static JSBool window_alert(JSContext *ctx, unsigned int argc, jsval *rval); -static JSBool window_open(JSContext *ctx, unsigned int argc, jsval *rval); -static JSBool window_setTimeout(JSContext *ctx, unsigned int argc, jsval *rval); +static bool window_alert(JSContext *ctx, unsigned int argc, jsval *rval); +static bool window_open(JSContext *ctx, unsigned int argc, jsval *rval); +static bool window_setTimeout(JSContext *ctx, unsigned int argc, jsval *rval); const spidermonkeyFunctionSpec window_funcs[] = { { "alert", window_alert, 1 }, @@ -271,41 +270,44 @@ const spidermonkeyFunctionSpec window_funcs[] = { }; /* @window_funcs{"alert"} */ -static JSBool +static bool window_alert(JSContext *ctx, unsigned int argc, jsval *rval) { jsval val; JSObject *obj = JS_THIS_OBJECT(ctx, rval); - jsval *argv = JS_ARGV(ctx, rval); + JS::RootedObject hobj(ctx, obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, rval); +// jsval *argv = JS_ARGV(ctx, rval); struct view_state *vs; unsigned char *string; - if (!JS_InstanceOf(ctx, obj, &window_class, argv)) return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &window_class, &args)) return false; - vs = JS_GetInstancePrivate(ctx, obj, &window_class, argv); + vs = JS_GetInstancePrivate(ctx, hobj, &window_class, &args); if (argc != 1) - return JS_TRUE; + return true; - string = jsval_to_string(ctx, &argv[0]); + string = jsval_to_string(ctx, args[0].address()); if (!*string) - return JS_TRUE; + return true; info_box(vs->doc_view->session->tab->term, MSGBOX_FREE_TEXT, N_("JavaScript Alert"), ALIGN_CENTER, stracpy(string)); - undef_to_jsval(ctx, &val); - JS_SET_RVAL(ctx, rval, val); - return JS_TRUE; + args.rval().setUndefined(); + return true; } /* @window_funcs{"open"} */ -static JSBool +static bool window_open(JSContext *ctx, unsigned int argc, jsval *rval) { jsval val; JSObject *obj = JS_THIS_OBJECT(ctx, rval); - jsval *argv = JS_ARGV(ctx, rval); + JS::RootedObject hobj(ctx, obj); + JS::CallArgs args = JS::CallArgsFromVp(argc, rval); +// jsval *argv = JS_ARGV(ctx, rval); struct view_state *vs; struct document_view *doc_view; struct session *ses; @@ -315,9 +317,9 @@ window_open(JSContext *ctx, unsigned int argc, jsval *rval) static time_t ratelimit_start; static int ratelimit_count; - if (!JS_InstanceOf(ctx, obj, &window_class, argv)) return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &window_class, &args)) return false; - vs = JS_GetInstancePrivate(ctx, obj, &window_class, argv); + vs = JS_GetInstancePrivate(ctx, hobj, &window_class, &args); doc_view = vs->doc_view; ses = doc_view->session; @@ -325,10 +327,10 @@ window_open(JSContext *ctx, unsigned int argc, jsval *rval) #ifdef CONFIG_LEDS set_led_value(ses->status.popup_led, 'P'); #endif - return JS_TRUE; + return true; } - if (argc < 1) return JS_TRUE; + if (argc < 1) return true; /* Ratelimit window opening. Recursive window.open() is very nice. * We permit at most 20 tabs in 2 seconds. The ratelimiter is very @@ -339,22 +341,22 @@ window_open(JSContext *ctx, unsigned int argc, jsval *rval) } else { ratelimit_count++; if (ratelimit_count > 20) { - return JS_TRUE; + return true; } } - url = stracpy(jsval_to_string(ctx, &argv[0])); + url = stracpy(jsval_to_string(ctx, args[0].address())); trim_chars(url, ' ', 0); url2 = join_urls(doc_view->document->uri, url); mem_free(url); if (!url2) { - return JS_TRUE; + return true; } if (argc > 1) { - frame = stracpy(jsval_to_string(ctx, &argv[1])); + frame = stracpy(jsval_to_string(ctx, args[1].address())); if (!frame) { mem_free(url2); - return JS_TRUE; + return true; } } @@ -364,7 +366,7 @@ window_open(JSContext *ctx, unsigned int argc, jsval *rval) mem_free(url2); if (!uri) { mem_free_if(frame); - return JS_TRUE; + return true; } if (frame && *frame && c_strcasecmp(frame, "_blank")) { @@ -406,39 +408,41 @@ end: done_uri(uri); mem_free_if(frame); - JS_SET_RVAL(ctx, rval, val); - return JS_TRUE; + args.rval().set(val); + return true; } /* @window_funcs{"setTimeout"} */ -static JSBool +static bool window_setTimeout(JSContext *ctx, unsigned int argc, jsval *rval) { - jsval *argv = JS_ARGV(ctx, rval); + JS::CallArgs args = JS::CallArgsFromVp(argc, rval); +// jsval *argv = JS_ARGV(ctx, rval); struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx); unsigned char *code; int timeout; if (argc != 2) - return JS_TRUE; + return true; - code = jsval_to_string(ctx, &argv[0]); + code = jsval_to_string(ctx, args[0].address()); if (!*code) - return JS_TRUE; + return true; code = stracpy(code); if (!code) - return JS_TRUE; - timeout = atoi(jsval_to_string(ctx, &argv[1])); + return true; + timeout = atoi(jsval_to_string(ctx, args[1].address())); if (timeout <= 0) { mem_free(code); - return JS_TRUE; + return true; } ecmascript_set_timeout(interpreter, code, timeout); - return JS_TRUE; + return true; } -static JSBool +#if 0 +static bool window_get_property_closed(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) { ELINKS_CAST_PROP_PARAMS @@ -446,24 +450,28 @@ window_get_property_closed(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h /* 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, obj, &window_class, NULL)) - return JS_FALSE; + if (!JS_InstanceOf(ctx, hobj, &window_class, NULL)) + return false; boolean_to_jsval(ctx, vp, 0); - return JS_TRUE; + return true; +} +#endif + +static bool +window_get_property_closed(JSContext *ctx, unsigned int argc, jsval *vp) +{ + JS::CallArgs args = CallArgsFromVp(argc, vp); + args.rval().setBoolean(false); + + return true; } -static JSBool -window_get_property_parent(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +window_get_property_parent(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS - - /* 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, obj, &window_class, NULL)) - return JS_FALSE; + JS::CallArgs args = CallArgsFromVp(argc, vp); /* XXX: It would be nice if the following worked, yes. * The problem is that we get called at the point where @@ -475,93 +483,79 @@ window_get_property_parent(JSContext *ctx, JS::HandleObject hobj, JS::HandleId h /* FIXME: So now we alias window.parent to window.top, which is * INCORRECT but works for the most common cases of just two * frames. Better something than nothing. */ + args.rval().setUndefined(); - undef_to_jsval(ctx, vp); - - return JS_TRUE; + return true; } -static JSBool -window_get_property_self(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +window_get_property_self(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + args.rval().setObject(args.thisv().toObject()); - /* 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, obj, &window_class, NULL)) - return JS_FALSE; - - object_to_jsval(ctx, vp, obj); - - return JS_TRUE; + return true; } -static JSBool -window_get_property_status(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +window_get_property_status(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + args.rval().setUndefined(); - /* 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, obj, &window_class, NULL)) - return JS_FALSE; - - undef_to_jsval(ctx, vp); - - return JS_TRUE; + return true; } -static JSBool -window_set_property_status(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JSBool strict, JS::MutableHandleValue hvp) +static bool +window_set_property_status(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); + if (args.length() != 1) { + return false; + } - struct view_state *vs; + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - /* 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, obj, &window_class, NULL)) - return JS_FALSE; + struct view_state *vs = JS_GetInstancePrivate(ctx, hobj, &window_class, NULL); - vs = JS_GetInstancePrivate(ctx, obj, &window_class, NULL); + if (!vs) { + return true; + } - mem_free_set(&vs->doc_view->session->status.window_status, stracpy(jsval_to_string(ctx, vp))); + mem_free_set(&vs->doc_view->session->status.window_status, stracpy(JS_EncodeString(ctx, args[0].toString()))); print_screen_status(vs->doc_view->session); - return JS_TRUE; + return true; } -static JSBool -window_get_property_top(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) +static bool +window_get_property_top(JSContext *ctx, unsigned int argc, jsval *vp) { - ELINKS_CAST_PROP_PARAMS + JS::CallArgs args = CallArgsFromVp(argc, vp); struct view_state *vs; struct document_view *doc_view; struct document_view *top_view; JSObject *newjsframe; - /* 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, obj, &window_class, NULL)) - return JS_FALSE; + JS::RootedObject hobj(ctx, &args.thisv().toObject()); - vs = JS_GetInstancePrivate(ctx, obj, &window_class, NULL); + vs = JS_GetInstancePrivate(ctx, hobj, &window_class, NULL); + + if (!vs) { + return false; + } doc_view = vs->doc_view; top_view = doc_view->session->doc_view; - undef_to_jsval(ctx, vp); - assert(top_view && top_view->vs); if (top_view->vs->ecmascript_fragile) ecmascript_reset_state(top_view->vs); - if (!top_view->vs->ecmascript) - return JS_TRUE; - newjsframe = JS_GetGlobalForScopeChain(top_view->vs->ecmascript->backend_data); + if (!top_view->vs->ecmascript) { + args.rval().setUndefined(); + return true; + } + newjsframe = JS::CurrentGlobalOrNull(top_view->vs->ecmascript->backend_data); /* Keep this unrolled this way. Will have to check document.domain * JS property. */ @@ -569,18 +563,14 @@ window_get_property_top(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, * is alien but some other child window is not, we should still * let the script walk thru. That'd mean moving the check to * other individual properties in this switch. */ - if (compare_uri(vs->uri, top_view->vs->uri, URI_HOST)) - object_to_jsval(ctx, vp, newjsframe); + if (compare_uri(vs->uri, top_view->vs->uri, URI_HOST)) { + args.rval().setObject(*newjsframe); + return true; + } /* else */ /****X*X*X*** SECURITY VIOLATION! RED ALERT, SHIELDS UP! ***X*X*X****\ |* (Pasky was apparently looking at the Links2 JS code . ___ ^.^ *| \* for too long.) `.(,_,)\o/ */ - - return JS_TRUE; -} - -static JSBool -window_get_property_window(JSContext *ctx, JS::HandleObject hobj, JS::HandleId hid, JS::MutableHandleValue hvp) -{ - return window_get_property_self(ctx, hobj, hid, hvp); + args.rval().setUndefined(); + return true; }