Make sure to notify XPConnect if an XBL constructor or destructor throws an

exception so they get reported in a timely manner.  Bug 299741, r+sr=jst, a=chofmann
This commit is contained in:
bzbarsky%mit.edu 2005-07-06 15:46:12 +00:00
parent c5278fd003
commit 75933a51dc
4 changed files with 28 additions and 20 deletions

View File

@ -539,6 +539,11 @@ public:
*/ */
static PRBool IsChromeDoc(nsIDocument *aDocument); static PRBool IsChromeDoc(nsIDocument *aDocument);
/**
* Notify XPConnect if an exception is pending on aCx.
*/
static void NotifyXPCIfExceptionPending(JSContext *aCx);
private: private:
static nsresult doReparentContentWrapper(nsIContent *aChild, static nsresult doReparentContentWrapper(nsIContent *aChild,
nsIDocument *aNewDocument, nsIDocument *aNewDocument,

View File

@ -2334,3 +2334,17 @@ nsContentUtils::IsChromeDoc(nsIDocument *aDocument)
return principal == systemPrincipal; return principal == systemPrincipal;
} }
void
nsContentUtils::NotifyXPCIfExceptionPending(JSContext* aCx)
{
if (!::JS_IsExceptionPending(aCx)) {
return;
}
nsCOMPtr<nsIXPCNativeCallContext> nccx;
XPConnect()->GetCurrentNativeCallContext(getter_AddRefs(nccx));
if (nccx) {
nccx->SetExceptionWasThrown(PR_TRUE);
}
}

View File

@ -329,6 +329,10 @@ nsXBLProtoImplAnonymousMethod::Execute(nsIContent* aBoundElement)
} }
if (!ok) { 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(cx);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }

View File

@ -476,21 +476,6 @@ LocaleCompare(JSContext *cx, JSString *src1, JSString *src2, jsval *rval)
return JS_TRUE; return JS_TRUE;
} }
static void
NotifyXPCIfExceptionPending(JSContext *cx)
{
if (!::JS_IsExceptionPending(cx)) {
return;
}
nsCOMPtr<nsIXPCNativeCallContext> nccx;
nsContentUtils::XPConnect()->
GetCurrentNativeCallContext(getter_AddRefs(nccx));
if (nccx) {
nccx->SetExceptionWasThrown(PR_TRUE);
}
}
// The number of branch callbacks between calls to JS_MaybeGC // The number of branch callbacks between calls to JS_MaybeGC
#define MAYBE_GC_BRANCH_COUNT_MASK 0x00000fff // 4095 #define MAYBE_GC_BRANCH_COUNT_MASK 0x00000fff // 4095
@ -888,7 +873,7 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
// to avoid dropping JS exceptions in case we got here through // to avoid dropping JS exceptions in case we got here through
// nested calls through XPConnect. // nested calls through XPConnect.
NotifyXPCIfExceptionPending(mContext); nsContentUtils::NotifyXPCIfExceptionPending(mContext);
} }
} }
} }
@ -975,7 +960,7 @@ JSValueToAString(JSContext *cx, jsval val, nsAString *result,
// avoid dropping JS exceptions in case we got here through nested // avoid dropping JS exceptions in case we got here through nested
// calls through XPConnect. // calls through XPConnect.
NotifyXPCIfExceptionPending(cx); nsContentUtils::NotifyXPCIfExceptionPending(cx);
} }
return NS_OK; return NS_OK;
@ -1083,7 +1068,7 @@ nsJSContext::EvaluateString(const nsAString& aScript,
// to avoid dropping JS exceptions in case we got here through // to avoid dropping JS exceptions in case we got here through
// nested calls through XPConnect. // nested calls through XPConnect.
NotifyXPCIfExceptionPending(mContext); nsContentUtils::NotifyXPCIfExceptionPending(mContext);
} }
} }
} }
@ -1246,7 +1231,7 @@ nsJSContext::ExecuteScript(void* aScriptObject,
// avoid dropping JS exceptions in case we got here through nested // avoid dropping JS exceptions in case we got here through nested
// calls through XPConnect. // calls through XPConnect.
NotifyXPCIfExceptionPending(mContext); nsContentUtils::NotifyXPCIfExceptionPending(mContext);
} }
// Pop here, after JS_ValueToString and any other possible evaluation. // Pop here, after JS_ValueToString and any other possible evaluation.
@ -1419,7 +1404,7 @@ nsJSContext::CallEventHandler(JSObject *aTarget, JSObject *aHandler,
// to avoid dropping JS exceptions in case we got here through // to avoid dropping JS exceptions in case we got here through
// nested calls through XPConnect. // nested calls through XPConnect.
NotifyXPCIfExceptionPending(mContext); nsContentUtils::NotifyXPCIfExceptionPending(mContext);
// Don't pass back results from failed calls. // Don't pass back results from failed calls.
*rval = JSVAL_VOID; *rval = JSVAL_VOID;