Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* vim: set ts=8 sts=4 et sw=4 tw=99: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /* Per JSContext object. */ |
michael@0 | 8 | |
michael@0 | 9 | #include "xpcprivate.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "jsapi.h" |
michael@0 | 12 | |
michael@0 | 13 | /***************************************************************************/ |
michael@0 | 14 | |
michael@0 | 15 | XPCContext::XPCContext(XPCJSRuntime* aRuntime, |
michael@0 | 16 | JSContext* aJSContext) |
michael@0 | 17 | : mRuntime(aRuntime), |
michael@0 | 18 | mJSContext(aJSContext), |
michael@0 | 19 | mLastResult(NS_OK), |
michael@0 | 20 | mPendingResult(NS_OK), |
michael@0 | 21 | mCallingLangType(LANG_UNKNOWN) |
michael@0 | 22 | { |
michael@0 | 23 | MOZ_COUNT_CTOR(XPCContext); |
michael@0 | 24 | |
michael@0 | 25 | PR_INIT_CLIST(&mScopes); |
michael@0 | 26 | |
michael@0 | 27 | MOZ_ASSERT(!JS_GetSecondContextPrivate(mJSContext), "Must be null"); |
michael@0 | 28 | JS_SetSecondContextPrivate(mJSContext, this); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | XPCContext::~XPCContext() |
michael@0 | 32 | { |
michael@0 | 33 | MOZ_COUNT_DTOR(XPCContext); |
michael@0 | 34 | MOZ_ASSERT(JS_GetSecondContextPrivate(mJSContext) == this, "Must match this"); |
michael@0 | 35 | JS_SetSecondContextPrivate(mJSContext, nullptr); |
michael@0 | 36 | |
michael@0 | 37 | // Iterate over our scopes and tell them that we have been destroyed |
michael@0 | 38 | for (PRCList *scopeptr = PR_NEXT_LINK(&mScopes); |
michael@0 | 39 | scopeptr != &mScopes; |
michael@0 | 40 | scopeptr = PR_NEXT_LINK(scopeptr)) { |
michael@0 | 41 | XPCWrappedNativeScope *scope = |
michael@0 | 42 | static_cast<XPCWrappedNativeScope*>(scopeptr); |
michael@0 | 43 | scope->ClearContext(); |
michael@0 | 44 | } |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | void |
michael@0 | 48 | XPCContext::DebugDump(int16_t depth) |
michael@0 | 49 | { |
michael@0 | 50 | #ifdef DEBUG |
michael@0 | 51 | depth--; |
michael@0 | 52 | XPC_LOG_ALWAYS(("XPCContext @ %x", this)); |
michael@0 | 53 | XPC_LOG_INDENT(); |
michael@0 | 54 | XPC_LOG_ALWAYS(("mRuntime @ %x", mRuntime)); |
michael@0 | 55 | XPC_LOG_ALWAYS(("mJSContext @ %x", mJSContext)); |
michael@0 | 56 | XPC_LOG_ALWAYS(("mLastResult of %x", mLastResult)); |
michael@0 | 57 | XPC_LOG_ALWAYS(("mPendingResult of %x", mPendingResult)); |
michael@0 | 58 | XPC_LOG_ALWAYS(("mException @ %x", mException.get())); |
michael@0 | 59 | if (depth && mException) { |
michael@0 | 60 | // XXX show the exception here... |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | XPC_LOG_ALWAYS(("mCallingLangType of %s", |
michael@0 | 64 | mCallingLangType == LANG_UNKNOWN ? "LANG_UNKNOWN" : |
michael@0 | 65 | mCallingLangType == LANG_JS ? "LANG_JS" : |
michael@0 | 66 | "LANG_NATIVE")); |
michael@0 | 67 | XPC_LOG_OUTDENT(); |
michael@0 | 68 | #endif |
michael@0 | 69 | } |