From 3e811f8ee0e25892ea500b6fb82caa8a7869916c Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Wed, 2 Apr 2014 15:28:03 +0100 Subject: [PATCH] Bug 959787 - Handlify remaining JS APIs r=sfink r=bholley r=smaug --- dom/base/nsDOMClassInfo.cpp | 5 +-- dom/base/nsGlobalWindow.cpp | 8 ++-- dom/base/nsJSEnvironment.cpp | 3 +- dom/plugins/base/nsJSNPRuntime.cpp | 5 ++- dom/workers/WorkerPrivate.cpp | 3 +- ipc/nfc/Nfc.cpp | 2 +- ipc/ril/Ril.cpp | 2 +- js/ipc/JavaScriptShared.cpp | 2 +- js/jsd/jsd_scpt.cpp | 5 ++- js/public/OldDebugAPI.h | 4 +- js/public/StructuredClone.h | 2 +- js/src/jsapi-tests/testDebugger.cpp | 3 +- js/src/jsapi.cpp | 32 ++++++++-------- js/src/jsapi.h | 21 ++++++----- js/src/jsfriendapi.cpp | 6 +-- js/src/jsfriendapi.h | 5 ++- js/src/shell/js.cpp | 2 +- js/src/vm/ArrayBufferObject.cpp | 4 +- js/src/vm/OldDebugAPI.cpp | 8 ++-- js/src/vm/StructuredClone.cpp | 5 +-- js/xpconnect/src/Sandbox.cpp | 9 ++--- js/xpconnect/src/XPCComponents.cpp | 45 +++++++++++------------ js/xpconnect/src/XPCMaps.h | 5 ++- js/xpconnect/src/XPCQuickStubs.h | 2 +- js/xpconnect/src/XPCWrappedNative.cpp | 5 +-- storage/src/mozStorageStatementParams.cpp | 6 +-- xpcom/io/nsBinaryStream.cpp | 2 +- 27 files changed, 101 insertions(+), 100 deletions(-) diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 3725a2e97b9..aa060208c49 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -3912,12 +3912,11 @@ nsStorage2SH::NewEnumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx, if (enum_op == JSENUMERATE_NEXT && keys->Length() != 0) { nsString& key = keys->ElementAt(0); - JSString *str = - JS_NewUCStringCopyN(cx, key.get(), key.Length()); + JS::Rooted str(cx, JS_NewUCStringCopyN(cx, key.get(), key.Length())); NS_ENSURE_TRUE(str, NS_ERROR_OUT_OF_MEMORY); JS::Rooted id(cx); - JS_ValueToId(cx, JS::StringValue(str), &id); + JS_StringToId(cx, str, &id); *idp = id; keys->RemoveElementAt(0); diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index bb093e9b880..ecf6fe2fdd8 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -2487,18 +2487,18 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, { JSAutoCompartment ac(cx, mJSObject); - JS_SetParent(cx, mJSObject, newInnerWindow->mJSObject); - JS::Rooted obj(cx, mJSObject); + JS::Rooted newParent(cx, newInnerWindow->mJSObject); + JS_SetParent(cx, obj, newParent); // Inform the nsJSContext, which is the canonical holder of the outer. mContext->SetWindowProxy(obj); NS_ASSERTION(!JS_IsExceptionPending(cx), "We might overwrite a pending exception!"); - XPCWrappedNativeScope* scope = xpc::GetObjectScope(mJSObject); + XPCWrappedNativeScope* scope = xpc::GetObjectScope(obj); if (scope->mWaiverWrapperMap) { - scope->mWaiverWrapperMap->Reparent(cx, newInnerWindow->mJSObject); + scope->mWaiverWrapperMap->Reparent(cx, newParent); } } } diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 446f1bf6f79..1a3d4eca4be 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -2793,9 +2793,10 @@ NS_DOMWriteStructuredClone(JSContext* cx, // Write the internals to the stream. JSAutoCompartment ac(cx, dataArray); + JS::Rooted arrayValue(cx, JS::ObjectValue(*dataArray)); return JS_WriteUint32Pair(writer, SCTAG_DOM_IMAGEDATA, 0) && JS_WriteUint32Pair(writer, width, height) && - JS_WriteTypedArray(writer, JS::ObjectValue(*dataArray)); + JS_WriteTypedArray(writer, arrayValue); } void diff --git a/dom/plugins/base/nsJSNPRuntime.cpp b/dom/plugins/base/nsJSNPRuntime.cpp index 48e76a92d03..9443e27506b 100644 --- a/dom/plugins/base/nsJSNPRuntime.cpp +++ b/dom/plugins/base/nsJSNPRuntime.cpp @@ -871,9 +871,10 @@ nsJSObjWrapper::NP_Enumerate(NPObject *npobj, NPIdentifier **idarray, nsCxPusher pusher; pusher.Push(cx); AutoJSExceptionReporter reporter(cx); - JSAutoCompartment ac(cx, npjsobj->mJSObj); + JS::Rooted jsobj(cx, npjsobj->mJSObj); + JSAutoCompartment ac(cx, jsobj); - JS::AutoIdArray ida(cx, JS_Enumerate(cx, npjsobj->mJSObj)); + JS::AutoIdArray ida(cx, JS_Enumerate(cx, jsobj)); if (!ida) { return false; } diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index dc00b2be91b..165b2142cc5 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -426,9 +426,10 @@ struct WorkerStructuredCloneCallbacks // Write the internals to the stream. JSAutoCompartment ac(aCx, dataArray); + JS::Rooted arrayValue(aCx, JS::ObjectValue(*dataArray)); return JS_WriteUint32Pair(aWriter, SCTAG_DOM_IMAGEDATA, 0) && JS_WriteUint32Pair(aWriter, width, height) && - JS_WriteTypedArray(aWriter, JS::ObjectValue(*dataArray)); + JS_WriteTypedArray(aWriter, arrayValue); } } diff --git a/ipc/nfc/Nfc.cpp b/ipc/nfc/Nfc.cpp index cc6189f6d45..285cd66edc0 100644 --- a/ipc/nfc/Nfc.cpp +++ b/ipc/nfc/Nfc.cpp @@ -91,7 +91,7 @@ PostToNFC(JSContext* aCx, void* data; size_t size; if (JSVAL_IS_STRING(v)) { - JSString* str = JSVAL_TO_STRING(v); + JS::Rooted str(aCx, v.toString()); if (!abs.encodeUtf8(aCx, str)) { return false; } diff --git a/ipc/ril/Ril.cpp b/ipc/ril/Ril.cpp index 84f9b16ad7a..6ccce829c5c 100644 --- a/ipc/ril/Ril.cpp +++ b/ipc/ril/Ril.cpp @@ -96,7 +96,7 @@ PostToRIL(JSContext *aCx, void *data; size_t size; if (JSVAL_IS_STRING(v)) { - JSString *str = JSVAL_TO_STRING(v); + JS::Rooted str(aCx, v.toString()); if (!abs.encodeUtf8(aCx, str)) { return false; } diff --git a/js/ipc/JavaScriptShared.cpp b/js/ipc/JavaScriptShared.cpp index 9f68f046601..295e1902447 100644 --- a/js/ipc/JavaScriptShared.cpp +++ b/js/ipc/JavaScriptShared.cpp @@ -158,7 +158,7 @@ JavaScriptShared::convertGeckoStringToId(JSContext *cx, const nsString &from, JS if (!str) return false; - return JS_ValueToId(cx, StringValue(str), to); + return JS_StringToId(cx, str, to); } bool diff --git a/js/jsd/jsd_scpt.cpp b/js/jsd/jsd_scpt.cpp index 0223bd960bb..ff542f6cf94 100644 --- a/js/jsd/jsd_scpt.cpp +++ b/js/jsd/jsd_scpt.cpp @@ -542,9 +542,10 @@ jsd_EnableSingleStepInterrupts(JSDContext* jsdc, JSDScript* jsdscript, bool enab { bool rv; AutoSafeJSContext cx; - JSAutoCompartment ac(cx, jsdscript->script); + JS::RootedScript script(cx, jsdscript->script); + JSAutoCompartment ac(cx, script); JSD_LOCK(); - rv = JS_SetSingleStepMode(cx, jsdscript->script, enable); + rv = JS_SetSingleStepMode(cx, script, enable); JSD_UNLOCK(); return rv; } diff --git a/js/public/OldDebugAPI.h b/js/public/OldDebugAPI.h index ba4658b3c86..fe5e3368636 100644 --- a/js/public/OldDebugAPI.h +++ b/js/public/OldDebugAPI.h @@ -199,7 +199,7 @@ JS_SetDebugMode(JSContext *cx, bool debug); /* Turn on single step mode. */ extern JS_PUBLIC_API(bool) -JS_SetSingleStepMode(JSContext *cx, JSScript *script, bool singleStep); +JS_SetSingleStepMode(JSContext *cx, JS::HandleScript script, bool singleStep); /* The closure argument will be marked. */ extern JS_PUBLIC_API(bool) @@ -532,7 +532,7 @@ extern JS_PUBLIC_API(bool) JS_DefineDebuggerObject(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(void) -JS_DumpPCCounts(JSContext *cx, JSScript *script); +JS_DumpPCCounts(JSContext *cx, JS::HandleScript script); extern JS_PUBLIC_API(void) JS_DumpCompartmentPCCounts(JSContext *cx); diff --git a/js/public/StructuredClone.h b/js/public/StructuredClone.h index 8e13a898383..f83fd4e83b5 100644 --- a/js/public/StructuredClone.h +++ b/js/public/StructuredClone.h @@ -158,6 +158,6 @@ JS_PUBLIC_API(bool) JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len); JS_PUBLIC_API(bool) -JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::Value v); +JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::HandleValue v); #endif /* js_StructuredClone_h */ diff --git a/js/src/jsapi-tests/testDebugger.cpp b/js/src/jsapi-tests/testDebugger.cpp index c433fd11c99..bf910d23c65 100644 --- a/js/src/jsapi-tests/testDebugger.cpp +++ b/js/src/jsapi-tests/testDebugger.cpp @@ -258,7 +258,8 @@ BEGIN_TEST(testDebugger_singleStepThrow) CallArgs args = CallArgsFromVp(argc, vp); NonBuiltinScriptFrameIter iter(cx); - if (!JS_SetSingleStepMode(cx, iter.script(), true)) + JS::RootedScript script(cx, iter.script()); + if (!JS_SetSingleStepMode(cx, script, true)) return false; args.rval().set(UndefinedValue()); diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index a468714e2b7..5d6ad8247c2 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -2175,15 +2175,24 @@ JS_DestroyIdArray(JSContext *cx, JSIdArray *ida) } JS_PUBLIC_API(bool) -JS_ValueToId(JSContext *cx, jsval valueArg, MutableHandleId idp) +JS_ValueToId(JSContext *cx, HandleValue value, MutableHandleId idp) { - RootedValue value(cx, valueArg); AssertHeapIsIdle(cx); CHECK_REQUEST(cx); assertSameCompartment(cx, value); return ValueToId(cx, value, idp); } +JS_PUBLIC_API(bool) +JS_StringToId(JSContext *cx, HandleString string, MutableHandleId idp) +{ + AssertHeapIsIdle(cx); + CHECK_REQUEST(cx); + assertSameCompartment(cx, string); + RootedValue value(cx, StringValue(string)); + return ValueToId(cx, value, idp); +} + JS_PUBLIC_API(bool) JS_IdToValue(JSContext *cx, jsid id, MutableHandleValue vp) { @@ -2351,10 +2360,8 @@ JS_GetParent(JSObject *obj) } JS_PUBLIC_API(bool) -JS_SetParent(JSContext *cx, JSObject *objArg, JSObject *parentArg) +JS_SetParent(JSContext *cx, HandleObject obj, HandleObject parent) { - RootedObject obj(cx, objArg); - RootedObject parent(cx, parentArg); AssertHeapIsIdle(cx); CHECK_REQUEST(cx); JS_ASSERT(!obj->is()); @@ -3310,11 +3317,9 @@ JS_GetElement(JSContext *cx, HandleObject objArg, uint32_t index, MutableHandleV } JS_PUBLIC_API(bool) -JS_ForwardGetElementTo(JSContext *cx, JSObject *objArg, uint32_t index, JSObject *onBehalfOfArg, +JS_ForwardGetElementTo(JSContext *cx, HandleObject obj, uint32_t index, HandleObject onBehalfOf, MutableHandleValue vp) { - RootedObject obj(cx, objArg); - RootedObject onBehalfOf(cx, onBehalfOfArg); AssertHeapIsIdle(cx); CHECK_REQUEST(cx); assertSameCompartment(cx, obj); @@ -3512,9 +3517,8 @@ LastConfigurableShape(JSObject *obj) } JS_PUBLIC_API(void) -JS_ClearNonGlobalObject(JSContext *cx, JSObject *objArg) +JS_ClearNonGlobalObject(JSContext *cx, HandleObject obj) { - RootedObject obj(cx, objArg); AssertHeapIsIdle(cx); CHECK_REQUEST(cx); assertSameCompartment(cx, obj); @@ -3563,9 +3567,8 @@ JS_SetAllNonReservedSlotsToUndefined(JSContext *cx, JSObject *objArg) } JS_PUBLIC_API(JSIdArray *) -JS_Enumerate(JSContext *cx, JSObject *objArg) +JS_Enumerate(JSContext *cx, HandleObject obj) { - RootedObject obj(cx, objArg); AssertHeapIsIdle(cx); CHECK_REQUEST(cx); assertSameCompartment(cx, obj); @@ -4978,9 +4981,8 @@ JS::Call(JSContext *cx, HandleValue thisv, HandleValue fval, const JS::HandleVal } JS_PUBLIC_API(JSObject *) -JS_New(JSContext *cx, JSObject *ctorArg, const JS::HandleValueArray& inputArgs) +JS_New(JSContext *cx, HandleObject ctor, const JS::HandleValueArray& inputArgs) { - RootedObject ctor(cx, ctorArg); AssertHeapIsIdle(cx); CHECK_REQUEST(cx); assertSameCompartment(cx, ctor, inputArgs); @@ -5387,7 +5389,7 @@ JS_EncodeString(JSContext *cx, JSString *str) } JS_PUBLIC_API(char *) -JS_EncodeStringToUTF8(JSContext *cx, JSString *str) +JS_EncodeStringToUTF8(JSContext *cx, HandleString str) { AssertHeapIsIdle(cx); CHECK_REQUEST(cx); diff --git a/js/src/jsapi.h b/js/src/jsapi.h index e2d37c15191..dcc0fbcb81b 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -2273,7 +2273,10 @@ class AutoIdArray : private AutoGCRooter } /* namespace JS */ extern JS_PUBLIC_API(bool) -JS_ValueToId(JSContext *cx, jsval v, JS::MutableHandle idp); +JS_ValueToId(JSContext *cx, JS::HandleValue v, JS::MutableHandleId idp); + +extern JS_PUBLIC_API(bool) +JS_StringToId(JSContext *cx, JS::HandleString s, JS::MutableHandleId idp); extern JS_PUBLIC_API(bool) JS_IdToValue(JSContext *cx, jsid id, JS::MutableHandle vp); @@ -2520,7 +2523,7 @@ extern JS_PUBLIC_API(JSObject *) JS_GetParent(JSObject *obj); extern JS_PUBLIC_API(bool) -JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent); +JS_SetParent(JSContext *cx, JS::HandleObject obj, JS::HandleObject parent); extern JS_PUBLIC_API(JSObject *) JS_GetConstructor(JSContext *cx, JS::Handle proto); @@ -2722,7 +2725,7 @@ extern JS_PUBLIC_API(bool) JS_PreventExtensions(JSContext *cx, JS::HandleObject obj); extern JS_PUBLIC_API(JSObject *) -JS_New(JSContext *cx, JSObject *ctor, const JS::HandleValueArray& args); +JS_New(JSContext *cx, JS::HandleObject ctor, const JS::HandleValueArray& args); extern JS_PUBLIC_API(JSObject *) JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, const JSClass *clasp, @@ -3037,8 +3040,8 @@ extern JS_PUBLIC_API(bool) JS_GetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) -JS_ForwardGetElementTo(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf, - JS::MutableHandleValue vp); +JS_ForwardGetElementTo(JSContext *cx, JS::HandleObject obj, uint32_t index, + JS::HandleObject onBehalfOf, JS::MutableHandleValue vp); extern JS_PUBLIC_API(bool) JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue v); @@ -3069,7 +3072,7 @@ JS_DeleteElement2(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *suc * assign undefined to all writable data properties. */ JS_PUBLIC_API(void) -JS_ClearNonGlobalObject(JSContext *cx, JSObject *objArg); +JS_ClearNonGlobalObject(JSContext *cx, JS::HandleObject obj); /* * Assign 'undefined' to all of the object's non-reserved slots. Note: this is @@ -3113,7 +3116,7 @@ extern JS_PUBLIC_API(void *) JS_ReallocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void *oldContents, uint32_t oldNbytes); extern JS_PUBLIC_API(JSIdArray *) -JS_Enumerate(JSContext *cx, JSObject *obj); +JS_Enumerate(JSContext *cx, JS::HandleObject obj); /* * Create an object to iterate over enumerable properties of obj, in arbitrary @@ -4055,7 +4058,7 @@ JS_EncodeString(JSContext *cx, JSString *str); * Same behavior as JS_EncodeString(), but encode into UTF-8 string */ JS_PUBLIC_API(char *) -JS_EncodeStringToUTF8(JSContext *cx, JSString *str); +JS_EncodeStringToUTF8(JSContext *cx, JS::HandleString str); /* * Get number of bytes in the string encoding (without accounting for a @@ -4112,7 +4115,7 @@ class JSAutoByteString char *encodeLatin1(js::ExclusiveContext *cx, JSString *str); - char *encodeUtf8(JSContext *cx, JSString *str) { + char *encodeUtf8(JSContext *cx, JS::HandleString str) { JS_ASSERT(!mBytes); JS_ASSERT(cx); mBytes = JS_EncodeStringToUTF8(cx, str); diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index 4618377899e..66c1d732161 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -683,11 +683,9 @@ JS_SetAccumulateTelemetryCallback(JSRuntime *rt, JSAccumulateTelemetryDataCallba } JS_FRIEND_API(JSObject *) -JS_CloneObject(JSContext *cx, JSObject *obj_, JSObject *proto_, JSObject *parent_) +JS_CloneObject(JSContext *cx, HandleObject obj, HandleObject protoArg, HandleObject parent) { - RootedObject obj(cx, obj_); - Rooted proto(cx, proto_); - RootedObject parent(cx, parent_); + Rooted proto(cx, protoArg.get()); return CloneObject(cx, obj, proto, parent); } diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index e5bf5e98ee6..07f5ceb6e6d 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -133,7 +133,8 @@ extern JS_FRIEND_API(JSObject *) JS_ObjectToOuterObject(JSContext *cx, JS::HandleObject obj); extern JS_FRIEND_API(JSObject *) -JS_CloneObject(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent); +JS_CloneObject(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto, + JS::HandleObject parent); extern JS_FRIEND_API(JSString *) JS_BasicObjectToString(JSContext *cx, JS::HandleObject obj); @@ -1416,7 +1417,7 @@ JS_GetFloat64ArrayData(JSObject *obj); * as the object is live. */ extern JS_FRIEND_API(uint8_t *) -JS_GetStableArrayBufferData(JSContext *cx, JSObject *obj); +JS_GetStableArrayBufferData(JSContext *cx, JS::HandleObject obj); /* * Same as above, but for any kind of ArrayBufferView. Prefer the type-specific diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index cca773ed4d8..83c87589e5f 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -872,7 +872,7 @@ ParseCompileOptions(JSContext *cx, CompileOptions &options, HandleObject opts, if (!JS_GetProperty(cx, opts, "sourcePolicy", &v)) return false; if (!v.isUndefined()) { - JSString *s = ToString(cx, v); + RootedString s(cx, ToString(cx, v)); if (!s) return false; diff --git a/js/src/vm/ArrayBufferObject.cpp b/js/src/vm/ArrayBufferObject.cpp index ef87c77d12d..209bd54dddf 100644 --- a/js/src/vm/ArrayBufferObject.cpp +++ b/js/src/vm/ArrayBufferObject.cpp @@ -955,9 +955,9 @@ JS_GetArrayBufferData(JSObject *obj) } JS_FRIEND_API(uint8_t *) -JS_GetStableArrayBufferData(JSContext *cx, JSObject *obj) +JS_GetStableArrayBufferData(JSContext *cx, HandleObject objArg) { - obj = CheckedUnwrap(obj); + JSObject *obj = CheckedUnwrap(objArg); if (!obj) return nullptr; diff --git a/js/src/vm/OldDebugAPI.cpp b/js/src/vm/OldDebugAPI.cpp index cd26624d116..47e97046295 100644 --- a/js/src/vm/OldDebugAPI.cpp +++ b/js/src/vm/OldDebugAPI.cpp @@ -211,9 +211,8 @@ CheckDebugMode(JSContext *cx) } JS_PUBLIC_API(bool) -JS_SetSingleStepMode(JSContext *cx, JSScript *scriptArg, bool singleStep) +JS_SetSingleStepMode(JSContext *cx, HandleScript script, bool singleStep) { - RootedScript script(cx, scriptArg); assertSameCompartment(cx, script); if (!CheckDebugMode(cx)) @@ -819,9 +818,8 @@ JS_GetGlobalDebugHooks(JSRuntime *rt) /************************************************************************/ extern JS_PUBLIC_API(void) -JS_DumpPCCounts(JSContext *cx, JSScript *scriptArg) +JS_DumpPCCounts(JSContext *cx, HandleScript script) { - Rooted script(cx, scriptArg); JS_ASSERT(script->hasScriptCounts()); Sprinter sprinter(cx); @@ -838,7 +836,7 @@ JS_PUBLIC_API(void) JS_DumpCompartmentPCCounts(JSContext *cx) { for (CellIter i(cx->zone(), gc::FINALIZE_SCRIPT); !i.done(); i.next()) { - JSScript *script = i.get(); + RootedScript script(cx, i.get()); if (script->compartment() != cx->compartment()) continue; diff --git a/js/src/vm/StructuredClone.cpp b/js/src/vm/StructuredClone.cpp index c38a0ceafd9..040a5b756af 100644 --- a/js/src/vm/StructuredClone.cpp +++ b/js/src/vm/StructuredClone.cpp @@ -300,7 +300,7 @@ struct JSStructuredCloneWriter { JS::RootedValue transferable; JS::AutoObjectVector transferableObjects; - friend bool JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::Value v); + friend bool JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::HandleValue v); }; JS_FRIEND_API(uint64_t) @@ -1840,7 +1840,7 @@ JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len) } JS_PUBLIC_API(bool) -JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::Value v) +JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::HandleValue v) { JS_ASSERT(v.isObject()); assertSameCompartment(w->context(), v); @@ -1856,4 +1856,3 @@ JS_WriteTypedArray(JSStructuredCloneWriter *w, JS::Value v) } return w->writeTypedArray(obj); } - diff --git a/js/xpconnect/src/Sandbox.cpp b/js/xpconnect/src/Sandbox.cpp index f595e5bbed2..2536a37c54d 100644 --- a/js/xpconnect/src/Sandbox.cpp +++ b/js/xpconnect/src/Sandbox.cpp @@ -177,7 +177,7 @@ SandboxImport(JSContext *cx, unsigned argc, Value *vp) } RootedId id(cx); - if (!JS_ValueToId(cx, StringValue(funname), &id)) + if (!JS_StringToId(cx, funname, &id)) return false; // We need to resolve the this object, because this function is used @@ -299,9 +299,7 @@ ExportFunction(JSContext *cx, HandleValue vfunction, HandleValue vscope, HandleV if (!funName) funName = JS_InternString(cx, ""); - RootedValue vname(cx); - vname.setString(funName); - if (!JS_ValueToId(cx, vname, &id)) + if (!JS_StringToId(cx, funName, &id)) return false; } MOZ_ASSERT(JSID_IS_STRING(id)); @@ -1841,7 +1839,8 @@ xpc::NewFunctionForwarder(JSContext *cx, HandleObject callable, bool doclone, MutableHandleValue vp) { RootedId emptyId(cx); - if (!JS_ValueToId(cx, JS_GetEmptyStringValue(cx), &emptyId)) + RootedValue emptyStringValue(cx, JS_GetEmptyStringValue(cx)); + if (!JS_ValueToId(cx, emptyStringValue, &emptyId)) return false; return NewFunctionForwarder(cx, emptyId, callable, doclone, vp); diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index 375c6103b8d..c58803df4df 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -265,15 +265,15 @@ nsXPCComponents_Interfaces::NewEnumerate(nsIXPConnectWrappedNative *wrapper, *statep = UINT_TO_JSVAL(idx + 1); if (interface) { - JSString* idstr; const char* name; - JS::Rooted id(cx); - if (NS_SUCCEEDED(interface->GetNameShared(&name)) && name && - nullptr != (idstr = JS_NewStringCopyZ(cx, name)) && - JS_ValueToId(cx, StringValue(idstr), &id)) { - *idp = id; - return NS_OK; + RootedId id(cx); + if (NS_SUCCEEDED(interface->GetNameShared(&name)) && name) { + RootedString idstr(cx, JS_NewStringCopyZ(cx, name)); + if (idstr && JS_StringToId(cx, idstr, &id)) { + *idp = id; + return NS_OK; + } } } // fall through @@ -514,13 +514,12 @@ nsXPCComponents_InterfacesByID::NewEnumerate(nsIXPConnectWrappedNative *wrapper, if (interface) { nsIID const *iid; char idstr[NSID_LENGTH]; - JSString* jsstr; if (NS_SUCCEEDED(interface->GetIIDShared(&iid))) { iid->ToProvidedString(idstr); - jsstr = JS_NewStringCopyZ(cx, idstr); - JS::Rooted id(cx); - if (jsstr && JS_ValueToId(cx, StringValue(jsstr), &id)) { + RootedString jsstr(cx, JS_NewStringCopyZ(cx, idstr)); + RootedId id(cx); + if (jsstr && JS_StringToId(cx, jsstr, &id)) { *idp = id; return NS_OK; } @@ -774,10 +773,9 @@ nsXPCComponents_Classes::NewEnumerate(nsIXPConnectWrappedNative *wrapper, if (holder) { nsAutoCString name; if (NS_SUCCEEDED(holder->GetData(name))) { - JSString* idstr = JS_NewStringCopyN(cx, name.get(), name.Length()); - JS::Rooted id(cx); - if (idstr && - JS_ValueToId(cx, StringValue(idstr), &id)) { + RootedString idstr(cx, JS_NewStringCopyN(cx, name.get(), name.Length())); + RootedId id(cx); + if (idstr && JS_StringToId(cx, idstr, &id)) { *idp = id; return NS_OK; } @@ -1015,11 +1013,10 @@ nsXPCComponents_ClassesByID::NewEnumerate(nsIXPConnectWrappedNative *wrapper, if (holder) { char* name; if (NS_SUCCEEDED(holder->ToString(&name)) && name) { - JSString* idstr = JS_NewStringCopyZ(cx, name); + RootedString idstr(cx, JS_NewStringCopyZ(cx, name)); nsMemory::Free(name); - JS::Rooted id(cx); - if (idstr && - JS_ValueToId(cx, StringValue(idstr), &id)) { + RootedId id(cx); + if (idstr && JS_StringToId(cx, idstr, &id)) { *idp = id; return NS_OK; } @@ -1270,9 +1267,9 @@ nsXPCComponents_Results::NewEnumerate(nsIXPConnectWrappedNative *wrapper, const char* name; iter = (const void**) JSVAL_TO_PRIVATE(*statep); if (nsXPCException::IterateNSResults(nullptr, &name, nullptr, iter)) { - JSString* idstr = JS_NewStringCopyZ(cx, name); - JS::Rooted id(cx); - if (idstr && JS_ValueToId(cx, StringValue(idstr), &id)) { + RootedString idstr(cx, JS_NewStringCopyZ(cx, name)); + JS::RootedId id(cx); + if (idstr && JS_StringToId(cx, idstr, &id)) { *idp = id; return NS_OK; } @@ -2417,7 +2414,7 @@ nsXPCComponents_Constructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper, RootedString str(cx, ToString(cx, args[1])); RootedId id(cx); - if (!str || !JS_ValueToId(cx, StringValue(str), &id)) + if (!str || !JS_StringToId(cx, str, &id)) return ThrowAndFail(NS_ERROR_XPC_BAD_CONVERT_JS, cx, _retval); RootedValue val(cx); @@ -2465,7 +2462,7 @@ nsXPCComponents_Constructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper, RootedString str(cx, ToString(cx, args[0])); RootedId id(cx); - if (!str || !JS_ValueToId(cx, StringValue(str), &id)) + if (!str || !JS_StringToId(cx, str, &id)) return ThrowAndFail(NS_ERROR_XPC_BAD_CONVERT_JS, cx, _retval); RootedValue val(cx); diff --git a/js/xpconnect/src/XPCMaps.h b/js/xpconnect/src/XPCMaps.h index 583911e5f53..6a4ce127c68 100644 --- a/js/xpconnect/src/XPCMaps.h +++ b/js/xpconnect/src/XPCMaps.h @@ -672,12 +672,13 @@ public: * We reparent wrappers that have as their parent an inner window * whose outer has the new inner window as its current inner. */ - JS::RootedObject parent(aCx, JS_GetParent(e.front().value())); + JS::RootedObject wrapper(aCx, e.front().value()); + JS::RootedObject parent(aCx, JS_GetParent(wrapper)); JS::RootedObject outer(aCx, JS_ObjectToOuterObject(aCx, parent)); if (outer) { JSObject *inner = JS_ObjectToInnerObject(aCx, outer); if (inner == aNewInner && inner != parent) - JS_SetParent(aCx, e.front().value(), aNewInner); + JS_SetParent(aCx, wrapper, aNewInner); } else { JS_ClearPendingException(aCx); } diff --git a/js/xpconnect/src/XPCQuickStubs.h b/js/xpconnect/src/XPCQuickStubs.h index 5f5e20eae20..c88511fa222 100644 --- a/js/xpconnect/src/XPCQuickStubs.h +++ b/js/xpconnect/src/XPCQuickStubs.h @@ -601,7 +601,7 @@ PropertyOpForwarder(JSContext *cx, unsigned argc, jsval *vp) if (!obj) return false; - jsval v = js::GetFunctionNativeReserved(callee, 0); + JS::RootedValue v(cx, js::GetFunctionNativeReserved(callee, 0)); JSObject *ptrobj = JSVAL_TO_OBJECT(v); Op *popp = static_cast(JS_GetPrivate(ptrobj)); diff --git a/js/xpconnect/src/XPCWrappedNative.cpp b/js/xpconnect/src/XPCWrappedNative.cpp index 7501832b226..420f721b093 100644 --- a/js/xpconnect/src/XPCWrappedNative.cpp +++ b/js/xpconnect/src/XPCWrappedNative.cpp @@ -1160,9 +1160,8 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCWrappedNativeScope* aOldScope, // ending up with two reflectors pointing to the same WN. Other than // that, the objects we create will just go away if we return early. - RootedObject newobj(cx, JS_CloneObject(cx, flat, - newProto->GetJSProtoObject(), - aNewParent)); + RootedObject proto(cx, newProto->GetJSProtoObject()); + RootedObject newobj(cx, JS_CloneObject(cx, flat, proto, aNewParent)); if (!newobj) return NS_ERROR_FAILURE; diff --git a/storage/src/mozStorageStatementParams.cpp b/storage/src/mozStorageStatementParams.cpp index 9f9cc20d371..c187032e563 100644 --- a/storage/src/mozStorageStatementParams.cpp +++ b/storage/src/mozStorageStatementParams.cpp @@ -123,13 +123,13 @@ StatementParams::NewEnumerate(nsIXPConnectWrappedNative *aWrapper, NS_ENSURE_SUCCESS(rv, rv); // But drop the first character, which is going to be a ':'. - JSString *jsname = ::JS_NewStringCopyN(aCtx, &(name.get()[1]), - name.Length() - 1); + JS::RootedString jsname(aCtx, ::JS_NewStringCopyN(aCtx, &(name.get()[1]), + name.Length() - 1)); NS_ENSURE_TRUE(jsname, NS_ERROR_OUT_OF_MEMORY); // Set our name. JS::Rooted id(aCtx); - if (!::JS_ValueToId(aCtx, JS::StringValue(jsname), &id)) { + if (!::JS_StringToId(aCtx, jsname, &id)) { *_retval = false; return NS_OK; } diff --git a/xpcom/io/nsBinaryStream.cpp b/xpcom/io/nsBinaryStream.cpp index ea68aa9ba09..7ae96a9464b 100644 --- a/xpcom/io/nsBinaryStream.cpp +++ b/xpcom/io/nsBinaryStream.cpp @@ -752,7 +752,7 @@ nsBinaryInputStream::ReadArrayBuffer(uint32_t aLength, JS::Handle aBu JS_GetArrayBufferByteLength(buffer) < aLength) { return NS_ERROR_FAILURE; } - uint8_t* data = JS_GetStableArrayBufferData(cx, &aBuffer.toObject()); + uint8_t* data = JS_GetStableArrayBufferData(cx, buffer); if (!data) { return NS_ERROR_FAILURE; }