1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : *
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla Communicator client code, released
17 : * March 31, 1998.
18 : *
19 : * The Initial Developer of the Original Code is
20 : * Netscape Communications Corporation.
21 : * Portions created by the Initial Developer are Copyright (C) 1998
22 : * the Initial Developer. All Rights Reserved.
23 : *
24 : * Contributor(s):
25 : * John Bandhauer <jband@netscape.com> (original author)
26 : *
27 : * Alternatively, the contents of this file may be used under the terms of
28 : * either of the GNU General Public License Version 2 or later (the "GPL"),
29 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 : * in which case the provisions of the GPL or the LGPL are applicable instead
31 : * of those above. If you wish to allow use of your version of this file only
32 : * under the terms of either the GPL or the LGPL, and not to allow others to
33 : * use your version of this file under the terms of the MPL, indicate your
34 : * decision by deleting the provisions above and replace them with the notice
35 : * and other provisions required by the GPL or the LGPL. If you do not delete
36 : * the provisions above, a recipient may use your version of this file under
37 : * the terms of any one of the MPL, the GPL or the LGPL.
38 : *
39 : * ***** END LICENSE BLOCK ***** */
40 :
41 : /* Per JSContext object. */
42 :
43 : #include "xpcprivate.h"
44 :
45 : #include "jsapi.h"
46 :
47 : /***************************************************************************/
48 :
49 7715 : XPCContext::XPCContext(XPCJSRuntime* aRuntime,
50 : JSContext* aJSContext)
51 : : mRuntime(aRuntime),
52 : mJSContext(aJSContext),
53 : mLastResult(NS_OK),
54 : mPendingResult(NS_OK),
55 : mSecurityManager(nsnull),
56 : mException(nsnull),
57 : mCallingLangType(LANG_UNKNOWN),
58 7715 : mSecurityManagerFlags(0)
59 : {
60 7715 : MOZ_COUNT_CTOR(XPCContext);
61 :
62 7715 : PR_INIT_CLIST(&mScopes);
63 :
64 7715 : NS_ASSERTION(!JS_GetSecondContextPrivate(mJSContext), "Must be null");
65 7715 : JS_SetSecondContextPrivate(mJSContext, this);
66 7715 : }
67 :
68 7713 : XPCContext::~XPCContext()
69 : {
70 7713 : MOZ_COUNT_DTOR(XPCContext);
71 7713 : NS_ASSERTION(JS_GetSecondContextPrivate(mJSContext) == this, "Must match this");
72 7713 : JS_SetSecondContextPrivate(mJSContext, nsnull);
73 7713 : NS_IF_RELEASE(mException);
74 7713 : NS_IF_RELEASE(mSecurityManager);
75 :
76 : // Iterate over our scopes and tell them that we have been destroyed
77 21548 : for (PRCList *scopeptr = PR_NEXT_LINK(&mScopes);
78 : scopeptr != &mScopes;
79 : scopeptr = PR_NEXT_LINK(scopeptr)) {
80 13835 : XPCWrappedNativeScope *scope = (XPCWrappedNativeScope *)scopeptr;
81 13835 : scope->SetContext(nsnull);
82 : }
83 :
84 : // we do not call JS_RemoveArgumentFormatter because we now only
85 : // delete XPCContext *after* the underlying JSContext is dead
86 7713 : }
87 :
88 : void
89 0 : XPCContext::DebugDump(PRInt16 depth)
90 : {
91 : #ifdef DEBUG
92 0 : depth--;
93 0 : XPC_LOG_ALWAYS(("XPCContext @ %x", this));
94 0 : XPC_LOG_INDENT();
95 0 : XPC_LOG_ALWAYS(("mRuntime @ %x", mRuntime));
96 0 : XPC_LOG_ALWAYS(("mJSContext @ %x", mJSContext));
97 0 : XPC_LOG_ALWAYS(("mLastResult of %x", mLastResult));
98 0 : XPC_LOG_ALWAYS(("mPendingResult of %x", mPendingResult));
99 0 : XPC_LOG_ALWAYS(("mSecurityManager @ %x", mSecurityManager));
100 0 : XPC_LOG_ALWAYS(("mSecurityManagerFlags of %x", mSecurityManagerFlags));
101 :
102 0 : XPC_LOG_ALWAYS(("mException @ %x", mException));
103 0 : if (depth && mException) {
104 : // XXX show the exception here...
105 : }
106 :
107 0 : XPC_LOG_ALWAYS(("mCallingLangType of %s",
108 : mCallingLangType == LANG_UNKNOWN ? "LANG_UNKNOWN" :
109 : mCallingLangType == LANG_JS ? "LANG_JS" :
110 : "LANG_NATIVE"));
111 0 : XPC_LOG_OUTDENT();
112 : #endif
113 0 : }
|