Bug 1825336 - Make toolkit/components/url-classifier/ buildable outside of a unified...
[gecko.git] / xpcom / base / DebuggerOnGCRunnable.cpp
blobbcb13b3226204bfaf67c1dafb9861c5070b01bdc
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/DebuggerOnGCRunnable.h"
9 #include <utility>
11 #include "js/Debug.h"
12 #include "mozilla/CycleCollectedJSContext.h"
13 #include "mozilla/dom/ScriptSettings.h"
14 #include "mozilla/SchedulerGroup.h"
16 namespace mozilla {
18 /* static */
19 nsresult DebuggerOnGCRunnable::Enqueue(JSContext* aCx,
20 const JS::GCDescription& aDesc) {
21 auto gcEvent = aDesc.toGCEvent(aCx);
22 if (!gcEvent) {
23 return NS_ERROR_OUT_OF_MEMORY;
26 RefPtr<DebuggerOnGCRunnable> runOnGC =
27 new DebuggerOnGCRunnable(std::move(gcEvent));
28 if (NS_IsMainThread()) {
29 return SchedulerGroup::Dispatch(TaskCategory::GarbageCollection,
30 runOnGC.forget());
31 } else {
32 return NS_DispatchToCurrentThread(runOnGC);
36 NS_IMETHODIMP
37 DebuggerOnGCRunnable::Run() {
38 dom::AutoJSAPI jsapi;
39 jsapi.Init();
40 if (!JS::dbg::FireOnGarbageCollectionHook(jsapi.cx(), std::move(mGCData))) {
41 return NS_ERROR_OUT_OF_MEMORY;
43 return NS_OK;
46 nsresult DebuggerOnGCRunnable::Cancel() {
47 mGCData = nullptr;
48 return NS_OK;
51 } // namespace mozilla