dom/base/nsWrapperCacheInlines.h

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: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef nsWrapperCacheInline_h___
     7 #define nsWrapperCacheInline_h___
     9 #include "nsWrapperCache.h"
    10 #include "js/GCAPI.h"
    11 #include "js/TracingAPI.h"
    13 inline JSObject*
    14 nsWrapperCache::GetWrapper() const
    15 {
    16     JSObject* obj = GetWrapperPreserveColor();
    17     if (obj) {
    18       JS::ExposeObjectToActiveJS(obj);
    19     }
    20     return obj;
    21 }
    23 inline bool
    24 nsWrapperCache::IsBlack()
    25 {
    26   JSObject* o = GetWrapperPreserveColor();
    27   return o && !JS::GCThingIsMarkedGray(o);
    28 }
    30 static void
    31 SearchGray(void* aGCThing, const char* aName, void* aClosure)
    32 {
    33   bool* hasGrayObjects = static_cast<bool*>(aClosure);
    34   if (!*hasGrayObjects && aGCThing && JS::GCThingIsMarkedGray(aGCThing)) {
    35     *hasGrayObjects = true;
    36   }
    37 }
    39 inline bool
    40 nsWrapperCache::HasNothingToTrace(nsISupports* aThis)
    41 {
    42   nsXPCOMCycleCollectionParticipant* participant = nullptr;
    43   CallQueryInterface(aThis, &participant);
    44   bool hasGrayObjects = false;
    45   participant->Trace(aThis, TraceCallbackFunc(SearchGray), &hasGrayObjects);
    46   return !hasGrayObjects;
    47 }
    49 inline bool
    50 nsWrapperCache::IsBlackAndDoesNotNeedTracing(nsISupports* aThis)
    51 {
    52   return IsBlack() && HasNothingToTrace(aThis);
    53 }
    55 inline void
    56 nsWrapperCache::TraceWrapperJSObject(JSTracer* aTrc, const char* aName)
    57 {
    58   JS_CallHeapObjectTracer(aTrc, &mWrapper, aName);
    59 }
    61 #endif /* nsWrapperCache_h___ */

mercurial