|
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/. */ |
|
5 |
|
6 #ifndef nsWrapperCacheInline_h___ |
|
7 #define nsWrapperCacheInline_h___ |
|
8 |
|
9 #include "nsWrapperCache.h" |
|
10 #include "js/GCAPI.h" |
|
11 #include "js/TracingAPI.h" |
|
12 |
|
13 inline JSObject* |
|
14 nsWrapperCache::GetWrapper() const |
|
15 { |
|
16 JSObject* obj = GetWrapperPreserveColor(); |
|
17 if (obj) { |
|
18 JS::ExposeObjectToActiveJS(obj); |
|
19 } |
|
20 return obj; |
|
21 } |
|
22 |
|
23 inline bool |
|
24 nsWrapperCache::IsBlack() |
|
25 { |
|
26 JSObject* o = GetWrapperPreserveColor(); |
|
27 return o && !JS::GCThingIsMarkedGray(o); |
|
28 } |
|
29 |
|
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 } |
|
38 |
|
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 } |
|
48 |
|
49 inline bool |
|
50 nsWrapperCache::IsBlackAndDoesNotNeedTracing(nsISupports* aThis) |
|
51 { |
|
52 return IsBlack() && HasNothingToTrace(aThis); |
|
53 } |
|
54 |
|
55 inline void |
|
56 nsWrapperCache::TraceWrapperJSObject(JSTracer* aTrc, const char* aName) |
|
57 { |
|
58 JS_CallHeapObjectTracer(aTrc, &mWrapper, aName); |
|
59 } |
|
60 |
|
61 #endif /* nsWrapperCache_h___ */ |