Bug 877673 - Part 1: AutoDontReportUncaught. r=bholley

This commit is contained in:
Gabor Krizsanits 2013-08-19 11:46:24 +02:00
parent 1131d483d0
commit a96850e4d4

View File

@ -189,6 +189,27 @@ nsJSUtils::CompileFunction(JSContext* aCx,
return NS_OK;
}
class MOZ_STACK_CLASS AutoDontReportUncaught {
JSContext* mContext;
bool mWasSet;
public:
AutoDontReportUncaught(JSContext* aContext) : mContext(aContext) {
MOZ_ASSERT(aContext);
uint32_t oldOptions = JS_GetOptions(mContext);
mWasSet = oldOptions & JSOPTION_DONT_REPORT_UNCAUGHT;
if (!mWasSet) {
JS_SetOptions(mContext, oldOptions | JSOPTION_DONT_REPORT_UNCAUGHT);
}
}
~AutoDontReportUncaught() {
if (!mWasSet) {
JS_SetOptions(mContext,
JS_GetOptions(mContext) & ~JSOPTION_DONT_REPORT_UNCAUGHT);
}
}
};
nsresult
nsJSUtils::EvaluateString(JSContext* aCx,
const nsAString& aScript,
@ -224,6 +245,13 @@ nsJSUtils::EvaluateString(JSContext* aCx,
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(ok, NS_OK);
mozilla::Maybe<AutoDontReportUncaught> dontReport;
if (!aEvaluateOptions.reportUncaught) {
// We need to prevent AutoLastFrameCheck from reporting and clearing
// any pending exceptions.
dontReport.construct(aCx);
}
// Scope the JSAutoCompartment so that we can later wrap the return value
// into the caller's cx.
{