Skip to content

Instantly share code, notes, and snippets.

@benjamn
Created December 5, 2008 23:41
Show Gist options
  • Save benjamn/32559 to your computer and use it in GitHub Desktop.
Save benjamn/32559 to your computer and use it in GitHub Desktop.
diff --git a/js/src/xpconnect/src/xpcthrower.cpp b/js/src/xpconnect/src/xpcthrower.cpp
--- a/js/src/xpconnect/src/xpcthrower.cpp
+++ b/js/src/xpconnect/src/xpcthrower.cpp
@@ -257,16 +257,18 @@ XPCThrower::BuildAndThrowException(JSCon
// most likely out of memory
if(!success)
JS_ReportOutOfMemory(cx);
}
static PRBool
IsCallerChrome()
{
+ NS_ASSERTION(NS_IsMainThread(),
+ "Acessing security manager off main thread.");
PRBool isChrome = PR_FALSE;
nsCOMPtr<nsIScriptSecurityManager> securityManager =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
nsresult rv = securityManager->SubjectPrincipalIsSystem(&isChrome);
return NS_SUCCEEDED(rv) && isChrome;
}
// static
@@ -278,17 +280,19 @@ XPCThrower::ThrowExceptionObject(JSConte
{
nsCOMPtr<nsXPCException> xpcEx;
jsval thrown;
nsXPConnect* xpc;
// If we stored the original thrown JS value in the exception
// (see XPCConvert::ConstructException) and we are in a web
// context (i.e., not chrome), rethrow the original value.
- if((xpcEx = do_QueryInterface(e)) &&
+ if(XPCPerThreadData::IsMainThread(cx) &&
+ NS_IsMainThread() && // redundant?
+ (xpcEx = do_QueryInterface(e)) &&
xpcEx->StealThrownJSVal(&thrown) &&
!IsCallerChrome())
{
JS_SetPendingException(cx, thrown);
success = JS_TRUE;
}
else if((xpc = nsXPConnect::GetXPConnect()))
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment