diff --git a/dom/base/MessagePort.cpp b/dom/base/MessagePort.cpp index b0e265b81776..ebccfb50907d 100644 --- a/dom/base/MessagePort.cpp +++ b/dom/base/MessagePort.cpp @@ -125,7 +125,7 @@ PostMessageReadStructuredClone(JSContext* cx, { nsRefPtr blob = new File(scInfo->mPort->GetParentObject(), blobImpl); - if (!WrapNewBindingObject(cx, blob, &val)) { + if (!GetOrCreateDOMReflector(cx, blob, &val)) { return nullptr; } } diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index fa552b19b626..ade5c6502230 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -2056,7 +2056,7 @@ Navigator::DoResolve(JSContext* aCx, JS::Handle aObject, nsISupports* existingObject = mCachedResolveResults.GetWeak(name); if (existingObject) { // We know all of our WebIDL objects here are wrappercached, so just go - // ahead and WrapObject() them. We can't use WrapNewBindingObject, + // ahead and WrapObject() them. We can't use GetOrCreateDOMReflector, // because we don't have the concrete type. JS::Rooted wrapped(aCx); if (!dom::WrapObject(aCx, existingObject, &wrapped)) { diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index d17cde71837c..8326342d8d1a 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -6041,7 +6041,7 @@ nsContentUtils::CreateBlobBuffer(JSContext* aCx, return NS_ERROR_OUT_OF_MEMORY; } - if (!WrapNewBindingObject(aCx, blob, aBlob)) { + if (!GetOrCreateDOMReflector(aCx, blob, aBlob)) { return NS_ERROR_FAILURE; } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 7c013f216e00..49967ff637a5 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -7912,7 +7912,7 @@ PostMessageReadStructuredClone(JSContext* cx, JS::Rooted val(cx); { nsRefPtr blob = new File(scInfo->window, blobImpl); - if (!WrapNewBindingObject(cx, blob, &val)) { + if (!GetOrCreateDOMReflector(cx, blob, &val)) { return nullptr; } } @@ -14034,7 +14034,7 @@ nsGlobalWindow::GetConsole(JSContext* aCx, return rv.ErrorCode(); } - if (!WrapNewBindingObject(aCx, console, aConsole)) { + if (!GetOrCreateDOMReflector(aCx, console, aConsole)) { return NS_ERROR_FAILURE; } diff --git a/dom/base/nsJSUtils.cpp b/dom/base/nsJSUtils.cpp index b6846c3f5652..2edde34a4f26 100644 --- a/dom/base/nsJSUtils.cpp +++ b/dom/base/nsJSUtils.cpp @@ -337,7 +337,7 @@ nsJSUtils::GetScopeChainForElement(JSContext* aCx, { for (nsINode* cur = aElement; cur; cur = cur->GetScopeChainParent()) { JS::RootedValue val(aCx); - if (!WrapNewBindingObject(aCx, cur, &val)) { + if (!GetOrCreateDOMReflector(aCx, cur, &val)) { return false; } diff --git a/dom/base/nsXMLHttpRequest.cpp b/dom/base/nsXMLHttpRequest.cpp index ad8849cadf2c..3dcbcb7adf0e 100644 --- a/dom/base/nsXMLHttpRequest.cpp +++ b/dom/base/nsXMLHttpRequest.cpp @@ -1014,7 +1014,7 @@ nsXMLHttpRequest::GetResponse(JSContext* aCx, return; } - WrapNewBindingObject(aCx, mResponseBlob, aResponse); + GetOrCreateDOMReflector(aCx, mResponseBlob, aResponse); return; } case XML_HTTP_RESPONSE_TYPE_DOCUMENT: diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index 2a52a7a46f3b..a614b6e9949f 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -2533,7 +2533,7 @@ ConvertExceptionToPromise(JSContext* cx, return false; } - return WrapNewBindingObject(cx, promise, rval); + return GetOrCreateDOMReflector(cx, promise, rval); } /* static */ diff --git a/dom/bindings/BindingUtils.h b/dom/bindings/BindingUtils.h index 7d64ccb683bd..4dcebb0526aa 100644 --- a/dom/bindings/BindingUtils.h +++ b/dom/bindings/BindingUtils.h @@ -866,7 +866,8 @@ MaybeWrapValue(JSContext* cx, JS::MutableHandle rval) // compartment of cx, and outerized as needed. template MOZ_ALWAYS_INLINE bool -WrapNewBindingObject(JSContext* cx, T* value, JS::MutableHandle rval) +GetOrCreateDOMReflector(JSContext* cx, T* value, + JS::MutableHandle rval) { MOZ_ASSERT(value); JSObject* obj = value->GetWrapperPreserveColor(); @@ -1279,8 +1280,8 @@ VariantToJsval(JSContext* aCx, nsIVariant* aVariant, // Wrap an object "p" which is not using WebIDL bindings yet. This _will_ // actually work on WebIDL binding objects that are wrappercached, but will be -// much slower than WrapNewBindingObject. "cache" must either be null or be the -// nsWrapperCache for "p". +// much slower than GetOrCreateDOMReflector. "cache" must either be null or be +// the nsWrapperCache for "p". template inline bool WrapObject(JSContext* cx, T* p, nsWrapperCache* cache, const nsIID* iid, @@ -1583,44 +1584,45 @@ WrapCallThisObject>(JSContext* cx, return obj; } -// Helper for calling WrapNewBindingObject with smart pointers +// Helper for calling GetOrCreateDOMReflector with smart pointers // (nsAutoPtr/nsRefPtr/nsCOMPtr) or references. template ::Value> -struct WrapNewBindingObjectHelper +struct GetOrCreateDOMReflectorHelper { - static inline bool Wrap(JSContext* cx, const T& value, - JS::MutableHandle rval) + static inline bool GetOrCreate(JSContext* cx, const T& value, + JS::MutableHandle rval) { - return WrapNewBindingObject(cx, value.get(), rval); + return GetOrCreateDOMReflector(cx, value.get(), rval); } }; template -struct WrapNewBindingObjectHelper +struct GetOrCreateDOMReflectorHelper { - static inline bool Wrap(JSContext* cx, T& value, - JS::MutableHandle rval) + static inline bool GetOrCreate(JSContext* cx, T& value, + JS::MutableHandle rval) { - return WrapNewBindingObject(cx, &value, rval); + return GetOrCreateDOMReflector(cx, &value, rval); } }; template inline bool -WrapNewBindingObject(JSContext* cx, T& value, JS::MutableHandle rval) +GetOrCreateDOMReflector(JSContext* cx, T& value, + JS::MutableHandle rval) { - return WrapNewBindingObjectHelper::Wrap(cx, value, rval); + return GetOrCreateDOMReflectorHelper::GetOrCreate(cx, value, rval); } -// We need this version of WrapNewBindingObject for codegen, so it'll have the -// same signature as WrapNewBindingNonWrapperCachedObject and +// We need this version of GetOrCreateDOMReflector for codegen, so it'll have +// the same signature as WrapNewBindingNonWrapperCachedObject and // WrapNewBindingNonWrapperCachedOwnedObject, which still need the scope. template inline bool -WrapNewBindingObject(JSContext* cx, JS::Handle scope, T& value, - JS::MutableHandle rval) +GetOrCreateDOMReflector(JSContext* cx, JS::Handle scope, T& value, + JS::MutableHandle rval) { - return WrapNewBindingObject(cx, value, rval); + return GetOrCreateDOMReflector(cx, value, rval); } template diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 2e9f052dca8c..39a3cbf00297 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -417,7 +417,7 @@ DOMInterfaces = { 'EventTarget': { # When we get rid of hasXPConnectImpls, we can get rid of the - # couldBeDOMBinding stuff in WrapNewBindingObject. + # couldBeDOMBinding stuff in GetOrCreateDOMReflector. # # We can also get rid of the UnwrapArg bits in # the dom QueryInterface (in BindingUtils.cpp) at that point. diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index d757c9bb12df..3c3553cc3280 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -1735,7 +1735,7 @@ class CGConstructNavigatorObject(CGAbstractMethod): ThrowMethodFailedWithDetails(aCx, rv, "${descriptorName}", "navigatorConstructor"); return nullptr; } - if (!WrapNewBindingObject(aCx, result, &v)) { + if (!GetOrCreateDOMReflector(aCx, result, &v)) { //XXX Assertion disabled for now, see bug 991271. MOZ_ASSERT(true || JS_IsExceptionPending(aCx)); return nullptr; @@ -5764,7 +5764,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode, if not descriptor.interface.isExternal() and not descriptor.skipGen: if descriptor.wrapperCache: assert descriptor.nativeOwnership != 'owned' - wrapMethod = "WrapNewBindingObject" + wrapMethod = "GetOrCreateDOMReflector" else: if not returnsNewObject: raise MethodNotNewObjectError(descriptor.interface.identifier.name) @@ -5854,7 +5854,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode, return wrapCode, False if type.isAny(): - # See comments in WrapNewBindingObject explaining why we need + # See comments in GetOrCreateDOMReflector explaining why we need # to wrap here. # NB: _setValue(..., type-that-is-any) calls JS_WrapValue(), so is fallible head = "JS::ExposeValueToActiveJS(%s);\n" % result @@ -5862,7 +5862,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode, if (type.isObject() or (type.isSpiderMonkeyInterface() and not typedArraysAreStructs)): - # See comments in WrapNewBindingObject explaining why we need + # See comments in GetOrCreateDOMReflector explaining why we need # to wrap here. if type.nullable(): toValue = "%s" @@ -5895,7 +5895,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode, if type.isSpiderMonkeyInterface(): assert typedArraysAreStructs - # See comments in WrapNewBindingObject explaining why we need + # See comments in GetOrCreateDOMReflector explaining why we need # to wrap here. # NB: setObject(..., some-object-type) calls JS_WrapValue(), so is fallible return (setObject("*%s.Obj()" % result, @@ -13255,7 +13255,7 @@ class CGJSImplMethod(CGJSImplMember): JS::Rooted scopeObj(cx, globalHolder->GetGlobalJSObject()); MOZ_ASSERT(js::IsObjectInContextCompartment(scopeObj, cx)); JS::Rooted wrappedVal(cx); - if (!WrapNewBindingObject(cx, impl, &wrappedVal)) { + if (!GetOrCreateDOMReflector(cx, impl, &wrappedVal)) { //XXX Assertion disabled for now, see bug 991271. MOZ_ASSERT(true || JS_IsExceptionPending(cx)); aRv.Throw(NS_ERROR_UNEXPECTED); @@ -13545,7 +13545,7 @@ class CGJSImplClass(CGBindingImplClass): JS::Rooted arg(cx, &args[1].toObject()); nsRefPtr<${implName}> impl = new ${implName}(arg, window); MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx)); - return WrapNewBindingObject(cx, impl, args.rval()); + return GetOrCreateDOMReflector(cx, impl, args.rval()); """, ifaceName=self.descriptor.interface.identifier.name, implName=self.descriptor.name) diff --git a/dom/bindings/Exceptions.cpp b/dom/bindings/Exceptions.cpp index d35abccd828e..9886328b98e2 100644 --- a/dom/bindings/Exceptions.cpp +++ b/dom/bindings/Exceptions.cpp @@ -76,7 +76,7 @@ ThrowExceptionObject(JSContext* aCx, Exception* aException) return false; } - if (!WrapNewBindingObject(aCx, aException, &thrown)) { + if (!GetOrCreateDOMReflector(aCx, aException, &thrown)) { return false; } diff --git a/dom/bindings/ToJSValue.h b/dom/bindings/ToJSValue.h index ddf4e5c741c3..55d8a335e708 100644 --- a/dom/bindings/ToJSValue.h +++ b/dom/bindings/ToJSValue.h @@ -151,7 +151,7 @@ ToJSValue(JSContext* aCx, // Make sure non-webidl objects don't sneak in here MOZ_ASSERT(aArgument.IsDOMBinding()); - return WrapNewBindingObject(aCx, aArgument, aValue); + return GetOrCreateDOMReflector(aCx, aArgument, aValue); } // Accept typed arrays built from appropriate nsTArray values diff --git a/dom/canvas/WebGLContextUtils.h b/dom/canvas/WebGLContextUtils.h index 436d42ce0d9b..cf6c54943252 100644 --- a/dom/canvas/WebGLContextUtils.h +++ b/dom/canvas/WebGLContextUtils.h @@ -88,7 +88,8 @@ WebGLContext::WebGLObjectAsJSValue(JSContext *cx, const WebGLObjectType *object, JS::Rooted v(cx); JS::Rooted wrapper(cx, GetWrapper()); JSAutoCompartment ac(cx, wrapper); - if (!dom::WrapNewBindingObject(cx, const_cast(object), &v)) { + if (!dom::GetOrCreateDOMReflector(cx, const_cast(object), + &v)) { rv.Throw(NS_ERROR_FAILURE); return JS::NullValue(); } diff --git a/dom/events/EventListenerManager.cpp b/dom/events/EventListenerManager.cpp index 8afd0c25409d..a929d6d1846e 100644 --- a/dom/events/EventListenerManager.cpp +++ b/dom/events/EventListenerManager.cpp @@ -900,7 +900,7 @@ EventListenerManager::CompileEventHandlerInternal(Listener* aListener, NS_ENSURE_TRUE(jsStr, NS_ERROR_OUT_OF_MEMORY); // Get the reflector for |aElement|, so that we can pass to setElement. - if (NS_WARN_IF(!WrapNewBindingObject(cx, target, aElement, &v))) { + if (NS_WARN_IF(!GetOrCreateDOMReflector(cx, target, aElement, &v))) { return NS_ERROR_FAILURE; } JS::CompileOptions options(cx); diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp index bc32935b264a..34fdfd3ecf94 100644 --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -628,7 +628,7 @@ public: } JS::Rooted wrappedBlob(aCx); - if (!WrapNewBindingObject(aCx, aFile.mFile, &wrappedBlob)) { + if (!GetOrCreateDOMReflector(aCx, aFile.mFile, &wrappedBlob)) { return false; } @@ -647,7 +647,7 @@ public: } JS::Rooted wrappedFile(aCx); - if (!WrapNewBindingObject(aCx, aFile.mFile, &wrappedFile)) { + if (!GetOrCreateDOMReflector(aCx, aFile.mFile, &wrappedFile)) { return false; } diff --git a/dom/indexedDB/IndexedDatabaseManager.cpp b/dom/indexedDB/IndexedDatabaseManager.cpp index 0e72c817df50..8c4cdf642cd6 100644 --- a/dom/indexedDB/IndexedDatabaseManager.cpp +++ b/dom/indexedDB/IndexedDatabaseManager.cpp @@ -464,7 +464,7 @@ IndexedDatabaseManager::DefineIndexedDB(JSContext* aCx, JS::Rooted indexedDB(aCx); js::AssertSameCompartment(aCx, aGlobal); - if (!WrapNewBindingObject(aCx, factory, &indexedDB)) { + if (!GetOrCreateDOMReflector(aCx, factory, &indexedDB)) { return false; } diff --git a/dom/ipc/StructuredCloneUtils.cpp b/dom/ipc/StructuredCloneUtils.cpp index 9b7f6a82e4e6..8f3b10492cc6 100644 --- a/dom/ipc/StructuredCloneUtils.cpp +++ b/dom/ipc/StructuredCloneUtils.cpp @@ -65,7 +65,7 @@ Read(JSContext* aCx, JSStructuredCloneReader* aReader, uint32_t aTag, MOZ_ASSERT(global); nsRefPtr newBlob = new File(global, blob->Impl()); - if (!WrapNewBindingObject(aCx, newBlob, &val)) { + if (!GetOrCreateDOMReflector(aCx, newBlob, &val)) { return nullptr; } } diff --git a/dom/mobilemessage/MmsMessage.cpp b/dom/mobilemessage/MmsMessage.cpp index 15a77bd77d96..cd726f95dbed 100644 --- a/dom/mobilemessage/MmsMessage.cpp +++ b/dom/mobilemessage/MmsMessage.cpp @@ -580,7 +580,7 @@ MmsMessage::GetAttachments(JSContext* aCx, JS::MutableHandle aAttachm nsRefPtr newBlob = new File(global, attachment.content->Impl()); JS::Rooted val(aCx); - if (!WrapNewBindingObject(aCx, newBlob, &val)) { + if (!GetOrCreateDOMReflector(aCx, newBlob, &val)) { return NS_ERROR_FAILURE; } diff --git a/dom/mobilemessage/ipc/SmsParent.cpp b/dom/mobilemessage/ipc/SmsParent.cpp index 707d2d508a30..01a55327b48a 100644 --- a/dom/mobilemessage/ipc/SmsParent.cpp +++ b/dom/mobilemessage/ipc/SmsParent.cpp @@ -66,7 +66,7 @@ MmsAttachmentDataToJSObject(JSContext* aContext, MOZ_ASSERT(global); nsRefPtr blob = new File(global, blobImpl); - if (!WrapNewBindingObject(aContext, blob, &content)) { + if (!GetOrCreateDOMReflector(aContext, blob, &content)) { return nullptr; } } diff --git a/dom/promise/Promise.cpp b/dom/promise/Promise.cpp index dca593b4786e..eb9f05f2c47c 100644 --- a/dom/promise/Promise.cpp +++ b/dom/promise/Promise.cpp @@ -326,7 +326,7 @@ Promise::CreateWrapper(ErrorResult& aRv) JSContext* cx = jsapi.cx(); JS::Rooted wrapper(cx); - if (!WrapNewBindingObject(cx, this, &wrapper)) { + if (!GetOrCreateDOMReflector(cx, this, &wrapper)) { JS_ClearPendingException(cx); aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return; @@ -475,7 +475,7 @@ Promise::CreateFunction(JSContext* aCx, JSObject* aParent, Promise* aPromise, JS::Rooted obj(aCx, JS_GetFunctionObject(func)); JS::Rooted promiseObj(aCx); - if (!dom::WrapNewBindingObject(aCx, aPromise, &promiseObj)) { + if (!dom::GetOrCreateDOMReflector(aCx, aPromise, &promiseObj)) { return nullptr; } @@ -502,7 +502,7 @@ Promise::CreateThenableFunction(JSContext* aCx, Promise* aPromise, uint32_t aTas JS::Rooted obj(aCx, JS_GetFunctionObject(func)); JS::Rooted promiseObj(aCx); - if (!dom::WrapNewBindingObject(aCx, aPromise, &promiseObj)) { + if (!dom::GetOrCreateDOMReflector(aCx, aPromise, &promiseObj)) { return nullptr; } diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 2ff28cebc1c8..2f6b80a137fc 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -322,7 +322,7 @@ struct WorkerStructuredCloneCallbacks // New scope to protect |result| from a moving GC during ~nsRefPtr. nsRefPtr blob = new File(nullptr, blobImpl); JS::Rooted val(aCx); - if (WrapNewBindingObject(aCx, blob, &val)) { + if (GetOrCreateDOMReflector(aCx, blob, &val)) { result = val.toObjectOrNull(); } } @@ -426,7 +426,7 @@ struct MainThreadWorkerStructuredCloneCallbacks JS::Rooted val(aCx); { nsRefPtr blob = new File(nullptr, blobImpl); - if (!WrapNewBindingObject(aCx, blob, &val)) { + if (!GetOrCreateDOMReflector(aCx, blob, &val)) { return nullptr; } } diff --git a/dom/workers/XMLHttpRequest.cpp b/dom/workers/XMLHttpRequest.cpp index 0e6ba8ff4cb0..b49838a5e76a 100644 --- a/dom/workers/XMLHttpRequest.cpp +++ b/dom/workers/XMLHttpRequest.cpp @@ -1076,7 +1076,7 @@ Proxy::HandleEvent(nsIDOMEvent* aEvent) JSAutoCompartment ac(cx, scope); JS::Rooted value(cx); - if (!WrapNewBindingObject(cx, mXHR, &value)) { + if (!GetOrCreateDOMReflector(cx, mXHR, &value)) { return NS_ERROR_FAILURE; } @@ -2175,7 +2175,7 @@ XMLHttpRequest::Send(File& aBody, ErrorResult& aRv) } JS::Rooted value(cx); - if (!WrapNewBindingObject(cx, &aBody, &value)) { + if (!GetOrCreateDOMReflector(cx, &aBody, &value)) { aRv.Throw(NS_ERROR_FAILURE); return; } diff --git a/js/xpconnect/src/ExportHelpers.cpp b/js/xpconnect/src/ExportHelpers.cpp index b0ca0218f810..2938e75dd49d 100644 --- a/js/xpconnect/src/ExportHelpers.cpp +++ b/js/xpconnect/src/ExportHelpers.cpp @@ -113,7 +113,7 @@ StackScopedCloneRead(JSContext *cx, JSStructuredCloneReader *reader, uint32_t ta JS::Rooted val(cx); { nsRefPtr blob = new File(global, cloneData->mBlobImpls[idx]); - if (!WrapNewBindingObject(cx, blob, &val)) { + if (!GetOrCreateDOMReflector(cx, blob, &val)) { return nullptr; } } diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index b93b2f72a836..10f59ae9a98e 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -1160,7 +1160,7 @@ XPCWrappedNativeXrayTraits::resolveNativeProperty(JSContext *cx, HandleObject wr return true; } - if (!WrapNewBindingObject(cx, f, desc.value())) { + if (!GetOrCreateDOMReflector(cx, f, desc.value())) { return false; }