Bug 1626100 - Replace SetPendingExceptionAndStack with a ExceptionStack version. r=sfink

Differential Revision: https://phabricator.services.mozilla.com/D69667

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tom Schuster 2020-04-09 12:35:59 +00:00
parent b94a359d66
commit 763682c095
7 changed files with 28 additions and 30 deletions

View File

@ -214,8 +214,7 @@ void WorkletNodeEngine::SendProcessorError(AudioNodeTrack* aTrack,
SendErrorToMainThread(aTrack, details); SendErrorToMainThread(aTrack, details);
// Set the exception and stack back to have it in the console with a stack // Set the exception and stack back to have it in the console with a stack
// trace. // trace.
JS::SetPendingExceptionAndStack(aCx, exnStack.exception(), JS::SetPendingExceptionStack(aCx, exnStack);
exnStack.stack());
return; return;
} }
@ -234,8 +233,7 @@ void WorkletNodeEngine::SendProcessorError(AudioNodeTrack* aTrack,
// Set the exception and stack back to have it in the console with a stack // Set the exception and stack back to have it in the console with a stack
// trace. // trace.
JS::SetPendingExceptionAndStack(aCx, exnStack.exception(), JS::SetPendingExceptionStack(aCx, exnStack);
exnStack.stack());
} else { } else {
NS_WARNING("No exception, but processor errored out?"); NS_WARNING("No exception, but processor errored out?");
} }

View File

@ -527,8 +527,7 @@ void AutoJSAPI::ReportException() {
// because it may want to put it in its error events and has no other way // because it may want to put it in its error events and has no other way
// to get hold of it. After we invoke ReportError, clear the exception on // to get hold of it. After we invoke ReportError, clear the exception on
// cx(), just in case ReportError didn't. // cx(), just in case ReportError didn't.
JS::SetPendingExceptionAndStack(cx(), exnStack.exception(), JS::SetPendingExceptionStack(cx(), exnStack);
exnStack.stack());
ccjscx->ReportError(jsReport.report(), jsReport.toStringResult()); ccjscx->ReportError(jsReport.report(), jsReport.toStringResult());
ClearException(); ClearException();
} }

View File

@ -59,6 +59,11 @@ extern JS_PUBLIC_API bool GetPendingExceptionStack(
extern JS_PUBLIC_API bool StealPendingExceptionStack( extern JS_PUBLIC_API bool StealPendingExceptionStack(
JSContext* cx, JS::ExceptionStack* exceptionStack); JSContext* cx, JS::ExceptionStack* exceptionStack);
// Set both the exception value and its associated stack on the context as
// the current pending exception.
extern JS_PUBLIC_API void SetPendingExceptionStack(
JSContext* cx, const JS::ExceptionStack& exceptionStack);
} // namespace JS } // namespace JS
#endif // js_Exception_h #endif // js_Exception_h

View File

@ -4938,24 +4938,6 @@ JS_PUBLIC_API void JS_ClearPendingException(JSContext* cx) {
cx->clearPendingException(); cx->clearPendingException();
} }
JS_PUBLIC_API void JS::SetPendingExceptionAndStack(JSContext* cx,
HandleValue value,
HandleObject stack) {
AssertHeapIsIdle();
CHECK_THREAD(cx);
// We don't check the compartments of `value` and `stack` here,
// because we're not doing anything with them other than storing
// them, and stored exception values can be in an abitrary
// compartment while stored stack values are always the unwrapped
// object anyway.
RootedSavedFrame nstack(cx);
if (stack) {
nstack = &UncheckedUnwrap(stack)->as<SavedFrame>();
}
cx->setPendingException(value, nstack);
}
JS::AutoSaveExceptionState::AutoSaveExceptionState(JSContext* cx) JS::AutoSaveExceptionState::AutoSaveExceptionState(JSContext* cx)
: context(cx), : context(cx),
wasPropagatingForcedReturn(cx->propagatingForcedReturn_), wasPropagatingForcedReturn(cx->propagatingForcedReturn_),

View File

@ -2647,10 +2647,6 @@ class JS_PUBLIC_API AutoSaveExceptionState {
void restore(); 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);
} /* namespace JS */ } /* namespace JS */
/** /**

View File

@ -8,6 +8,7 @@
#include "jsapi.h" // AssertHeapIsIdle #include "jsapi.h" // AssertHeapIsIdle
#include "vm/JSContext.h" #include "vm/JSContext.h"
#include "vm/SavedFrame.h"
using namespace js; using namespace js;
@ -39,3 +40,21 @@ bool JS::GetPendingExceptionStack(JSContext* cx,
exceptionStack->init(exception, stack); exceptionStack->init(exception, stack);
return true; return true;
} }
void JS::SetPendingExceptionStack(JSContext* cx,
const JS::ExceptionStack& exceptionStack) {
AssertHeapIsIdle();
CHECK_THREAD(cx);
// We don't check the compartments of `exception` and `stack` here,
// because we're not doing anything with them other than storing
// them, and stored exception values can be in an abitrary
// compartment while stored stack values are always the unwrapped
// object anyway.
RootedSavedFrame nstack(cx);
if (exceptionStack.stack()) {
nstack = &UncheckedUnwrap(exceptionStack.stack())->as<SavedFrame>();
}
cx->setPendingException(exceptionStack.exception(), nstack);
}

View File

@ -305,8 +305,7 @@ static void MaybeSanitizeException(JSContext* cx,
{ // Scope for AutoJSAPI { // Scope for AutoJSAPI
AutoJSAPI jsapi; AutoJSAPI jsapi;
if (jsapi.Init(unwrappedFun)) { if (jsapi.Init(unwrappedFun)) {
JS::SetPendingExceptionAndStack(cx, exnStack.exception(), JS::SetPendingExceptionStack(cx, exnStack);
exnStack.stack());
} }
// If Init() fails, we can't report the exception, but oh, well. // If Init() fails, we can't report the exception, but oh, well.