summaryrefslogtreecommitdiff
path: root/js/src/jsapi.h
diff options
context:
space:
mode:
authorMartok <martok@martoks-place.de>2023-01-21 02:13:01 +0100
committerMartok <martok@martoks-place.de>2023-01-22 00:11:27 +0100
commitb1440d285b75a661e98c3ddf93a737211ed90b59 (patch)
tree889ec566a8b99576fa57c9bb0eba0a19f1e0c269 /js/src/jsapi.h
parentd78912ec17683c1c5a3d30b89c2c03f469f92a1a (diff)
downloaduxp-b1440d285b75a661e98c3ddf93a737211ed90b59.tar.gz
Issue #2089 - Use JS engine stack if necessary when reporting errors
Based-on: m-c 996060
Diffstat (limited to 'js/src/jsapi.h')
-rw-r--r--js/src/jsapi.h36
1 files changed, 29 insertions, 7 deletions
diff --git a/js/src/jsapi.h b/js/src/jsapi.h
index 938fcb2a33..6002d86ad5 100644
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -5762,8 +5762,22 @@ JS_IsExceptionPending(JSContext* cx);
extern JS_PUBLIC_API(bool)
JS_GetPendingException(JSContext* cx, JS::MutableHandleValue vp);
+namespace JS {
+
+enum class ExceptionStackBehavior: bool {
+ // Do not capture any stack.
+ DoNotCapture,
+
+ // Capture the current JS stack when setting the exception. It may be
+ // retrieved by JS::GetPendingExceptionStack.
+ Capture
+};
+
+} // namespace JS
+
extern JS_PUBLIC_API(void)
-JS_SetPendingException(JSContext* cx, JS::HandleValue v);
+JS_SetPendingException(JSContext* cx, JS::HandleValue v,
+ JS::ExceptionStackBehavior behavior = JS::ExceptionStackBehavior::Capture);
extern JS_PUBLIC_API(void)
JS_ClearPendingException(JSContext* cx);
@@ -5790,6 +5804,7 @@ class JS_PUBLIC_API(AutoSaveExceptionState)
bool wasOverRecursed;
bool wasThrowing;
RootedValue exceptionValue;
+ RootedObject exceptionStack;
public:
/*
@@ -5808,12 +5823,7 @@ class JS_PUBLIC_API(AutoSaveExceptionState)
* Discard any stored exception state.
* If this is called, the destructor is a no-op.
*/
- void drop() {
- wasPropagatingForcedReturn = false;
- wasOverRecursed = false;
- wasThrowing = false;
- exceptionValue.setUndefined();
- }
+ void drop();
/*
* Replace cx's exception state with the stored exception state. Then
@@ -5823,6 +5833,18 @@ class JS_PUBLIC_API(AutoSaveExceptionState)
void restore();
};
+/**
+ * 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).
+ */
+MOZ_MUST_USE JS_PUBLIC_API(JSObject*)
+GetPendingExceptionStack(JSContext* cx);
+
} /* namespace JS */
/* Deprecated API. Use AutoSaveExceptionState instead. */