diff --git a/js/jsd/jsd_xpc.cpp b/js/jsd/jsd_xpc.cpp index a9458b8e06d1..cb54ecb8bbe0 100644 --- a/js/jsd/jsd_xpc.cpp +++ b/js/jsd/jsd_xpc.cpp @@ -1467,12 +1467,9 @@ NS_IMPL_THREADSAFE_ISUPPORTS2(jsdContext, jsdIContext, jsdIEphemeral) jsdIContext * jsdContext::FromPtr (JSDContext *aJSDCx, JSContext *aJSCx) { - if (!aJSDCx || !aJSCx || - !(JS_GetOptions(aJSCx) & JSOPTION_PRIVATE_IS_NSISUPPORTS)) - { + if (!aJSDCx || !aJSCx) return nsnull; - } - + nsCOMPtr jsdicx; nsCOMPtr eph = jsds_FindEphemeral (&gLiveContexts, static_cast(aJSCx)); @@ -1482,17 +1479,15 @@ jsdContext::FromPtr (JSDContext *aJSDCx, JSContext *aJSCx) } else { - nsCOMPtr iscx = - static_cast(JS_GetContextPrivate(aJSCx)); - if (!iscx) - return nsnull; - + nsCOMPtr iscx; + if (JS_GetOptions(aJSCx) & JSOPTION_PRIVATE_IS_NSISUPPORTS) + iscx = static_cast(JS_GetContextPrivate(aJSCx)); jsdicx = new jsdContext (aJSDCx, aJSCx, iscx); } - jsdIContext *rv = jsdicx; - NS_IF_ADDREF(rv); - return rv; + jsdIContext *ctx = nsnull; + jsdicx.swap(ctx); + return ctx; } jsdContext::jsdContext (JSDContext *aJSDCx, JSContext *aJSCx, @@ -1592,8 +1587,7 @@ NS_IMETHODIMP jsdContext::GetWrappedContext(nsISupports **_rval) { ASSERT_VALID_EPHEMERAL; - *_rval = mISCx; - NS_IF_ADDREF(*_rval); + NS_IF_ADDREF(*_rval = mISCx); return NS_OK; } @@ -1643,6 +1637,11 @@ NS_IMETHODIMP jsdContext::GetScriptsEnabled (PRBool *_rval) { ASSERT_VALID_EPHEMERAL; + if (!mISCx) { + *_rval = PR_TRUE; + return NS_OK; + } + nsCOMPtr context = do_QueryInterface(mISCx); if (!context) return NS_ERROR_NO_INTERFACE; @@ -1656,6 +1655,12 @@ NS_IMETHODIMP jsdContext::SetScriptsEnabled (PRBool _rval) { ASSERT_VALID_EPHEMERAL; + if (!mISCx) { + if (_rval) + return NS_OK; + return NS_ERROR_NO_INTERFACE; + } + nsCOMPtr context = do_QueryInterface(mISCx); if (!context) return NS_ERROR_NO_INTERFACE;