michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsWrapperCacheInline_h___ michael@0: #define nsWrapperCacheInline_h___ michael@0: michael@0: #include "nsWrapperCache.h" michael@0: #include "js/GCAPI.h" michael@0: #include "js/TracingAPI.h" michael@0: michael@0: inline JSObject* michael@0: nsWrapperCache::GetWrapper() const michael@0: { michael@0: JSObject* obj = GetWrapperPreserveColor(); michael@0: if (obj) { michael@0: JS::ExposeObjectToActiveJS(obj); michael@0: } michael@0: return obj; michael@0: } michael@0: michael@0: inline bool michael@0: nsWrapperCache::IsBlack() michael@0: { michael@0: JSObject* o = GetWrapperPreserveColor(); michael@0: return o && !JS::GCThingIsMarkedGray(o); michael@0: } michael@0: michael@0: static void michael@0: SearchGray(void* aGCThing, const char* aName, void* aClosure) michael@0: { michael@0: bool* hasGrayObjects = static_cast(aClosure); michael@0: if (!*hasGrayObjects && aGCThing && JS::GCThingIsMarkedGray(aGCThing)) { michael@0: *hasGrayObjects = true; michael@0: } michael@0: } michael@0: michael@0: inline bool michael@0: nsWrapperCache::HasNothingToTrace(nsISupports* aThis) michael@0: { michael@0: nsXPCOMCycleCollectionParticipant* participant = nullptr; michael@0: CallQueryInterface(aThis, &participant); michael@0: bool hasGrayObjects = false; michael@0: participant->Trace(aThis, TraceCallbackFunc(SearchGray), &hasGrayObjects); michael@0: return !hasGrayObjects; michael@0: } michael@0: michael@0: inline bool michael@0: nsWrapperCache::IsBlackAndDoesNotNeedTracing(nsISupports* aThis) michael@0: { michael@0: return IsBlack() && HasNothingToTrace(aThis); michael@0: } michael@0: michael@0: inline void michael@0: nsWrapperCache::TraceWrapperJSObject(JSTracer* aTrc, const char* aName) michael@0: { michael@0: JS_CallHeapObjectTracer(aTrc, &mWrapper, aName); michael@0: } michael@0: michael@0: #endif /* nsWrapperCache_h___ */