diff --git a/js/src/jsapi-tests/moz.build b/js/src/jsapi-tests/moz.build index 8d8e74f77632..509dd24b3bb7 100644 --- a/js/src/jsapi-tests/moz.build +++ b/js/src/jsapi-tests/moz.build @@ -95,7 +95,6 @@ UNIFIED_SOURCES += [ 'testToIntWidth.cpp', 'testTypedArrays.cpp', 'testUbiNode.cpp', - 'testUncaughtError.cpp', 'testUncaughtSymbol.cpp', 'testUTF8.cpp', 'testWasmLEB128.cpp', diff --git a/js/src/jsapi-tests/testUncaughtError.cpp b/js/src/jsapi-tests/testUncaughtError.cpp deleted file mode 100644 index 690482c97e1b..000000000000 --- a/js/src/jsapi-tests/testUncaughtError.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "jsapi-tests/tests.h" - -using JS::CreateError; -using JS::Rooted; -using JS::ObjectValue; -using JS::Value; - -static size_t uncaughtCount = 0; - -BEGIN_TEST(testUncaughtError) -{ - JSErrorReporter old = JS_SetErrorReporter(rt, UncaughtErrorReporter); - - CHECK(uncaughtCount == 0); - - Rooted empty(cx, JS_GetEmptyString(JS_GetRuntime(cx))); - if (!empty) - return false; - - Rooted err(cx); - if (!CreateError(cx, JSEXN_TYPEERR, nullptr, empty, 0, 0, nullptr, empty, &err)) - return false; - - Rooted errObj(cx, &err.toObject()); - if (!JS_SetProperty(cx, errObj, "fileName", err)) - return false; - if (!JS_SetProperty(cx, errObj, "lineNumber", err)) - return false; - if (!JS_SetProperty(cx, errObj, "columnNumber", err)) - return false; - if (!JS_SetProperty(cx, errObj, "stack", err)) - return false; - if (!JS_SetProperty(cx, errObj, "message", err)) - return false; - - JS_SetPendingException(cx, err); - JS_ReportPendingException(cx); - - CHECK(uncaughtCount == 1); - - JS_SetErrorReporter(rt, old); - - return true; -} - -static void -UncaughtErrorReporter(JSContext* cx, const char* message, JSErrorReport* report) -{ - uncaughtCount++; -} - -END_TEST(testUncaughtError) diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 21ea619ccff9..7021f305f5cf 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -5928,18 +5928,6 @@ JS_ClearPendingException(JSContext* cx) cx->clearPendingException(); } -JS_PUBLIC_API(bool) -JS_ReportPendingException(JSContext* cx) -{ - AssertHeapIsIdle(cx); - CHECK_REQUEST(cx); - - // This can only fail due to oom. - bool ok = ReportUncaughtException(cx); - MOZ_ASSERT(!cx->isExceptionPending()); - return ok; -} - JS::AutoSaveExceptionState::AutoSaveExceptionState(JSContext* cx) : context(cx), wasPropagatingForcedReturn(cx->propagatingForcedReturn_), diff --git a/js/src/jsapi.h b/js/src/jsapi.h index a58f66dd66ac..023793ef1f9a 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -5413,9 +5413,6 @@ JS_SetPendingException(JSContext* cx, JS::HandleValue v); extern JS_PUBLIC_API(void) JS_ClearPendingException(JSContext* cx); -extern JS_PUBLIC_API(bool) -JS_ReportPendingException(JSContext* cx); - namespace JS { /** diff --git a/js/src/jsexn.cpp b/js/src/jsexn.cpp index 1193a9ef56e6..5bb80967c258 100644 --- a/js/src/jsexn.cpp +++ b/js/src/jsexn.cpp @@ -661,32 +661,6 @@ ErrorReportToString(JSContext* cx, JSErrorReport* reportp) return ConcatStrings(cx, str, message); } -bool -js::ReportUncaughtException(JSContext* cx) -{ - if (!cx->isExceptionPending()) - return true; - - RootedValue exn(cx); - if (!cx->getPendingException(&exn)) { - cx->clearPendingException(); - return false; - } - - cx->clearPendingException(); - - ErrorReport err(cx); - if (!err.init(cx, exn, js::ErrorReport::WithSideEffects)) { - cx->clearPendingException(); - return false; - } - - cx->setPendingException(exn); - CallErrorReporter(cx, err.message(), err.report()); - cx->clearPendingException(); - return true; -} - ErrorReport::ErrorReport(JSContext* cx) : reportp(nullptr), message_(nullptr), diff --git a/js/src/jsexn.h b/js/src/jsexn.h index 8e99142c4a23..91fa21b031fc 100644 --- a/js/src/jsexn.h +++ b/js/src/jsexn.h @@ -54,25 +54,6 @@ extern bool ErrorToException(JSContext* cx, const char* message, JSErrorReport* reportp, JSErrorCallback callback, void* userRef); -/* - * Called if a JS API call to js_Execute or js_InternalCall fails; calls the - * error reporter with the error report associated with any uncaught exception - * that has been raised. Returns true if there was an exception pending, and - * the error reporter was actually called. - * - * The JSErrorReport * that the error reporter is called with is currently - * associated with a JavaScript object, and is not guaranteed to persist after - * the object is collected. Any persistent uses of the JSErrorReport contents - * should make their own copy. - * - * The flags field of the JSErrorReport will have the JSREPORT_EXCEPTION flag - * set; embeddings that want to silently propagate JavaScript exceptions to - * other contexts may want to use an error reporter that ignores errors with - * this flag. - */ -extern bool -ReportUncaughtException(JSContext* cx); - extern JSErrorReport* ErrorFromException(JSContext* cx, HandleObject obj); diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index 0c9d14baa495..efe8e68be9e8 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -1210,23 +1210,10 @@ js::PrepareScriptEnvironmentAndInvoke(JSContext* cx, HandleObject scope, ScriptE { MOZ_ASSERT(!cx->isExceptionPending()); - if (cx->runtime()->scriptEnvironmentPreparer) { - cx->runtime()->scriptEnvironmentPreparer->invoke(scope, closure); - return; - } + MOZ_RELEASE_ASSERT(cx->runtime()->scriptEnvironmentPreparer, + "Embedding needs to set a scriptEnvironmentPreparer callback"); - JSAutoCompartment ac(cx, scope); - bool ok = closure(cx); - - MOZ_ASSERT_IF(ok, !cx->isExceptionPending()); - - // NB: This does not affect Gecko, which has a prepareScriptEnvironment - // callback. - if (!ok) { - JS_ReportPendingException(cx); - } - - MOZ_ASSERT(!cx->isExceptionPending()); + cx->runtime()->scriptEnvironmentPreparer->invoke(scope, closure); } JS_FRIEND_API(void)