Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / js / src / vm / Exception.cpp
blobd169e9e4a191ca1c78ef84d5c0e0332fb489b4ca
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "js/Exception.h"
9 #include "js/Context.h" // js::AssertHeapIsIdle
10 #include "vm/JSContext.h"
11 #include "vm/SavedFrame.h"
13 using namespace js;
15 bool JS::StealPendingExceptionStack(JSContext* cx,
16 JS::ExceptionStack* exceptionStack) {
17 if (!GetPendingExceptionStack(cx, exceptionStack)) {
18 return false;
21 // "Steal" exception by clearing it.
22 cx->clearPendingException();
23 return true;
26 bool JS::GetPendingExceptionStack(JSContext* cx,
27 JS::ExceptionStack* exceptionStack) {
28 AssertHeapIsIdle();
29 CHECK_THREAD(cx);
31 MOZ_ASSERT(exceptionStack);
32 MOZ_ASSERT(cx->isExceptionPending());
34 RootedValue exception(cx);
35 if (!cx->getPendingException(&exception)) {
36 return false;
39 RootedObject stack(cx, cx->getPendingExceptionStack());
40 exceptionStack->init(exception, stack);
41 return true;
44 void JS::SetPendingExceptionStack(JSContext* cx,
45 const JS::ExceptionStack& exceptionStack) {
46 AssertHeapIsIdle();
47 CHECK_THREAD(cx);
49 // We don't check the compartments of `exception` and `stack` here,
50 // because we're not doing anything with them other than storing
51 // them, and stored exception values can be in an abitrary
52 // compartment while stored stack values are always the unwrapped
53 // object anyway.
55 Rooted<SavedFrame*> nstack(cx);
56 if (exceptionStack.stack()) {
57 nstack = &UncheckedUnwrap(exceptionStack.stack())->as<SavedFrame>();
59 cx->setPendingException(exceptionStack.exception(), nstack);