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"
11 #include "js/TracingAPI.h"
14 nsWrapperCache::GetWrapper() const
16 JSObject
* obj
= GetWrapperPreserveColor();
18 JS::ExposeObjectToActiveJS(obj
);
24 nsWrapperCache::IsBlack()
26 JSObject
* o
= GetWrapperPreserveColor();
27 return o
&& !JS::GCThingIsMarkedGray(o
);
31 SearchGray(void* aGCThing
, const char* aName
, void* aClosure
)
33 bool* hasGrayObjects
= static_cast<bool*>(aClosure
);
34 if (!*hasGrayObjects
&& aGCThing
&& JS::GCThingIsMarkedGray(aGCThing
)) {
35 *hasGrayObjects
= true;
40 nsWrapperCache::HasNothingToTrace(nsISupports
* aThis
)
42 nsXPCOMCycleCollectionParticipant
* participant
= nullptr;
43 CallQueryInterface(aThis
, &participant
);
44 bool hasGrayObjects
= false;
45 participant
->Trace(aThis
, TraceCallbackFunc(SearchGray
), &hasGrayObjects
);
46 return !hasGrayObjects
;
50 nsWrapperCache::IsBlackAndDoesNotNeedTracing(nsISupports
* aThis
)
52 return IsBlack() && HasNothingToTrace(aThis
);
56 nsWrapperCache::TraceWrapperJSObject(JSTracer
* aTrc
, const char* aName
)
58 JS_CallObjectTracer(aTrc
, &mWrapper
, aName
);
61 #endif /* nsWrapperCache_h___ */