1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/src/XPCContext.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,69 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* vim: set ts=8 sts=4 et sw=4 tw=99: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +/* Per JSContext object. */ 1.11 + 1.12 +#include "xpcprivate.h" 1.13 + 1.14 +#include "jsapi.h" 1.15 + 1.16 +/***************************************************************************/ 1.17 + 1.18 +XPCContext::XPCContext(XPCJSRuntime* aRuntime, 1.19 + JSContext* aJSContext) 1.20 + : mRuntime(aRuntime), 1.21 + mJSContext(aJSContext), 1.22 + mLastResult(NS_OK), 1.23 + mPendingResult(NS_OK), 1.24 + mCallingLangType(LANG_UNKNOWN) 1.25 +{ 1.26 + MOZ_COUNT_CTOR(XPCContext); 1.27 + 1.28 + PR_INIT_CLIST(&mScopes); 1.29 + 1.30 + MOZ_ASSERT(!JS_GetSecondContextPrivate(mJSContext), "Must be null"); 1.31 + JS_SetSecondContextPrivate(mJSContext, this); 1.32 +} 1.33 + 1.34 +XPCContext::~XPCContext() 1.35 +{ 1.36 + MOZ_COUNT_DTOR(XPCContext); 1.37 + MOZ_ASSERT(JS_GetSecondContextPrivate(mJSContext) == this, "Must match this"); 1.38 + JS_SetSecondContextPrivate(mJSContext, nullptr); 1.39 + 1.40 + // Iterate over our scopes and tell them that we have been destroyed 1.41 + for (PRCList *scopeptr = PR_NEXT_LINK(&mScopes); 1.42 + scopeptr != &mScopes; 1.43 + scopeptr = PR_NEXT_LINK(scopeptr)) { 1.44 + XPCWrappedNativeScope *scope = 1.45 + static_cast<XPCWrappedNativeScope*>(scopeptr); 1.46 + scope->ClearContext(); 1.47 + } 1.48 +} 1.49 + 1.50 +void 1.51 +XPCContext::DebugDump(int16_t depth) 1.52 +{ 1.53 +#ifdef DEBUG 1.54 + depth--; 1.55 + XPC_LOG_ALWAYS(("XPCContext @ %x", this)); 1.56 + XPC_LOG_INDENT(); 1.57 + XPC_LOG_ALWAYS(("mRuntime @ %x", mRuntime)); 1.58 + XPC_LOG_ALWAYS(("mJSContext @ %x", mJSContext)); 1.59 + XPC_LOG_ALWAYS(("mLastResult of %x", mLastResult)); 1.60 + XPC_LOG_ALWAYS(("mPendingResult of %x", mPendingResult)); 1.61 + XPC_LOG_ALWAYS(("mException @ %x", mException.get())); 1.62 + if (depth && mException) { 1.63 + // XXX show the exception here... 1.64 + } 1.65 + 1.66 + XPC_LOG_ALWAYS(("mCallingLangType of %s", 1.67 + mCallingLangType == LANG_UNKNOWN ? "LANG_UNKNOWN" : 1.68 + mCallingLangType == LANG_JS ? "LANG_JS" : 1.69 + "LANG_NATIVE")); 1.70 + XPC_LOG_OUTDENT(); 1.71 +#endif 1.72 +}