michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim: set ts=8 sts=4 et sw=4 tw=99: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* Per JSContext object. */ michael@0: michael@0: #include "xpcprivate.h" michael@0: michael@0: #include "jsapi.h" michael@0: michael@0: /***************************************************************************/ michael@0: michael@0: XPCContext::XPCContext(XPCJSRuntime* aRuntime, michael@0: JSContext* aJSContext) michael@0: : mRuntime(aRuntime), michael@0: mJSContext(aJSContext), michael@0: mLastResult(NS_OK), michael@0: mPendingResult(NS_OK), michael@0: mCallingLangType(LANG_UNKNOWN) michael@0: { michael@0: MOZ_COUNT_CTOR(XPCContext); michael@0: michael@0: PR_INIT_CLIST(&mScopes); michael@0: michael@0: MOZ_ASSERT(!JS_GetSecondContextPrivate(mJSContext), "Must be null"); michael@0: JS_SetSecondContextPrivate(mJSContext, this); michael@0: } michael@0: michael@0: XPCContext::~XPCContext() michael@0: { michael@0: MOZ_COUNT_DTOR(XPCContext); michael@0: MOZ_ASSERT(JS_GetSecondContextPrivate(mJSContext) == this, "Must match this"); michael@0: JS_SetSecondContextPrivate(mJSContext, nullptr); michael@0: michael@0: // Iterate over our scopes and tell them that we have been destroyed michael@0: for (PRCList *scopeptr = PR_NEXT_LINK(&mScopes); michael@0: scopeptr != &mScopes; michael@0: scopeptr = PR_NEXT_LINK(scopeptr)) { michael@0: XPCWrappedNativeScope *scope = michael@0: static_cast(scopeptr); michael@0: scope->ClearContext(); michael@0: } michael@0: } michael@0: michael@0: void michael@0: XPCContext::DebugDump(int16_t depth) michael@0: { michael@0: #ifdef DEBUG michael@0: depth--; michael@0: XPC_LOG_ALWAYS(("XPCContext @ %x", this)); michael@0: XPC_LOG_INDENT(); michael@0: XPC_LOG_ALWAYS(("mRuntime @ %x", mRuntime)); michael@0: XPC_LOG_ALWAYS(("mJSContext @ %x", mJSContext)); michael@0: XPC_LOG_ALWAYS(("mLastResult of %x", mLastResult)); michael@0: XPC_LOG_ALWAYS(("mPendingResult of %x", mPendingResult)); michael@0: XPC_LOG_ALWAYS(("mException @ %x", mException.get())); michael@0: if (depth && mException) { michael@0: // XXX show the exception here... michael@0: } michael@0: michael@0: XPC_LOG_ALWAYS(("mCallingLangType of %s", michael@0: mCallingLangType == LANG_UNKNOWN ? "LANG_UNKNOWN" : michael@0: mCallingLangType == LANG_JS ? "LANG_JS" : michael@0: "LANG_NATIVE")); michael@0: XPC_LOG_OUTDENT(); michael@0: #endif michael@0: }