Bug 672971 - Remove SetSafeJSContext (r=bz,bent)

--HG--
extra : rebase_source : f7eb1dcd3bc8ae1bfda0a89d044c0da9621d99e9
This commit is contained in:
Luke Wagner 2011-07-27 16:15:50 -07:00
parent 23a2ca761c
commit 185aaf8f99
9 changed files with 11 additions and 117 deletions

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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.

View File

@ -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
{

View File

@ -3552,9 +3552,6 @@ public:
private:
nsAutoTArray<XPCJSContextInfo, 16> mStack;
JSContext* mSafeJSContext;
// If non-null, we own it; same as mSafeJSContext if SetSafeJSContext
// not called.
JSContext* mOwnSafeJSContext;
};

View File

@ -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;

View File

@ -110,49 +110,6 @@ NS_IMPL_ISUPPORTS2(nsAppShellService,
nsIAppShellService,
nsIObserver)
nsresult
nsAppShellService::SetXPConnectSafeContext()
{
nsresult rv;
nsCOMPtr<nsIThreadJSContextStack> cxstack =
do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMWindow> junk;
JSContext *cx;
rv = GetHiddenWindowAndJSContext(getter_AddRefs(junk), &cx);
NS_ENSURE_SUCCESS(rv, rv);
return cxstack->SetSafeJSContext(cx);
}
nsresult nsAppShellService::ClearXPConnectSafeContext()
{
nsresult rv;
nsCOMPtr<nsIThreadJSContextStack> 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<nsIDOMWindow> 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 {

View File

@ -70,8 +70,6 @@ protected:
PRBool aIsHiddenWindow, nsIAppShell* aAppShell,
nsWebShellWindow **aResult);
PRUint32 CalculateWindowZLevel(nsIXULWindow *aParent, PRUint32 aChromeMask);
nsresult SetXPConnectSafeContext();
nsresult ClearXPConnectSafeContext();
nsRefPtr<nsWebShellWindow> mHiddenWindow;
PRPackedBool mXPCOMWillShutDown;