Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/base/HoldDropJSObjects.cpp
Line
Count
Source (jump to first uncovered line)
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
15
void
16
HoldJSObjectsImpl(void* aHolder, nsScriptObjectTracer* aTracer)
17
3
{
18
3
  CycleCollectedJSRuntime* rt = CycleCollectedJSRuntime::Get();
19
3
  MOZ_ASSERT(rt, "Should have a CycleCollectedJSRuntime by now");
20
3
  rt->AddJSHolder(aHolder, aTracer);
21
3
}
22
23
void
24
HoldJSObjectsImpl(nsISupports* aHolder)
25
0
{
26
0
  nsXPCOMCycleCollectionParticipant* participant = nullptr;
27
0
  CallQueryInterface(aHolder, &participant);
28
0
  MOZ_ASSERT(participant, "Failed to QI to nsXPCOMCycleCollectionParticipant!");
29
0
  MOZ_ASSERT(participant->CheckForRightISupports(aHolder),
30
0
             "The result of QIing a JS holder should be the same as ToSupports");
31
0
32
0
  HoldJSObjectsImpl(aHolder, participant);
33
0
}
34
35
void
36
DropJSObjectsImpl(void* aHolder)
37
0
{
38
0
  CycleCollectedJSRuntime* rt = CycleCollectedJSRuntime::Get();
39
0
  MOZ_ASSERT(rt, "Should have a CycleCollectedJSRuntime by now");
40
0
  rt->RemoveJSHolder(aHolder);
41
0
}
42
43
void
44
DropJSObjectsImpl(nsISupports* aHolder)
45
0
{
46
#ifdef DEBUG
47
  nsXPCOMCycleCollectionParticipant* participant = nullptr;
48
  CallQueryInterface(aHolder, &participant);
49
  MOZ_ASSERT(participant, "Failed to QI to nsXPCOMCycleCollectionParticipant!");
50
  MOZ_ASSERT(participant->CheckForRightISupports(aHolder),
51
             "The result of QIing a JS holder should be the same as ToSupports");
52
#endif
53
  DropJSObjectsImpl(static_cast<void*>(aHolder));
54
0
}
55
56
} // namespace cyclecollector
57
58
#ifdef DEBUG
59
bool
60
IsJSHolder(void* aHolder)
61
{
62
  CycleCollectedJSRuntime* rt = CycleCollectedJSRuntime::Get();
63
  MOZ_ASSERT(rt, "Should have a CycleCollectedJSRuntime by now");
64
  return rt->IsJSHolder(aHolder);
65
}
66
#endif
67
68
} // namespace mozilla