Bug 1223990 - Cleanly throw errors in self-hosted code. (r=till)
authorEric Faust <efaustbmo@gmail.com>
Fri, 13 Nov 2015 18:23:57 -0800
changeset 309806 582d73c412f687f2ce682e3cf13b21bf179ac315
parent 309805 4a9ebc74d62a0b07a026a54631b15c21660a3933
child 309807 677cbf860ff298a4147e628f4dcab418d9a6db01
push id7649
push usermartin.thomson@gmail.com
push dateThu, 19 Nov 2015 00:06:17 +0000
reviewerstill
bugs1223990
milestone45.0a1
Bug 1223990 - Cleanly throw errors in self-hosted code. (r=till)
js/src/jsexn.cpp
--- a/js/src/jsexn.cpp
+++ b/js/src/jsexn.cpp
@@ -532,16 +532,23 @@ bool
 js::ErrorToException(JSContext* cx, const char* message, JSErrorReport* reportp,
                      JSErrorCallback callback, void* userRef)
 {
     // Tell our caller to report immediately if this report is just a warning.
     MOZ_ASSERT(reportp);
     if (JSREPORT_IS_WARNING(reportp->flags))
         return false;
 
+    // Similarly, we cannot throw a proper object inside the self-hosting
+    // compartment, as we cannot construct the Error constructor without
+    // self-hosted code. Tell our caller to report immediately.
+    // Without self-hosted code, we cannot get started anyway.
+    if (cx->runtime()->isSelfHostingCompartment(cx->compartment()))
+        return false;
+
     // Find the exception index associated with this error.
     JSErrNum errorNumber = static_cast<JSErrNum>(reportp->errorNumber);
     if (!callback)
         callback = GetErrorMessage;
     const JSErrorFormatString* errorString = callback(userRef, errorNumber);
     JSExnType exnType = errorString ? static_cast<JSExnType>(errorString->exnType) : JSEXN_NONE;
     MOZ_ASSERT(exnType < JSEXN_LIMIT);