зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1087851 part 1. Rename WrapNewBindingObject to GetOrCreateDOMReflector to make it clearer what it does. r=peterv for the idea; patch itself is just search-and-replace
This commit is contained in:
Родитель
e2db859d62
Коммит
8ec9d58716
|
@ -125,7 +125,7 @@ PostMessageReadStructuredClone(JSContext* cx,
|
|||
{
|
||||
nsRefPtr<File> blob = new File(scInfo->mPort->GetParentObject(),
|
||||
blobImpl);
|
||||
if (!WrapNewBindingObject(cx, blob, &val)) {
|
||||
if (!GetOrCreateDOMReflector(cx, blob, &val)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2056,7 +2056,7 @@ Navigator::DoResolve(JSContext* aCx, JS::Handle<JSObject*> 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<JS::Value> wrapped(aCx);
|
||||
if (!dom::WrapObject(aCx, existingObject, &wrapped)) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -7912,7 +7912,7 @@ PostMessageReadStructuredClone(JSContext* cx,
|
|||
JS::Rooted<JS::Value> val(cx);
|
||||
{
|
||||
nsRefPtr<File> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1014,7 +1014,7 @@ nsXMLHttpRequest::GetResponse(JSContext* aCx,
|
|||
return;
|
||||
}
|
||||
|
||||
WrapNewBindingObject(aCx, mResponseBlob, aResponse);
|
||||
GetOrCreateDOMReflector(aCx, mResponseBlob, aResponse);
|
||||
return;
|
||||
}
|
||||
case XML_HTTP_RESPONSE_TYPE_DOCUMENT:
|
||||
|
|
|
@ -2533,7 +2533,7 @@ ConvertExceptionToPromise(JSContext* cx,
|
|||
return false;
|
||||
}
|
||||
|
||||
return WrapNewBindingObject(cx, promise, rval);
|
||||
return GetOrCreateDOMReflector(cx, promise, rval);
|
||||
}
|
||||
|
||||
/* static */
|
||||
|
|
|
@ -866,7 +866,8 @@ MaybeWrapValue(JSContext* cx, JS::MutableHandle<JS::Value> rval)
|
|||
// compartment of cx, and outerized as needed.
|
||||
template <class T>
|
||||
MOZ_ALWAYS_INLINE bool
|
||||
WrapNewBindingObject(JSContext* cx, T* value, JS::MutableHandle<JS::Value> rval)
|
||||
GetOrCreateDOMReflector(JSContext* cx, T* value,
|
||||
JS::MutableHandle<JS::Value> 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<class T>
|
||||
inline bool
|
||||
WrapObject(JSContext* cx, T* p, nsWrapperCache* cache, const nsIID* iid,
|
||||
|
@ -1583,44 +1584,45 @@ WrapCallThisObject<JS::Rooted<JSObject*>>(JSContext* cx,
|
|||
return obj;
|
||||
}
|
||||
|
||||
// Helper for calling WrapNewBindingObject with smart pointers
|
||||
// Helper for calling GetOrCreateDOMReflector with smart pointers
|
||||
// (nsAutoPtr/nsRefPtr/nsCOMPtr) or references.
|
||||
template <class T, bool isSmartPtr=HasgetMember<T>::Value>
|
||||
struct WrapNewBindingObjectHelper
|
||||
struct GetOrCreateDOMReflectorHelper
|
||||
{
|
||||
static inline bool Wrap(JSContext* cx, const T& value,
|
||||
JS::MutableHandle<JS::Value> rval)
|
||||
static inline bool GetOrCreate(JSContext* cx, const T& value,
|
||||
JS::MutableHandle<JS::Value> rval)
|
||||
{
|
||||
return WrapNewBindingObject(cx, value.get(), rval);
|
||||
return GetOrCreateDOMReflector(cx, value.get(), rval);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct WrapNewBindingObjectHelper<T, false>
|
||||
struct GetOrCreateDOMReflectorHelper<T, false>
|
||||
{
|
||||
static inline bool Wrap(JSContext* cx, T& value,
|
||||
JS::MutableHandle<JS::Value> rval)
|
||||
static inline bool GetOrCreate(JSContext* cx, T& value,
|
||||
JS::MutableHandle<JS::Value> rval)
|
||||
{
|
||||
return WrapNewBindingObject(cx, &value, rval);
|
||||
return GetOrCreateDOMReflector(cx, &value, rval);
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
inline bool
|
||||
WrapNewBindingObject(JSContext* cx, T& value, JS::MutableHandle<JS::Value> rval)
|
||||
GetOrCreateDOMReflector(JSContext* cx, T& value,
|
||||
JS::MutableHandle<JS::Value> rval)
|
||||
{
|
||||
return WrapNewBindingObjectHelper<T>::Wrap(cx, value, rval);
|
||||
return GetOrCreateDOMReflectorHelper<T>::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<class T>
|
||||
inline bool
|
||||
WrapNewBindingObject(JSContext* cx, JS::Handle<JSObject*> scope, T& value,
|
||||
JS::MutableHandle<JS::Value> rval)
|
||||
GetOrCreateDOMReflector(JSContext* cx, JS::Handle<JSObject*> scope, T& value,
|
||||
JS::MutableHandle<JS::Value> rval)
|
||||
{
|
||||
return WrapNewBindingObject(cx, value, rval);
|
||||
return GetOrCreateDOMReflector(cx, value, rval);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<JSObject*> scopeObj(cx, globalHolder->GetGlobalJSObject());
|
||||
MOZ_ASSERT(js::IsObjectInContextCompartment(scopeObj, cx));
|
||||
JS::Rooted<JS::Value> 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<JSObject*> 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)
|
||||
|
|
|
@ -76,7 +76,7 @@ ThrowExceptionObject(JSContext* aCx, Exception* aException)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!WrapNewBindingObject(aCx, aException, &thrown)) {
|
||||
if (!GetOrCreateDOMReflector(aCx, aException, &thrown)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -88,7 +88,8 @@ WebGLContext::WebGLObjectAsJSValue(JSContext *cx, const WebGLObjectType *object,
|
|||
JS::Rooted<JS::Value> v(cx);
|
||||
JS::Rooted<JSObject*> wrapper(cx, GetWrapper());
|
||||
JSAutoCompartment ac(cx, wrapper);
|
||||
if (!dom::WrapNewBindingObject(cx, const_cast<WebGLObjectType*>(object), &v)) {
|
||||
if (!dom::GetOrCreateDOMReflector(cx, const_cast<WebGLObjectType*>(object),
|
||||
&v)) {
|
||||
rv.Throw(NS_ERROR_FAILURE);
|
||||
return JS::NullValue();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -628,7 +628,7 @@ public:
|
|||
}
|
||||
|
||||
JS::Rooted<JS::Value> wrappedBlob(aCx);
|
||||
if (!WrapNewBindingObject(aCx, aFile.mFile, &wrappedBlob)) {
|
||||
if (!GetOrCreateDOMReflector(aCx, aFile.mFile, &wrappedBlob)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -647,7 +647,7 @@ public:
|
|||
}
|
||||
|
||||
JS::Rooted<JS::Value> wrappedFile(aCx);
|
||||
if (!WrapNewBindingObject(aCx, aFile.mFile, &wrappedFile)) {
|
||||
if (!GetOrCreateDOMReflector(aCx, aFile.mFile, &wrappedFile)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -464,7 +464,7 @@ IndexedDatabaseManager::DefineIndexedDB(JSContext* aCx,
|
|||
|
||||
JS::Rooted<JS::Value> indexedDB(aCx);
|
||||
js::AssertSameCompartment(aCx, aGlobal);
|
||||
if (!WrapNewBindingObject(aCx, factory, &indexedDB)) {
|
||||
if (!GetOrCreateDOMReflector(aCx, factory, &indexedDB)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ Read(JSContext* aCx, JSStructuredCloneReader* aReader, uint32_t aTag,
|
|||
MOZ_ASSERT(global);
|
||||
|
||||
nsRefPtr<File> newBlob = new File(global, blob->Impl());
|
||||
if (!WrapNewBindingObject(aCx, newBlob, &val)) {
|
||||
if (!GetOrCreateDOMReflector(aCx, newBlob, &val)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -580,7 +580,7 @@ MmsMessage::GetAttachments(JSContext* aCx, JS::MutableHandle<JS::Value> aAttachm
|
|||
nsRefPtr<File> newBlob = new File(global, attachment.content->Impl());
|
||||
|
||||
JS::Rooted<JS::Value> val(aCx);
|
||||
if (!WrapNewBindingObject(aCx, newBlob, &val)) {
|
||||
if (!GetOrCreateDOMReflector(aCx, newBlob, &val)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ MmsAttachmentDataToJSObject(JSContext* aContext,
|
|||
MOZ_ASSERT(global);
|
||||
|
||||
nsRefPtr<File> blob = new File(global, blobImpl);
|
||||
if (!WrapNewBindingObject(aContext, blob, &content)) {
|
||||
if (!GetOrCreateDOMReflector(aContext, blob, &content)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -326,7 +326,7 @@ Promise::CreateWrapper(ErrorResult& aRv)
|
|||
JSContext* cx = jsapi.cx();
|
||||
|
||||
JS::Rooted<JS::Value> 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<JSObject*> obj(aCx, JS_GetFunctionObject(func));
|
||||
|
||||
JS::Rooted<JS::Value> 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<JSObject*> obj(aCx, JS_GetFunctionObject(func));
|
||||
|
||||
JS::Rooted<JS::Value> promiseObj(aCx);
|
||||
if (!dom::WrapNewBindingObject(aCx, aPromise, &promiseObj)) {
|
||||
if (!dom::GetOrCreateDOMReflector(aCx, aPromise, &promiseObj)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -322,7 +322,7 @@ struct WorkerStructuredCloneCallbacks
|
|||
// New scope to protect |result| from a moving GC during ~nsRefPtr.
|
||||
nsRefPtr<File> blob = new File(nullptr, blobImpl);
|
||||
JS::Rooted<JS::Value> val(aCx);
|
||||
if (WrapNewBindingObject(aCx, blob, &val)) {
|
||||
if (GetOrCreateDOMReflector(aCx, blob, &val)) {
|
||||
result = val.toObjectOrNull();
|
||||
}
|
||||
}
|
||||
|
@ -426,7 +426,7 @@ struct MainThreadWorkerStructuredCloneCallbacks
|
|||
JS::Rooted<JS::Value> val(aCx);
|
||||
{
|
||||
nsRefPtr<File> blob = new File(nullptr, blobImpl);
|
||||
if (!WrapNewBindingObject(aCx, blob, &val)) {
|
||||
if (!GetOrCreateDOMReflector(aCx, blob, &val)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1076,7 +1076,7 @@ Proxy::HandleEvent(nsIDOMEvent* aEvent)
|
|||
JSAutoCompartment ac(cx, scope);
|
||||
|
||||
JS::Rooted<JS::Value> 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<JS::Value> value(cx);
|
||||
if (!WrapNewBindingObject(cx, &aBody, &value)) {
|
||||
if (!GetOrCreateDOMReflector(cx, &aBody, &value)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ StackScopedCloneRead(JSContext *cx, JSStructuredCloneReader *reader, uint32_t ta
|
|||
JS::Rooted<JS::Value> val(cx);
|
||||
{
|
||||
nsRefPtr<File> blob = new File(global, cloneData->mBlobImpls[idx]);
|
||||
if (!WrapNewBindingObject(cx, blob, &val)) {
|
||||
if (!GetOrCreateDOMReflector(cx, blob, &val)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче