js/xpconnect/src/XPCContext.cpp

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:5367405dac9d
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim: set ts=8 sts=4 et sw=4 tw=99: */
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/. */
6
7 /* Per JSContext object. */
8
9 #include "xpcprivate.h"
10
11 #include "jsapi.h"
12
13 /***************************************************************************/
14
15 XPCContext::XPCContext(XPCJSRuntime* aRuntime,
16 JSContext* aJSContext)
17 : mRuntime(aRuntime),
18 mJSContext(aJSContext),
19 mLastResult(NS_OK),
20 mPendingResult(NS_OK),
21 mCallingLangType(LANG_UNKNOWN)
22 {
23 MOZ_COUNT_CTOR(XPCContext);
24
25 PR_INIT_CLIST(&mScopes);
26
27 MOZ_ASSERT(!JS_GetSecondContextPrivate(mJSContext), "Must be null");
28 JS_SetSecondContextPrivate(mJSContext, this);
29 }
30
31 XPCContext::~XPCContext()
32 {
33 MOZ_COUNT_DTOR(XPCContext);
34 MOZ_ASSERT(JS_GetSecondContextPrivate(mJSContext) == this, "Must match this");
35 JS_SetSecondContextPrivate(mJSContext, nullptr);
36
37 // Iterate over our scopes and tell them that we have been destroyed
38 for (PRCList *scopeptr = PR_NEXT_LINK(&mScopes);
39 scopeptr != &mScopes;
40 scopeptr = PR_NEXT_LINK(scopeptr)) {
41 XPCWrappedNativeScope *scope =
42 static_cast<XPCWrappedNativeScope*>(scopeptr);
43 scope->ClearContext();
44 }
45 }
46
47 void
48 XPCContext::DebugDump(int16_t depth)
49 {
50 #ifdef DEBUG
51 depth--;
52 XPC_LOG_ALWAYS(("XPCContext @ %x", this));
53 XPC_LOG_INDENT();
54 XPC_LOG_ALWAYS(("mRuntime @ %x", mRuntime));
55 XPC_LOG_ALWAYS(("mJSContext @ %x", mJSContext));
56 XPC_LOG_ALWAYS(("mLastResult of %x", mLastResult));
57 XPC_LOG_ALWAYS(("mPendingResult of %x", mPendingResult));
58 XPC_LOG_ALWAYS(("mException @ %x", mException.get()));
59 if (depth && mException) {
60 // XXX show the exception here...
61 }
62
63 XPC_LOG_ALWAYS(("mCallingLangType of %s",
64 mCallingLangType == LANG_UNKNOWN ? "LANG_UNKNOWN" :
65 mCallingLangType == LANG_JS ? "LANG_JS" :
66 "LANG_NATIVE"));
67 XPC_LOG_OUTDENT();
68 #endif
69 }

mercurial