author | Peter Van der Beken <peterv@propagandism.org> |
Fri, 08 Apr 2011 10:50:49 -0700 | |
changeset 67679 | 630f16c6e6f449c7f61364da36d84b26334297f1 |
parent 67678 | a6822a5df63359c0e731887fd8aab5f5fd02f6d6 |
child 67680 | 92c7b48558d51624e4c9b077100197b45be2d911 |
push id | 19412 |
push user | pvanderbeken@mozilla.com |
push date | Fri, 08 Apr 2011 20:41:27 +0000 |
treeherder | mozilla-central@ed2f1691ff2f [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | bent |
bugs | 648359 |
milestone | 2.2a1pre |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
dom/base/nsDOMClassInfo.cpp | file | annotate | diff | comparison | revisions | |
dom/base/nsDOMClassInfo.h | file | annotate | diff | comparison | revisions |
--- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -1737,16 +1737,111 @@ IdToString(JSContext *cx, jsid id) if (JSID_IS_STRING(id)) return JSID_TO_STRING(id); jsval idval; if (!::JS_IdToValue(cx, id, &idval)) return nsnull; return JS_ValueToString(cx, idval); } +static inline nsresult +WrapNative(JSContext *cx, JSObject *scope, nsISupports *native, + nsWrapperCache *cache, const nsIID* aIID, jsval *vp, + nsIXPConnectJSObjectHolder** aHolder, PRBool aAllowWrapping) +{ + if (!native) { + NS_ASSERTION(!aHolder || !*aHolder, "*aHolder should be null!"); + + *vp = JSVAL_NULL; + + return NS_OK; + } + + JSObject *wrapper = xpc_FastGetCachedWrapper(cache, scope, vp); + if (wrapper) { + return NS_OK; + } + + return nsDOMClassInfo::XPConnect()->WrapNativeToJSVal(cx, scope, native, + cache, aIID, + aAllowWrapping, vp, + aHolder); +} + +static inline nsresult +WrapNative(JSContext *cx, JSObject *scope, nsISupports *native, + const nsIID* aIID, PRBool aAllowWrapping, jsval *vp, + // If non-null aHolder will keep the jsval alive + // while there's a ref to it + nsIXPConnectJSObjectHolder** aHolder = nsnull) +{ + return WrapNative(cx, scope, native, nsnull, aIID, vp, aHolder, + aAllowWrapping); +} + +// Same as the WrapNative above, but use these if aIID is nsISupports' IID. +static inline nsresult +WrapNative(JSContext *cx, JSObject *scope, nsISupports *native, + PRBool aAllowWrapping, jsval *vp, + // If non-null aHolder will keep the jsval alive + // while there's a ref to it + nsIXPConnectJSObjectHolder** aHolder = nsnull) +{ + return WrapNative(cx, scope, native, nsnull, nsnull, vp, aHolder, + aAllowWrapping); +} + +static inline nsresult +WrapNative(JSContext *cx, JSObject *scope, nsISupports *native, + nsWrapperCache *cache, PRBool aAllowWrapping, jsval *vp, + // If non-null aHolder will keep the jsval alive + // while there's a ref to it + nsIXPConnectJSObjectHolder** aHolder = nsnull) +{ + return WrapNative(cx, scope, native, cache, nsnull, vp, aHolder, + aAllowWrapping); +} + +// Used for cases where PreCreate needs to wrap the native parent, and the +// native parent is likely to have been wrapped already. |native| must +// implement nsWrapperCache, and nativeWrapperCache must be |native|'s +// nsWrapperCache. +static inline nsresult +WrapNativeParent(JSContext *cx, JSObject *scope, nsISupports *native, + nsWrapperCache *nativeWrapperCache, + JSObject **parentObj) +{ + // In the common case, |native| is a wrapper cache with an existing wrapper +#ifdef DEBUG + nsWrapperCache* cache = nsnull; + CallQueryInterface(native, &cache); + NS_PRECONDITION(nativeWrapperCache && + cache == nativeWrapperCache, "What happened here?"); +#endif + + JSObject* obj = nativeWrapperCache->GetWrapper(); + if (obj) { +#ifdef DEBUG + jsval debugVal; + nsresult rv = WrapNative(cx, scope, native, nativeWrapperCache, PR_FALSE, + &debugVal); + NS_ASSERTION(NS_SUCCEEDED(rv) && JSVAL_TO_OBJECT(debugVal) == obj, + "Unexpected object in nsWrapperCache"); +#endif + *parentObj = obj; + return NS_OK; + } + + jsval v; + nsresult rv = WrapNative(cx, scope, native, nativeWrapperCache, PR_FALSE, &v); + NS_ENSURE_SUCCESS(rv, rv); + *parentObj = JSVAL_TO_OBJECT(v); + return NS_OK; +} + // static nsISupports * nsDOMClassInfo::GetNative(nsIXPConnectWrappedNative *wrapper, JSObject *obj) { return wrapper ? wrapper->Native() : static_cast<nsISupports*>(obj->getPrivate()); } @@ -1899,19 +1994,19 @@ CreateExceptionFromResult(JSContext *cx, nsCOMPtr<nsIException> exception; rv = xm->GetExceptionFromProvider(aResult, 0, getter_AddRefs(exception)); if (NS_FAILED(rv) || !exception) { return NS_ERROR_FAILURE; } jsval jv; nsCOMPtr<nsIXPConnectJSObjectHolder> holder; - rv = nsDOMClassInfo::WrapNative(cx, ::JS_GetGlobalObject(cx), exception, - &NS_GET_IID(nsIException), PR_FALSE, &jv, - getter_AddRefs(holder)); + rv = WrapNative(cx, ::JS_GetGlobalObject(cx), exception, + &NS_GET_IID(nsIException), PR_FALSE, &jv, + getter_AddRefs(holder)); if (NS_FAILED(rv) || JSVAL_IS_NULL(jv)) { return NS_ERROR_FAILURE; } JSAutoEnterCompartment ac; if (JSVAL_IS_OBJECT(jv)) { if (!ac.enter(cx, JSVAL_TO_OBJECT(jv))) { @@ -2117,51 +2212,16 @@ nsDOMClassInfo::RegisterExternalClasses( rv = nameSpaceManager->RegisterExternalClassName(categoryEntry.get(), *cid); nsMemory::Free(cid); NS_ENSURE_SUCCESS(rv, rv); } return nameSpaceManager->RegisterExternalInterfaces(PR_TRUE); } -// static -inline nsresult -nsDOMClassInfo::WrapNativeParent(JSContext *cx, JSObject *scope, - nsISupports *native, - nsWrapperCache *nativeWrapperCache, - JSObject **parentObj) -{ - // In the common case, |native| is a wrapper cache with an existing wrapper -#ifdef DEBUG - nsWrapperCache* cache = nsnull; - CallQueryInterface(native, &cache); - NS_PRECONDITION(nativeWrapperCache && - cache == nativeWrapperCache, "What happened here?"); -#endif - - JSObject* obj = nativeWrapperCache->GetWrapper(); - if (obj) { -#ifdef DEBUG - jsval debugVal; - nsresult rv = WrapNative(cx, scope, native, nativeWrapperCache, PR_FALSE, - &debugVal); - NS_ASSERTION(NS_SUCCEEDED(rv) && JSVAL_TO_OBJECT(debugVal) == obj, - "Unexpected object in nsWrapperCache"); -#endif - *parentObj = obj; - return NS_OK; - } - - jsval v; - nsresult rv = WrapNative(cx, scope, native, nativeWrapperCache, PR_FALSE, &v); - NS_ENSURE_SUCCESS(rv, rv); - *parentObj = JSVAL_TO_OBJECT(v); - return NS_OK; -} - #define _DOM_CLASSINFO_MAP_BEGIN(_class, _ifptr, _has_class_if) \ { \ nsDOMClassInfoData &d = sClassInfoData[eDOMClassInfo_##_class##_id]; \ d.mProtoChainInterface = _ifptr; \ d.mHasClassInterface = _has_class_if; \ d.mInterfacesBitmap = kDOMClassInfo_##_class##_interfaces; \ static const nsIID *interface_list[] = { @@ -4237,41 +4297,16 @@ nsDOMClassInfo::GetArrayIndexFromId(JSCo if (aIsNumber) { *aIsNumber = PR_TRUE; } return i; } -// static -nsresult -nsDOMClassInfo::WrapNative(JSContext *cx, JSObject *scope, - nsISupports *native, nsWrapperCache *cache, - const nsIID* aIID, jsval *vp, - nsIXPConnectJSObjectHolder** aHolder, - PRBool aAllowWrapping) -{ - if (!native) { - NS_ASSERTION(!aHolder || !*aHolder, "*aHolder should be null!"); - - *vp = JSVAL_NULL; - - return NS_OK; - } - - JSObject *wrapper = xpc_FastGetCachedWrapper(cache, scope, vp); - if (wrapper) { - return NS_OK; - } - - return sXPConnect->WrapNativeToJSVal(cx, scope, native, cache, aIID, - aAllowWrapping, vp, aHolder); -} - NS_IMETHODIMP nsDOMClassInfo::GetInterfaces(PRUint32 *aCount, nsIID ***aArray) { PRUint32 count = 0; while (mData->mInterfaces[count]) { count++; } @@ -5499,19 +5534,17 @@ BaseStubConstructor(nsIWeakReference* aW if (NS_SUCCEEDED(rv)) { *rval = OBJECT_TO_JSVAL(new_obj); } return rv; } - rv = nsDOMGenericSH::WrapNative(cx, obj, native, PR_TRUE, rval); - - return rv; + return WrapNative(cx, obj, native, PR_TRUE, rval); } static nsresult DefineInterfaceConstants(JSContext *cx, JSObject *obj, const nsIID *aIID) { nsCOMPtr<nsIInterfaceInfoManager> iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID)); NS_ENSURE_TRUE(iim, NS_ERROR_UNEXPECTED); @@ -6074,19 +6107,18 @@ ResolvePrototype(nsIXPConnect *aXPConnec nsRefPtr<nsDOMConstructor> constructor; nsresult rv = nsDOMConstructor::Create(name, ci_data, name_struct, aWin, getter_AddRefs(constructor)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIXPConnectJSObjectHolder> holder; jsval v; - rv = nsDOMClassInfo::WrapNative(cx, obj, constructor, - &NS_GET_IID(nsIDOMDOMConstructor), - PR_FALSE, &v, getter_AddRefs(holder)); + rv = WrapNative(cx, obj, constructor, &NS_GET_IID(nsIDOMDOMConstructor), + PR_FALSE, &v, getter_AddRefs(holder)); NS_ENSURE_SUCCESS(rv, rv); if (install) { rv = constructor->Install(cx, obj, v); NS_ENSURE_SUCCESS(rv, rv); } JSObject *class_obj; @@ -8673,20 +8705,19 @@ nsHTMLDocumentSH::GetDocumentAllNodeList nsRefPtr<nsContentList> list = domdoc->GetElementsByTagName(NS_LITERAL_STRING("*")); if (!list) { rv |= NS_ERROR_OUT_OF_MEMORY; } nsCOMPtr<nsIXPConnectJSObjectHolder> holder; - rv |= nsDOMClassInfo::WrapNative(cx, JS_GetGlobalForScopeChain(cx), - static_cast<nsINodeList*>(list), - list, PR_FALSE, &collection, - getter_AddRefs(holder)); + rv |= WrapNative(cx, JS_GetGlobalForScopeChain(cx), + static_cast<nsINodeList*>(list), list, PR_FALSE, + &collection, getter_AddRefs(holder)); list.forget(nodeList); // ... and store it in our reserved slot. if (!JS_SetReservedSlot(cx, obj, 0, collection)) { return JS_FALSE; } } @@ -9048,20 +9079,19 @@ nsHTMLDocumentSH::DocumentAllTagsNewReso } nsRefPtr<nsContentList> tags = doc->GetElementsByTagName(nsDependentJSString(id)); if (tags) { jsval v; nsCOMPtr<nsIXPConnectJSObjectHolder> holder; - nsresult rv = nsDOMClassInfo::WrapNative(cx, JS_GetGlobalForScopeChain(cx), - static_cast<nsINodeList*>(tags), - tags, PR_TRUE, &v, - getter_AddRefs(holder)); + nsresult rv = WrapNative(cx, JS_GetGlobalForScopeChain(cx), + static_cast<nsINodeList*>(tags), tags, PR_TRUE, + &v, getter_AddRefs(holder)); if (NS_FAILED(rv)) { nsDOMClassInfo::ThrowJSException(cx, rv); return JS_FALSE; } if (!::JS_DefinePropertyById(cx, obj, id, v, nsnull, nsnull, 0)) { return JS_FALSE;
--- a/dom/base/nsDOMClassInfo.h +++ b/dom/base/nsDOMClassInfo.h @@ -145,58 +145,16 @@ public: static void ShutDown(); static nsIClassInfo *doCreate(nsDOMClassInfoData* aData) { return new nsDOMClassInfo(aData); } - static nsresult WrapNative(JSContext *cx, JSObject *scope, - nsISupports *native, const nsIID* aIID, - PRBool aAllowWrapping, jsval *vp, - // If non-null aHolder will keep the jsval alive - // while there's a ref to it - nsIXPConnectJSObjectHolder** aHolder = nsnull) - { - return WrapNative(cx, scope, native, nsnull, aIID, vp, aHolder, - aAllowWrapping); - } - - // Used for cases where PreCreate needs to wrap the native parent, and the - // native parent is likely to have been wrapped already. |native| must - // implement nsWrapperCache, and nativeWrapperCache must be |native|'s - // nsWrapperCache. - static inline nsresult WrapNativeParent(JSContext *cx, JSObject *scope, - nsISupports *native, - nsWrapperCache *nativeWrapperCache, - JSObject **parentObj); - - // Same as the WrapNative above, but use these if aIID is nsISupports' IID. - static nsresult WrapNative(JSContext *cx, JSObject *scope, - nsISupports *native, PRBool aAllowWrapping, - jsval *vp, - // If non-null aHolder will keep the jsval alive - // while there's a ref to it - nsIXPConnectJSObjectHolder** aHolder = nsnull) - { - return WrapNative(cx, scope, native, nsnull, nsnull, vp, aHolder, - aAllowWrapping); - } - static nsresult WrapNative(JSContext *cx, JSObject *scope, - nsISupports *native, nsWrapperCache *cache, - PRBool aAllowWrapping, jsval *vp, - // If non-null aHolder will keep the jsval alive - // while there's a ref to it - nsIXPConnectJSObjectHolder** aHolder = nsnull) - { - return WrapNative(cx, scope, native, cache, nsnull, vp, aHolder, - aAllowWrapping); - } - static nsresult ThrowJSException(JSContext *cx, nsresult aResult); /* * The following two functions exist because of the way that Xray wrappers * work. In order to allow scriptable helpers to define non-IDL defined but * still "safe" properties for Xray wrappers, we call into the scriptable * helper with |obj| being the wrapper. * @@ -271,22 +229,16 @@ protected: id == sOuterHeight_id || id == sOuterWidth_id || id == sScreenX_id || id == sScreenY_id || id == sStatus_id || id == sName_id); } - inline static nsresult WrapNative(JSContext *cx, JSObject *scope, - nsISupports *native, nsWrapperCache *cache, - const nsIID* aIID, jsval *vp, - nsIXPConnectJSObjectHolder** aHolder, - PRBool aAllowWrapping); - static nsIXPConnect *sXPConnect; static nsIScriptSecurityManager *sSecMan; // nsIXPCScriptable code static nsresult DefineStaticJSVals(JSContext *cx); static PRBool sIsInitialized; static PRBool sDisableDocumentAllSupport;