michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "JSDebugger.h" michael@0: #include "nsIXPConnect.h" michael@0: #include "nsThreadUtils.h" michael@0: #include "jsapi.h" michael@0: #include "jsfriendapi.h" michael@0: #include "jswrapper.h" michael@0: #include "js/OldDebugAPI.h" michael@0: #include "mozilla/ModuleUtils.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: #include "nsMemory.h" michael@0: michael@0: #define JSDEBUGGER_CONTRACTID \ michael@0: "@mozilla.org/jsdebugger;1" michael@0: michael@0: #define JSDEBUGGER_CID \ michael@0: { 0x0365cbd5, 0xd46e, 0x4e94, { 0xa3, 0x9f, 0x83, 0xb6, 0x3c, 0xd1, 0xa9, 0x63 } } michael@0: michael@0: namespace mozilla { michael@0: namespace jsdebugger { michael@0: michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(JSDebugger) michael@0: michael@0: NS_IMPL_ISUPPORTS(JSDebugger, IJSDebugger) michael@0: michael@0: JSDebugger::JSDebugger() michael@0: { michael@0: } michael@0: michael@0: JSDebugger::~JSDebugger() michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: JSDebugger::AddClass(JS::Handle global, JSContext* cx) michael@0: { michael@0: nsresult rv; michael@0: nsCOMPtr xpc = do_GetService(nsIXPConnect::GetCID(), &rv); michael@0: michael@0: if (!global.isObject()) { michael@0: return NS_ERROR_INVALID_ARG; michael@0: } michael@0: michael@0: JS::RootedObject obj(cx, &global.toObject()); michael@0: obj = js::UncheckedUnwrap(obj, /* stopAtOuter = */ false); michael@0: if (!obj) { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: JSAutoCompartment ac(cx, obj); michael@0: if (JS_GetGlobalForObject(cx, obj) != obj) { michael@0: return NS_ERROR_INVALID_ARG; michael@0: } michael@0: michael@0: if (!JS_DefineDebuggerObject(cx, obj)) { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: } michael@0: } michael@0: michael@0: NS_DEFINE_NAMED_CID(JSDEBUGGER_CID); michael@0: michael@0: static const mozilla::Module::CIDEntry kJSDebuggerCIDs[] = { michael@0: { &kJSDEBUGGER_CID, false, nullptr, mozilla::jsdebugger::JSDebuggerConstructor }, michael@0: { nullptr } michael@0: }; michael@0: michael@0: static const mozilla::Module::ContractIDEntry kJSDebuggerContracts[] = { michael@0: { JSDEBUGGER_CONTRACTID, &kJSDEBUGGER_CID }, michael@0: { nullptr } michael@0: }; michael@0: michael@0: static const mozilla::Module kJSDebuggerModule = { michael@0: mozilla::Module::kVersion, michael@0: kJSDebuggerCIDs, michael@0: kJSDebuggerContracts michael@0: }; michael@0: michael@0: NSMODULE_DEFN(jsdebugger) = &kJSDebuggerModule;