From 66faed38af5e3d1518328552982a7a71d397e583 Mon Sep 17 00:00:00 2001 From: Jan de Mooij Date: Tue, 7 Jun 2016 20:30:48 +0200 Subject: [PATCH] Bug 1277278 part 1 - Remove ContextOptions and make autoJSAPIOwnsErrorReporting the default. r=luke --HG-- extra : rebase_source : aa1dcba100a3bb7a5057b07284cf4a99353afe5a --- dom/base/BodyUtil.cpp | 1 - dom/base/ScriptSettings.cpp | 13 +--- dom/base/ScriptSettings.h | 2 - dom/base/nsJSUtils.cpp | 8 --- dom/bindings/Exceptions.cpp | 12 ---- dom/bindings/Exceptions.h | 13 ---- dom/bindings/ToJSValue.cpp | 1 - dom/promise/Promise.cpp | 1 - js/ipc/WrapperAnswer.cpp | 1 - js/src/frontend/TokenStream.cpp | 2 +- js/src/jsapi-tests/testCallArgs.cpp | 20 ------ js/src/jsapi-tests/testProfileStrings.cpp | 1 - js/src/jsapi-tests/tests.h | 8 +-- js/src/jsapi.cpp | 81 ++--------------------- js/src/jsapi.h | 63 ------------------ js/src/jscntxt.cpp | 50 +++----------- js/src/jscntxt.h | 11 --- js/src/shell/js.cpp | 3 - js/src/vm/SelfHosting.cpp | 12 +--- js/xpconnect/src/XPCWrappedJSClass.cpp | 4 -- netwerk/base/ProxyAutoConfig.cpp | 2 - 21 files changed, 17 insertions(+), 292 deletions(-) diff --git a/dom/base/BodyUtil.cpp b/dom/base/BodyUtil.cpp index 572d17100e21..b5870338776d 100644 --- a/dom/base/BodyUtil.cpp +++ b/dom/base/BodyUtil.cpp @@ -550,7 +550,6 @@ BodyUtil::ConsumeJson(JSContext* aCx, JS::MutableHandle aValue, { aRv.MightThrowJSException(); - AutoForceSetExceptionOnContext forceExn(aCx); JS::Rooted json(aCx); if (!JS_ParseJSON(aCx, aStr.get(), aStr.Length(), &json)) { if (!JS_IsExceptionPending(aCx)) { diff --git a/dom/base/ScriptSettings.cpp b/dom/base/ScriptSettings.cpp index 8b9d7920e784..d189da143148 100644 --- a/dom/base/ScriptSettings.cpp +++ b/dom/base/ScriptSettings.cpp @@ -296,7 +296,6 @@ GetWebIDLCallerPrincipal() AutoJSAPI::AutoJSAPI() : mCx(nullptr) - , mOldAutoJSAPIOwnsErrorReporting(false) , mIsMainThread(false) // For lack of anything better { } @@ -312,13 +311,6 @@ AutoJSAPI::~AutoJSAPI() ReportException(); - // We need to do this _after_ processing the existing exception, because the - // JS engine can throw while doing that, and uses this bit to determine what - // to do in that case: squelch the exception if the bit is set, otherwise - // call the error reporter. Calling WarningOnlyErrorReporter with a - // non-warning will assert, so we need to make sure we do the former. - JS::ContextOptionsRef(cx()).setAutoJSAPIOwnsErrorReporting(mOldAutoJSAPIOwnsErrorReporting); - if (mOldErrorReporter.isSome()) { JS_SetErrorReporter(JS_GetRuntime(cx()), mOldErrorReporter.value()); } @@ -358,8 +350,6 @@ AutoJSAPI::InitInternal(nsIGlobalObject* aGlobalObject, JSObject* aGlobal, JSRuntime* rt = JS_GetRuntime(aCx); mOldErrorReporter.emplace(JS_GetErrorReporter(rt)); - mOldAutoJSAPIOwnsErrorReporting = JS::ContextOptionsRef(aCx).autoJSAPIOwnsErrorReporting(); - JS::ContextOptionsRef(aCx).setAutoJSAPIOwnsErrorReporting(true); JS_SetErrorReporter(rt, WarningOnlyErrorReporter); #ifdef DEBUG @@ -432,8 +422,7 @@ AutoJSAPI::InitInternal(nsIGlobalObject* aGlobalObject, JSObject* aGlobal, AutoJSAPI::AutoJSAPI(nsIGlobalObject* aGlobalObject, bool aIsMainThread, JSContext* aCx) - : mOldAutoJSAPIOwnsErrorReporting(false) - , mIsMainThread(aIsMainThread) + : mIsMainThread(aIsMainThread) { MOZ_ASSERT(aGlobalObject); MOZ_ASSERT(aGlobalObject->GetGlobalJSObject(), "Must have a JS global"); diff --git a/dom/base/ScriptSettings.h b/dom/base/ScriptSettings.h index 0daf4b0e85a3..cbe267bf6c09 100644 --- a/dom/base/ScriptSettings.h +++ b/dom/base/ScriptSettings.h @@ -311,8 +311,6 @@ private: mozilla::Maybe mAutoNullableCompartment; JSContext *mCx; - // Track state between the old and new error reporting modes. - bool mOldAutoJSAPIOwnsErrorReporting; // Whether we're mainthread or not; set when we're initialized. bool mIsMainThread; Maybe mOldErrorReporter; diff --git a/dom/base/nsJSUtils.cpp b/dom/base/nsJSUtils.cpp index 133f70fe5171..5982a4d9fcda 100644 --- a/dom/base/nsJSUtils.cpp +++ b/dom/base/nsJSUtils.cpp @@ -149,8 +149,6 @@ nsJSUtils::EvaluateString(JSContext* aCx, PROFILER_LABEL("nsJSUtils", "EvaluateString", js::ProfileEntry::Category::JS); - MOZ_ASSERT(JS::ContextOptionsRef(aCx).autoJSAPIOwnsErrorReporting(), - "Caller must own error reporting"); MOZ_ASSERT_IF(aCompileOptions.versionSet, aCompileOptions.version != JSVERSION_UNKNOWN); MOZ_ASSERT(aCx == nsContentUtils::GetCurrentJSContext()); @@ -278,8 +276,6 @@ nsJSUtils::CompileModule(JSContext* aCx, PROFILER_LABEL("nsJSUtils", "CompileModule", js::ProfileEntry::Category::JS); - MOZ_ASSERT(JS::ContextOptionsRef(aCx).autoJSAPIOwnsErrorReporting(), - "Caller must own error reporting"); MOZ_ASSERT_IF(aCompileOptions.versionSet, aCompileOptions.version != JSVERSION_UNKNOWN); MOZ_ASSERT(aCx == nsContentUtils::GetCurrentJSContext()); @@ -305,8 +301,6 @@ nsJSUtils::ModuleDeclarationInstantiation(JSContext* aCx, JS::Handle PROFILER_LABEL("nsJSUtils", "ModuleDeclarationInstantiation", js::ProfileEntry::Category::JS); - MOZ_ASSERT(JS::ContextOptionsRef(aCx).autoJSAPIOwnsErrorReporting(), - "Caller must own error reporting"); MOZ_ASSERT(aCx == nsContentUtils::GetCurrentJSContext()); MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(nsContentUtils::IsInMicroTask()); @@ -326,8 +320,6 @@ nsJSUtils::ModuleEvaluation(JSContext* aCx, JS::Handle aModule) PROFILER_LABEL("nsJSUtils", "ModuleEvaluation", js::ProfileEntry::Category::JS); - MOZ_ASSERT(JS::ContextOptionsRef(aCx).autoJSAPIOwnsErrorReporting(), - "Caller must own error reporting"); MOZ_ASSERT(aCx == nsContentUtils::GetCurrentJSContext()); MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(nsContentUtils::IsInMicroTask()); diff --git a/dom/bindings/Exceptions.cpp b/dom/bindings/Exceptions.cpp index b85a9ee2995b..99da0a23624e 100644 --- a/dom/bindings/Exceptions.cpp +++ b/dom/bindings/Exceptions.cpp @@ -206,18 +206,6 @@ GetCurrentJSStack(int32_t aMaxDepth) return dom::exceptions::CreateStack(cx, aMaxDepth); } -AutoForceSetExceptionOnContext::AutoForceSetExceptionOnContext(JSContext* aCx) - : mCx(aCx) -{ - mOldValue = JS::ContextOptionsRef(mCx).autoJSAPIOwnsErrorReporting(); - JS::ContextOptionsRef(mCx).setAutoJSAPIOwnsErrorReporting(true); -} - -AutoForceSetExceptionOnContext::~AutoForceSetExceptionOnContext() -{ - JS::ContextOptionsRef(mCx).setAutoJSAPIOwnsErrorReporting(mOldValue); -} - namespace exceptions { class JSStackFrame : public nsIStackFrame diff --git a/dom/bindings/Exceptions.h b/dom/bindings/Exceptions.h index 4ff8c6964259..4bb1ea87c498 100644 --- a/dom/bindings/Exceptions.h +++ b/dom/bindings/Exceptions.h @@ -54,19 +54,6 @@ CreateException(JSContext* aCx, nsresult aRv, already_AddRefed GetCurrentJSStack(int32_t aMaxDepth = -1); -// Throwing a TypeError on an ErrorResult may result in SpiderMonkey using its -// own error reporting mechanism instead of just setting the exception on the -// context. This happens if no script is running. Bug 1107777 adds a flag that -// forcibly turns this behaviour off. This is a stack helper to set the flag. -class MOZ_STACK_CLASS AutoForceSetExceptionOnContext { -private: - JSContext* mCx; - bool mOldValue; -public: - explicit AutoForceSetExceptionOnContext(JSContext* aCx); - ~AutoForceSetExceptionOnContext(); -}; - // Internal stuff not intended to be widely used. namespace exceptions { diff --git a/dom/bindings/ToJSValue.cpp b/dom/bindings/ToJSValue.cpp index fb2be1b87978..d84428fb386b 100644 --- a/dom/bindings/ToJSValue.cpp +++ b/dom/bindings/ToJSValue.cpp @@ -58,7 +58,6 @@ ToJSValue(JSContext* aCx, MOZ_ASSERT(aArgument.Failed()); MOZ_ASSERT(!aArgument.IsUncatchableException(), "Doesn't make sense to convert uncatchable exception to a JS value!"); - AutoForceSetExceptionOnContext forceExn(aCx); DebugOnly throwResult = aArgument.MaybeSetPendingException(aCx); MOZ_ASSERT(throwResult); DebugOnly getPendingResult = JS_GetPendingException(aCx, aValue); diff --git a/dom/promise/Promise.cpp b/dom/promise/Promise.cpp index 213330db9a94..b065b39d7bd6 100644 --- a/dom/promise/Promise.cpp +++ b/dom/promise/Promise.cpp @@ -2623,7 +2623,6 @@ Promise::ResolveInternal(JSContext* aCx, mResolvePending = true; if (aValue.isObject()) { - MOZ_ASSERT(JS::ContextOptionsRef(aCx).autoJSAPIOwnsErrorReporting()); JS::Rooted valueObj(aCx, &aValue.toObject()); // Thenables. diff --git a/js/ipc/WrapperAnswer.cpp b/js/ipc/WrapperAnswer.cpp index efcb77c3dcca..bb1013ef2610 100644 --- a/js/ipc/WrapperAnswer.cpp +++ b/js/ipc/WrapperAnswer.cpp @@ -410,7 +410,6 @@ WrapperAnswer::RecvCallOrConstruct(const ObjectId& objId, RootedValue rval(cx); { - MOZ_ASSERT(JS::ContextOptionsRef(cx).autoJSAPIOwnsErrorReporting()); HandleValueArray args = HandleValueArray::subarray(vals, 2, vals.length() - 2); if (construct) { RootedObject obj(cx); diff --git a/js/src/frontend/TokenStream.cpp b/js/src/frontend/TokenStream.cpp index 980f7b2f7ce4..589aff75b2a4 100644 --- a/js/src/frontend/TokenStream.cpp +++ b/js/src/frontend/TokenStream.cpp @@ -584,7 +584,7 @@ CompileError::throwError(JSContext* cx) // Like ReportError, don't call the error reporter if the embedding is // responsible for handling exceptions. In this case the error reporter // must only be used for warnings. - if (cx->options().autoJSAPIOwnsErrorReporting() && !JSREPORT_IS_WARNING(report.flags)) + if (!JSREPORT_IS_WARNING(report.flags)) return; CallErrorReporter(cx, message, &report); diff --git a/js/src/jsapi-tests/testCallArgs.cpp b/js/src/jsapi-tests/testCallArgs.cpp index 45207e83222f..b924bbe4e51f 100644 --- a/js/src/jsapi-tests/testCallArgs.cpp +++ b/js/src/jsapi-tests/testCallArgs.cpp @@ -42,16 +42,6 @@ BEGIN_TEST(testCallArgs_isConstructing_native) return true; } - -virtual bool init() override -{ - if (!JSAPITest::init()) - return false; - - JS::ContextOptionsRef(cx).setAutoJSAPIOwnsErrorReporting(true); - - return true; -} END_TEST(testCallArgs_isConstructing_native) static bool @@ -93,14 +83,4 @@ BEGIN_TEST(testCallArgs_isConstructing_constructor) return true; } - -virtual bool init() override -{ - if (!JSAPITest::init()) - return false; - - JS::ContextOptionsRef(cx).setAutoJSAPIOwnsErrorReporting(true); - - return true; -} END_TEST(testCallArgs_isConstructing_constructor) diff --git a/js/src/jsapi-tests/testProfileStrings.cpp b/js/src/jsapi-tests/testProfileStrings.cpp index 903c87af582a..02737c0a4f43 100644 --- a/js/src/jsapi-tests/testProfileStrings.cpp +++ b/js/src/jsapi-tests/testProfileStrings.cpp @@ -203,7 +203,6 @@ BEGIN_TEST(testProfileStrings_isCalledWhenError) EXEC("function check2() { throw 'a'; }"); reset(cx); - JS::ContextOptionsRef(cx).setDontReportUncaught(true); { JS::RootedValue rval(cx); /* Make sure the stack resets and we have an entry for each stack */ diff --git a/js/src/jsapi-tests/tests.h b/js/src/jsapi-tests/tests.h index f47de0170a1f..4cb466ba0461 100644 --- a/js/src/jsapi-tests/tests.h +++ b/js/src/jsapi-tests/tests.h @@ -312,13 +312,7 @@ class JSAPITest } virtual JSContext* createContext() { - JSContext* cx = JS_NewContext(rt, 8192); - if (!cx) - return nullptr; - - JS::ContextOptionsRef(cx).setDontReportUncaught(true); - JS::ContextOptionsRef(cx).setAutoJSAPIOwnsErrorReporting(true); - return cx; + return JS_NewContext(rt, 8192); } virtual const JSClass * getGlobalClass() { diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 8fce111308b4..21ea619ccff9 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -700,12 +700,6 @@ JS::RuntimeOptionsRef(JSContext* cx) return cx->runtime()->options(); } -JS_PUBLIC_API(JS::ContextOptions&) -JS::ContextOptionsRef(JSContext* cx) -{ - return cx->options(); -} - JS_PUBLIC_API(const char*) JS_GetImplementationVersion(void) { @@ -2825,29 +2819,6 @@ JS::IsConstructor(JSObject* obj) return obj->isConstructor(); } -struct AutoLastFrameCheck -{ - explicit AutoLastFrameCheck(JSContext* cx - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : cx(cx) - { - MOZ_ASSERT(cx); - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - ~AutoLastFrameCheck() { - if (cx->isExceptionPending() && - !JS_IsRunning(cx) && - (!cx->options().dontReportUncaught() && !cx->options().autoJSAPIOwnsErrorReporting())) { - ReportUncaughtException(cx); - } - } - - private: - JSContext* cx; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER -}; - JS_PUBLIC_API(bool) JS_CallFunctionValue(JSContext* cx, HandleObject obj, HandleValue fval, const HandleValueArray& args, MutableHandleValue rval) @@ -2856,7 +2827,6 @@ JS_CallFunctionValue(JSContext* cx, HandleObject obj, HandleValue fval, const Ha AssertHeapIsIdle(cx); CHECK_REQUEST(cx); assertSameCompartment(cx, obj, fval, args); - AutoLastFrameCheck lfc(cx); InvokeArgs iargs(cx); if (!FillArgumentsFromArraylike(cx, iargs, args)) @@ -2874,7 +2844,6 @@ JS_CallFunction(JSContext* cx, HandleObject obj, HandleFunction fun, const Handl AssertHeapIsIdle(cx); CHECK_REQUEST(cx); assertSameCompartment(cx, obj, fun, args); - AutoLastFrameCheck lfc(cx); InvokeArgs iargs(cx); if (!FillArgumentsFromArraylike(cx, iargs, args)) @@ -2893,7 +2862,6 @@ JS_CallFunctionName(JSContext* cx, HandleObject obj, const char* name, const Han AssertHeapIsIdle(cx); CHECK_REQUEST(cx); assertSameCompartment(cx, obj, args); - AutoLastFrameCheck lfc(cx); JSAtom* atom = Atomize(cx, name, strlen(name)); if (!atom) @@ -2919,7 +2887,6 @@ JS::Call(JSContext* cx, HandleValue thisv, HandleValue fval, const JS::HandleVal AssertHeapIsIdle(cx); CHECK_REQUEST(cx); assertSameCompartment(cx, thisv, fval, args); - AutoLastFrameCheck lfc(cx); InvokeArgs iargs(cx); if (!FillArgumentsFromArraylike(cx, iargs, args)) @@ -2935,7 +2902,6 @@ JS::Construct(JSContext* cx, HandleValue fval, HandleObject newTarget, const JS: AssertHeapIsIdle(cx); CHECK_REQUEST(cx); assertSameCompartment(cx, fval, newTarget, args); - AutoLastFrameCheck lfc(cx); if (!IsConstructor(fval)) { ReportValueError(cx, JSMSG_NOT_CONSTRUCTOR, JSDVG_IGNORE_STACK, fval, nullptr); @@ -2962,7 +2928,6 @@ JS::Construct(JSContext* cx, HandleValue fval, const JS::HandleValueArray& args, AssertHeapIsIdle(cx); CHECK_REQUEST(cx); assertSameCompartment(cx, fval, args); - AutoLastFrameCheck lfc(cx); if (!IsConstructor(fval)) { ReportValueError(cx, JSMSG_NOT_CONSTRUCTOR, JSDVG_IGNORE_STACK, fval, nullptr); @@ -3994,7 +3959,6 @@ Compile(JSContext* cx, const ReadOnlyCompileOptions& options, SyntacticScopeOpti MOZ_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment())); AssertHeapIsIdle(cx); CHECK_REQUEST(cx); - AutoLastFrameCheck lfc(cx); Rooted staticScope(cx, &cx->global()->lexicalScope().staticBlock()); if (scopeOption == HasNonSyntacticScope) { @@ -4163,17 +4127,7 @@ JS_PUBLIC_API(JSScript*) JS::FinishOffThreadScript(JSContext* maybecx, JSRuntime* rt, void* token) { MOZ_ASSERT(CurrentThreadCanAccessRuntime(rt)); - - if (maybecx) { - RootedScript script(maybecx); - { - AutoLastFrameCheck lfc(maybecx); - script = HelperThreadState().finishScriptParseTask(maybecx, rt, token); - } - return script; - } else { - return HelperThreadState().finishScriptParseTask(maybecx, rt, token); - } + return HelperThreadState().finishScriptParseTask(maybecx, rt, token); } JS_PUBLIC_API(bool) @@ -4189,17 +4143,7 @@ JS_PUBLIC_API(JSObject*) JS::FinishOffThreadModule(JSContext* maybecx, JSRuntime* rt, void* token) { MOZ_ASSERT(CurrentThreadCanAccessRuntime(rt)); - - if (maybecx) { - RootedObject module(maybecx); - { - AutoLastFrameCheck lfc(maybecx); - module = HelperThreadState().finishModuleParseTask(maybecx, rt, token); - } - return module; - } else { - return HelperThreadState().finishModuleParseTask(maybecx, rt, token); - } + return HelperThreadState().finishModuleParseTask(maybecx, rt, token); } JS_PUBLIC_API(bool) @@ -4311,7 +4255,6 @@ CompileFunction(JSContext* cx, const ReadOnlyCompileOptions& optionsArg, assertSameCompartment(cx, enclosingDynamicScope); assertSameCompartment(cx, enclosingStaticScope); RootedAtom funAtom(cx); - AutoLastFrameCheck lfc(cx); if (name) { funAtom = Atomize(cx, name, strlen(name)); @@ -4423,7 +4366,6 @@ ExecuteScript(JSContext* cx, HandleObject scope, HandleScript script, Value* rva CHECK_REQUEST(cx); assertSameCompartment(cx, scope, script); MOZ_ASSERT_IF(!IsGlobalLexicalScope(scope), script->hasNonSyntacticScope()); - AutoLastFrameCheck lfc(cx); return Execute(cx, script, *scope, rval); } @@ -4503,8 +4445,6 @@ Evaluate(JSContext* cx, HandleObject scope, Handle staticScope, CHECK_REQUEST(cx); assertSameCompartment(cx, scope); - AutoLastFrameCheck lfc(cx); - MOZ_ASSERT_IF(!IsGlobalLexicalScope(scope), HasNonSyntacticStaticScopeChain(staticScope)); options.setIsRunOnce(true); @@ -4656,8 +4596,6 @@ JS::CompileModule(JSContext* cx, const ReadOnlyCompileOptions& options, AssertHeapIsIdle(cx); CHECK_REQUEST(cx); - AutoLastFrameCheck lfc(cx); - module.set(frontend::CompileModule(cx, options, srcBuf)); return !!module; } @@ -4710,8 +4648,8 @@ JS::GetModuleScript(JSContext* cx, JS::HandleObject moduleArg) return moduleArg->as().script(); } -static JSObject* -JS_NewHelper(JSContext* cx, HandleObject ctor, const JS::HandleValueArray& inputArgs) +JS_PUBLIC_API(JSObject*) +JS_New(JSContext* cx, HandleObject ctor, const JS::HandleValueArray& inputArgs) { AssertHeapIsIdle(cx); CHECK_REQUEST(cx); @@ -4734,17 +4672,6 @@ JS_NewHelper(JSContext* cx, HandleObject ctor, const JS::HandleValueArray& input return obj; } -JS_PUBLIC_API(JSObject*) -JS_New(JSContext* cx, HandleObject ctor, const JS::HandleValueArray& inputArgs) -{ - RootedObject obj(cx); - { - AutoLastFrameCheck lfc(cx); - obj = JS_NewHelper(cx, ctor, inputArgs); - } - return obj; -} - JS_PUBLIC_API(bool) JS_CheckForInterrupt(JSContext* cx) { diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 4d833666bae4..a58f66dd66ac 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -1268,69 +1268,6 @@ RuntimeOptionsRef(JSRuntime* rt); JS_PUBLIC_API(RuntimeOptions&) RuntimeOptionsRef(JSContext* cx); -class JS_PUBLIC_API(ContextOptions) { - public: - ContextOptions() - : dontReportUncaught_(false), - autoJSAPIOwnsErrorReporting_(false) - { - } - - bool dontReportUncaught() const { return dontReportUncaught_; } - ContextOptions& setDontReportUncaught(bool flag) { - dontReportUncaught_ = flag; - return *this; - } - ContextOptions& toggleDontReportUncaught() { - dontReportUncaught_ = !dontReportUncaught_; - return *this; - } - - bool autoJSAPIOwnsErrorReporting() const { return autoJSAPIOwnsErrorReporting_; } - ContextOptions& setAutoJSAPIOwnsErrorReporting(bool flag) { - autoJSAPIOwnsErrorReporting_ = flag; - return *this; - } - ContextOptions& toggleAutoJSAPIOwnsErrorReporting() { - autoJSAPIOwnsErrorReporting_ = !autoJSAPIOwnsErrorReporting_; - return *this; - } - - - private: - bool privateIsNSISupports_ : 1; - bool dontReportUncaught_ : 1; - // dontReportUncaught isn't respected by all JSAPI codepaths, particularly the - // JS_ReportError* functions that eventually report the error even when dontReportUncaught is - // set, if script is not running. We want a way to indicate that the embedder will always - // handle any exceptions, and that SpiderMonkey should just leave them on the context. This is - // the way we want to do all future error handling in Gecko - stealing the exception explicitly - // from the context and handling it as per the situation. This will eventually become the - // default and these 2 flags should go away. - bool autoJSAPIOwnsErrorReporting_ : 1; -}; - -JS_PUBLIC_API(ContextOptions&) -ContextOptionsRef(JSContext* cx); - -class JS_PUBLIC_API(AutoSaveContextOptions) { - public: - explicit AutoSaveContextOptions(JSContext* cx) - : cx_(cx), - oldOptions_(ContextOptionsRef(cx_)) - { - } - - ~AutoSaveContextOptions() - { - ContextOptionsRef(cx_) = oldOptions_; - } - - private: - JSContext* cx_; - JS::ContextOptions oldOptions_; -}; - } /* namespace JS */ extern JS_PUBLIC_API(const char*) diff --git a/js/src/jscntxt.cpp b/js/src/jscntxt.cpp index f3dba85b94a2..0cb0b18c5779 100644 --- a/js/src/jscntxt.cpp +++ b/js/src/jscntxt.cpp @@ -225,17 +225,15 @@ ReportError(JSContext* cx, const char* message, JSErrorReport* reportp, reportp->flags |= JSREPORT_EXCEPTION; } - if (cx->options().autoJSAPIOwnsErrorReporting() || JS_IsRunning(cx)) { - if (ErrorToException(cx, message, reportp, callback, userRef)) - return; + if (ErrorToException(cx, message, reportp, callback, userRef)) + return; - /* - * The AutoJSAPI error reporter only allows warnings to be reported so - * just ignore this error rather than try to report it. - */ - if (cx->options().autoJSAPIOwnsErrorReporting() && !JSREPORT_IS_WARNING(reportp->flags)) - return; - } + /* + * The AutoJSAPI error reporter only allows warnings to be reported so + * just ignore this error rather than try to report it. + */ + if (!JSREPORT_IS_WARNING(reportp->flags)) + return; /* * Call the error reporter only if an exception wasn't raised. @@ -304,36 +302,7 @@ js::ReportOutOfMemory(ExclusiveContext* cxArg) if (JS::OutOfMemoryCallback oomCallback = cx->runtime()->oomCallback) oomCallback(cx, cx->runtime()->oomCallbackData); - if (cx->options().autoJSAPIOwnsErrorReporting() || JS_IsRunning(cx)) { - cx->setPendingException(StringValue(cx->names().outOfMemory)); - return; - } - - /* Get the message for this error, but we don't expand any arguments. */ - const JSErrorFormatString* efs = GetErrorMessage(nullptr, JSMSG_OUT_OF_MEMORY); - const char* msg = efs ? efs->format : "Out of memory"; - - /* Fill out the report, but don't do anything that requires allocation. */ - JSErrorReport report; - report.flags = JSREPORT_ERROR; - report.errorNumber = JSMSG_OUT_OF_MEMORY; - PopulateReportBlame(cx, &report); - - /* Report the error. */ - if (JSErrorReporter onError = cx->runtime()->errorReporter) - onError(cx, msg, &report); - - /* - * We would like to enforce the invariant that any exception reported - * during an OOM situation does not require wrapping. Besides avoiding - * allocation when memory is low, this reduces the number of places where - * we might need to GC. - * - * When JS code is running, we set the pending exception to an atom, which - * does not need wrapping. If no JS code is running, no exception should be - * set at all. - */ - MOZ_ASSERT(!cx->isExceptionPending()); + cx->setPendingException(StringValue(cx->names().outOfMemory)); } void @@ -964,7 +933,6 @@ JSContext::JSContext(JSRuntime* rt) : ExclusiveContext(rt, &rt->mainThread, Context_JS), throwing(false), unwrappedException_(this), - options_(), overRecursed_(false), propagatingForcedReturn_(false), liveVolatileJitFrameIterators_(nullptr), diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index 3e26e302e659..3ac30d6921bd 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -321,9 +321,6 @@ struct JSContext : public js::ExclusiveContext, bool throwing; /* is there a pending exception? */ JS::PersistentRooted unwrappedException_; /* most-recently-thrown exception */ - /* Per-context options. */ - JS::ContextOptions options_; - // True if the exception currently being thrown is by result of // ReportOverRecursed. See Debugger::slowPathOnExceptionUnwind. bool overRecursed_; @@ -363,14 +360,6 @@ struct JSContext : public js::ExclusiveContext, */ JSVersion findVersion() const; - const JS::ContextOptions& options() const { - return options_; - } - - JS::ContextOptions& options() { - return options_; - } - js::LifoAlloc& tempLifoAlloc() { return runtime()->tempLifoAlloc; } unsigned outstandingRequests;/* number of JS_BeginRequest calls diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 2a0c11f6db3a..bbdc8c8f4c70 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -6453,9 +6453,6 @@ NewContext(JSRuntime* rt) if (!cx) return nullptr; - JS::ContextOptionsRef(cx).setDontReportUncaught(true); - JS::ContextOptionsRef(cx).setAutoJSAPIOwnsErrorReporting(true); - JSShellContextData* data = NewContextData(); if (!data) { DestroyContext(cx, false); diff --git a/js/src/vm/SelfHosting.cpp b/js/src/vm/SelfHosting.cpp index f0a1eb7604ff..92015fc05e1f 100644 --- a/js/src/vm/SelfHosting.cpp +++ b/js/src/vm/SelfHosting.cpp @@ -2714,25 +2714,15 @@ MaybePrintAndClearPendingException(JSContext* cx, FILE* file) class MOZ_STACK_CLASS AutoSelfHostingErrorReporter { JSContext* cx_; - bool prevDontReportUncaught_; - bool prevAutoJSAPIOwnsErrorReporting_; JSErrorReporter oldReporter_; public: explicit AutoSelfHostingErrorReporter(JSContext* cx) - : cx_(cx), - prevDontReportUncaught_(cx_->options().dontReportUncaught()), - prevAutoJSAPIOwnsErrorReporting_(cx_->options().autoJSAPIOwnsErrorReporting()) + : cx_(cx) { - cx_->options().setDontReportUncaught(true); - cx_->options().setAutoJSAPIOwnsErrorReporting(true); - oldReporter_ = JS_SetErrorReporter(cx_->runtime(), selfHosting_WarningReporter); } ~AutoSelfHostingErrorReporter() { - cx_->options().setDontReportUncaught(prevDontReportUncaught_); - cx_->options().setAutoJSAPIOwnsErrorReporting(prevAutoJSAPIOwnsErrorReporting_); - JS_SetErrorReporter(cx_->runtime(), oldReporter_); // Exceptions in self-hosted code will usually be printed to stderr in diff --git a/js/xpconnect/src/XPCWrappedJSClass.cpp b/js/xpconnect/src/XPCWrappedJSClass.cpp index 36007358d663..d753d1c13d74 100644 --- a/js/xpconnect/src/XPCWrappedJSClass.cpp +++ b/js/xpconnect/src/XPCWrappedJSClass.cpp @@ -239,7 +239,6 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(JSContext* cx, // to eat all exceptions either. { - MOZ_ASSERT(JS::ContextOptionsRef(cx).autoJSAPIOwnsErrorReporting()); RootedValue arg(cx, JS::ObjectValue(*id)); success = JS_CallFunctionValue(cx, jsobj, fun, HandleValueArray(arg), &retval); } @@ -274,8 +273,6 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(JSContext* cx, JS_ClearPendingException(cx); } } - - MOZ_ASSERT(ContextOptionsRef(cx).autoJSAPIOwnsErrorReporting()); } else if (!success) { NS_WARNING("QI hook ran OOMed - this is probably a bug!"); } @@ -1213,7 +1210,6 @@ pre_call_clean_up: success = JS_SetProperty(cx, obj, name, rval); } else { if (!fval.isPrimitive()) { - MOZ_ASSERT(JS::ContextOptionsRef(cx).autoJSAPIOwnsErrorReporting()); success = JS_CallFunctionValue(cx, thisObj, fval, args, &rval); } else { // The property was not an object so can't be a function. diff --git a/netwerk/base/ProxyAutoConfig.cpp b/netwerk/base/ProxyAutoConfig.cpp index 5f8920b59286..674c1256f1ac 100644 --- a/netwerk/base/ProxyAutoConfig.cpp +++ b/netwerk/base/ProxyAutoConfig.cpp @@ -687,8 +687,6 @@ private: mContext = JS_NewContext(mRuntime, 0); NS_ENSURE_TRUE(mContext, NS_ERROR_OUT_OF_MEMORY); - JS::ContextOptionsRef(mContext).setAutoJSAPIOwnsErrorReporting(true); - JSAutoRequest ar(mContext); JS::CompartmentOptions options;