1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #include "mozilla/HoldDropJSObjects.h"
8
9 #include "mozilla/Assertions.h"
10 #include "mozilla/CycleCollectedJSRuntime.h"
11
12 namespace mozilla {
13 namespace cyclecollector {
14
HoldJSObjectsImpl(void * aHolder,nsScriptObjectTracer * aTracer,JS::Zone * aZone)15 void HoldJSObjectsImpl(void* aHolder, nsScriptObjectTracer* aTracer,
16 JS::Zone* aZone) {
17 CycleCollectedJSRuntime* rt = CycleCollectedJSRuntime::Get();
18 MOZ_ASSERT(rt, "Should have a CycleCollectedJSRuntime by now");
19 rt->AddJSHolder(aHolder, aTracer, aZone);
20 }
21
HoldJSObjectsImpl(nsISupports * aHolder)22 void HoldJSObjectsImpl(nsISupports* aHolder) {
23 nsXPCOMCycleCollectionParticipant* participant = nullptr;
24 CallQueryInterface(aHolder, &participant);
25 MOZ_ASSERT(participant, "Failed to QI to nsXPCOMCycleCollectionParticipant!");
26 MOZ_ASSERT(
27 participant->CheckForRightISupports(aHolder),
28 "The result of QIing a JS holder should be the same as ToSupports");
29
30 HoldJSObjectsImpl(aHolder, participant);
31 }
32
DropJSObjectsImpl(void * aHolder)33 void DropJSObjectsImpl(void* aHolder) {
34 CycleCollectedJSRuntime* rt = CycleCollectedJSRuntime::Get();
35 MOZ_ASSERT(rt, "Should have a CycleCollectedJSRuntime by now");
36 rt->RemoveJSHolder(aHolder);
37 }
38
DropJSObjectsImpl(nsISupports * aHolder)39 void DropJSObjectsImpl(nsISupports* aHolder) {
40 #ifdef DEBUG
41 nsXPCOMCycleCollectionParticipant* participant = nullptr;
42 CallQueryInterface(aHolder, &participant);
43 MOZ_ASSERT(participant, "Failed to QI to nsXPCOMCycleCollectionParticipant!");
44 MOZ_ASSERT(
45 participant->CheckForRightISupports(aHolder),
46 "The result of QIing a JS holder should be the same as ToSupports");
47 #endif
48 DropJSObjectsImpl(static_cast<void*>(aHolder));
49 }
50
51 } // namespace cyclecollector
52
53 } // namespace mozilla
54