1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "JSDebugger.h"
7 #include "nsIXPConnect.h"
8 #include "nsThreadUtils.h"
10 #include "jsfriendapi.h"
11 #include "jswrapper.h"
12 #include "mozilla/ModuleUtils.h"
13 #include "nsServiceManagerUtils.h"
16 #define JSDEBUGGER_CONTRACTID \
17 "@mozilla.org/jsdebugger;1"
19 #define JSDEBUGGER_CID \
20 { 0x0365cbd5, 0xd46e, 0x4e94, { 0xa3, 0x9f, 0x83, 0xb6, 0x3c, 0xd1, 0xa9, 0x63 } }
23 namespace jsdebugger
{
25 NS_GENERIC_FACTORY_CONSTRUCTOR(JSDebugger
)
27 NS_IMPL_ISUPPORTS(JSDebugger
, IJSDebugger
)
29 JSDebugger::JSDebugger()
33 JSDebugger::~JSDebugger()
38 JSDebugger::AddClass(JS::Handle
<JS::Value
> global
, JSContext
* cx
)
41 nsCOMPtr
<nsIXPConnect
> xpc
= do_GetService(nsIXPConnect::GetCID(), &rv
);
43 if (!global
.isObject()) {
44 return NS_ERROR_INVALID_ARG
;
47 JS::RootedObject
obj(cx
, &global
.toObject());
48 obj
= js::UncheckedUnwrap(obj
, /* stopAtOuter = */ false);
50 return NS_ERROR_FAILURE
;
53 JSAutoCompartment
ac(cx
, obj
);
54 if (JS_GetGlobalForObject(cx
, obj
) != obj
) {
55 return NS_ERROR_INVALID_ARG
;
58 if (!JS_DefineDebuggerObject(cx
, obj
)) {
59 return NS_ERROR_FAILURE
;
68 NS_DEFINE_NAMED_CID(JSDEBUGGER_CID
);
70 static const mozilla::Module::CIDEntry kJSDebuggerCIDs
[] = {
71 { &kJSDEBUGGER_CID
, false, nullptr, mozilla::jsdebugger::JSDebuggerConstructor
},
75 static const mozilla::Module::ContractIDEntry kJSDebuggerContracts
[] = {
76 { JSDEBUGGER_CONTRACTID
, &kJSDEBUGGER_CID
},
80 static const mozilla::Module kJSDebuggerModule
= {
81 mozilla::Module::kVersion
,
86 NSMODULE_DEFN(jsdebugger
) = &kJSDebuggerModule
;