Bug 1277278 part 2 - Remove JS_ReportPendingException and js::ReportUncaughtException. r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Tue, 07 Jun 2016 20:30:48 +0200
changeset 300949 3e9f480972b441c53802cace2cacbfb7510c53c6
parent 300948 aaebaccae0a2c9595c3009f08cdb4c84ad82d4b4
child 300950 3b42129e45a9bdfbefeb35a2ea26d60d757c7e1f
push id19599
push usercbook@mozilla.com
push dateWed, 08 Jun 2016 10:16:21 +0000
treeherderfx-team@81f4cc3f6f4c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1277278
milestone50.0a1
Bug 1277278 part 2 - Remove JS_ReportPendingException and js::ReportUncaughtException. r=luke
js/src/jsapi-tests/moz.build
js/src/jsapi-tests/testUncaughtError.cpp
js/src/jsapi.cpp
js/src/jsapi.h
js/src/jsexn.cpp
js/src/jsexn.h
js/src/jsfriendapi.cpp
--- a/js/src/jsapi-tests/moz.build
+++ b/js/src/jsapi-tests/moz.build
@@ -90,17 +90,16 @@ UNIFIED_SOURCES += [
     'testSymbol.cpp',
     'testThreadingConditionVariable.cpp',
     'testThreadingExclusiveData.cpp',
     'testThreadingMutex.cpp',
     'testThreadingThread.cpp',
     'testToIntWidth.cpp',
     'testTypedArrays.cpp',
     'testUbiNode.cpp',
-    'testUncaughtError.cpp',
     'testUncaughtSymbol.cpp',
     'testUTF8.cpp',
     'testWasmLEB128.cpp',
     'testWeakMap.cpp',
     'testXDR.cpp',
 ]
 
 SOURCES += [
deleted file mode 100644
--- 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<JSString*> empty(cx, JS_GetEmptyString(JS_GetRuntime(cx)));
-    if (!empty)
-        return false;
-
-    Rooted<Value> err(cx);
-    if (!CreateError(cx, JSEXN_TYPEERR, nullptr, empty, 0, 0, nullptr, empty, &err))
-        return false;
-
-    Rooted<JSObject*> 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)
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -5923,28 +5923,16 @@ JS_SetPendingException(JSContext* cx, Ha
 
 JS_PUBLIC_API(void)
 JS_ClearPendingException(JSContext* cx)
 {
     AssertHeapIsIdle(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_),
     wasOverRecursed(cx->overRecursed_),
     wasThrowing(cx->throwing),
     exceptionValue(cx)
 {
     AssertHeapIsIdle(cx);
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -5408,19 +5408,16 @@ extern JS_PUBLIC_API(bool)
 JS_GetPendingException(JSContext* cx, JS::MutableHandleValue vp);
 
 extern JS_PUBLIC_API(void)
 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 {
 
 /**
  * Save and later restore the current exception state of a given JSContext.
  * This is useful for implementing behavior in C++ that's like try/catch
  * or try/finally in JS.
  *
  * Typical usage:
--- a/js/src/jsexn.cpp
+++ b/js/src/jsexn.cpp
@@ -656,42 +656,16 @@ ErrorReportToString(JSContext* cx, JSErr
         return nullptr;
 
     if (!str)
         return message;
 
     return ConcatStrings<CanGC>(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),
     ownedMessage(nullptr),
     str(cx),
     strChars(cx),
     exnObject(cx)
 {
--- a/js/src/jsexn.h
+++ b/js/src/jsexn.h
@@ -49,35 +49,16 @@ ComputeStackString(JSContext* cx);
  *     we decided to do nothing in order to avoid recursion, then return
  *     false. In those cases, this error is just being swept under the rug
  *     unless the caller decides to call CallErrorReporter explicitly.
  */
 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);
 
 /*
  * Make a copy of errobj parented to cx's compartment's global.
  *
  * errobj may be in a different compartment than cx, but it must be an Error
  * object (not a wrapper of one) and it must not be one of the standard error
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -1205,33 +1205,20 @@ js::detail::IdMatchesAtom(jsid id, JSAto
     return id == INTERNED_STRING_TO_JSID(nullptr, atom);
 }
 
 JS_FRIEND_API(void)
 js::PrepareScriptEnvironmentAndInvoke(JSContext* cx, HandleObject scope, ScriptEnvironmentPreparer::Closure& closure)
 {
     MOZ_ASSERT(!cx->isExceptionPending());
 
-    if (cx->runtime()->scriptEnvironmentPreparer) {
-        cx->runtime()->scriptEnvironmentPreparer->invoke(scope, closure);
-        return;
-    }
-
-    JSAutoCompartment ac(cx, scope);
-    bool ok = closure(cx);
+    MOZ_RELEASE_ASSERT(cx->runtime()->scriptEnvironmentPreparer,
+                       "Embedding needs to set a scriptEnvironmentPreparer callback");
 
-    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)
 js::SetScriptEnvironmentPreparer(JSRuntime* rt, ScriptEnvironmentPreparer* preparer)
 {
     rt->scriptEnvironmentPreparer = preparer;
 }