Bug 1839316: part 5) Guard the "fetchpriority" attribute behind a pref. r=kershaw...
[gecko.git] / devtools / platform / JSDebugger.cpp
blob54fde46a54e5d0468a64272d6715f1d0d8f09027
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 */
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 "JSDebugger.h"
8 #include "nsThreadUtils.h"
9 #include "jsapi.h"
10 #include "jsfriendapi.h"
11 #include "js/Wrapper.h"
12 #include "nsServiceManagerUtils.h"
14 #define JSDEBUGGER_CONTRACTID "@mozilla.org/jsdebugger;1"
16 #define JSDEBUGGER_CID \
17 { \
18 0x0365cbd5, 0xd46e, 0x4e94, { \
19 0xa3, 0x9f, 0x83, 0xb6, 0x3c, 0xd1, 0xa9, 0x63 \
20 } \
23 namespace mozilla::jsdebugger {
25 NS_IMPL_ISUPPORTS(JSDebugger, IJSDebugger)
27 JSDebugger::JSDebugger() = default;
29 JSDebugger::~JSDebugger() = default;
31 NS_IMETHODIMP
32 JSDebugger::AddClass(JS::Handle<JS::Value> global, JSContext* cx) {
33 if (!global.isObject()) {
34 return NS_ERROR_INVALID_ARG;
37 JS::Rooted<JSObject*> obj(cx, &global.toObject());
38 obj = js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false);
39 if (!obj) {
40 return NS_ERROR_FAILURE;
43 if (!JS_IsGlobalObject(obj)) {
44 return NS_ERROR_INVALID_ARG;
47 JSAutoRealm ar(cx, obj);
48 if (!JS_DefineDebuggerObject(cx, obj)) {
49 return NS_ERROR_FAILURE;
52 return NS_OK;
55 } // namespace mozilla::jsdebugger