Bug 451571 - Delete SetExceptionWasThrown (r=dbradley, sr=jst)

This commit is contained in:
Jason Orendorff 2008-08-30 18:58:36 -05:00
parent 87c0ed791b
commit b94820fbeb
18 changed files with 12 additions and 134 deletions

View File

@ -828,14 +828,6 @@ nsScriptSecurityManager::CheckPropertyAccessImpl(PRUint32 aAction,
}
SetPendingException(cx, errorMsg.get());
if (sXPConnect)
{
nsAXPCNativeCallContext *xpcCallContext = nsnull;
sXPConnect->GetCurrentNativeCallContext(&xpcCallContext);
if (xpcCallContext)
xpcCallContext->SetExceptionWasThrown(PR_TRUE);
}
}
return rv;
@ -1465,14 +1457,6 @@ nsScriptSecurityManager::ReportError(JSContext* cx, const nsAString& messageTag,
if (cx)
{
SetPendingException(cx, message.get());
// Tell XPConnect that an exception was thrown, if appropriate
if (sXPConnect)
{
nsAXPCNativeCallContext* xpcCallContext = nsnull;
sXPConnect->GetCurrentNativeCallContext(&xpcCallContext);
if (xpcCallContext)
xpcCallContext->SetExceptionWasThrown(PR_TRUE);
}
}
else // Print directly to the console
{

View File

@ -805,11 +805,6 @@ public:
*/
static PRBool IsChromeDoc(nsIDocument *aDocument);
/**
* Notify XPConnect if an exception is pending on aCx.
*/
static void NotifyXPCIfExceptionPending(JSContext *aCx);
/**
* Release *aSupportsPtr when the shutdown notification is received
*/

View File

@ -2865,27 +2865,6 @@ nsContentUtils::IsChromeDoc(nsIDocument *aDocument)
return aDocument->NodePrincipal() == systemPrincipal;
}
void
nsContentUtils::NotifyXPCIfExceptionPending(JSContext* aCx)
{
if (!::JS_IsExceptionPending(aCx)) {
return;
}
nsAXPCNativeCallContext *nccx = nsnull;
XPConnect()->GetCurrentNativeCallContext(&nccx);
if (nccx) {
// Check to make sure that the JSContext that nccx will mess with is the
// same as the JSContext we've set an exception on. If they're not the
// same, don't mess with nccx.
JSContext* cx;
nccx->GetJSContext(&cx);
if (cx == aCx) {
nccx->SetExceptionWasThrown(PR_TRUE);
}
}
}
// static
nsIContentPolicy*
nsContentUtils::GetContentPolicy()

View File

@ -606,15 +606,8 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest,
context->SetProcessingScriptTag(oldProcessingScriptTag);
if (stid == nsIProgrammingLanguage::JAVASCRIPT) {
nsAXPCNativeCallContext *ncc = nsnull;
nsContentUtils::XPConnect()->
GetCurrentNativeCallContext(&ncc);
if (ncc) {
NS_ASSERTION(!::JS_IsExceptionPending(cx),
"JS_ReportPendingException wasn't called");
ncc->SetExceptionWasThrown(PR_FALSE);
}
NS_ASSERTION(!::JS_IsExceptionPending(cx),
"JS_ReportPendingException wasn't called");
::JS_EndRequest(cx);
}
return rv;

View File

@ -1402,14 +1402,6 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
aURL,
aLineNo,
&val);
if (!ok) {
// Tell XPConnect about any pending exceptions. This is needed
// to avoid dropping JS exceptions in case we got here through
// nested calls through XPConnect.
nsContentUtils::NotifyXPCIfExceptionPending(mContext);
}
}
// Whew! Finally done with these manually ref-counted things.
@ -1479,12 +1471,6 @@ JSValueToAString(JSContext *cx, jsval val, nsAString *result,
return NS_ERROR_OUT_OF_MEMORY;
}
// Tell XPConnect about any pending exceptions. This is needed to
// avoid dropping JS exceptions in case we got here through nested
// calls through XPConnect.
nsContentUtils::NotifyXPCIfExceptionPending(cx);
}
return NS_OK;
@ -1742,12 +1728,6 @@ nsJSContext::ExecuteScript(void *aScriptObject,
if (aRetValue) {
aRetValue->Truncate();
}
// Tell XPConnect about any pending exceptions. This is needed to
// avoid dropping JS exceptions in case we got here through nested
// calls through XPConnect.
nsContentUtils::NotifyXPCIfExceptionPending(mContext);
}
// Pop here, after JS_ValueToString and any other possible evaluation.

View File

@ -205,8 +205,6 @@ nsJSScriptTimeoutHandler::Init(nsGlobalWindow *aWindow, PRBool *aIsInterval,
if (argc < 1) {
::JS_ReportError(cx, "Function %s requires at least 1 parameter",
*aIsInterval ? kSetIntervalStr : kSetTimeoutStr);
ncc->SetExceptionWasThrown(PR_TRUE);
return NS_ERROR_DOM_TYPE_ERR;
}
@ -214,8 +212,6 @@ nsJSScriptTimeoutHandler::Init(nsGlobalWindow *aWindow, PRBool *aIsInterval,
::JS_ReportError(cx,
"Second argument to %s must be a millisecond interval",
aIsInterval ? kSetIntervalStr : kSetTimeoutStr);
ncc->SetExceptionWasThrown(PR_TRUE);
return NS_ERROR_DOM_TYPE_ERR;
}
@ -243,7 +239,6 @@ nsJSScriptTimeoutHandler::Init(nsGlobalWindow *aWindow, PRBool *aIsInterval,
*aIsInterval ? kSetIntervalStr : kSetTimeoutStr);
// Return an error that nsGlobalWindow can recognize and turn into NS_OK.
ncc->SetExceptionWasThrown(PR_TRUE);
return NS_ERROR_DOM_TYPE_ERR;
}

View File

@ -1522,7 +1522,6 @@ mozJSComponentLoader::ImportInto(const nsACString & aLocation,
JSContext *callercx;
cc->GetJSContext(&callercx);
JS_SetPendingException(callercx, exception);
cc->SetExceptionWasThrown(PR_TRUE);
return NS_OK;
}
@ -1631,7 +1630,7 @@ mozJSComponentLoader::ReportOnCaller(nsAXPCNativeCallContext *cc,
char* buf = JS_vsmprintf(format, ap);
JS_ReportError(callerContext, buf);
JS_smprintf_free(buf);
return cc->SetExceptionWasThrown(PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP

View File

@ -151,7 +151,6 @@ mozJSSubScriptLoader::LoadSubScript (const PRUnichar * /*url*/
ok = JS_ConvertArguments (cx, argc, argv, "s / o", &url, &target_obj);
if (!ok)
{
cc->SetExceptionWasThrown (JS_TRUE);
/* let the exception raised by JS_ConvertArguments show through */
return NS_OK;
}
@ -348,7 +347,6 @@ mozJSSubScriptLoader::LoadSubScript (const PRUnichar * /*url*/
/* repent for our evil deeds */
JS_SetErrorReporter (cx, er);
cc->SetExceptionWasThrown (!ok);
cc->SetReturnValueWasSet (ok);
JSPRINCIPALS_DROP(cx, jsPrincipals);
@ -356,7 +354,6 @@ mozJSSubScriptLoader::LoadSubScript (const PRUnichar * /*url*/
return_exception:
JS_SetPendingException (cx, STRING_TO_JSVAL(errmsg));
cc->SetExceptionWasThrown (JS_TRUE);
return NS_OK;
}

View File

@ -64,14 +64,6 @@ public:
*/
NS_IMETHOD GetRetValPtr(jsval **aResult) = 0;
/**
* Set this if JS_SetPendingException has been called. Return NS_OK or
* else this will be ignored and the native method's nsresult will be
* converted into an exception and thrown into JS as is the normal case.
*/
NS_IMETHOD GetExceptionWasThrown(PRBool *aResult) = 0;
NS_IMETHOD SetExceptionWasThrown(PRBool aValue) = 0;
/**
* Set this to indicate that the callee has directly set the return value
* (using RetValPtr and the JSAPI). If set then xpconnect will not attempt

View File

@ -73,10 +73,8 @@ nsresult xpcJSWeakReference::Init()
if (JSVAL_IS_NULL(argv[0])) return NS_ERROR_FAILURE;
JSObject *obj;
if (!JS_ValueToObject(cx, argv[0], &obj)) {
cc->SetExceptionWasThrown(JS_TRUE);
if (!JS_ValueToObject(cx, argv[0], &obj))
return NS_ERROR_FAILURE;
}
XPCCallContext ccx(NATIVE_CALLER, cx);

View File

@ -258,7 +258,7 @@ XPCCallContext::SetArgsAndResultPtr(uintN argc,
mArgv = argv;
mRetVal = rval;
mExceptionWasThrown = mReturnValueWasSet = JS_FALSE;
mReturnValueWasSet = JS_FALSE;
mState = HAVE_ARGS;
}
@ -513,20 +513,6 @@ XPCCallContext::GetRetValPtr(jsval * *aRetValPtr)
return NS_OK;
}
/* attribute PRBool ExceptionWasThrown; */
NS_IMETHODIMP
XPCCallContext::GetExceptionWasThrown(PRBool *aExceptionWasThrown)
{
*aExceptionWasThrown = mExceptionWasThrown;
return NS_OK;
}
NS_IMETHODIMP
XPCCallContext::SetExceptionWasThrown(PRBool aExceptionWasThrown)
{
mExceptionWasThrown = aExceptionWasThrown;
return NS_OK;
}
/* attribute PRBool ReturnValueWasSet; */
NS_IMETHODIMP
XPCCallContext::GetReturnValueWasSet(PRBool *aReturnValueWasSet)

View File

@ -3465,13 +3465,8 @@ nsXPCComponents_Utils::EvalInSandbox(const nsAString &source)
rv = xpc_EvalInSandbox(cx, sandbox, source, filename.get(), lineNo,
PR_FALSE, rval);
if (NS_SUCCEEDED(rv)) {
if (JS_IsExceptionPending(cx)) {
cc->SetExceptionWasThrown(PR_TRUE);
} else {
cc->SetReturnValueWasSet(PR_TRUE);
}
}
if (NS_SUCCEEDED(rv) && !JS_IsExceptionPending(cx))
cc->SetReturnValueWasSet(PR_TRUE);
return rv;
#endif /* XPCONNECT_STANDALONE */

View File

@ -279,13 +279,6 @@ XPCCallContext::GetRetVal() const
return mRetVal;
}
inline JSBool
XPCCallContext::GetExceptionWasThrown() const
{
CHECK_STATE(READY_TO_CALL);
return mExceptionWasThrown;
}
inline JSBool
XPCCallContext::GetReturnValueWasSet() const
{

View File

@ -802,8 +802,8 @@ nsJSCID::CreateInstance(nsISupports **_retval)
nsIXPCSecurityManager::HOOK_CREATE_INSTANCE);
if(sm && NS_FAILED(sm->CanCreateInstance(cx, mDetails.ID())))
{
// the security manager vetoed. It should have set an exception.
ccxp->SetExceptionWasThrown(JS_TRUE);
NS_ASSERTION(JS_IsExceptionPending(cx),
"security manager vetoed CreateInstance without setting exception");
return NS_OK;
}
@ -875,8 +875,8 @@ nsJSCID::GetService(nsISupports **_retval)
nsIXPCSecurityManager::HOOK_GET_SERVICE);
if(sm && NS_FAILED(sm->CanCreateInstance(cx, mDetails.ID())))
{
// the security manager vetoed. It should have set an exception.
ccxp->SetExceptionWasThrown(JS_TRUE);
NS_ASSERTION(JS_IsExceptionPending(cx),
"security manager vetoed GetService without setting exception");
return NS_OK;
}

View File

@ -959,8 +959,6 @@ public:
NS_IMETHOD GetArgc(PRUint32 *aResult);
NS_IMETHOD GetArgvPtr(jsval **aResult);
NS_IMETHOD GetRetValPtr(jsval **aResult);
NS_IMETHOD GetExceptionWasThrown(PRBool *aResult);
NS_IMETHOD SetExceptionWasThrown(PRBool aValue);
NS_IMETHOD GetReturnValueWasSet(PRBool *aResult);
NS_IMETHOD SetReturnValueWasSet(PRBool aValue);
NS_IMETHOD GetCalleeInterface(nsIInterfaceInfo **aResult);
@ -1014,7 +1012,6 @@ public:
inline uintN GetArgc() const ;
inline jsval* GetArgv() const ;
inline jsval* GetRetVal() const ;
inline JSBool GetExceptionWasThrown() const ;
inline JSBool GetReturnValueWasSet() const ;
inline PRUint16 GetMethodIndex() const ;
@ -1120,7 +1117,6 @@ private:
jsval* mArgv;
jsval* mRetVal;
JSBool mExceptionWasThrown;
JSBool mReturnValueWasSet;
#ifdef XPC_IDISPATCH_SUPPORT
void* mIDispatchMember;

View File

@ -2400,9 +2400,8 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
ThrowBadResult(invokeResult, ccx);
goto done;
}
else if(ccx.GetExceptionWasThrown())
else if(JS_IsExceptionPending(ccx))
{
// the native callee claims to have already set a JSException
goto done;
}

View File

@ -517,8 +517,6 @@ xpctestEcho::ThrowArg(void)
return NS_ERROR_FAILURE;
JS_SetPendingException(cx, argv[0]);
cc->SetExceptionWasThrown(JS_TRUE);
return NS_OK;
}

View File

@ -2533,7 +2533,6 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
if (!aCaOption.EqualsLiteral("auto") &&
!aCaOption.EqualsLiteral("ask")) {
JS_ReportError(cx, "%s%s\n", JS_ERROR, "caOption argument must be ask or auto");
ncc->SetExceptionWasThrown(PR_TRUE);
aResult.Append(internalError);