js/xpconnect/src/XPCContext.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     7 /* Per JSContext object. */
     9 #include "xpcprivate.h"
    11 #include "jsapi.h"
    13 /***************************************************************************/
    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);
    25     PR_INIT_CLIST(&mScopes);
    27     MOZ_ASSERT(!JS_GetSecondContextPrivate(mJSContext), "Must be null");
    28     JS_SetSecondContextPrivate(mJSContext, this);
    29 }
    31 XPCContext::~XPCContext()
    32 {
    33     MOZ_COUNT_DTOR(XPCContext);
    34     MOZ_ASSERT(JS_GetSecondContextPrivate(mJSContext) == this, "Must match this");
    35     JS_SetSecondContextPrivate(mJSContext, nullptr);
    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 }
    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         }
    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