From dd7bb24003ec188035747d7fd4fc15495a357362 Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Mon, 17 Mar 2014 16:17:58 +0000 Subject: [PATCH] Bug 959787 - Handlify some friend and debug APIs r=sfink r=bholley --- dom/bindings/BindingUtils.cpp | 2 +- js/jsd/jsd_val.cpp | 3 +-- js/public/OldDebugAPI.h | 10 ++++---- js/src/builtin/TestingFunctions.cpp | 3 ++- js/src/jsapi-tests/testCloneScript.cpp | 2 +- js/src/jsapi-tests/testOriginPrincipals.cpp | 3 ++- js/src/jsapi-tests/testXDR.cpp | 3 ++- js/src/jsfriendapi.cpp | 14 ++++------- js/src/jsfriendapi.h | 13 +++++----- js/src/jsobj.cpp | 4 +-- js/src/jsweakmap.cpp | 6 ++--- js/src/vm/Debugger.cpp | 4 +-- js/src/vm/Debugger.h | 2 +- js/src/vm/OldDebugAPI.cpp | 27 +++++++++------------ js/xpconnect/src/XPCComponents.cpp | 3 ++- js/xpconnect/src/XPCWrappedNative.cpp | 3 ++- js/xpconnect/src/nsXPConnect.cpp | 7 ++++-- js/xpconnect/wrappers/XrayWrapper.cpp | 4 +-- 18 files changed, 55 insertions(+), 58 deletions(-) diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index 24304f7d75b..21c5ebcd686 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -1765,7 +1765,7 @@ ReparentWrapper(JSContext* aCx, JS::Handle aObjArg) cache->SetPreservingWrapper(preserving); if (propertyHolder) { - JSObject* copyTo; + JS::Rooted copyTo(aCx); if (isProxy) { copyTo = DOMProxyHandler::EnsureExpandoObject(aCx, aObj); } else { diff --git a/js/jsd/jsd_val.cpp b/js/jsd/jsd_val.cpp index 87a9fc00fb5..0bad4583363 100644 --- a/js/jsd/jsd_val.cpp +++ b/js/jsd/jsd_val.cpp @@ -678,7 +678,6 @@ jsd_GetScriptForValue(JSDContext* jsdc, JSDValue* jsdval) { AutoSafeJSContext cx; JS::RootedValue val(cx, jsdval->val); - JSFunction* fun = nullptr; JS::RootedScript script(cx); JSDScript* jsdscript; @@ -688,7 +687,7 @@ jsd_GetScriptForValue(JSDContext* jsdc, JSDValue* jsdval) { JSAutoCompartment ac(cx, JSVAL_TO_OBJECT(val)); AutoSaveExceptionState as(cx); - fun = JSD_GetValueFunction(jsdc, jsdval); + JS::RootedFunction fun(cx, JSD_GetValueFunction(jsdc, jsdval)); if (fun) script = JS_GetFunctionScript(cx, fun); } diff --git a/js/public/OldDebugAPI.h b/js/public/OldDebugAPI.h index daf2c897437..a0bd24089f3 100644 --- a/js/public/OldDebugAPI.h +++ b/js/public/OldDebugAPI.h @@ -225,8 +225,8 @@ JS_ClearInterrupt(JSRuntime *rt, JSInterruptHook *handlerp, void **closurep); /************************************************************************/ extern JS_PUBLIC_API(bool) -JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsid id, - JSWatchPointHandler handler, JSObject *closure); +JS_SetWatchPoint(JSContext *cx, JS::HandleObject obj, JS::HandleId id, + JSWatchPointHandler handler, JS::HandleObject closure); extern JS_PUBLIC_API(bool) JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsid id, @@ -272,7 +272,7 @@ extern JS_PUBLIC_API(void) JS_ReleaseFunctionLocalNameArray(JSContext *cx, void *mark); extern JS_PUBLIC_API(JSScript *) -JS_GetFunctionScript(JSContext *cx, JSFunction *fun); +JS_GetFunctionScript(JSContext *cx, JS::HandleFunction fun); extern JS_PUBLIC_API(JSNative) JS_GetFunctionNative(JSContext *cx, JSFunction *fun); @@ -360,7 +360,7 @@ typedef struct JSPropertyDescArray { typedef struct JSScopeProperty JSScopeProperty; extern JS_PUBLIC_API(bool) -JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda); +JS_GetPropertyDescArray(JSContext *cx, JS::HandleObject obj, JSPropertyDescArray *pda); extern JS_PUBLIC_API(void) JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda); @@ -529,7 +529,7 @@ JS_DefineProfilingFunctions(JSContext *cx, JSObject *obj); /* Defined in vm/Debugger.cpp. */ extern JS_PUBLIC_API(bool) -JS_DefineDebuggerObject(JSContext *cx, JSObject *obj); +JS_DefineDebuggerObject(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(void) JS_DumpPCCounts(JSContext *cx, JSScript *script); diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index 22475d59717..383d2b2e725 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -655,7 +655,8 @@ NondeterministicGetWeakMapKeys(JSContext *cx, unsigned argc, jsval *vp) return false; } RootedObject arr(cx); - if (!JS_NondeterministicGetWeakMapKeys(cx, &args[0].toObject(), arr.address())) + RootedObject mapObj(cx, &args[0].toObject()); + if (!JS_NondeterministicGetWeakMapKeys(cx, mapObj, &arr)) return false; if (!arr) { JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_NOT_EXPECTED_TYPE, diff --git a/js/src/jsapi-tests/testCloneScript.cpp b/js/src/jsapi-tests/testCloneScript.cpp index 5f8a926f91a..8596f2493fc 100644 --- a/js/src/jsapi-tests/testCloneScript.cpp +++ b/js/src/jsapi-tests/testCloneScript.cpp @@ -126,7 +126,7 @@ BEGIN_TEST(test_cloneScriptWithPrincipals) JS::RootedObject cloned(cx); CHECK(cloned = JS_CloneFunctionObject(cx, obj, B)); - JSFunction *fun; + JS::RootedFunction fun(cx); JS::RootedValue clonedValue(cx, JS::ObjectValue(*cloned)); CHECK(fun = JS_ValueToFunction(cx, clonedValue)); diff --git a/js/src/jsapi-tests/testOriginPrincipals.cpp b/js/src/jsapi-tests/testOriginPrincipals.cpp index a846ee4e313..5e3632661f3 100644 --- a/js/src/jsapi-tests/testOriginPrincipals.cpp +++ b/js/src/jsapi-tests/testOriginPrincipals.cpp @@ -89,7 +89,8 @@ testInner(const char *asciiChars, JSPrincipals *principal, JSPrincipals *originP JS::RootedValue rval(cx); CHECK(eval(asciiChars, principal, originPrincipal, &rval)); - JSScript *script = JS_GetFunctionScript(cx, &rval.toObject().as()); + JS::RootedFunction fun(cx, &rval.toObject().as()); + JSScript *script = JS_GetFunctionScript(cx, fun); CHECK(JS_GetScriptPrincipals(script) == principal); CHECK(JS_GetScriptOriginPrincipals(script) == originPrincipal); diff --git a/js/src/jsapi-tests/testXDR.cpp b/js/src/jsapi-tests/testXDR.cpp index aceb8c8b3fb..7a62bd97d86 100644 --- a/js/src/jsapi-tests/testXDR.cpp +++ b/js/src/jsapi-tests/testXDR.cpp @@ -54,7 +54,8 @@ FreezeThaw(JSContext *cx, JS::HandleScript script) static JSScript * GetScript(JSContext *cx, JS::HandleObject funobj) { - return JS_GetFunctionScript(cx, JS_GetObjectFunction(funobj)); + JS::RootedFunction fun(cx, JS_GetObjectFunction(funobj)); + return JS_GetFunctionScript(cx, fun); } static JSObject * diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index 39cff8d3974..f792eafca54 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -80,7 +80,7 @@ JS_SetIsWorkerRuntime(JSRuntime *rt) } JS_FRIEND_API(JSObject *) -JS_FindCompilationScope(JSContext *cx, JSObject *objArg) +JS_FindCompilationScope(JSContext *cx, HandleObject objArg) { RootedObject obj(cx, objArg); @@ -109,10 +109,8 @@ JS_GetObjectFunction(JSObject *obj) } JS_FRIEND_API(bool) -JS_SplicePrototype(JSContext *cx, JSObject *objArg, JSObject *protoArg) +JS_SplicePrototype(JSContext *cx, HandleObject obj, HandleObject proto) { - RootedObject obj(cx, objArg); - RootedObject proto(cx, protoArg); /* * Change the prototype of an object which hasn't been used anywhere * and does not share its type with another object. Unlike JS_SetPrototype, @@ -133,10 +131,9 @@ JS_SplicePrototype(JSContext *cx, JSObject *objArg, JSObject *protoArg) } JS_FRIEND_API(JSObject *) -JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JSObject *protoArg, JSObject *parentArg) +JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, HandleObject proto, + HandleObject parent) { - RootedObject proto(cx, protoArg); - RootedObject parent(cx, parentArg); /* * Create our object with a null proto and then splice in the correct proto * after we setSingletonType, so that we don't pollute the default @@ -288,9 +285,8 @@ DefineHelpProperty(JSContext *cx, HandleObject obj, const char *prop, const char } JS_FRIEND_API(bool) -JS_DefineFunctionsWithHelp(JSContext *cx, JSObject *objArg, const JSFunctionSpecWithHelp *fs) +JS_DefineFunctionsWithHelp(JSContext *cx, HandleObject obj, const JSFunctionSpecWithHelp *fs) { - RootedObject obj(cx, objArg); JS_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment())); CHECK_REQUEST(cx); diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index 30e9eaf2fb8..adbddd2759c 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -53,16 +53,17 @@ extern JS_FRIEND_API(void) JS_SetIsWorkerRuntime(JSRuntime *rt); extern JS_FRIEND_API(JSObject *) -JS_FindCompilationScope(JSContext *cx, JSObject *obj); +JS_FindCompilationScope(JSContext *cx, JS::HandleObject obj); extern JS_FRIEND_API(JSFunction *) JS_GetObjectFunction(JSObject *obj); extern JS_FRIEND_API(bool) -JS_SplicePrototype(JSContext *cx, JSObject *obj, JSObject *proto); +JS_SplicePrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto); extern JS_FRIEND_API(JSObject *) -JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JSObject *proto, JSObject *parent); +JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JS::HandleObject proto, + JS::HandleObject parent); extern JS_FRIEND_API(uint32_t) JS_ObjectCountDynamicSlots(JS::HandleObject obj); @@ -74,7 +75,7 @@ extern JS_FRIEND_API(size_t) JS_GetCustomIteratorCount(JSContext *cx); extern JS_FRIEND_API(bool) -JS_NondeterministicGetWeakMapKeys(JSContext *cx, JSObject *obj, JSObject **ret); +JS_NondeterministicGetWeakMapKeys(JSContext *cx, JS::HandleObject obj, JS::MutableHandleObject ret); /* * Determine whether the given object is backed by a DeadObjectProxy. @@ -185,7 +186,7 @@ js_DumpChars(const jschar *s, size_t n); * restrictions on the compartment of |cx|. */ extern JS_FRIEND_API(bool) -JS_CopyPropertiesFrom(JSContext *cx, JSObject *target, JSObject *obj); +JS_CopyPropertiesFrom(JSContext *cx, JS::HandleObject target, JS::HandleObject obj); /* * Single-property version of the above. This function asserts that an |own| @@ -222,7 +223,7 @@ struct JSFunctionSpecWithHelp { {nullptr, nullptr, 0, 0, nullptr, nullptr} extern JS_FRIEND_API(bool) -JS_DefineFunctionsWithHelp(JSContext *cx, JSObject *obj, const JSFunctionSpecWithHelp *fs); +JS_DefineFunctionsWithHelp(JSContext *cx, JS::HandleObject obj, const JSFunctionSpecWithHelp *fs); namespace js { diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index 1a8e5871ff0..73c7ea19d31 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -1748,10 +1748,8 @@ JS_CopyPropertyFrom(JSContext *cx, HandleId id, HandleObject target, } JS_FRIEND_API(bool) -JS_CopyPropertiesFrom(JSContext *cx, JSObject *targetArg, JSObject *objArg) +JS_CopyPropertiesFrom(JSContext *cx, HandleObject target, HandleObject obj) { - RootedObject target(cx, targetArg); - RootedObject obj(cx, objArg); JSAutoCompartment ac(cx, obj); AutoIdVector props(cx); diff --git a/js/src/jsweakmap.cpp b/js/src/jsweakmap.cpp index 845f21de57b..5bae62d0a59 100644 --- a/js/src/jsweakmap.cpp +++ b/js/src/jsweakmap.cpp @@ -350,12 +350,12 @@ WeakMap_set(JSContext *cx, unsigned argc, Value *vp) } JS_FRIEND_API(bool) -JS_NondeterministicGetWeakMapKeys(JSContext *cx, JSObject *objArg, JSObject **ret) +JS_NondeterministicGetWeakMapKeys(JSContext *cx, HandleObject objArg, MutableHandleObject ret) { RootedObject obj(cx, objArg); obj = UncheckedUnwrap(obj); if (!obj || !obj->is()) { - *ret = nullptr; + ret.set(nullptr); return true; } RootedObject arr(cx, NewDenseEmptyArray(cx)); @@ -373,7 +373,7 @@ JS_NondeterministicGetWeakMapKeys(JSContext *cx, JSObject *objArg, JSObject **re return false; } } - *ret = arr; + ret.set(arr); return true; } diff --git a/js/src/vm/Debugger.cpp b/js/src/vm/Debugger.cpp index ae5febd63c9..284e2b43676 100644 --- a/js/src/vm/Debugger.cpp +++ b/js/src/vm/Debugger.cpp @@ -5895,10 +5895,8 @@ static const JSFunctionSpec DebuggerEnv_methods[] = { /*** Glue ****************************************************************************************/ extern JS_PUBLIC_API(bool) -JS_DefineDebuggerObject(JSContext *cx, JSObject *obj_) +JS_DefineDebuggerObject(JSContext *cx, HandleObject obj) { - RootedObject obj(cx, obj_); - RootedObject objProto(cx), debugCtor(cx), diff --git a/js/src/vm/Debugger.h b/js/src/vm/Debugger.h index 6eb8fd4d93e..3f2d1b683d1 100644 --- a/js/src/vm/Debugger.h +++ b/js/src/vm/Debugger.h @@ -159,7 +159,7 @@ class Debugger : private mozilla::LinkedListElement { friend class Breakpoint; friend class mozilla::LinkedListElement; - friend bool (::JS_DefineDebuggerObject)(JSContext *cx, JSObject *obj); + friend bool (::JS_DefineDebuggerObject)(JSContext *cx, JS::HandleObject obj); public: enum Hook { diff --git a/js/src/vm/OldDebugAPI.cpp b/js/src/vm/OldDebugAPI.cpp index 47cf0dc4cab..3441305b220 100644 --- a/js/src/vm/OldDebugAPI.cpp +++ b/js/src/vm/OldDebugAPI.cpp @@ -294,13 +294,11 @@ JS_ClearInterrupt(JSRuntime *rt, JSInterruptHook *hoop, void **closurep) /************************************************************************/ JS_PUBLIC_API(bool) -JS_SetWatchPoint(JSContext *cx, JSObject *obj_, jsid id_, - JSWatchPointHandler handler, JSObject *closure_) +JS_SetWatchPoint(JSContext *cx, HandleObject origobj, HandleId id, + JSWatchPointHandler handler, HandleObject closure) { - assertSameCompartment(cx, obj_); + assertSameCompartment(cx, origobj); - RootedId id(cx, id_); - RootedObject origobj(cx, obj_), closure(cx, closure_); RootedObject obj(cx, GetInnerObject(cx, origobj)); if (!obj) return false; @@ -496,14 +494,13 @@ JS_ReleaseFunctionLocalNameArray(JSContext *cx, void *mem) } JS_PUBLIC_API(JSScript *) -JS_GetFunctionScript(JSContext *cx, JSFunction *fun) +JS_GetFunctionScript(JSContext *cx, HandleFunction fun) { if (fun->isNative()) return nullptr; if (fun->isInterpretedLazy()) { - RootedFunction rootedFun(cx, fun); - AutoCompartment funCompartment(cx, rootedFun); - JSScript *script = rootedFun->getOrCreateScript(cx); + AutoCompartment funCompartment(cx, fun); + JSScript *script = fun->getOrCreateScript(cx); if (!script) MOZ_CRASH(); return script; @@ -659,10 +656,8 @@ GetPropertyDesc(JSContext *cx, JSObject *obj_, HandleShape shape, JSPropertyDesc } JS_PUBLIC_API(bool) -JS_GetPropertyDescArray(JSContext *cx, JSObject *obj_, JSPropertyDescArray *pda) +JS_GetPropertyDescArray(JSContext *cx, JS::HandleObject obj, JSPropertyDescArray *pda) { - RootedObject obj(cx, obj_); - assertSameCompartment(cx, obj); uint32_t i = 0; JSPropertyDesc *pd = nullptr; @@ -995,7 +990,7 @@ class AutoPropertyDescArray JS_PutPropertyDescArray(cx_, &descArray_); } - void fetch(JSObject *obj) { + void fetch(JS::HandleObject obj) { JS_ASSERT(!descArray_.array); if (!JS_GetPropertyDescArray(cx_, obj, &descArray_)) descArray_.array = nullptr; @@ -1059,8 +1054,10 @@ FormatFrame(JSContext *cx, const NonBuiltinScriptFrameIter &iter, char *buf, int AutoPropertyDescArray thisProps(cx); if (iter.computeThis(cx)) { thisVal = iter.thisv(); - if (showThisProps && !thisVal.isPrimitive()) - thisProps.fetch(&thisVal.toObject()); + if (showThisProps && !thisVal.isPrimitive()) { + RootedObject thisObj(cx, &thisVal.toObject()); + thisProps.fetch(thisObj); + } } // print the frame number and function name diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index c12b08dda83..324c27fc301 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -2881,7 +2881,8 @@ nsXPCComponents_Utils::NondeterministicGetWeakMapKeys(HandleValue aMap, return NS_OK; } RootedObject objRet(aCx); - if (!JS_NondeterministicGetWeakMapKeys(aCx, &aMap.toObject(), objRet.address())) + RootedObject mapObj(aCx, &aMap.toObject()); + if (!JS_NondeterministicGetWeakMapKeys(aCx, mapObj, &objRet)) return NS_ERROR_OUT_OF_MEMORY; aKeys.set(objRet ? ObjectValue(*objRet) : UndefinedValue()); return NS_OK; diff --git a/js/xpconnect/src/XPCWrappedNative.cpp b/js/xpconnect/src/XPCWrappedNative.cpp index 9dddd229dbf..7501832b226 100644 --- a/js/xpconnect/src/XPCWrappedNative.cpp +++ b/js/xpconnect/src/XPCWrappedNative.cpp @@ -194,7 +194,8 @@ XPCWrappedNative::WrapNewGlobal(xpcObjectHelper &nativeHelper, // Set up the prototype on the global. MOZ_ASSERT(proto->GetJSProtoObject()); - bool success = JS_SplicePrototype(cx, global, proto->GetJSProtoObject()); + RootedObject protoObj(cx, proto->GetJSProtoObject()); + bool success = JS_SplicePrototype(cx, global, protoObj); if (!success) return NS_ERROR_FAILURE; diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index 05a9f2299e7..dfb77f926a4 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -1354,8 +1354,11 @@ WriteScriptOrFunction(nsIObjectOutputStream *stream, JSContext *cx, // Exactly one of script or functionObj must be given MOZ_ASSERT(!scriptArg != !functionObj); - RootedScript script(cx, scriptArg ? scriptArg : - JS_GetFunctionScript(cx, JS_GetObjectFunction(functionObj))); + RootedScript script(cx, scriptArg); + if (!script) { + RootedFunction fun(cx, JS_GetObjectFunction(functionObj)); + script.set(JS_GetFunctionScript(cx, fun)); + } nsIPrincipal *principal = nsJSPrincipals::get(JS_GetScriptPrincipals(script)); diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index 219d6ae4cbb..03d21cc798c 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -487,8 +487,8 @@ XrayTraits::cloneExpandoChain(JSContext *cx, HandleObject dst, HandleObject src) .toObjectOrNull()); if (!JS_WrapObject(cx, &exclusive)) return false; - JSObject *newHead = attachExpandoObject(cx, dst, GetExpandoObjectPrincipal(oldHead), - exclusive); + RootedObject newHead(cx, attachExpandoObject(cx, dst, GetExpandoObjectPrincipal(oldHead), + exclusive)); if (!JS_CopyPropertiesFrom(cx, newHead, oldHead)) return false; oldHead = JS_GetReservedSlot(oldHead, JSSLOT_EXPANDO_NEXT).toObjectOrNull();