|
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/. */ |
|
5 |
|
6 #include "JSDebugger.h" |
|
7 #include "nsIXPConnect.h" |
|
8 #include "nsThreadUtils.h" |
|
9 #include "jsapi.h" |
|
10 #include "jsfriendapi.h" |
|
11 #include "jswrapper.h" |
|
12 #include "js/OldDebugAPI.h" |
|
13 #include "mozilla/ModuleUtils.h" |
|
14 #include "nsServiceManagerUtils.h" |
|
15 #include "nsMemory.h" |
|
16 |
|
17 #define JSDEBUGGER_CONTRACTID \ |
|
18 "@mozilla.org/jsdebugger;1" |
|
19 |
|
20 #define JSDEBUGGER_CID \ |
|
21 { 0x0365cbd5, 0xd46e, 0x4e94, { 0xa3, 0x9f, 0x83, 0xb6, 0x3c, 0xd1, 0xa9, 0x63 } } |
|
22 |
|
23 namespace mozilla { |
|
24 namespace jsdebugger { |
|
25 |
|
26 NS_GENERIC_FACTORY_CONSTRUCTOR(JSDebugger) |
|
27 |
|
28 NS_IMPL_ISUPPORTS(JSDebugger, IJSDebugger) |
|
29 |
|
30 JSDebugger::JSDebugger() |
|
31 { |
|
32 } |
|
33 |
|
34 JSDebugger::~JSDebugger() |
|
35 { |
|
36 } |
|
37 |
|
38 NS_IMETHODIMP |
|
39 JSDebugger::AddClass(JS::Handle<JS::Value> global, JSContext* cx) |
|
40 { |
|
41 nsresult rv; |
|
42 nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID(), &rv); |
|
43 |
|
44 if (!global.isObject()) { |
|
45 return NS_ERROR_INVALID_ARG; |
|
46 } |
|
47 |
|
48 JS::RootedObject obj(cx, &global.toObject()); |
|
49 obj = js::UncheckedUnwrap(obj, /* stopAtOuter = */ false); |
|
50 if (!obj) { |
|
51 return NS_ERROR_FAILURE; |
|
52 } |
|
53 |
|
54 JSAutoCompartment ac(cx, obj); |
|
55 if (JS_GetGlobalForObject(cx, obj) != obj) { |
|
56 return NS_ERROR_INVALID_ARG; |
|
57 } |
|
58 |
|
59 if (!JS_DefineDebuggerObject(cx, obj)) { |
|
60 return NS_ERROR_FAILURE; |
|
61 } |
|
62 |
|
63 return NS_OK; |
|
64 } |
|
65 |
|
66 } |
|
67 } |
|
68 |
|
69 NS_DEFINE_NAMED_CID(JSDEBUGGER_CID); |
|
70 |
|
71 static const mozilla::Module::CIDEntry kJSDebuggerCIDs[] = { |
|
72 { &kJSDEBUGGER_CID, false, nullptr, mozilla::jsdebugger::JSDebuggerConstructor }, |
|
73 { nullptr } |
|
74 }; |
|
75 |
|
76 static const mozilla::Module::ContractIDEntry kJSDebuggerContracts[] = { |
|
77 { JSDEBUGGER_CONTRACTID, &kJSDEBUGGER_CID }, |
|
78 { nullptr } |
|
79 }; |
|
80 |
|
81 static const mozilla::Module kJSDebuggerModule = { |
|
82 mozilla::Module::kVersion, |
|
83 kJSDebuggerCIDs, |
|
84 kJSDebuggerContracts |
|
85 }; |
|
86 |
|
87 NSMODULE_DEFN(jsdebugger) = &kJSDebuggerModule; |