Bug 1543751 Part 1 - Add API to set the stack for a pending exception, r=sfink.
authorBrian Hackett <bhackett1024@gmail.com>
Mon, 15 Apr 2019 13:39:07 -1000
changeset 469754 57904fc5ae57
parent 469753 7a56f4bec684
child 469755 39a877972476
push id35881
push usercbrindusan@mozilla.com
push dateWed, 17 Apr 2019 09:38:58 +0000
treeherdermozilla-central@bbca68b2af26 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1543751
milestone68.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 1543751 Part 1 - Add API to set the stack for a pending exception, r=sfink.
js/src/jsapi.cpp
js/src/jsapi.h
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -5003,16 +5003,32 @@ JS_PUBLIC_API void JS_SetPendingExceptio
   }
 }
 
 JS_PUBLIC_API void JS_ClearPendingException(JSContext* cx) {
   AssertHeapIsIdle();
   cx->clearPendingException();
 }
 
+JS_PUBLIC_API void
+JS::SetPendingExceptionAndStack(JSContext* cx, HandleValue value,
+                                HandleObject stack)
+{
+  AssertHeapIsIdle();
+  CHECK_THREAD(cx);
+  cx->releaseCheck(value);
+  cx->releaseCheck(stack);
+
+  RootedSavedFrame nstack(cx);
+  if (stack) {
+    nstack = &UncheckedUnwrap(stack)->as<SavedFrame>();
+  }
+  cx->setPendingException(value, nstack);
+}
+
 JS_PUBLIC_API JSObject* JS::GetPendingExceptionStack(JSContext* cx) {
   AssertHeapIsIdle();
   CHECK_THREAD(cx);
   return cx->getPendingExceptionStack();
 }
 
 JS::AutoSaveExceptionState::AutoSaveExceptionState(JSContext* cx)
     : context(cx),
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -2843,16 +2843,21 @@ class JS_PUBLIC_API AutoSaveExceptionSta
   /*
    * Replace cx's exception state with the stored exception state. Then
    * discard the stored exception state. If this is called, the
    * destructor is a no-op.
    */
   void restore();
 };
 
+// Set both the exception and its associated stack on the context. The stack
+// must be a SavedFrame.
+JS_PUBLIC_API void SetPendingExceptionAndStack(JSContext* cx, HandleValue value,
+                                               HandleObject stack);
+
 /**
  * Get the SavedFrame stack object captured when the pending exception was set
  * on the JSContext. This fuzzily correlates with a `throw` statement in JS,
  * although arbitrary JSAPI consumers or VM code may also set pending exceptions
  * via `JS_SetPendingException`.
  *
  * This is not the same stack as `e.stack` when `e` is an `Error` object. (That
  * would be JS::ExceptionStackOrNull).