Bug 1343481 - Part 6: Add native functions wrapper for GetInternalError and GetTypeError. r=shu
authorTooru Fujisawa <arai_a@mac.com>
Wed, 01 Mar 2017 20:40:05 +0900
changeset 394272 b623bf54b41f1ba8a406851e19e74340417540b9
parent 394271 be60a3cf158e177f70a3f48d7904c0267676fe47
child 394273 bf3219269a11aff5b64a61b6c782aa97bb4594c1
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu
bugs1343481
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1343481 - Part 6: Add native functions wrapper for GetInternalError and GetTypeError. r=shu
js/src/builtin/Promise.cpp
js/src/jsexn.cpp
js/src/jsexn.h
--- a/js/src/builtin/Promise.cpp
+++ b/js/src/builtin/Promise.cpp
@@ -6,21 +6,21 @@
 
 
 #include "builtin/Promise.h"
 
 #include "mozilla/Atomics.h"
 #include "mozilla/TimeStamp.h"
 
 #include "jscntxt.h"
+#include "jsexn.h"
 
 #include "gc/Heap.h"
 #include "js/Debug.h"
 #include "vm/AsyncFunction.h"
-#include "vm/SelfHosting.h"
 
 #include "jsobjinlines.h"
 
 #include "vm/NativeObject-inl.h"
 
 using namespace js;
 
 static double
@@ -765,19 +765,17 @@ RejectMaybeWrappedPromise(JSContext *cx,
         // rejection handler.
         if (!promise->compartment()->wrap(cx, &reason))
             return false;
         if (reason.isObject() && !CheckedUnwrap(&reason.toObject())) {
             // Async stacks are only properly adopted if there's at least one
             // interpreter frame active right now. If a thenable job with a
             // throwing `then` function got us here, that'll not be the case,
             // so we add one by throwing the error from self-hosted code.
-            FixedInvokeArgs<1> getErrorArgs(cx);
-            getErrorArgs[0].set(Int32Value(JSMSG_PROMISE_ERROR_IN_WRAPPED_REJECTION_REASON));
-            if (!CallSelfHostedFunction(cx, "GetInternalError", reason, getErrorArgs, &reason))
+            if (!GetInternalError(cx, JSMSG_PROMISE_ERROR_IN_WRAPPED_REJECTION_REASON, &reason))
                 return false;
         }
     }
 
     MOZ_ASSERT(promise->state() == JS::PromiseState::Pending);
 
     return ResolvePromise(cx, promise, reason, JS::PromiseState::Rejected);
 }
--- a/js/src/jsexn.cpp
+++ b/js/src/jsexn.cpp
@@ -27,16 +27,17 @@
 #include "jsutil.h"
 #include "jswrapper.h"
 
 #include "gc/Marking.h"
 #include "js/CharacterEncoding.h"
 #include "vm/ErrorObject.h"
 #include "vm/GlobalObject.h"
 #include "vm/SavedStacks.h"
+#include "vm/SelfHosting.h"
 #include "vm/StringBuffer.h"
 
 #include "jsobjinlines.h"
 
 #include "vm/ErrorObject-inl.h"
 #include "vm/SavedStacks-inl.h"
 
 using namespace js;
@@ -1141,8 +1142,24 @@ js::ValueToSourceForError(JSContext* cx,
     }
     if (!sb.append(str))
         return "<<error converting value to string>>";
     str = sb.finishString();
     if (!str)
         return "<<error converting value to string>>";
     return bytes.encodeLatin1(cx, str);
 }
+
+bool
+js::GetInternalError(JSContext* cx, unsigned errorNumber, MutableHandleValue error)
+{
+    FixedInvokeArgs<1> args(cx);
+    args[0].set(Int32Value(errorNumber));
+    return CallSelfHostedFunction(cx, "GetInternalError", NullHandleValue, args, error);
+}
+
+bool
+js::GetTypeError(JSContext* cx, unsigned errorNumber, MutableHandleValue error)
+{
+    FixedInvokeArgs<1> args(cx);
+    args[0].set(Int32Value(errorNumber));
+    return CallSelfHostedFunction(cx, "GetTypeError", NullHandleValue, args, error);
+}
--- a/js/src/jsexn.h
+++ b/js/src/jsexn.h
@@ -127,11 +127,16 @@ class AutoAssertNoPendingException
     ~AutoAssertNoPendingException() {
         MOZ_ASSERT(!JS_IsExceptionPending(cx));
     }
 };
 
 extern const char*
 ValueToSourceForError(JSContext* cx, HandleValue val, JSAutoByteString& bytes);
 
+bool
+GetInternalError(JSContext* cx, unsigned errorNumber, MutableHandleValue error);
+bool
+GetTypeError(JSContext* cx, unsigned errorNumber, MutableHandleValue error);
+
 } // namespace js
 
 #endif /* jsexn_h */