diff --git a/dom/workers/Events.cpp b/dom/workers/Events.cpp index ff35f312824..072991dbe1b 100644 --- a/dom/workers/Events.cpp +++ b/dom/workers/Events.cpp @@ -1051,7 +1051,7 @@ JSObject* CreateGenericEvent(JSContext* aCx, JSString* aType, bool aBubbles, bool aCancelable, bool aMainRuntime) { - JSObject* global = JS_GetGlobalObject(aCx); + JSObject* global = JS_GetGlobalForScopeChain(aCx); return Event::Create(aCx, global, aType, aBubbles, aCancelable, aMainRuntime); } @@ -1059,7 +1059,7 @@ JSObject* CreateMessageEvent(JSContext* aCx, JSAutoStructuredCloneBuffer& aData, bool aMainRuntime) { - JSObject* global = JS_GetGlobalObject(aCx); + JSObject* global = JS_GetGlobalForScopeChain(aCx); return MessageEvent::Create(aCx, global, aData, aMainRuntime); } @@ -1067,7 +1067,7 @@ JSObject* CreateErrorEvent(JSContext* aCx, JSString* aMessage, JSString* aFilename, uint32 aLineNumber, bool aMainRuntime) { - JSObject* global = JS_GetGlobalObject(aCx); + JSObject* global = JS_GetGlobalForScopeChain(aCx); return ErrorEvent::Create(aCx, global, aMessage, aFilename, aLineNumber, aMainRuntime); } @@ -1076,7 +1076,7 @@ JSObject* CreateProgressEvent(JSContext* aCx, JSString* aType, bool aLengthComputable, jsdouble aLoaded, jsdouble aTotal) { - JSObject* global = JS_GetGlobalObject(aCx); + JSObject* global = JS_GetGlobalForScopeChain(aCx); return ProgressEvent::Create(aCx, global, aType, aLengthComputable, aLoaded, aTotal); } diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index e2a741d1eaf..52a47fb801f 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -1206,15 +1206,17 @@ NS_IMETHODIMP WorkerRunnable::Run() { JSContext* cx; - + JSObject* targetCompartmentObject; nsIThreadJSContextStack* contextStack = nsnull; if (mTarget == WorkerThread) { mWorkerPrivate->AssertIsOnWorkerThread(); cx = mWorkerPrivate->GetJSContext(); + targetCompartmentObject = JS_GetGlobalObject(cx); } else { mWorkerPrivate->AssertIsOnParentThread(); cx = mWorkerPrivate->ParentJSContext(); + targetCompartmentObject = mWorkerPrivate->GetJSObject(); if (!mWorkerPrivate->GetParent()) { AssertIsOnMainThread(); @@ -1233,10 +1235,8 @@ WorkerRunnable::Run() JSAutoRequest ar(cx); - JSObject* global = JS_GetGlobalObject(cx); - JSAutoEnterCompartment ac; - if (global && !ac.enter(cx, global)) { + if (targetCompartmentObject && !ac.enter(cx, targetCompartmentObject)) { return false; } diff --git a/js/src/xpconnect/idl/nsIJSContextStack.idl b/js/src/xpconnect/idl/nsIJSContextStack.idl index 27ae04e3f8d..dbb941b6951 100644 --- a/js/src/xpconnect/idl/nsIJSContextStack.idl +++ b/js/src/xpconnect/idl/nsIJSContextStack.idl @@ -77,9 +77,9 @@ interface nsIJSContextStackIterator : nsISupports JSContext prev(); }; -[uuid(a1339ae0-05c1-11d4-8f92-0010a4e73d9a)] +[uuid(b7056a2a-a02d-43b1-abb9-47f81f8bf258)] interface nsIThreadJSContextStack : nsIJSContextStack { /* inherits methods of nsIJSContextStack */ - attribute JSContext safeJSContext; + readonly attribute JSContext safeJSContext; }; diff --git a/js/src/xpconnect/idl/nsIXPConnect.idl b/js/src/xpconnect/idl/nsIXPConnect.idl index 45547f3d304..c5bb7418e0e 100644 --- a/js/src/xpconnect/idl/nsIXPConnect.idl +++ b/js/src/xpconnect/idl/nsIXPConnect.idl @@ -596,14 +596,6 @@ interface nsIXPConnect : nsISupports void debugDumpEvalInJSStackFrame(in PRUint32 aFrameNumber, in string aSourceText); - /** - * Set fallback JSContext to use when xpconnect can't find an appropriate - * context to use to execute JavaScript. - * - * @deprecated Use nsIThreadJSContextStack::safeJSContext instead. - */ - [deprecated] void setSafeJSContextForCurrentThread(in JSContextPtr cx); - /** * wrapJSAggregatedToNative is just like wrapJS except it is used in cases * where the JSObject is also aggregated to some native xpcom Object. diff --git a/js/src/xpconnect/src/nsXPConnect.cpp b/js/src/xpconnect/src/nsXPConnect.cpp index 88aa027c33b..52488d6216a 100644 --- a/js/src/xpconnect/src/nsXPConnect.cpp +++ b/js/src/xpconnect/src/nsXPConnect.cpp @@ -1939,16 +1939,6 @@ nsXPConnect::GetFunctionThisTranslator(const nsIID & aIID, return NS_OK; } -/* void setSafeJSContextForCurrentThread (in JSContextPtr cx); */ -NS_IMETHODIMP -nsXPConnect::SetSafeJSContextForCurrentThread(JSContext * cx) -{ - XPCCallContext ccx(NATIVE_CALLER); - if(!ccx.IsValid()) - return UnexpectedFailure(NS_ERROR_FAILURE); - return ccx.GetThreadData()->GetJSContextStack()->SetSafeJSContext(cx); -} - /* void clearAllWrappedNativeSecurityPolicies (); */ NS_IMETHODIMP nsXPConnect::ClearAllWrappedNativeSecurityPolicies() @@ -2660,18 +2650,6 @@ nsXPConnect::GetSafeJSContext(JSContext * *aSafeJSContext) return data->GetJSContextStack()->GetSafeJSContext(aSafeJSContext); } -/* attribute JSContext SafeJSContext; */ -NS_IMETHODIMP -nsXPConnect::SetSafeJSContext(JSContext * aSafeJSContext) -{ - XPCPerThreadData* data = XPCPerThreadData::GetData(aSafeJSContext); - - if(!data) - return NS_ERROR_FAILURE; - - return data->GetJSContextStack()->SetSafeJSContext(aSafeJSContext); -} - nsIPrincipal* nsXPConnect::GetPrincipal(JSObject* obj, PRBool allowShortCircuit) const { diff --git a/js/src/xpconnect/src/xpcprivate.h b/js/src/xpconnect/src/xpcprivate.h index 8fa62ef5021..48cb799aa69 100644 --- a/js/src/xpconnect/src/xpcprivate.h +++ b/js/src/xpconnect/src/xpcprivate.h @@ -3552,9 +3552,6 @@ public: private: nsAutoTArray mStack; JSContext* mSafeJSContext; - - // If non-null, we own it; same as mSafeJSContext if SetSafeJSContext - // not called. JSContext* mOwnSafeJSContext; }; diff --git a/js/src/xpconnect/src/xpcthreadcontext.cpp b/js/src/xpconnect/src/xpcthreadcontext.cpp index 883f23e0669..5cc6e343953 100644 --- a/js/src/xpconnect/src/xpcthreadcontext.cpp +++ b/js/src/xpconnect/src/xpcthreadcontext.cpp @@ -300,12 +300,7 @@ XPCJSContextStack::GetSafeJSContext(JSContext * *aSafeJSContext) JS_DestroyContext(mSafeJSContext); mSafeJSContext = nsnull; } - // Save it off so we can destroy it later, even if - // mSafeJSContext has been set to another context - // via SetSafeJSContext. If we don't get here, - // then mSafeJSContext must have been set via - // SetSafeJSContext, and we're not responsible for - // destroying the passed-in context. + // Save it off so we can destroy it later. mOwnSafeJSContext = mSafeJSContext; } } @@ -314,21 +309,6 @@ XPCJSContextStack::GetSafeJSContext(JSContext * *aSafeJSContext) return mSafeJSContext ? NS_OK : NS_ERROR_UNEXPECTED; } -NS_IMETHODIMP -XPCJSContextStack::SetSafeJSContext(JSContext * aSafeJSContext) -{ - if(mOwnSafeJSContext && - mOwnSafeJSContext == mSafeJSContext && - mOwnSafeJSContext != aSafeJSContext) - { - JS_DestroyContextNoGC(mOwnSafeJSContext); - mOwnSafeJSContext = nsnull; - } - - mSafeJSContext = aSafeJSContext; - return NS_OK; -} - /***************************************************************************/ PRUintn XPCPerThreadData::gTLSIndex = BAD_TLS_INDEX; diff --git a/xpfe/appshell/src/nsAppShellService.cpp b/xpfe/appshell/src/nsAppShellService.cpp index 45b9fae321c..3f975ef5077 100644 --- a/xpfe/appshell/src/nsAppShellService.cpp +++ b/xpfe/appshell/src/nsAppShellService.cpp @@ -110,49 +110,6 @@ NS_IMPL_ISUPPORTS2(nsAppShellService, nsIAppShellService, nsIObserver) -nsresult -nsAppShellService::SetXPConnectSafeContext() -{ - nsresult rv; - - nsCOMPtr cxstack = - do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr junk; - JSContext *cx; - rv = GetHiddenWindowAndJSContext(getter_AddRefs(junk), &cx); - NS_ENSURE_SUCCESS(rv, rv); - - return cxstack->SetSafeJSContext(cx); -} - -nsresult nsAppShellService::ClearXPConnectSafeContext() -{ - nsresult rv; - - nsCOMPtr cxstack = - do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv); - if (NS_FAILED(rv)) { - NS_ERROR("XPConnect ContextStack gone before XPCOM shutdown?"); - return rv; - } - - nsCOMPtr junk; - JSContext *cx; - rv = GetHiddenWindowAndJSContext(getter_AddRefs(junk), &cx); - NS_ENSURE_SUCCESS(rv, rv); - - JSContext *safe_cx; - rv = cxstack->GetSafeJSContext(&safe_cx); - NS_ENSURE_SUCCESS(rv, rv); - - if (cx == safe_cx) - rv = cxstack->SetSafeJSContext(nsnull); - - return rv; -} - NS_IMETHODIMP nsAppShellService::CreateHiddenWindow(nsIAppShell* aAppShell) { @@ -182,12 +139,6 @@ nsAppShellService::CreateHiddenWindow(nsIAppShell* aAppShell) mHiddenWindow.swap(newWindow); - // Set XPConnect's fallback JSContext (used for JS Components) - // to the DOM JSContext for this thread, so that DOM-to-XPConnect - // conversions get the JSContext private magic they need to - // succeed. - SetXPConnectSafeContext(); - // RegisterTopLevelWindow(newWindow); -- Mac only return NS_OK; @@ -197,7 +148,6 @@ NS_IMETHODIMP nsAppShellService::DestroyHiddenWindow() { if (mHiddenWindow) { - ClearXPConnectSafeContext(); mHiddenWindow->Destroy(); mHiddenWindow = nsnull; @@ -622,7 +572,6 @@ nsAppShellService::Observe(nsISupports* aSubject, const char *aTopic, } else if (!strcmp(aTopic, "xpcom-shutdown")) { mXPCOMShuttingDown = PR_TRUE; if (mHiddenWindow) { - ClearXPConnectSafeContext(); mHiddenWindow->Destroy(); } } else { diff --git a/xpfe/appshell/src/nsAppShellService.h b/xpfe/appshell/src/nsAppShellService.h index 0f74abd7c38..bbde0b725bf 100644 --- a/xpfe/appshell/src/nsAppShellService.h +++ b/xpfe/appshell/src/nsAppShellService.h @@ -70,8 +70,6 @@ protected: PRBool aIsHiddenWindow, nsIAppShell* aAppShell, nsWebShellWindow **aResult); PRUint32 CalculateWindowZLevel(nsIXULWindow *aParent, PRUint32 aChromeMask); - nsresult SetXPConnectSafeContext(); - nsresult ClearXPConnectSafeContext(); nsRefPtr mHiddenWindow; PRPackedBool mXPCOMWillShutDown;