/src/mozilla-central/xpcom/base/DebuggerOnGCRunnable.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/DebuggerOnGCRunnable.h" |
8 | | |
9 | | #include "mozilla/dom/ScriptSettings.h" |
10 | | #include "mozilla/CycleCollectedJSContext.h" |
11 | | #include "mozilla/Move.h" |
12 | | #include "mozilla/SystemGroup.h" |
13 | | #include "js/Debug.h" |
14 | | |
15 | | namespace mozilla { |
16 | | |
17 | | /* static */ nsresult |
18 | | DebuggerOnGCRunnable::Enqueue(JSContext* aCx, const JS::GCDescription& aDesc) |
19 | 0 | { |
20 | 0 | auto gcEvent = aDesc.toGCEvent(aCx); |
21 | 0 | if (!gcEvent) { |
22 | 0 | return NS_ERROR_OUT_OF_MEMORY; |
23 | 0 | } |
24 | 0 | |
25 | 0 | RefPtr<DebuggerOnGCRunnable> runOnGC = |
26 | 0 | new DebuggerOnGCRunnable(std::move(gcEvent)); |
27 | 0 | if (NS_IsMainThread()) { |
28 | 0 | return SystemGroup::Dispatch(TaskCategory::GarbageCollection, runOnGC.forget()); |
29 | 0 | } else { |
30 | 0 | return NS_DispatchToCurrentThread(runOnGC); |
31 | 0 | } |
32 | 0 | } |
33 | | |
34 | | NS_IMETHODIMP |
35 | | DebuggerOnGCRunnable::Run() |
36 | 0 | { |
37 | 0 | AutoJSAPI jsapi; |
38 | 0 | jsapi.Init(); |
39 | 0 | if (!JS::dbg::FireOnGarbageCollectionHook(jsapi.cx(), std::move(mGCData))) { |
40 | 0 | return NS_ERROR_OUT_OF_MEMORY; |
41 | 0 | } |
42 | 0 | return NS_OK; |
43 | 0 | } |
44 | | |
45 | | nsresult |
46 | | DebuggerOnGCRunnable::Cancel() |
47 | 0 | { |
48 | 0 | mGCData = nullptr; |
49 | 0 | return NS_OK; |
50 | 0 | } |
51 | | |
52 | | } // namespace mozilla |