2011-08-31 15:39:39 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-08-31 15:39:39 +00:00
|
|
|
|
|
|
|
#include "JSDebugger.h"
|
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "jsfriendapi.h"
|
2013-05-01 16:19:18 +00:00
|
|
|
#include "jswrapper.h"
|
2013-08-27 02:05:20 +00:00
|
|
|
#include "js/OldDebugAPI.h"
|
2011-08-31 15:39:39 +00:00
|
|
|
#include "mozilla/ModuleUtils.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsMemory.h"
|
|
|
|
|
|
|
|
#define JSDEBUGGER_CONTRACTID \
|
|
|
|
"@mozilla.org/jsdebugger;1"
|
|
|
|
|
|
|
|
#define JSDEBUGGER_CID \
|
|
|
|
{ 0x0365cbd5, 0xd46e, 0x4e94, { 0xa3, 0x9f, 0x83, 0xb6, 0x3c, 0xd1, 0xa9, 0x63 } }
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace jsdebugger {
|
|
|
|
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(JSDebugger)
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(JSDebugger, IJSDebugger)
|
2011-08-31 15:39:39 +00:00
|
|
|
|
|
|
|
JSDebugger::JSDebugger()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
JSDebugger::~JSDebugger()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-09 17:39:36 +00:00
|
|
|
JSDebugger::AddClass(JS::Handle<JS::Value> global, JSContext* cx)
|
2011-08-31 15:39:39 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID(), &rv);
|
|
|
|
|
2012-05-01 15:17:32 +00:00
|
|
|
if (!global.isObject()) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2013-05-02 09:22:55 +00:00
|
|
|
|
|
|
|
JS::RootedObject obj(cx, &global.toObject());
|
2013-05-01 16:19:18 +00:00
|
|
|
obj = js::UncheckedUnwrap(obj, /* stopAtOuter = */ false);
|
2012-05-01 15:17:32 +00:00
|
|
|
if (!obj) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-08-22 01:42:53 +00:00
|
|
|
JSAutoCompartment ac(cx, obj);
|
2012-05-01 15:17:32 +00:00
|
|
|
if (JS_GetGlobalForObject(cx, obj) != obj) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2011-08-31 15:39:39 +00:00
|
|
|
}
|
|
|
|
|
2012-05-01 15:17:32 +00:00
|
|
|
if (!JS_DefineDebuggerObject(cx, obj)) {
|
2011-08-31 15:39:39 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DEFINE_NAMED_CID(JSDEBUGGER_CID);
|
|
|
|
|
|
|
|
static const mozilla::Module::CIDEntry kJSDebuggerCIDs[] = {
|
2013-09-19 19:24:53 +00:00
|
|
|
{ &kJSDEBUGGER_CID, false, nullptr, mozilla::jsdebugger::JSDebuggerConstructor },
|
|
|
|
{ nullptr }
|
2011-08-31 15:39:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const mozilla::Module::ContractIDEntry kJSDebuggerContracts[] = {
|
|
|
|
{ JSDEBUGGER_CONTRACTID, &kJSDEBUGGER_CID },
|
2013-09-19 19:24:53 +00:00
|
|
|
{ nullptr }
|
2011-08-31 15:39:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const mozilla::Module kJSDebuggerModule = {
|
|
|
|
mozilla::Module::kVersion,
|
|
|
|
kJSDebuggerCIDs,
|
|
|
|
kJSDebuggerContracts
|
|
|
|
};
|
|
|
|
|
|
|
|
NSMODULE_DEFN(jsdebugger) = &kJSDebuggerModule;
|