/src/mozilla-central/xpcom/base/DeferredFinalize.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/DeferredFinalize.h" |
8 | | |
9 | | #include "mozilla/Assertions.h" |
10 | | #include "mozilla/CycleCollectedJSRuntime.h" |
11 | | |
12 | | void |
13 | | mozilla::DeferredFinalize(nsISupports* aSupports) |
14 | 7.50M | { |
15 | 7.50M | CycleCollectedJSRuntime* rt = CycleCollectedJSRuntime::Get(); |
16 | 7.50M | MOZ_ASSERT(rt, "Should have a CycleCollectedJSRuntime by now"); |
17 | 7.50M | if (mozilla::recordreplay::IsRecordingOrReplaying()) { |
18 | 0 | // RecordReplayRegisterDeferredFinalizeThing should have been called when |
19 | 0 | // the reference on this object was added earlier. Cause the reference to |
20 | 0 | // be released soon, at a consistent point in the recording and replay. |
21 | 0 | mozilla::recordreplay::ActivateTrigger(aSupports); |
22 | 7.50M | } else { |
23 | 7.50M | rt->DeferredFinalize(aSupports); |
24 | 7.50M | } |
25 | 7.50M | } |
26 | | |
27 | | void |
28 | | mozilla::DeferredFinalize(DeferredFinalizeAppendFunction aAppendFunc, |
29 | | DeferredFinalizeFunction aFunc, |
30 | | void* aThing) |
31 | 0 | { |
32 | 0 | CycleCollectedJSRuntime* rt = CycleCollectedJSRuntime::Get(); |
33 | 0 | MOZ_ASSERT(rt, "Should have a CycleCollectedJSRuntime by now"); |
34 | 0 | if (mozilla::recordreplay::IsRecordingOrReplaying()) { |
35 | 0 | // As above, cause the finalization action to occur soon, at a consistent |
36 | 0 | // point in the recording and replay. |
37 | 0 | mozilla::recordreplay::ActivateTrigger(aThing); |
38 | 0 | } else { |
39 | 0 | rt->DeferredFinalize(aAppendFunc, aFunc, aThing); |
40 | 0 | } |
41 | 0 | } |
42 | | |
43 | | static void |
44 | | RecordReplayDeferredFinalize(DeferredFinalizeAppendFunction aAppendFunc, |
45 | | DeferredFinalizeFunction aFunc, |
46 | | void* aThing) |
47 | 0 | { |
48 | 0 | mozilla::recordreplay::UnregisterTrigger(aThing); |
49 | 0 |
|
50 | 0 | CycleCollectedJSRuntime* rt = CycleCollectedJSRuntime::Get(); |
51 | 0 | if (aAppendFunc) { |
52 | 0 | rt->DeferredFinalize(aAppendFunc, aFunc, aThing); |
53 | 0 | } else { |
54 | 0 | rt->DeferredFinalize(reinterpret_cast<nsISupports*>(aThing)); |
55 | 0 | } |
56 | 0 | } |
57 | | |
58 | | void |
59 | | mozilla::RecordReplayRegisterDeferredFinalizeThing(DeferredFinalizeAppendFunction aAppendFunc, |
60 | | DeferredFinalizeFunction aFunc, |
61 | | void* aThing) |
62 | 8.12M | { |
63 | 8.12M | if (mozilla::recordreplay::IsRecordingOrReplaying()) { |
64 | 0 | mozilla::recordreplay::RegisterTrigger(aThing, |
65 | 0 | [=]() { |
66 | 0 | RecordReplayDeferredFinalize(aAppendFunc, |
67 | 0 | aFunc, aThing); |
68 | 0 | }); |
69 | 0 | } |
70 | 8.12M | } |