From 180ece029420661698dd0d1e767e9a9231992c38 Mon Sep 17 00:00:00 2001 From: Igor Bukanov Date: Fri, 26 Nov 2010 15:11:14 +0100 Subject: [PATCH] Bug 614578 - Removal of nsAutoGCRoot. r=mrbkap --- content/base/public/nsContentUtils.h | 81 ++-------------- content/base/src/nsContentUtils.cpp | 134 +++++--------------------- content/base/src/nsFrameMessageManager.cpp | 17 +--- content/events/src/nsEventListenerService.cpp | 69 +++++++------ content/xbl/src/nsXBLProtoImplField.cpp | 9 +- content/xbl/src/nsXBLProtoImplMember.h | 2 - content/xbl/src/nsXBLProtoImplMethod.cpp | 4 - content/xbl/src/nsXBLProtoImplProperty.cpp | 7 -- dom/base/nsDOMClassInfo.cpp | 12 --- dom/base/nsGlobalWindow.cpp | 6 +- dom/base/nsJSEnvironment.cpp | 15 +-- dom/src/jsurl/nsJSProtocolHandler.cpp | 4 - js/src/jsapi.cpp | 9 ++ js/src/jsapi.h | 27 ++++++ js/src/xpconnect/src/XPCDispTearOff.cpp | 3 +- js/src/xpconnect/src/xpcwrappedjsclass.cpp | 2 - 16 files changed, 119 insertions(+), 282 deletions(-) diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 6c7b516301..1913d64840 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -192,20 +192,18 @@ public: static nsresult Init(); /** - * Get a scope from aOldDocument and one from aNewDocument. Also get a - * context through one of the scopes, from the stack or the safe context. + * Get a scope from aNewDocument. Also get a context through the scope of one + * of the documents, from the stack or the safe context. * - * @param aOldDocument The document to get aOldScope from. + * @param aOldDocument The document to try to get a context from. May be null. * @param aNewDocument The document to get aNewScope from. * @param aCx [out] Context gotten through one of the scopes, from the stack * or the safe context. - * @param aOldScope [out] Scope gotten from aOldDocument. * @param aNewScope [out] Scope gotten from aNewDocument. */ - static nsresult GetContextAndScopes(nsIDocument *aOldDocument, - nsIDocument *aNewDocument, - JSContext **aCx, JSObject **aOldScope, - JSObject **aNewScope); + static nsresult GetContextAndScope(nsIDocument *aOldDocument, + nsIDocument *aNewDocument, + JSContext **aCx, JSObject **aNewScope); /** * When a document's scope changes (e.g., from document.open(), call this @@ -1685,23 +1683,6 @@ public: LayerManagerForDocument(nsIDocument *aDoc); /** - * Returns a layer manager to use for the given document. Basically we - * look up the document hierarchy for the first document which has - * a presentation with an associated widget, and use that widget's - * layer manager. In addition to the normal layer manager lookup this will - * specifically request a persistent layer manager. This means that the layer - * manager is expected to remain the layer manager for the document in the - * forseeable future. This function should be used carefully as it may change - * the document's layer manager. - * - * If one can't be found, a BasicLayerManager is created and returned. - * - * @param aDoc the document for which to return a layer manager. - */ - static already_AddRefed - PersistentLayerManagerForDocument(nsIDocument *aDoc); - - /** * Determine whether a content node is focused or not, * * @param aContent the content node to check @@ -1734,6 +1715,7 @@ public: static bool AllowXULXBLForPrincipal(nsIPrincipal* aPrincipal); private: + static PRBool InitializeEventTable(); static nsresult EnsureStringBundle(PropertiesFile aFile); @@ -1865,48 +1847,6 @@ private: #endif }; -class NS_STACK_CLASS nsAutoGCRoot { -public: - // aPtr should be the pointer to the jsval we want to protect - nsAutoGCRoot(jsval* aPtr, nsresult* aResult - MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM) : - mPtr(aPtr), mRootType(RootType_JSVal) - { - MOZILLA_GUARD_OBJECT_NOTIFIER_INIT; - mResult = *aResult = AddJSGCRoot(aPtr, RootType_JSVal, "nsAutoGCRoot"); - } - - // aPtr should be the pointer to the JSObject* we want to protect - nsAutoGCRoot(JSObject** aPtr, nsresult* aResult - MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM) : - mPtr(aPtr), mRootType(RootType_Object) - { - MOZILLA_GUARD_OBJECT_NOTIFIER_INIT; - mResult = *aResult = AddJSGCRoot(aPtr, RootType_Object, "nsAutoGCRoot"); - } - - ~nsAutoGCRoot() { - if (NS_SUCCEEDED(mResult)) { - RemoveJSGCRoot((jsval *)mPtr, mRootType); - } - } - - static void Shutdown(); - -private: - enum RootType { RootType_JSVal, RootType_Object }; - static nsresult AddJSGCRoot(void *aPtr, RootType aRootType, const char* aName); - static nsresult RemoveJSGCRoot(void *aPtr, RootType aRootType); - - static nsIJSRuntimeService* sJSRuntimeService; - static JSRuntime* sJSScriptRuntime; - - void* mPtr; - RootType mRootType; - nsresult mResult; - MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER -}; - class NS_STACK_CLASS nsAutoScriptBlocker { public: nsAutoScriptBlocker(MOZILLA_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) { @@ -1934,13 +1874,6 @@ private: MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER }; -#define NS_AUTO_GCROOT_PASTE2(tok,line) tok##line -#define NS_AUTO_GCROOT_PASTE(tok,line) \ - NS_AUTO_GCROOT_PASTE2(tok,line) -#define NS_AUTO_GCROOT(ptr, result) \ \ - nsAutoGCRoot NS_AUTO_GCROOT_PASTE(_autoGCRoot_, __LINE__) \ - (ptr, result) - #define NS_INTERFACE_MAP_ENTRY_TEAROFF(_interface, _allocator) \ if (aIID.Equals(NS_GET_IID(_interface))) { \ foundInterface = static_cast<_interface *>(_allocator); \ diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index b97a447710..229787eea0 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -260,9 +260,6 @@ PRUint32 nsContentUtils::sRunnersCountAtFirstBlocker = 0; PRUint32 nsContentUtils::sScriptBlockerCountWhereRunnersPrevented = 0; nsIInterfaceRequestor* nsContentUtils::sSameOriginChecker = nsnull; -nsIJSRuntimeService *nsAutoGCRoot::sJSRuntimeService; -JSRuntime *nsAutoGCRoot::sJSScriptRuntime; - PRBool nsContentUtils::sIsHandlingKeyBoardEvent = PR_FALSE; PRBool nsContentUtils::sAllowXULXBL_for_file = PR_FALSE; @@ -1211,8 +1208,6 @@ nsContentUtils::Shutdown() NS_IF_RELEASE(sSameOriginChecker); - nsAutoGCRoot::Shutdown(); - nsTextEditorState::ShutDown(); } @@ -1371,22 +1366,17 @@ nsContentUtils::InProlog(nsINode *aNode) } static JSContext * -GetContextFromDocument(nsIDocument *aDocument, JSObject** aGlobalObject) +GetContextFromDocument(nsIDocument *aDocument) { nsIScriptGlobalObject *sgo = aDocument->GetScopeObject(); if (!sgo) { // No script global, no context. - - *aGlobalObject = nsnull; - return nsnull; } - *aGlobalObject = sgo->GetGlobalJSObject(); - nsIScriptContext *scx = sgo->GetContext(); if (!scx) { - // No context left in the old scope... + // No context left in the scope... return nsnull; } @@ -1396,39 +1386,27 @@ GetContextFromDocument(nsIDocument *aDocument, JSObject** aGlobalObject) // static nsresult -nsContentUtils::GetContextAndScopes(nsIDocument *aOldDocument, - nsIDocument *aNewDocument, JSContext **aCx, - JSObject **aOldScope, JSObject **aNewScope) +nsContentUtils::GetContextAndScope(nsIDocument *aOldDocument, + nsIDocument *aNewDocument, JSContext **aCx, + JSObject **aNewScope) { *aCx = nsnull; - *aOldScope = nsnull; *aNewScope = nsnull; - JSObject *newScope = nsnull; - nsIScriptGlobalObject *newSGO = aNewDocument->GetScopeObject(); - if (!newSGO || !(newScope = newSGO->GetGlobalJSObject())) { - return NS_OK; + JSObject *newScope = aNewDocument->GetWrapper(); + JSObject *global; + if (!newScope) { + nsIScriptGlobalObject *newSGO = aNewDocument->GetScopeObject(); + if (!newSGO || !(global = newSGO->GetGlobalJSObject())) { + return NS_OK; + } } NS_ENSURE_TRUE(sXPConnect, NS_ERROR_NOT_INITIALIZED); - // Make sure to get our hands on the right scope object, since - // GetWrappedNativeOfNativeObject doesn't call PreCreate and hence won't get - // the right scope if we pass in something bogus. The right scope lives on - // the script global of the old document. - // XXXbz note that if GetWrappedNativeOfNativeObject did call PreCreate it - // would get the wrong scope (that of the _new_ document), so we should be - // glad it doesn't! - JSObject *oldScope = nsnull; - JSContext *cx = GetContextFromDocument(aOldDocument, &oldScope); - - if (!oldScope) { - return NS_OK; - } - + JSContext *cx = aOldDocument ? GetContextFromDocument(aOldDocument) : nsnull; if (!cx) { - JSObject *dummy; - cx = GetContextFromDocument(aNewDocument, &dummy); + cx = GetContextFromDocument(aNewDocument); if (!cx) { // No context reachable from the old or new document, use the @@ -1450,8 +1428,15 @@ nsContentUtils::GetContextAndScopes(nsIDocument *aOldDocument, } } + if (!newScope && cx) { + jsval v; + nsresult rv = WrapNative(cx, global, aNewDocument, aNewDocument, &v); + NS_ENSURE_SUCCESS(rv, rv); + + newScope = JSVAL_TO_OBJECT(v); + } + *aCx = cx; - *aOldScope = oldScope; *aNewScope = newScope; return NS_OK; @@ -3286,53 +3271,6 @@ nsContentUtils::GetContentPolicy() } // static -nsresult -nsAutoGCRoot::AddJSGCRoot(void* aPtr, RootType aRootType, const char* aName) -{ - if (!sJSScriptRuntime) { - nsresult rv = CallGetService("@mozilla.org/js/xpc/RuntimeService;1", - &sJSRuntimeService); - NS_ENSURE_TRUE(sJSRuntimeService, rv); - - sJSRuntimeService->GetRuntime(&sJSScriptRuntime); - if (!sJSScriptRuntime) { - NS_RELEASE(sJSRuntimeService); - NS_WARNING("Unable to get JS runtime from JS runtime service"); - return NS_ERROR_FAILURE; - } - } - - PRBool ok; - if (aRootType == RootType_JSVal) - ok = ::js_AddRootRT(sJSScriptRuntime, (jsval *)aPtr, aName); - else - ok = ::js_AddGCThingRootRT(sJSScriptRuntime, (void **)aPtr, aName); - if (!ok) { - NS_WARNING("JS_AddNamedRootRT failed"); - return NS_ERROR_OUT_OF_MEMORY; - } - - return NS_OK; -} - -/* static */ -nsresult -nsAutoGCRoot::RemoveJSGCRoot(void* aPtr, RootType aRootType) -{ - if (!sJSScriptRuntime) { - NS_NOTREACHED("Trying to remove a JS GC root when none were added"); - return NS_ERROR_UNEXPECTED; - } - - if (aRootType == RootType_JSVal) - ::js_RemoveRoot(sJSScriptRuntime, (jsval *)aPtr); - else - ::js_RemoveRoot(sJSScriptRuntime, (JSObject **)aPtr); - - return NS_OK; -} - -// static PRBool nsContentUtils::IsEventAttributeName(nsIAtom* aName, PRInt32 aType) { @@ -5195,13 +5133,6 @@ nsContentUtils::EqualsIgnoreASCIICase(const nsAString& aStr1, } /* static */ -void -nsAutoGCRoot::Shutdown() -{ - NS_IF_RELEASE(sJSRuntimeService); -} - -/* static */ nsIInterfaceRequestor* nsContentUtils::GetSameOriginChecker() { @@ -6380,8 +6311,8 @@ nsContentUtils::PlatformToDOMLineBreaks(nsString &aString) } } -static already_AddRefed -LayerManagerForDocumentInternal(nsIDocument *aDoc, bool aRequirePersistent) +already_AddRefed +nsContentUtils::LayerManagerForDocument(nsIDocument *aDoc) { nsIDocument* doc = aDoc; nsIDocument* displayDoc = doc->GetDisplayDocument(); @@ -6415,10 +6346,7 @@ LayerManagerForDocumentInternal(nsIDocument *aDoc, bool aRequirePersistent) nsIWidget* widget = nsLayoutUtils::GetDisplayRootFrame(rootFrame)->GetNearestWidget(); if (widget) { - nsRefPtr manager = - static_cast(widget)-> - GetLayerManager(aRequirePersistent ? nsIWidget_MOZILLA_2_0_BRANCH::LAYER_MANAGER_PERSISTENT : - nsIWidget_MOZILLA_2_0_BRANCH::LAYER_MANAGER_CURRENT); + nsRefPtr manager = widget->GetLayerManager(); return manager.forget(); } } @@ -6428,18 +6356,6 @@ LayerManagerForDocumentInternal(nsIDocument *aDoc, bool aRequirePersistent) return manager.forget(); } -already_AddRefed -nsContentUtils::LayerManagerForDocument(nsIDocument *aDoc) -{ - return LayerManagerForDocumentInternal(aDoc, false); -} - -already_AddRefed -nsContentUtils::PersistentLayerManagerForDocument(nsIDocument *aDoc) -{ - return LayerManagerForDocumentInternal(aDoc, true); -} - bool nsContentUtils::AllowXULXBLForPrincipal(nsIPrincipal* aPrincipal) { diff --git a/content/base/src/nsFrameMessageManager.cpp b/content/base/src/nsFrameMessageManager.cpp index 2aa0a2fce2..8cb2f58ae3 100644 --- a/content/base/src/nsFrameMessageManager.cpp +++ b/content/base/src/nsFrameMessageManager.cpp @@ -213,8 +213,6 @@ nsFrameMessageManager::GetParamsForMessage(nsAString& aMessageName, if (argc >= 2) { jsval v = argv[1]; - nsAutoGCRoot root(&v, &rv); - NS_ENSURE_SUCCESS(rv, JS_FALSE); if (JS_TryJSON(ctx, &v)) { JS_Stringify(ctx, &v, nsnull, JSVAL_NULL, JSONCreator, &aJSON); } @@ -364,13 +362,7 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget, JSObject* param = JS_NewObject(ctx, NULL, NULL, NULL); NS_ENSURE_TRUE(param, NS_ERROR_OUT_OF_MEMORY); - nsresult rv; - nsAutoGCRoot resultGCRoot(¶m, &rv); - NS_ENSURE_SUCCESS(rv, rv); - jsval targetv; - nsAutoGCRoot resultGCRoot2(&targetv, &rv); - NS_ENSURE_SUCCESS(rv, rv); nsContentUtils::WrapNative(ctx, JS_GetGlobalObject(ctx), aTarget, &targetv); @@ -385,12 +377,9 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget, return false; } } - nsAutoGCRoot arrayGCRoot(&aObjectsArray, &rv); - NS_ENSURE_SUCCESS(rv, rv); jsval json = JSVAL_NULL; - nsAutoGCRoot root(&json, &rv); - if (NS_SUCCEEDED(rv) && !aJSON.IsEmpty()) { + if (!aJSON.IsEmpty()) { JSONParser* parser = JS_BeginJSONParse(ctx, &json); if (parser) { JSBool ok = JS_ConsumeJSONText(ctx, parser, @@ -417,8 +406,6 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget, NULL, NULL, JSPROP_ENUMERATE); jsval thisValue = JSVAL_VOID; - nsAutoGCRoot resultGCRoot3(&thisValue, &rv); - NS_ENSURE_SUCCESS(rv, rv); JSAutoEnterCompartment ac; @@ -454,8 +441,6 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget, } jsval rval = JSVAL_VOID; - nsAutoGCRoot resultGCRoot4(&rval, &rv); - NS_ENSURE_SUCCESS(rv, rv); js::AutoValueRooter argv(ctx); argv.set(OBJECT_TO_JSVAL(param)); diff --git a/content/events/src/nsEventListenerService.cpp b/content/events/src/nsEventListenerService.cpp index 90bf95a2ca..49abd9d9bc 100644 --- a/content/events/src/nsEventListenerService.cpp +++ b/content/events/src/nsEventListenerService.cpp @@ -127,31 +127,27 @@ nsEventListenerInfo::ToSource(nsAString& aResult) { aResult.SetIsVoid(PR_TRUE); - nsresult rv; - jsval v = JSVAL_NULL; - nsAutoGCRoot root(&v, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - if (GetJSVal(&v)) { - nsCOMPtr stack = - nsContentUtils::ThreadJSContextStack(); - if (stack) { - JSContext* cx = nsnull; - stack->GetSafeJSContext(&cx); - if (cx && NS_SUCCEEDED(stack->Push(cx))) { - { - // Extra block to finish the auto request before calling pop - JSAutoRequest ar(cx); + nsCOMPtr stack = + nsContentUtils::ThreadJSContextStack(); + if (stack) { + JSContext* cx = nsnull; + stack->GetSafeJSContext(&cx); + if (cx && NS_SUCCEEDED(stack->Push(cx))) { + { + // Extra block to finish the auto request before calling pop + JSAutoRequest ar(cx); + jsval v = JSVAL_NULL; + if (GetJSVal(&v)) { JSString* str = JS_ValueToSource(cx, v); if (str) { aResult.Assign(nsDependentJSString(str)); } } - stack->Pop(&cx); } + stack->Pop(&cx); } } - + return NS_OK; } @@ -162,22 +158,33 @@ nsEventListenerInfo::GetDebugObject(nsISupports** aRetVal) #ifdef MOZ_JSDEBUGGER nsresult rv = NS_OK; - jsval v = JSVAL_NULL; - nsAutoGCRoot root(&v, &rv); - NS_ENSURE_SUCCESS(rv, rv); - if (GetJSVal(&v)) { - nsCOMPtr jsd = - do_GetService("@mozilla.org/js/jsd/debugger-service;1", &rv); - NS_ENSURE_SUCCESS(rv, NS_OK); + nsCOMPtr jsd = + do_GetService("@mozilla.org/js/jsd/debugger-service;1", &rv); + NS_ENSURE_SUCCESS(rv, NS_OK); + + PRBool isOn = PR_FALSE; + jsd->GetIsOn(&isOn); + NS_ENSURE_TRUE(isOn, NS_OK); - PRBool isOn = PR_FALSE; - jsd->GetIsOn(&isOn); - NS_ENSURE_TRUE(isOn, NS_OK); + nsCOMPtr stack = + nsContentUtils::ThreadJSContextStack(); + if (stack) { + JSContext* cx = nsnull; + stack->GetSafeJSContext(&cx); + if (cx && NS_SUCCEEDED(stack->Push(cx))) { + { + // Extra block to finish the auto request before calling pop + JSAutoRequest ar(cx); - nsCOMPtr jsdValue; - jsd->WrapJSValue(v, getter_AddRefs(jsdValue)); - *aRetVal = jsdValue.forget().get(); - return NS_OK; + jsval v = JSVAL_NULL; + if (GetJSVal(&v)) { + nsCOMPtr jsdValue; + jsd->WrapJSValue(v, getter_AddRefs(jsdValue)); + *aRetVal = jsdValue.forget().get(); + return NS_OK; + } + } + } } #endif diff --git a/content/xbl/src/nsXBLProtoImplField.cpp b/content/xbl/src/nsXBLProtoImplField.cpp index c2248ab55f..4aee61c6cf 100644 --- a/content/xbl/src/nsXBLProtoImplField.cpp +++ b/content/xbl/src/nsXBLProtoImplField.cpp @@ -110,14 +110,9 @@ nsXBLProtoImplField::InstallField(nsIScriptContext* aContext, return NS_OK; } - jsval result = JSVAL_NULL; - // EvaluateStringWithValue and JS_DefineUCProperty can both trigger GC, so // protect |result| here. nsresult rv; - nsAutoGCRoot root(&result, &rv); - if (NS_FAILED(rv)) - return rv; nsCAutoString uriSpec; aBindingDocURI->GetSpec(uriSpec); @@ -129,6 +124,9 @@ nsXBLProtoImplField::InstallField(nsIScriptContext* aContext, // compile the literal string PRBool undefined; nsCOMPtr context = aContext; + + JSAutoRequest ar(cx); + jsval result = JSVAL_NULL; rv = context->EvaluateStringWithValue(nsDependentString(mFieldText, mFieldTextLength), aBoundNode, @@ -144,7 +142,6 @@ nsXBLProtoImplField::InstallField(nsIScriptContext* aContext, // Define the evaluated result as a JS property nsDependentString name(mName); - JSAutoRequest ar(cx); if (!::JS_DefineUCProperty(cx, aBoundNode, reinterpret_cast(mName), name.Length(), result, nsnull, nsnull, diff --git a/content/xbl/src/nsXBLProtoImplMember.h b/content/xbl/src/nsXBLProtoImplMember.h index 83e3e71421..c3bf05db05 100644 --- a/content/xbl/src/nsXBLProtoImplMember.h +++ b/content/xbl/src/nsXBLProtoImplMember.h @@ -120,8 +120,6 @@ public: virtual void Trace(TraceCallback aCallback, void *aClosure) const = 0; protected: - friend class nsAutoGCRoot; - nsXBLProtoImplMember* mNext; // The members of an implementation are chained. PRUnichar* mName; // The name of the field, method, or property. }; diff --git a/content/xbl/src/nsXBLProtoImplMethod.cpp b/content/xbl/src/nsXBLProtoImplMethod.cpp index 5c7b9222e1..0acf29eafc 100644 --- a/content/xbl/src/nsXBLProtoImplMethod.cpp +++ b/content/xbl/src/nsXBLProtoImplMethod.cpp @@ -160,10 +160,6 @@ nsXBLProtoImplMethod::InstallMember(nsIScriptContext* aContext, return NS_ERROR_OUT_OF_MEMORY; } - nsresult rv; - nsAutoGCRoot root(&method, &rv); - NS_ENSURE_SUCCESS(rv, rv); - if (!::JS_DefineUCProperty(cx, targetClassObject, reinterpret_cast(mName), name.Length(), OBJECT_TO_JSVAL(method), diff --git a/content/xbl/src/nsXBLProtoImplProperty.cpp b/content/xbl/src/nsXBLProtoImplProperty.cpp index c941e879fd..12b39f6884 100644 --- a/content/xbl/src/nsXBLProtoImplProperty.cpp +++ b/content/xbl/src/nsXBLProtoImplProperty.cpp @@ -185,18 +185,11 @@ nsXBLProtoImplProperty::InstallMember(nsIScriptContext* aContext, if (!(getter = ::JS_CloneFunctionObject(cx, mJSGetterObject, globalObject))) return NS_ERROR_OUT_OF_MEMORY; - nsresult rv; - nsAutoGCRoot getterroot(&getter, &rv); - NS_ENSURE_SUCCESS(rv, rv); - JSObject * setter = nsnull; if (mJSSetterObject) if (!(setter = ::JS_CloneFunctionObject(cx, mJSSetterObject, globalObject))) return NS_ERROR_OUT_OF_MEMORY; - nsAutoGCRoot setterroot(&setter, &rv); - NS_ENSURE_SUCCESS(rv, rv); - nsDependentString name(mName); if (!::JS_DefineUCProperty(cx, targetClassObject, reinterpret_cast(mName), diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 90d919b6c6..5438b3ced2 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -1635,7 +1635,6 @@ jsid nsDOMClassInfo::sOnmessage_id = JSID_VOID; jsid nsDOMClassInfo::sOnbeforescriptexecute_id = JSID_VOID; jsid nsDOMClassInfo::sOnafterscriptexecute_id = JSID_VOID; jsid nsDOMClassInfo::sWrappedJSObject_id = JSID_VOID; -jsid nsDOMClassInfo::sURL_id = JSID_VOID; static const JSClass *sObjectClass = nsnull; @@ -1861,7 +1860,6 @@ nsDOMClassInfo::DefineStaticJSVals(JSContext *cx) SET_JSID_TO_STRING(sOnafterscriptexecute_id, cx, "onafterscriptexecute"); #endif // MOZ_MEDIA SET_JSID_TO_STRING(sWrappedJSObject_id, cx, "wrappedJSObject"); - SET_JSID_TO_STRING(sURL_id, cx, "URL"); return NS_OK; } @@ -6345,13 +6343,6 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx, return NS_OK; } - // For now don't expose web sockets unless user has explicitly enabled them - if (name_struct->mDOMClassInfoID == eDOMClassInfo_WebSocket_id) { - if (!nsWebSocket::PrefEnabled()) { - return NS_OK; - } - } - // Create the XPConnect prototype for our classinfo, PostCreateProto will // set up the prototype chain. nsCOMPtr proto_holder; @@ -6749,9 +6740,6 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *funObj = ::JS_GetFunctionObject(fun); - nsAutoGCRoot root(&funObj, &rv); - NS_ENSURE_SUCCESS(rv, rv); - if (!::JS_DefinePropertyById(cx, windowObj, id, JSVAL_VOID, JS_DATA_TO_FUNC_PTR(JSPropertyOp, funObj), nsnull, diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 50f971da99..59c880cba1 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -7584,14 +7584,14 @@ nsGlobalWindow::DispatchSyncPopState() JSContext *cx = (JSContext*) scx->GetNativeContext(); + // Make sure we in the request while we have jsval on the native stack. + JSAutoRequest ar(cx); + // If our json call triggers a JS-to-C++ call, we want that call to use cx // as the context. So we push cx onto the context stack. nsCxPusher cxPusher; jsval jsStateObj = JSVAL_NULL; - // Root the container which will hold our decoded state object. - nsAutoGCRoot root(&jsStateObj, &rv); - NS_ENSURE_SUCCESS(rv, rv); // Deserialize the state object into an nsIVariant. nsCOMPtr json = do_GetService("@mozilla.org/dom/json;1"); diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 29a5d0819d..b36282361a 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -2219,17 +2219,15 @@ nsJSContext::BindCompiledEventHandler(nsISupports* aTarget, void *aScope, NS_ENSURE_TRUE(mIsInitialized, NS_ERROR_NOT_INITIALIZED); NS_PRECONDITION(AtomIsEventHandlerName(aName), "Bad event name"); - nsresult rv; + + JSAutoRequest ar(mContext); // Get the jsobject associated with this target JSObject *target = nsnull; - nsAutoGCRoot root(&target, &rv); - NS_ENSURE_SUCCESS(rv, rv); - rv = JSObjectFromInterface(aTarget, aScope, &target); + nsresult rv = JSObjectFromInterface(aTarget, aScope, &target); NS_ENSURE_SUCCESS(rv, rv); JSObject *funobj = (JSObject*) aHandler; - JSAutoRequest ar(mContext); #ifdef DEBUG { @@ -2290,12 +2288,9 @@ nsJSContext::GetBoundEventHandler(nsISupports* aTarget, void *aScope, { NS_PRECONDITION(AtomIsEventHandlerName(aName), "Bad event name"); - nsresult rv; - JSObject *obj = nsnull; - nsAutoGCRoot root(&obj, &rv); - NS_ENSURE_SUCCESS(rv, rv); JSAutoRequest ar(mContext); - rv = JSObjectFromInterface(aTarget, aScope, &obj); + JSObject *obj = nsnull; + nsresult rv = JSObjectFromInterface(aTarget, aScope, &obj); NS_ENSURE_SUCCESS(rv, rv); JSAutoEnterCompartment ac; diff --git a/dom/src/jsurl/nsJSProtocolHandler.cpp b/dom/src/jsurl/nsJSProtocolHandler.cpp index 93e7a29732..ab1a30b31a 100644 --- a/dom/src/jsurl/nsJSProtocolHandler.cpp +++ b/dom/src/jsurl/nsJSProtocolHandler.cpp @@ -308,10 +308,6 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel, NS_ENSURE_SUCCESS(rv, rv); jsval rval = JSVAL_VOID; - nsAutoGCRoot root(&rval, &rv); - if (NS_FAILED(rv)) { - return rv; - } // Push our JSContext on the context stack so the JS_ValueToString call (and // JS_ReportPendingException, if relevant) will use the principal of cx. diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 3ced17a4e6..c3b33a6529 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -941,6 +941,15 @@ JS_ResumeRequest(JSContext *cx, jsrefcount saveDepth) #endif } +JS_PUBLIC_API(JSBool) +JS_IsInRequest(JSContext *cx) +{ +#ifdef JS_THREADSAFE + JS_ASSERT(CURRENT_THREAD_IS_ME(cx->thread)); + return JS_THREAD_DATA(cx)->requestDepth != 0; +#endif +} + JS_PUBLIC_API(void) JS_Lock(JSRuntime *rt) { diff --git a/js/src/jsapi.h b/js/src/jsapi.h index d98842b951..190ba14a82 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -755,6 +755,9 @@ JS_SuspendRequest(JSContext *cx); extern JS_PUBLIC_API(void) JS_ResumeRequest(JSContext *cx, jsrefcount saveDepth); +extern JS_PUBLIC_API(JSBool) +JS_IsInRequest(JSContext *cx); + #ifdef __cplusplus JS_END_EXTERN_C @@ -820,6 +823,30 @@ class JSAutoSuspendRequest { #endif }; +class JSAutoCheckRequest { + public: + JSAutoCheckRequest(JSContext *cx JS_GUARD_OBJECT_NOTIFIER_PARAM) { +#if defined JS_THREADSAFE && defined DEBUG + mContext = cx; + JS_ASSERT(JS_IsInRequest(cx)); +#endif + JS_GUARD_OBJECT_NOTIFIER_INIT; + } + + ~JSAutoCheckRequest() { +#if defined JS_THREADSAFE && defined DEBUG + JS_ASSERT(JS_IsInRequest(mContext)); +#endif + } + + + private: +#if defined JS_THREADSAFE && defined DEBUG + JSContext *mContext; +#endif + JS_DECL_USE_GUARD_OBJECT_NOTIFIER +}; + JS_BEGIN_EXTERN_C #endif diff --git a/js/src/xpconnect/src/XPCDispTearOff.cpp b/js/src/xpconnect/src/XPCDispTearOff.cpp index ad93a2ab70..316c4ad1e2 100644 --- a/js/src/xpconnect/src/XPCDispTearOff.cpp +++ b/js/src/xpconnect/src/XPCDispTearOff.cpp @@ -353,8 +353,7 @@ STDMETHODIMP XPCDispatchTearOff::Invoke(DISPID dispIdMember, REFIID riid, // We use js_Invoke so that the gcthings we use as args will be rooted // by the engine as we do conversions and prepare to do the function - // call. This adds a fair amount of complexity, but it's a good - // optimization compared to calling JS_AddRoot for each item. + // call. js::LeaveTrace(cx); diff --git a/js/src/xpconnect/src/xpcwrappedjsclass.cpp b/js/src/xpconnect/src/xpcwrappedjsclass.cpp index 56c8147e71..e8781040d1 100644 --- a/js/src/xpconnect/src/xpcwrappedjsclass.cpp +++ b/js/src/xpconnect/src/xpcwrappedjsclass.cpp @@ -1349,8 +1349,6 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex, // We use js_Invoke so that the gcthings we use as args will be rooted by // the engine as we do conversions and prepare to do the function call. - // This adds a fair amount of complexity, but it's a good optimization - // compared to calling JS_AddRoot for each item. js::LeaveTrace(cx); -- 2.11.4.GIT