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"
15 bool JS::StealPendingExceptionStack(JSContext
* cx
,
16 JS::ExceptionStack
* exceptionStack
) {
17 if (!GetPendingExceptionStack(cx
, exceptionStack
)) {
21 // "Steal" exception by clearing it.
22 cx
->clearPendingException();
26 bool JS::GetPendingExceptionStack(JSContext
* cx
,
27 JS::ExceptionStack
* exceptionStack
) {
31 MOZ_ASSERT(exceptionStack
);
32 MOZ_ASSERT(cx
->isExceptionPending());
34 RootedValue
exception(cx
);
35 if (!cx
->getPendingException(&exception
)) {
39 RootedObject
stack(cx
, cx
->getPendingExceptionStack());
40 exceptionStack
->init(exception
, stack
);
44 void JS::SetPendingExceptionStack(JSContext
* cx
,
45 const JS::ExceptionStack
& exceptionStack
) {
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
55 Rooted
<SavedFrame
*> nstack(cx
);
56 if (exceptionStack
.stack()) {
57 nstack
= &UncheckedUnwrap(exceptionStack
.stack())->as
<SavedFrame
>();
59 cx
->setPendingException(exceptionStack
.exception(), nstack
);