dom/base/nsWrapperCacheInlines.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/base/nsWrapperCacheInlines.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,61 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsWrapperCacheInline_h___
    1.10 +#define nsWrapperCacheInline_h___
    1.11 +
    1.12 +#include "nsWrapperCache.h"
    1.13 +#include "js/GCAPI.h"
    1.14 +#include "js/TracingAPI.h"
    1.15 +
    1.16 +inline JSObject*
    1.17 +nsWrapperCache::GetWrapper() const
    1.18 +{
    1.19 +    JSObject* obj = GetWrapperPreserveColor();
    1.20 +    if (obj) {
    1.21 +      JS::ExposeObjectToActiveJS(obj);
    1.22 +    }
    1.23 +    return obj;
    1.24 +}
    1.25 +
    1.26 +inline bool
    1.27 +nsWrapperCache::IsBlack()
    1.28 +{
    1.29 +  JSObject* o = GetWrapperPreserveColor();
    1.30 +  return o && !JS::GCThingIsMarkedGray(o);
    1.31 +}
    1.32 +
    1.33 +static void
    1.34 +SearchGray(void* aGCThing, const char* aName, void* aClosure)
    1.35 +{
    1.36 +  bool* hasGrayObjects = static_cast<bool*>(aClosure);
    1.37 +  if (!*hasGrayObjects && aGCThing && JS::GCThingIsMarkedGray(aGCThing)) {
    1.38 +    *hasGrayObjects = true;
    1.39 +  }
    1.40 +}
    1.41 +
    1.42 +inline bool
    1.43 +nsWrapperCache::HasNothingToTrace(nsISupports* aThis)
    1.44 +{
    1.45 +  nsXPCOMCycleCollectionParticipant* participant = nullptr;
    1.46 +  CallQueryInterface(aThis, &participant);
    1.47 +  bool hasGrayObjects = false;
    1.48 +  participant->Trace(aThis, TraceCallbackFunc(SearchGray), &hasGrayObjects);
    1.49 +  return !hasGrayObjects;
    1.50 +}
    1.51 +
    1.52 +inline bool
    1.53 +nsWrapperCache::IsBlackAndDoesNotNeedTracing(nsISupports* aThis)
    1.54 +{
    1.55 +  return IsBlack() && HasNothingToTrace(aThis);
    1.56 +}
    1.57 +
    1.58 +inline void
    1.59 +nsWrapperCache::TraceWrapperJSObject(JSTracer* aTrc, const char* aName)
    1.60 +{
    1.61 +  JS_CallHeapObjectTracer(aTrc, &mWrapper, aName);
    1.62 +}
    1.63 +
    1.64 +#endif /* nsWrapperCache_h___ */

mercurial