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/. */
7 #include "mozilla/HoldDropJSObjects.h"
9 #include "mozilla/Assertions.h"
10 #include "mozilla/CycleCollectedJSRuntime.h"
13 namespace cyclecollector
{
15 void HoldJSObjectsImpl(void* aHolder
, nsScriptObjectTracer
* aTracer
,
17 CycleCollectedJSRuntime
* rt
= CycleCollectedJSRuntime::Get();
18 MOZ_ASSERT(rt
, "Should have a CycleCollectedJSRuntime by now");
19 rt
->AddJSHolder(aHolder
, aTracer
, aZone
);
22 void HoldJSObjectsImpl(nsISupports
* aHolder
) {
23 nsXPCOMCycleCollectionParticipant
* participant
= nullptr;
24 CallQueryInterface(aHolder
, &participant
);
25 MOZ_ASSERT(participant
, "Failed to QI to nsXPCOMCycleCollectionParticipant!");
27 participant
->CheckForRightISupports(aHolder
),
28 "The result of QIing a JS holder should be the same as ToSupports");
30 HoldJSObjectsImpl(aHolder
, participant
);
33 void DropJSObjectsImpl(void* aHolder
) {
34 CycleCollectedJSRuntime
* rt
= CycleCollectedJSRuntime::Get();
35 MOZ_ASSERT(rt
, "Should have a CycleCollectedJSRuntime by now");
36 rt
->RemoveJSHolder(aHolder
);
39 void DropJSObjectsImpl(nsISupports
* aHolder
) {
41 nsXPCOMCycleCollectionParticipant
* participant
= nullptr;
42 CallQueryInterface(aHolder
, &participant
);
43 MOZ_ASSERT(participant
, "Failed to QI to nsXPCOMCycleCollectionParticipant!");
45 participant
->CheckForRightISupports(aHolder
),
46 "The result of QIing a JS holder should be the same as ToSupports");
48 DropJSObjectsImpl(static_cast<void*>(aHolder
));
51 } // namespace cyclecollector
53 } // namespace mozilla