From 31ccf86cf95712a3cdff4999998f8b94c23f6f91 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 6 Jun 2012 15:59:46 -0400 Subject: [PATCH] Bug 761707 part 2. Drop the vestigial jsclass argument to UnwrapDOMObject. r=bholley --- caps/src/nsScriptSecurityManager.cpp | 4 ++-- dom/bindings/BindingUtils.cpp | 5 +++-- dom/bindings/BindingUtils.h | 17 ++++++++--------- dom/bindings/Codegen.py | 3 +-- dom/workers/Worker.cpp | 12 ++++++------ dom/workers/WorkerScope.cpp | 8 ++++---- js/xpconnect/src/XPCConvert.cpp | 4 ++-- js/xpconnect/src/XPCJSID.cpp | 3 +-- js/xpconnect/src/XPCJSRuntime.cpp | 7 ++++--- js/xpconnect/src/XPCWrappedNativeScope.cpp | 4 ++-- js/xpconnect/src/nsXPConnect.cpp | 4 ++-- 11 files changed, 35 insertions(+), 36 deletions(-) diff --git a/caps/src/nsScriptSecurityManager.cpp b/caps/src/nsScriptSecurityManager.cpp index 54a2535ed81..bd41bb8ea15 100644 --- a/caps/src/nsScriptSecurityManager.cpp +++ b/caps/src/nsScriptSecurityManager.cpp @@ -2442,9 +2442,9 @@ nsScriptSecurityManager::doGetObjectPrincipal(JSObject *aObj if (!(~jsClass->flags & (JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS))) { priv = (nsISupports *) js::GetObjectPrivate(aObj); - } else if ((jsClass->flags & JSCLASS_IS_DOMJSCLASS) && + } else if (IsDOMClass(jsClass) && DOMJSClass::FromJSClass(jsClass)->mDOMObjectIsISupports) { - priv = UnwrapDOMObject(aObj, jsClass); + priv = UnwrapDOMObject(aObj); } else { priv = nsnull; } diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index b124a13da46..be6d8fa4f76 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -340,11 +340,12 @@ QueryInterface(JSContext* cx, unsigned argc, JS::Value* vp) JSObject* obj = JSVAL_TO_OBJECT(thisv); JSClass* clasp = js::GetObjectJSClass(obj); - if (!IsDOMClass(clasp)) { + if (!IsDOMClass(clasp) || + !DOMJSClass::FromJSClass(clasp)->mDOMObjectIsISupports) { return Throw(cx, NS_ERROR_FAILURE); } - nsISupports* native = UnwrapDOMObject(obj, clasp); + nsISupports* native = UnwrapDOMObject(obj); if (argc < 1) { return Throw(cx, NS_ERROR_XPC_NOT_ENOUGH_ARGS); diff --git a/dom/bindings/BindingUtils.h b/dom/bindings/BindingUtils.h index b67110bec54..7a36e5fa096 100644 --- a/dom/bindings/BindingUtils.h +++ b/dom/bindings/BindingUtils.h @@ -60,9 +60,15 @@ IsDOMClass(const JSClass* clasp) return clasp->flags & JSCLASS_IS_DOMJSCLASS; } +inline bool +IsDOMClass(const js::Class* clasp) +{ + return clasp->flags & JSCLASS_IS_DOMJSCLASS; +} + template inline T* -UnwrapDOMObject(JSObject* obj, const JSClass* clasp) +UnwrapDOMObject(JSObject* obj) { JS::Value val = js::GetReservedSlot(obj, DOM_OBJECT_SLOT); // XXXbz/khuey worker code tries to unwrap interface objects (which have @@ -76,13 +82,6 @@ UnwrapDOMObject(JSObject* obj, const JSClass* clasp) return static_cast(val.toPrivate()); } -template -inline T* -UnwrapDOMObject(JSObject* obj, const js::Class* clasp) -{ - return UnwrapDOMObject(obj, Jsvalify(clasp)); -} - // Some callers don't want to set an exception when unwrappin fails // (for example, overload resolution uses unwrapping to tell what sort // of thing it's looking at). @@ -120,7 +119,7 @@ UnwrapObject(JSContext* cx, JSObject* obj, U& value) DOMJSClass* domClass = DOMJSClass::FromJSClass(clasp); if (domClass->mInterfaceChain[PrototypeTraits::Depth] == PrototypeID) { - value = UnwrapDOMObject(obj, clasp); + value = UnwrapDOMObject(obj); return NS_OK; } diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index e32050ee23c..6a898583bc3 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -464,8 +464,7 @@ class CGAbstractClassHook(CGAbstractStaticMethod): def definition_body_prologue(self): return """ - MOZ_ASSERT(js::GetObjectJSClass(obj) == Class.ToJSClass()); - %s* self = UnwrapDOMObject<%s>(obj, Class.ToJSClass()); + %s* self = UnwrapDOMObject<%s>(obj); """ % (self.descriptor.nativeType, self.descriptor.nativeType) def definition_body(self): diff --git a/dom/workers/Worker.cpp b/dom/workers/Worker.cpp index ab1eb20d473..25ea433c158 100644 --- a/dom/workers/Worker.cpp +++ b/dom/workers/Worker.cpp @@ -217,7 +217,7 @@ private: Finalize(JSFreeOp* aFop, JSObject* aObj) { JS_ASSERT(JS_GetClass(aObj) == Class()); - WorkerPrivate* worker = UnwrapDOMObject(aObj, Class()); + WorkerPrivate* worker = UnwrapDOMObject(aObj); if (worker) { worker->_finalize(aFop); } @@ -227,7 +227,7 @@ private: Trace(JSTracer* aTrc, JSObject* aObj) { JS_ASSERT(JS_GetClass(aObj) == Class()); - WorkerPrivate* worker = UnwrapDOMObject(aObj, Class()); + WorkerPrivate* worker = UnwrapDOMObject(aObj); if (worker) { worker->_trace(aTrc); } @@ -358,7 +358,7 @@ private: if (aObj) { JSClass* classPtr = JS_GetClass(aObj); if (classPtr == Class()) { - return UnwrapDOMObject(aObj, Class()); + return UnwrapDOMObject(aObj); } } @@ -375,7 +375,7 @@ private: Finalize(JSFreeOp* aFop, JSObject* aObj) { JS_ASSERT(JS_GetClass(aObj) == Class()); - WorkerPrivate* worker = UnwrapDOMObject(aObj, Class()); + WorkerPrivate* worker = UnwrapDOMObject(aObj); if (worker) { worker->_finalize(aFop); } @@ -385,7 +385,7 @@ private: Trace(JSTracer* aTrc, JSObject* aObj) { JS_ASSERT(JS_GetClass(aObj) == Class()); - WorkerPrivate* worker = UnwrapDOMObject(aObj, Class()); + WorkerPrivate* worker = UnwrapDOMObject(aObj); if (worker) { worker->_trace(aTrc); } @@ -414,7 +414,7 @@ Worker::GetInstancePrivate(JSContext* aCx, JSObject* aObj, { JSClass* classPtr = JS_GetClass(aObj); if (classPtr == Class() || classPtr == ChromeWorker::Class()) { - return UnwrapDOMObject(aObj, classPtr); + return UnwrapDOMObject(aObj); } JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO, diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index d0b0051eee5..d9387f1375e 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -768,7 +768,7 @@ private: { JSClass* classPtr = JS_GetClass(aObj); if (classPtr == Class()) { - return UnwrapDOMObject(aObj, classPtr); + return UnwrapDOMObject(aObj); } JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, @@ -803,7 +803,7 @@ private: { JS_ASSERT(JS_GetClass(aObj) == Class()); DedicatedWorkerGlobalScope* scope = - UnwrapDOMObject(aObj, Class()); + UnwrapDOMObject(aObj); if (scope) { DestroyProtoOrIfaceCache(aObj); scope->_finalize(aFop); @@ -815,7 +815,7 @@ private: { JS_ASSERT(JS_GetClass(aObj) == Class()); DedicatedWorkerGlobalScope* scope = - UnwrapDOMObject(aObj, Class()); + UnwrapDOMObject(aObj); if (scope) { mozilla::dom::TraceProtoOrIfaceCache(aTrc, aObj); scope->_trace(aTrc); @@ -888,7 +888,7 @@ WorkerGlobalScope::GetInstancePrivate(JSContext* aCx, JSObject* aObj, JS_ASSERT(classPtr != Class()); if (classPtr == DedicatedWorkerGlobalScope::Class()) { - return UnwrapDOMObject(aObj, classPtr); + return UnwrapDOMObject(aObj); } JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO, diff --git a/js/xpconnect/src/XPCConvert.cpp b/js/xpconnect/src/XPCConvert.cpp index 9df149b2b94..8e730241c92 100644 --- a/js/xpconnect/src/XPCConvert.cpp +++ b/js/xpconnect/src/XPCConvert.cpp @@ -74,9 +74,9 @@ XPCConvert::GetISupportsFromJSObject(JSObject* obj, nsISupports** iface) *iface = (nsISupports*) xpc_GetJSPrivate(obj); return true; } - if (jsclass && (jsclass->flags & JSCLASS_IS_DOMJSCLASS) && + if (jsclass && IsDOMClass(jsclass) && DOMJSClass::FromJSClass(jsclass)->mDOMObjectIsISupports) { - *iface = UnwrapDOMObject(obj, jsclass); + *iface = UnwrapDOMObject(obj); return true; } return false; diff --git a/js/xpconnect/src/XPCJSID.cpp b/js/xpconnect/src/XPCJSID.cpp index 06ca95107b6..14a104463d5 100644 --- a/js/xpconnect/src/XPCJSID.cpp +++ b/js/xpconnect/src/XPCJSID.cpp @@ -489,8 +489,7 @@ nsJSIID::HasInstance(nsIXPConnectWrappedNative *wrapper, js::GetObjectJSClass(obj))->mDOMObjectIsISupports, "This only works on nsISupports classes!"); identity = - mozilla::dom::UnwrapDOMObject(obj, - js::GetObjectJSClass(obj)); + mozilla::dom::UnwrapDOMObject(obj); } else { identity = nsnull; } diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index b75d0295877..8a562231bd2 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -25,6 +25,7 @@ #include "jsfriendapi.h" #include "js/MemoryMetrics.h" #include "mozilla/dom/DOMJSClass.h" +#include "mozilla/dom/BindingUtils.h" #include "nsJSPrincipals.h" @@ -460,14 +461,14 @@ SuspectDOMExpandos(nsPtrHashKey *key, void *arg) JSObject* obj = key->GetKey(); nsISupports* native = nsnull; if (js::IsProxy(obj)) { - NS_ASSERTION(mozilla::dom::binding::instanceIsProxy(obj), + NS_ASSERTION(dom::binding::instanceIsProxy(obj), "Not a DOM proxy?"); native = static_cast(js::GetProxyPrivate(obj).toPrivate()); } else { - NS_ASSERTION(mozilla::dom::DOMJSClass::FromJSClass(JS_GetClass(obj))->mDOMObjectIsISupports, + NS_ASSERTION(dom::DOMJSClass::FromJSClass(JS_GetClass(obj))->mDOMObjectIsISupports, "Someone added a wrapper for a non-nsISupports native to DOMExpandos!"); - native = static_cast(js::GetReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate()); + native = dom::UnwrapDOMObject(obj); } closure->cb->NoteXPCOMRoot(native); return PL_DHASH_NEXT; diff --git a/js/xpconnect/src/XPCWrappedNativeScope.cpp b/js/xpconnect/src/XPCWrappedNativeScope.cpp index 1f62ddd42c6..680a3c5b294 100644 --- a/js/xpconnect/src/XPCWrappedNativeScope.cpp +++ b/js/xpconnect/src/XPCWrappedNativeScope.cpp @@ -223,9 +223,9 @@ XPCWrappedNativeScope::SetGlobal(XPCCallContext& ccx, JSObject* aGlobal, // Our global has an nsISupports native pointer. Let's // see whether it's what we want. priv = static_cast(xpc_GetJSPrivate(aGlobal)); - } else if ((jsClass->flags & JSCLASS_IS_DOMJSCLASS) && + } else if (dom::IsDOMClass(jsClass) && dom::DOMJSClass::FromJSClass(jsClass)->mDOMObjectIsISupports) { - priv = dom::UnwrapDOMObject(aGlobal, jsClass); + priv = dom::UnwrapDOMObject(aGlobal); } else { priv = nsnull; } diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index f1bc49f5c66..afe264c5c77 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -870,10 +870,10 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb) nsISupports *identity = static_cast(js::GetProxyPrivate(obj).toPrivate()); cb.NoteXPCOMChild(identity); - } else if ((clazz->flags & JSCLASS_IS_DOMJSCLASS) && + } else if (IsDOMClass(clazz) && DOMJSClass::FromJSClass(clazz)->mDOMObjectIsISupports) { NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "UnwrapDOMObject(obj)"); - nsISupports *identity = UnwrapDOMObject(obj, clazz); + nsISupports *identity = UnwrapDOMObject(obj); cb.NoteXPCOMChild(identity); }