Bug 991742 part 9. Remove the "scope" argument of WrapNewBindingObject. r=bholley

This commit is contained in:
Boris Zbarsky 2014-04-08 18:27:19 -04:00
Родитель 79dab91ff6
Коммит feebd363fb
9 изменённых файлов: 34 добавлений и 39 удалений

Просмотреть файл

@ -26,7 +26,7 @@ WebGLContext::WebGLObjectAsJSValue(JSContext *cx, const WebGLObjectType *object,
JS::Rooted<JS::Value> v(cx); JS::Rooted<JS::Value> v(cx);
JS::Rooted<JSObject*> wrapper(cx, GetWrapper()); JS::Rooted<JSObject*> wrapper(cx, GetWrapper());
JSAutoCompartment ac(cx, wrapper); JSAutoCompartment ac(cx, wrapper);
if (!dom::WrapNewBindingObject(cx, wrapper, const_cast<WebGLObjectType*>(object), &v)) { if (!dom::WrapNewBindingObject(cx, const_cast<WebGLObjectType*>(object), &v)) {
rv.Throw(NS_ERROR_FAILURE); rv.Throw(NS_ERROR_FAILURE);
return JS::NullValue(); return JS::NullValue();
} }

Просмотреть файл

@ -13553,13 +13553,7 @@ nsGlobalWindow::GetConsole(JSContext* aCx,
return rv.ErrorCode(); return rv.ErrorCode();
} }
JS::Rooted<JSObject*> thisObj(aCx, GetWrapper()); if (!WrapNewBindingObject(aCx, console, aConsole)) {
if (!thisObj) {
return NS_ERROR_UNEXPECTED;
}
if (!JS_WrapObject(aCx, &thisObj) ||
!WrapNewBindingObject(aCx, thisObj, console, aConsole)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }

Просмотреть файл

@ -2390,8 +2390,7 @@ ConvertExceptionToPromise(JSContext* cx,
return false; return false;
} }
JS::Rooted<JSObject*> wrapScope(cx, JS::CurrentGlobalOrNull(cx)); return WrapNewBindingObject(cx, promise, rval);
return WrapNewBindingObject(cx, wrapScope, promise, rval);
} }
} // namespace dom } // namespace dom

Просмотреть файл

@ -790,8 +790,7 @@ MaybeWrapValue(JSContext* cx, JS::MutableHandle<JS::Value> rval)
// having "value" inherit from nsWrapperCache. // having "value" inherit from nsWrapperCache.
template <class T> template <class T>
MOZ_ALWAYS_INLINE bool MOZ_ALWAYS_INLINE bool
WrapNewBindingObject(JSContext* cx, JS::Handle<JSObject*> scope, T* value, WrapNewBindingObject(JSContext* cx, T* value, JS::MutableHandle<JS::Value> rval)
JS::MutableHandle<JS::Value> rval)
{ {
MOZ_ASSERT(value); MOZ_ASSERT(value);
JSObject* obj = value->GetWrapperPreserveColor(); JSObject* obj = value->GetWrapperPreserveColor();
@ -805,7 +804,6 @@ WrapNewBindingObject(JSContext* cx, JS::Handle<JSObject*> scope, T* value,
return false; return false;
} }
MOZ_ASSERT(js::IsObjectInContextCompartment(scope, cx));
obj = value->WrapObject(cx); obj = value->WrapObject(cx);
if (!obj) { if (!obj) {
// At this point, obj is null, so just return false. // At this point, obj is null, so just return false.
@ -817,8 +815,7 @@ WrapNewBindingObject(JSContext* cx, JS::Handle<JSObject*> scope, T* value,
#ifdef DEBUG #ifdef DEBUG
const DOMClass* clasp = GetDOMClass(obj); const DOMClass* clasp = GetDOMClass(obj);
// clasp can be null if the cache contained a non-DOM object from a // clasp can be null if the cache contained a non-DOM object.
// different compartment than scope.
if (clasp) { if (clasp) {
// Some sanity asserts about our object. Specifically: // Some sanity asserts about our object. Specifically:
// 1) If our class claims we're nsISupports, we better be nsISupports // 1) If our class claims we're nsISupports, we better be nsISupports
@ -830,13 +827,6 @@ WrapNewBindingObject(JSContext* cx, JS::Handle<JSObject*> scope, T* value,
MOZ_ASSERT_IF(clasp->mDOMObjectIsISupports, (IsBaseOf<nsISupports, T>::value)); MOZ_ASSERT_IF(clasp->mDOMObjectIsISupports, (IsBaseOf<nsISupports, T>::value));
MOZ_ASSERT(CheckWrapperCacheCast<T>::Check()); MOZ_ASSERT(CheckWrapperCacheCast<T>::Check());
} }
// When called via XrayWrapper, we end up here while running in the
// chrome compartment. But the obj we have would be created in
// whatever the content compartment is. So at this point we need to
// make sure it's correctly wrapped for the compartment of |scope|.
// cx should already be in the compartment of |scope| here.
MOZ_ASSERT(js::IsObjectInContextCompartment(scope, cx));
#endif #endif
rval.set(JS::ObjectValue(*obj)); rval.set(JS::ObjectValue(*obj));
@ -1495,29 +1485,39 @@ WrapCallThisObject<JS::Rooted<JSObject*>>(JSContext* cx,
template <class T, bool isSmartPtr=HasgetMember<T>::Value> template <class T, bool isSmartPtr=HasgetMember<T>::Value>
struct WrapNewBindingObjectHelper struct WrapNewBindingObjectHelper
{ {
static inline bool Wrap(JSContext* cx, JS::Handle<JSObject*> scope, static inline bool Wrap(JSContext* cx, const T& value,
const T& value, JS::MutableHandle<JS::Value> rval) JS::MutableHandle<JS::Value> rval)
{ {
return WrapNewBindingObject(cx, scope, value.get(), rval); return WrapNewBindingObject(cx, value.get(), rval);
} }
}; };
template <class T> template <class T>
struct WrapNewBindingObjectHelper<T, false> struct WrapNewBindingObjectHelper<T, false>
{ {
static inline bool Wrap(JSContext* cx, JS::Handle<JSObject*> scope, T& value, static inline bool Wrap(JSContext* cx, T& value,
JS::MutableHandle<JS::Value> rval) JS::MutableHandle<JS::Value> rval)
{ {
return WrapNewBindingObject(cx, scope, &value, rval); return WrapNewBindingObject(cx, &value, rval);
} }
}; };
template<class T>
inline bool
WrapNewBindingObject(JSContext* cx, T& value, JS::MutableHandle<JS::Value> rval)
{
return WrapNewBindingObjectHelper<T>::Wrap(cx, value, rval);
}
// We need this version of WrapNewBindingObject for codegen, so it'll have the
// same signature as WrapNewBindingNonWrapperCachedObject and
// WrapNewBindingNonWrapperCachedOwnedObject, which still need the scope.
template<class T> template<class T>
inline bool inline bool
WrapNewBindingObject(JSContext* cx, JS::Handle<JSObject*> scope, T& value, WrapNewBindingObject(JSContext* cx, JS::Handle<JSObject*> scope, T& value,
JS::MutableHandle<JS::Value> rval) JS::MutableHandle<JS::Value> rval)
{ {
return WrapNewBindingObjectHelper<T>::Wrap(cx, scope, value, rval); return WrapNewBindingObject(cx, value, rval);
} }
template <class T> template <class T>

Просмотреть файл

@ -1506,7 +1506,7 @@ class CGConstructNavigatorObject(CGAbstractMethod):
return nullptr; return nullptr;
} }
JS::Rooted<JS::Value> v(aCx); JS::Rooted<JS::Value> v(aCx);
if (!WrapNewBindingObject(aCx, aObj, result, &v)) { if (!WrapNewBindingObject(aCx, result, &v)) {
//XXX Assertion disabled for now, see bug 991271. //XXX Assertion disabled for now, see bug 991271.
MOZ_ASSERT(true || JS_IsExceptionPending(aCx)); MOZ_ASSERT(true || JS_IsExceptionPending(aCx));
return nullptr; return nullptr;
@ -11402,8 +11402,9 @@ class CGJSImplMethod(CGJSImplMember):
// Wrap the object before calling __Init so that __DOM_IMPL__ is available. // Wrap the object before calling __Init so that __DOM_IMPL__ is available.
nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(window); nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(window);
JS::Rooted<JSObject*> scopeObj(cx, globalHolder->GetGlobalJSObject()); JS::Rooted<JSObject*> scopeObj(cx, globalHolder->GetGlobalJSObject());
MOZ_ASSERT(js::IsObjectInContextCompartment(scopeObj, cx));
JS::Rooted<JS::Value> wrappedVal(cx); JS::Rooted<JS::Value> wrappedVal(cx);
if (!WrapNewBindingObject(cx, scopeObj, impl, &wrappedVal)) { if (!WrapNewBindingObject(cx, impl, &wrappedVal)) {
//XXX Assertion disabled for now, see bug 991271. //XXX Assertion disabled for now, see bug 991271.
MOZ_ASSERT(true || JS_IsExceptionPending(cx)); MOZ_ASSERT(true || JS_IsExceptionPending(cx));
aRv.Throw(NS_ERROR_UNEXPECTED); aRv.Throw(NS_ERROR_UNEXPECTED);
@ -11664,7 +11665,8 @@ class CGJSImplClass(CGBindingImplClass):
"}\n" "}\n"
"JS::Rooted<JSObject*> arg(cx, &args[1].toObject());\n" "JS::Rooted<JSObject*> arg(cx, &args[1].toObject());\n"
"nsRefPtr<${implName}> impl = new ${implName}(arg, window);\n" "nsRefPtr<${implName}> impl = new ${implName}(arg, window);\n"
"return WrapNewBindingObject(cx, arg, impl, args.rval());" "MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx));\n"
"return WrapNewBindingObject(cx, impl, args.rval());"
).substitute({ ).substitute({
"ifaceName": self.descriptor.interface.identifier.name, "ifaceName": self.descriptor.interface.identifier.name,
"implName": self.descriptor.name "implName": self.descriptor.name

Просмотреть файл

@ -90,10 +90,11 @@ ThrowExceptionObject(JSContext* aCx, Exception* aException)
JS::Rooted<JSObject*> glob(aCx, JS::CurrentGlobalOrNull(aCx)); JS::Rooted<JSObject*> glob(aCx, JS::CurrentGlobalOrNull(aCx));
if (!glob) { if (!glob) {
// XXXbz Can this actually be null here?
return false; return false;
} }
if (!WrapNewBindingObject(aCx, glob, aException, &thrown)) { if (!WrapNewBindingObject(aCx, aException, &thrown)) {
return false; return false;
} }

Просмотреть файл

@ -441,7 +441,8 @@ IndexedDatabaseManager::DefineIndexedDB(JSContext* aCx,
MOZ_ASSERT(factory, "This should never fail for chrome!"); MOZ_ASSERT(factory, "This should never fail for chrome!");
JS::Rooted<JS::Value> indexedDB(aCx); JS::Rooted<JS::Value> indexedDB(aCx);
if (!WrapNewBindingObject(aCx, aGlobal, factory, &indexedDB)) { js::AssertSameCompartment(aCx, aGlobal);
if (!WrapNewBindingObject(aCx, factory, &indexedDB)) {
return false; return false;
} }

Просмотреть файл

@ -257,7 +257,7 @@ Promise::GetOrCreateWrapper(JSContext* aCx)
JSAutoCompartment ac(aCx, scope); JSAutoCompartment ac(aCx, scope);
JS::Rooted<JS::Value> val(aCx); JS::Rooted<JS::Value> val(aCx);
if (!WrapNewBindingObject(aCx, scope, this, &val)) { if (!WrapNewBindingObject(aCx, this, &val)) {
MOZ_ASSERT(JS_IsExceptionPending(aCx)); MOZ_ASSERT(JS_IsExceptionPending(aCx));
return nullptr; return nullptr;
} }
@ -433,7 +433,7 @@ Promise::CreateFunction(JSContext* aCx, JSObject* aParent, Promise* aPromise,
JS::Rooted<JSObject*> obj(aCx, JS_GetFunctionObject(func)); JS::Rooted<JSObject*> obj(aCx, JS_GetFunctionObject(func));
JS::Rooted<JS::Value> promiseObj(aCx); JS::Rooted<JS::Value> promiseObj(aCx);
if (!dom::WrapNewBindingObject(aCx, obj, aPromise, &promiseObj)) { if (!dom::WrapNewBindingObject(aCx, aPromise, &promiseObj)) {
return nullptr; return nullptr;
} }
@ -460,7 +460,7 @@ Promise::CreateThenableFunction(JSContext* aCx, Promise* aPromise, uint32_t aTas
JS::Rooted<JSObject*> obj(aCx, JS_GetFunctionObject(func)); JS::Rooted<JSObject*> obj(aCx, JS_GetFunctionObject(func));
JS::Rooted<JS::Value> promiseObj(aCx); JS::Rooted<JS::Value> promiseObj(aCx);
if (!dom::WrapNewBindingObject(aCx, obj, aPromise, &promiseObj)) { if (!dom::WrapNewBindingObject(aCx, aPromise, &promiseObj)) {
return nullptr; return nullptr;
} }

Просмотреть файл

@ -229,9 +229,7 @@ private:
JSObject* aScope, JSObject* aScope,
JS::MutableHandle<JS::Value> aValue) JS::MutableHandle<JS::Value> aValue)
{ {
JS::Rooted<JSObject*> scope(aCx, aScope); return WrapNewBindingObject(aCx, aArgument, aValue);
return WrapNewBindingObject(aCx, scope, aArgument, aValue);
} }
// Accept typed arrays built from appropriate nsTArray values // Accept typed arrays built from appropriate nsTArray values