1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/ductwork/debugger/JSDebugger.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,87 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "JSDebugger.h" 1.10 +#include "nsIXPConnect.h" 1.11 +#include "nsThreadUtils.h" 1.12 +#include "jsapi.h" 1.13 +#include "jsfriendapi.h" 1.14 +#include "jswrapper.h" 1.15 +#include "js/OldDebugAPI.h" 1.16 +#include "mozilla/ModuleUtils.h" 1.17 +#include "nsServiceManagerUtils.h" 1.18 +#include "nsMemory.h" 1.19 + 1.20 +#define JSDEBUGGER_CONTRACTID \ 1.21 + "@mozilla.org/jsdebugger;1" 1.22 + 1.23 +#define JSDEBUGGER_CID \ 1.24 +{ 0x0365cbd5, 0xd46e, 0x4e94, { 0xa3, 0x9f, 0x83, 0xb6, 0x3c, 0xd1, 0xa9, 0x63 } } 1.25 + 1.26 +namespace mozilla { 1.27 +namespace jsdebugger { 1.28 + 1.29 +NS_GENERIC_FACTORY_CONSTRUCTOR(JSDebugger) 1.30 + 1.31 +NS_IMPL_ISUPPORTS(JSDebugger, IJSDebugger) 1.32 + 1.33 +JSDebugger::JSDebugger() 1.34 +{ 1.35 +} 1.36 + 1.37 +JSDebugger::~JSDebugger() 1.38 +{ 1.39 +} 1.40 + 1.41 +NS_IMETHODIMP 1.42 +JSDebugger::AddClass(JS::Handle<JS::Value> global, JSContext* cx) 1.43 +{ 1.44 + nsresult rv; 1.45 + nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID(), &rv); 1.46 + 1.47 + if (!global.isObject()) { 1.48 + return NS_ERROR_INVALID_ARG; 1.49 + } 1.50 + 1.51 + JS::RootedObject obj(cx, &global.toObject()); 1.52 + obj = js::UncheckedUnwrap(obj, /* stopAtOuter = */ false); 1.53 + if (!obj) { 1.54 + return NS_ERROR_FAILURE; 1.55 + } 1.56 + 1.57 + JSAutoCompartment ac(cx, obj); 1.58 + if (JS_GetGlobalForObject(cx, obj) != obj) { 1.59 + return NS_ERROR_INVALID_ARG; 1.60 + } 1.61 + 1.62 + if (!JS_DefineDebuggerObject(cx, obj)) { 1.63 + return NS_ERROR_FAILURE; 1.64 + } 1.65 + 1.66 + return NS_OK; 1.67 +} 1.68 + 1.69 +} 1.70 +} 1.71 + 1.72 +NS_DEFINE_NAMED_CID(JSDEBUGGER_CID); 1.73 + 1.74 +static const mozilla::Module::CIDEntry kJSDebuggerCIDs[] = { 1.75 + { &kJSDEBUGGER_CID, false, nullptr, mozilla::jsdebugger::JSDebuggerConstructor }, 1.76 + { nullptr } 1.77 +}; 1.78 + 1.79 +static const mozilla::Module::ContractIDEntry kJSDebuggerContracts[] = { 1.80 + { JSDEBUGGER_CONTRACTID, &kJSDEBUGGER_CID }, 1.81 + { nullptr } 1.82 +}; 1.83 + 1.84 +static const mozilla::Module kJSDebuggerModule = { 1.85 + mozilla::Module::kVersion, 1.86 + kJSDebuggerCIDs, 1.87 + kJSDebuggerContracts 1.88 +}; 1.89 + 1.90 +NSMODULE_DEFN(jsdebugger) = &kJSDebuggerModule;