mirror of https://github.com/axmolengine/axmol.git
Merge pull request #3912 from dumganhar/iss2823-jsb-remote-debugger-sp23
issue #2823: [JSB] Support remote debugging JSB project by FireFox.
This commit is contained in:
commit
643e8fa23e
|
@ -1 +1 @@
|
||||||
3959af89b6bbc8fb982769d22d2591991107d6e5
|
8ad5afb135018cfa93b3aee4dddbea24f0ef9b9e
|
|
@ -95,7 +95,7 @@ fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# copy bindings/*.js into assets' root
|
# copy bindings/*.js into assets' root
|
||||||
cp -f "$BINDINGS_JS_ROOT"/*.js "$APP_ANDROID_ROOT"/assets
|
cp -rf "$BINDINGS_JS_ROOT"/* "$APP_ANDROID_ROOT"/assets
|
||||||
|
|
||||||
# copy icons (if they exist)
|
# copy icons (if they exist)
|
||||||
file="$APP_ANDROID_ROOT"/assets/Icon-72.png
|
file="$APP_ANDROID_ROOT"/assets/Icon-72.png
|
||||||
|
|
|
@ -129,6 +129,10 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
|
|
||||||
sc->start();
|
sc->start();
|
||||||
|
|
||||||
|
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
|
||||||
|
sc->enableDebugger();
|
||||||
|
#endif
|
||||||
|
|
||||||
js_log("RUNNING Main");
|
js_log("RUNNING Main");
|
||||||
auto pEngine = ScriptingCore::getInstance();
|
auto pEngine = ScriptingCore::getInstance();
|
||||||
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
||||||
|
|
|
@ -102,7 +102,7 @@ mkdir "$APP_ANDROID_ROOT"/assets
|
||||||
cp -rf "$RESROUCE_ROOT"/* "$APP_ANDROID_ROOT"/assets
|
cp -rf "$RESROUCE_ROOT"/* "$APP_ANDROID_ROOT"/assets
|
||||||
|
|
||||||
# copy bindings/*.js into assets' root
|
# copy bindings/*.js into assets' root
|
||||||
cp -f "$BINDINGS_JS_ROOT"/*.js "$APP_ANDROID_ROOT"/assets
|
cp -rf "$BINDINGS_JS_ROOT"/* "$APP_ANDROID_ROOT"/assets
|
||||||
|
|
||||||
echo "Using prebuilt externals"
|
echo "Using prebuilt externals"
|
||||||
echo
|
echo
|
||||||
|
|
|
@ -111,6 +111,10 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
|
|
||||||
sc->start();
|
sc->start();
|
||||||
|
|
||||||
|
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
|
||||||
|
sc->enableDebugger();
|
||||||
|
#endif
|
||||||
|
|
||||||
js_log("RUNNING Main");
|
js_log("RUNNING Main");
|
||||||
auto pEngine = ScriptingCore::getInstance();
|
auto pEngine = ScriptingCore::getInstance();
|
||||||
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
||||||
|
|
|
@ -102,7 +102,7 @@ mkdir "$APP_ANDROID_ROOT"/assets
|
||||||
cp -rf "$RESROUCE_ROOT"/* "$APP_ANDROID_ROOT"/assets
|
cp -rf "$RESROUCE_ROOT"/* "$APP_ANDROID_ROOT"/assets
|
||||||
|
|
||||||
# copy bindings/*.js into assets' root
|
# copy bindings/*.js into assets' root
|
||||||
cp -f "$BINDINGS_JS_ROOT"/*.js "$APP_ANDROID_ROOT"/assets
|
cp -rf "$BINDINGS_JS_ROOT"/* "$APP_ANDROID_ROOT"/assets
|
||||||
|
|
||||||
|
|
||||||
echo "Using prebuilt externals"
|
echo "Using prebuilt externals"
|
||||||
|
|
|
@ -40,6 +40,8 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
// set FPS. the default value is 1.0/60 if you don't call this
|
// set FPS. the default value is 1.0/60 if you don't call this
|
||||||
pDirector->setAnimationInterval(1.0 / 60);
|
pDirector->setAnimationInterval(1.0 / 60);
|
||||||
|
|
||||||
|
FileUtils::getInstance()->addSearchPath("js");
|
||||||
|
|
||||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||||
sc->addRegisterCallback(register_all_cocos2dx);
|
sc->addRegisterCallback(register_all_cocos2dx);
|
||||||
sc->addRegisterCallback(register_all_cocos2dx_extension);
|
sc->addRegisterCallback(register_all_cocos2dx_extension);
|
||||||
|
@ -52,13 +54,14 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
|
|
||||||
sc->start();
|
sc->start();
|
||||||
|
|
||||||
|
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
|
||||||
|
sc->enableDebugger();
|
||||||
|
#endif
|
||||||
|
|
||||||
auto pEngine = ScriptingCore::getInstance();
|
auto pEngine = ScriptingCore::getInstance();
|
||||||
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
||||||
#if JSB_ENABLE_DEBUGGER
|
|
||||||
ScriptingCore::getInstance()->runScript("main.debug.js");
|
|
||||||
#else
|
|
||||||
ScriptingCore::getInstance()->runScript("MoonWarriors-jsb.js");
|
ScriptingCore::getInstance()->runScript("MoonWarriors-jsb.js");
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ cp -rf "$RESROUCE_ROOT"/../src "$APP_ANDROID_ROOT"/assets
|
||||||
cp "$RESROUCE_ROOT"/../*.js "$APP_ANDROID_ROOT"/assets
|
cp "$RESROUCE_ROOT"/../*.js "$APP_ANDROID_ROOT"/assets
|
||||||
|
|
||||||
# copy bindings/*.js into assets' root
|
# copy bindings/*.js into assets' root
|
||||||
cp -f "$BINDINGS_JS_ROOT"/*.js "$APP_ANDROID_ROOT"/assets
|
cp -rf "$BINDINGS_JS_ROOT"/* "$APP_ANDROID_ROOT"/assets
|
||||||
|
|
||||||
|
|
||||||
echo "Using prebuilt externals"
|
echo "Using prebuilt externals"
|
||||||
|
|
|
@ -41,6 +41,9 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
// set FPS. the default value is 1.0/60 if you don't call this
|
// set FPS. the default value is 1.0/60 if you don't call this
|
||||||
pDirector->setAnimationInterval(1.0 / 60);
|
pDirector->setAnimationInterval(1.0 / 60);
|
||||||
|
|
||||||
|
FileUtils::getInstance()->addSearchPath("res");
|
||||||
|
FileUtils::getInstance()->addSearchPath("js");
|
||||||
|
|
||||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||||
sc->addRegisterCallback(register_all_cocos2dx);
|
sc->addRegisterCallback(register_all_cocos2dx);
|
||||||
sc->addRegisterCallback(register_all_cocos2dx_extension);
|
sc->addRegisterCallback(register_all_cocos2dx_extension);
|
||||||
|
@ -55,7 +58,9 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
|
|
||||||
sc->start();
|
sc->start();
|
||||||
|
|
||||||
FileUtils::getInstance()->addSearchPath("res");
|
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
|
||||||
|
sc->enableDebugger();
|
||||||
|
#endif
|
||||||
|
|
||||||
auto pEngine = ScriptingCore::getInstance();
|
auto pEngine = ScriptingCore::getInstance();
|
||||||
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
||||||
|
|
|
@ -102,7 +102,7 @@ cp -rf "$APP_ROOT"/../Shared/tests/* "$APP_ANDROID_ROOT"/assets
|
||||||
|
|
||||||
|
|
||||||
# copy bindings/*.js into assets' root
|
# copy bindings/*.js into assets' root
|
||||||
cp -f "$BINDINGS_JS_ROOT"/* "$APP_ANDROID_ROOT"/assets
|
cp -rf "$BINDINGS_JS_ROOT"/* "$APP_ANDROID_ROOT"/assets
|
||||||
|
|
||||||
echo "Using prebuilt externals"
|
echo "Using prebuilt externals"
|
||||||
echo
|
echo
|
||||||
|
|
|
@ -50,6 +50,10 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
|
|
||||||
sc->start();
|
sc->start();
|
||||||
|
|
||||||
|
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
|
||||||
|
sc->enableDebugger();
|
||||||
|
#endif
|
||||||
|
|
||||||
auto pEngine = ScriptingCore::getInstance();
|
auto pEngine = ScriptingCore::getInstance();
|
||||||
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
||||||
ScriptingCore::getInstance()->runScript("boot-jsb.js");
|
ScriptingCore::getInstance()->runScript("boot-jsb.js");
|
||||||
|
|
|
@ -101,7 +101,7 @@ mkdir "$APP_ANDROID_ROOT"/assets
|
||||||
cp -rf "$RESROUCE_ROOT"/* "$APP_ANDROID_ROOT"/assets
|
cp -rf "$RESROUCE_ROOT"/* "$APP_ANDROID_ROOT"/assets
|
||||||
|
|
||||||
# copy bindings/*.js into assets' root
|
# copy bindings/*.js into assets' root
|
||||||
cp -f "$BINDINGS_JS_ROOT"/*.js "$APP_ANDROID_ROOT"/assets
|
cp -rf "$BINDINGS_JS_ROOT"/* "$APP_ANDROID_ROOT"/assets
|
||||||
|
|
||||||
echo "Using prebuilt externals"
|
echo "Using prebuilt externals"
|
||||||
echo
|
echo
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
381c282bed409f4b41a82505460d4d6c84ba70ab
|
036581b6dd46245d778816a7258c42ea68c06959
|
|
@ -59,9 +59,8 @@ static string outData;
|
||||||
static vector<string> g_queue;
|
static vector<string> g_queue;
|
||||||
static std::mutex g_qMutex;
|
static std::mutex g_qMutex;
|
||||||
static std::mutex g_rwMutex;
|
static std::mutex g_rwMutex;
|
||||||
static bool vmLock = false;
|
|
||||||
static jsval frame = JSVAL_NULL, script = JSVAL_NULL;
|
|
||||||
static int clientSocket = -1;
|
static int clientSocket = -1;
|
||||||
|
static unsigned long s_nestedLoopLevel = 0;
|
||||||
|
|
||||||
// server entry point for the bg thread
|
// server entry point for the bg thread
|
||||||
static void serverEntryPoint(void);
|
static void serverEntryPoint(void);
|
||||||
|
@ -193,14 +192,18 @@ void ScriptingCore::executeJSFunctionWithThisObj(jsval thisObj,
|
||||||
}
|
}
|
||||||
|
|
||||||
void js_log(const char *format, ...) {
|
void js_log(const char *format, ...) {
|
||||||
if (_js_log_buf == NULL) {
|
|
||||||
|
if (_js_log_buf == NULL)
|
||||||
|
{
|
||||||
_js_log_buf = (char *)calloc(sizeof(char), kMaxLogLen+1);
|
_js_log_buf = (char *)calloc(sizeof(char), kMaxLogLen+1);
|
||||||
|
_js_log_buf[kMaxLogLen] = '\0';
|
||||||
}
|
}
|
||||||
va_list vl;
|
va_list vl;
|
||||||
va_start(vl, format);
|
va_start(vl, format);
|
||||||
int len = vsnprintf(_js_log_buf, kMaxLogLen, format, vl);
|
int len = vsnprintf(_js_log_buf, kMaxLogLen, format, vl);
|
||||||
va_end(vl);
|
va_end(vl);
|
||||||
if (len) {
|
if (len > 0)
|
||||||
|
{
|
||||||
CCLOG("JS: %s\n", _js_log_buf);
|
CCLOG("JS: %s\n", _js_log_buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -392,7 +395,6 @@ JSBool ScriptingCore::evalString(const char *string, jsval *outVal, const char *
|
||||||
global = global_;
|
global = global_;
|
||||||
JSScript* script = JS_CompileScript(cx, global, string, strlen(string), filename, 1);
|
JSScript* script = JS_CompileScript(cx, global, string, strlen(string), filename, 1);
|
||||||
if (script) {
|
if (script) {
|
||||||
// JSAutoCompartment ac(cx, global);
|
|
||||||
JSAutoCompartment ac(cx, global);
|
JSAutoCompartment ac(cx, global);
|
||||||
JSBool evaluatedOK = JS_ExecuteScript(cx, global, script, outVal);
|
JSBool evaluatedOK = JS_ExecuteScript(cx, global, script, outVal);
|
||||||
if (JS_FALSE == evaluatedOK) {
|
if (JS_FALSE == evaluatedOK) {
|
||||||
|
@ -406,9 +408,6 @@ JSBool ScriptingCore::evalString(const char *string, jsval *outVal, const char *
|
||||||
void ScriptingCore::start() {
|
void ScriptingCore::start() {
|
||||||
// for now just this
|
// for now just this
|
||||||
this->createGlobalContext();
|
this->createGlobalContext();
|
||||||
#if JSB_ENABLE_DEBUGGER
|
|
||||||
this->enableDebugger();
|
|
||||||
#endif //JSB_ENABLE_DEBUGGER
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptingCore::addRegisterCallback(sc_register_sth callback) {
|
void ScriptingCore::addRegisterCallback(sc_register_sth callback) {
|
||||||
|
@ -476,9 +475,7 @@ void ScriptingCore::createGlobalContext() {
|
||||||
//JS_SetGCZeal(this->cx_, 2, JS_DEFAULT_ZEAL_FREQ);
|
//JS_SetGCZeal(this->cx_, 2, JS_DEFAULT_ZEAL_FREQ);
|
||||||
#endif
|
#endif
|
||||||
this->global_ = NewGlobalObject(cx_);
|
this->global_ = NewGlobalObject(cx_);
|
||||||
#if JSB_ENABLE_DEBUGGER
|
|
||||||
JS_SetDebugMode(cx_, JS_TRUE);
|
|
||||||
#endif
|
|
||||||
for (std::vector<sc_register_sth>::iterator it = registrationList.begin(); it != registrationList.end(); it++) {
|
for (std::vector<sc_register_sth>::iterator it = registrationList.begin(); it != registrationList.end(); it++) {
|
||||||
sc_register_sth callback = *it;
|
sc_register_sth callback = *it;
|
||||||
callback(this->cx_, this->global_);
|
callback(this->cx_, this->global_);
|
||||||
|
@ -500,6 +497,8 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c
|
||||||
if (!path) {
|
if (!path) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cocos2d::FileUtils *futil = cocos2d::FileUtils::getInstance();
|
cocos2d::FileUtils *futil = cocos2d::FileUtils::getInstance();
|
||||||
std::string fullPath = futil->fullPathForFilename(path);
|
std::string fullPath = futil->fullPathForFilename(path);
|
||||||
if (global == NULL) {
|
if (global == NULL) {
|
||||||
|
@ -516,9 +515,10 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c
|
||||||
// a) check jsc file first
|
// a) check jsc file first
|
||||||
std::string byteCodePath = RemoveFileExt(std::string(path)) + BYTE_CODE_FILE_EXT;
|
std::string byteCodePath = RemoveFileExt(std::string(path)) + BYTE_CODE_FILE_EXT;
|
||||||
unsigned long length = 0;
|
unsigned long length = 0;
|
||||||
void *data = futil->getFileData(byteCodePath.c_str(),
|
unsigned char* data = futil->getFileData(byteCodePath.c_str(),
|
||||||
"rb",
|
"rb",
|
||||||
&length);
|
&length);
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
script = JS_DecodeScript(cx, data, length, NULL, NULL);
|
script = JS_DecodeScript(cx, data, length, NULL, NULL);
|
||||||
CC_SAFE_DELETE_ARRAY(data);
|
CC_SAFE_DELETE_ARRAY(data);
|
||||||
|
@ -650,9 +650,10 @@ JSBool ScriptingCore::executeScript(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
if (argc == 2 && argv[1].isString()) {
|
if (argc == 2 && argv[1].isString()) {
|
||||||
JSString* globalName = JSVAL_TO_STRING(argv[1]);
|
JSString* globalName = JSVAL_TO_STRING(argv[1]);
|
||||||
JSStringWrapper name(globalName);
|
JSStringWrapper name(globalName);
|
||||||
js::RootedObject* rootedGlobal = globals[name];
|
// js::RootedObject* rootedGlobal = globals[name];
|
||||||
if (rootedGlobal) {
|
JSObject* debugObj = ScriptingCore::getInstance()->getDebugGlobal();
|
||||||
res = ScriptingCore::getInstance()->runScript(path, rootedGlobal->get());
|
if (debugObj) {
|
||||||
|
res = ScriptingCore::getInstance()->runScript(path, debugObj);
|
||||||
} else {
|
} else {
|
||||||
JS_ReportError(cx, "Invalid global object: %s", (char*)name);
|
JS_ReportError(cx, "Invalid global object: %s", (char*)name);
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
|
@ -930,6 +931,8 @@ JSBool ScriptingCore::executeFunctionWithOwner(jsval owner, const char *name, ui
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
JSAutoCompartment ac(cx, obj);
|
||||||
|
|
||||||
if (JS_HasProperty(cx, obj, name, &hasAction) && hasAction) {
|
if (JS_HasProperty(cx, obj, name, &hasAction) && hasAction) {
|
||||||
if (!JS_GetProperty(cx, obj, name, &temp_retval)) {
|
if (!JS_GetProperty(cx, obj, name, &temp_retval)) {
|
||||||
break;
|
break;
|
||||||
|
@ -938,7 +941,6 @@ JSBool ScriptingCore::executeFunctionWithOwner(jsval owner, const char *name, ui
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSAutoCompartment ac(cx, obj);
|
|
||||||
if (retVal) {
|
if (retVal) {
|
||||||
bRet = JS_CallFunctionName(cx, obj, name, argc, vp, retVal);
|
bRet = JS_CallFunctionName(cx, obj, name, argc, vp, retVal);
|
||||||
}
|
}
|
||||||
|
@ -1100,6 +1102,8 @@ int ScriptingCore::sendEvent(ScriptEvent* evt)
|
||||||
if (NULL == evt)
|
if (NULL == evt)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
JSAutoCompartment ac(cx_, global_);
|
||||||
|
|
||||||
switch (evt->type)
|
switch (evt->type)
|
||||||
{
|
{
|
||||||
case kNodeEvent:
|
case kNodeEvent:
|
||||||
|
@ -1199,7 +1203,7 @@ JSBool jsval_to_long_long(JSContext *cx, jsval vp, long long* r) {
|
||||||
}
|
}
|
||||||
|
|
||||||
JSBool jsval_to_std_string(JSContext *cx, jsval v, std::string* ret) {
|
JSBool jsval_to_std_string(JSContext *cx, jsval v, std::string* ret) {
|
||||||
JSString *tmp = v.isString() ? JS_ValueToString(cx, v) : NULL;
|
JSString *tmp = JS_ValueToString(cx, v);
|
||||||
JSB_PRECONDITION3(tmp, cx, JS_FALSE, "Error processing arguments");
|
JSB_PRECONDITION3(tmp, cx, JS_FALSE, "Error processing arguments");
|
||||||
|
|
||||||
JSStringWrapper str(tmp);
|
JSStringWrapper str(tmp);
|
||||||
|
@ -1736,14 +1740,24 @@ jsval long_long_to_jsval(JSContext* cx, long long v) {
|
||||||
return OBJECT_TO_JSVAL(tmp);
|
return OBJECT_TO_JSVAL(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval std_string_to_jsval(JSContext* cx, const std::string& v) {
|
jsval std_string_to_jsval(JSContext* cx, const std::string& v)
|
||||||
return c_string_to_jsval(cx, v.c_str());
|
{
|
||||||
|
return c_string_to_jsval(cx, v.c_str(), v.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
jsval c_string_to_jsval(JSContext* cx, const char* v, size_t length /* = -1 */) {
|
jsval c_string_to_jsval(JSContext* cx, const char* v, size_t length /* = -1 */)
|
||||||
if (v == NULL) {
|
{
|
||||||
|
if (v == NULL)
|
||||||
|
{
|
||||||
return JSVAL_NULL;
|
return JSVAL_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (0 == length)
|
||||||
|
{
|
||||||
|
auto emptyStr = JS_NewStringCopyZ(cx, "");
|
||||||
|
return STRING_TO_JSVAL(emptyStr);
|
||||||
|
}
|
||||||
|
|
||||||
jsval ret = JSVAL_NULL;
|
jsval ret = JSVAL_NULL;
|
||||||
int utf16_size = 0;
|
int utf16_size = 0;
|
||||||
jschar* strUTF16 = (jschar*)cc_utf8_to_utf16(v, length, &utf16_size);
|
jschar* strUTF16 = (jschar*)cc_utf8_to_utf16(v, length, &utf16_size);
|
||||||
|
@ -1902,40 +1916,251 @@ jsval FontDefinition_to_jsval(JSContext* cx, const FontDefinition& t)
|
||||||
|
|
||||||
#pragma mark - Debug
|
#pragma mark - Debug
|
||||||
|
|
||||||
void SimpleRunLoop::update(float dt) {
|
void SimpleRunLoop::update(float dt)
|
||||||
std::lock_guard<std::mutex> lk(g_qMutex);
|
{
|
||||||
|
g_qMutex.lock();
|
||||||
|
size_t size = g_queue.size();
|
||||||
|
g_qMutex.unlock();
|
||||||
|
|
||||||
while (g_queue.size() > 0) {
|
while (size > 0)
|
||||||
|
{
|
||||||
|
g_qMutex.lock();
|
||||||
vector<string>::iterator first = g_queue.begin();
|
vector<string>::iterator first = g_queue.begin();
|
||||||
string str = *first;
|
string str = *first;
|
||||||
ScriptingCore::getInstance()->debugProcessInput(str);
|
|
||||||
g_queue.erase(first);
|
g_queue.erase(first);
|
||||||
|
size = g_queue.size();
|
||||||
|
g_qMutex.unlock();
|
||||||
|
|
||||||
|
ScriptingCore::getInstance()->debugProcessInput(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptingCore::debugProcessInput(string str) {
|
void ScriptingCore::debugProcessInput(string str) {
|
||||||
|
JSAutoCompartment ac(cx_, debugGlobal_);
|
||||||
|
|
||||||
JSString* jsstr = JS_NewStringCopyZ(cx_, str.c_str());
|
JSString* jsstr = JS_NewStringCopyZ(cx_, str.c_str());
|
||||||
jsval argv[3] = {
|
jsval argv[] = {
|
||||||
STRING_TO_JSVAL(jsstr),
|
STRING_TO_JSVAL(jsstr)
|
||||||
frame,
|
|
||||||
script
|
|
||||||
};
|
};
|
||||||
jsval outval;
|
jsval outval;
|
||||||
JSAutoCompartment ac(cx_, debugGlobal_);
|
|
||||||
JS_CallFunctionName(cx_, debugGlobal_, "processInput", 3, argv, &outval);
|
JS_CallFunctionName(cx_, debugGlobal_, "processInput", 1, argv, &outval);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptingCore::enableDebugger() {
|
static bool NS_ProcessNextEvent()
|
||||||
if (debugGlobal_ == NULL) {
|
{
|
||||||
|
g_qMutex.lock();
|
||||||
|
size_t size = g_queue.size();
|
||||||
|
g_qMutex.unlock();
|
||||||
|
|
||||||
|
while (size > 0)
|
||||||
|
{
|
||||||
|
g_qMutex.lock();
|
||||||
|
vector<string>::iterator first = g_queue.begin();
|
||||||
|
string str = *first;
|
||||||
|
g_queue.erase(first);
|
||||||
|
size = g_queue.size();
|
||||||
|
g_qMutex.unlock();
|
||||||
|
|
||||||
|
ScriptingCore::getInstance()->debugProcessInput(str);
|
||||||
|
}
|
||||||
|
// std::this_thread::yield();
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSBool JSBDebug_enterNestedEventLoop(JSContext* cx, unsigned argc, jsval* vp)
|
||||||
|
{
|
||||||
|
enum {
|
||||||
|
NS_OK = 0,
|
||||||
|
NS_ERROR_UNEXPECTED
|
||||||
|
};
|
||||||
|
|
||||||
|
#define NS_SUCCEEDED(v) ((v) == NS_OK)
|
||||||
|
|
||||||
|
int rv = NS_OK;
|
||||||
|
|
||||||
|
uint32_t nestLevel = ++s_nestedLoopLevel;
|
||||||
|
|
||||||
|
while (NS_SUCCEEDED(rv) && s_nestedLoopLevel >= nestLevel) {
|
||||||
|
if (!NS_ProcessNextEvent())
|
||||||
|
rv = NS_ERROR_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCASSERT(s_nestedLoopLevel <= nestLevel,
|
||||||
|
"nested event didn't unwind properly");
|
||||||
|
|
||||||
|
JS_SET_RVAL(cx, vp, UINT_TO_JSVAL(s_nestedLoopLevel));
|
||||||
|
return JS_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSBool JSBDebug_exitNestedEventLoop(JSContext* cx, unsigned argc, jsval* vp)
|
||||||
|
{
|
||||||
|
if (s_nestedLoopLevel > 0) {
|
||||||
|
--s_nestedLoopLevel;
|
||||||
|
} else {
|
||||||
|
JS_SET_RVAL(cx, vp, UINT_TO_JSVAL(0));
|
||||||
|
return JS_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_SET_RVAL(cx, vp, UINT_TO_JSVAL(s_nestedLoopLevel));
|
||||||
|
return JS_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSBool JSBDebug_getEventLoopNestLevel(JSContext* cx, unsigned argc, jsval* vp)
|
||||||
|
{
|
||||||
|
JS_SET_RVAL(cx, vp, UINT_TO_JSVAL(s_nestedLoopLevel));
|
||||||
|
return JS_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//#pragma mark - Debugger
|
||||||
|
|
||||||
|
static void _clientSocketWriteAndClearString(std::string& s)
|
||||||
|
{
|
||||||
|
::send(clientSocket, s.c_str(), s.length(), 0);
|
||||||
|
s.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void processInput(string data) {
|
||||||
|
std::lock_guard<std::mutex> lk(g_qMutex);
|
||||||
|
g_queue.push_back(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void clearBuffers() {
|
||||||
|
std::lock_guard<std::mutex> lk(g_rwMutex);
|
||||||
|
// only process input if there's something and we're not locked
|
||||||
|
if (inData.length() > 0) {
|
||||||
|
processInput(inData);
|
||||||
|
inData.clear();
|
||||||
|
}
|
||||||
|
if (outData.length() > 0) {
|
||||||
|
_clientSocketWriteAndClearString(outData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void serverEntryPoint(void)
|
||||||
|
{
|
||||||
|
// start a server, accept the connection and keep reading data from it
|
||||||
|
struct addrinfo hints, *result = nullptr, *rp = nullptr;
|
||||||
|
int s = 0;
|
||||||
|
memset(&hints, 0, sizeof(struct addrinfo));
|
||||||
|
hints.ai_family = AF_INET; // IPv4
|
||||||
|
hints.ai_socktype = SOCK_STREAM; // TCP stream sockets
|
||||||
|
hints.ai_flags = AI_PASSIVE; // fill in my IP for me
|
||||||
|
|
||||||
|
stringstream portstr;
|
||||||
|
portstr << JSB_DEBUGGER_PORT;
|
||||||
|
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||||
|
WSADATA wsaData;
|
||||||
|
err = WSAStartup(MAKEWORD(2, 2),&wsaData);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if ((err = getaddrinfo(NULL, portstr.str().c_str(), &hints, &result)) != 0) {
|
||||||
|
LOGD("getaddrinfo error : %s\n", gai_strerror(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
||||||
|
if ((s = socket(rp->ai_family, rp->ai_socktype, 0)) < 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int optval = 1;
|
||||||
|
if ((setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&optval, sizeof(optval))) < 0) {
|
||||||
|
close(s);
|
||||||
|
TRACE_DEBUGGER_SERVER("debug server : error setting socket option SO_REUSEADDR");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||||
|
if ((setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, &optval, sizeof(optval))) < 0) {
|
||||||
|
close(s);
|
||||||
|
TRACE_DEBUGGER_SERVER("debug server : error setting socket option SO_NOSIGPIPE");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif //(CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||||
|
|
||||||
|
if ((::bind(s, rp->ai_addr, rp->ai_addrlen)) == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
close(s);
|
||||||
|
s = -1;
|
||||||
|
}
|
||||||
|
if (s < 0 || rp == NULL) {
|
||||||
|
TRACE_DEBUGGER_SERVER("debug server : error creating/binding socket");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
freeaddrinfo(result);
|
||||||
|
|
||||||
|
listen(s, 1);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
clientSocket = accept(s, NULL, NULL);
|
||||||
|
|
||||||
|
if (clientSocket < 0)
|
||||||
|
{
|
||||||
|
TRACE_DEBUGGER_SERVER("debug server : error on accept");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// read/write data
|
||||||
|
TRACE_DEBUGGER_SERVER("debug server : client connected");
|
||||||
|
|
||||||
|
inData = "connected";
|
||||||
|
// process any input, send any output
|
||||||
|
clearBuffers();
|
||||||
|
|
||||||
|
char buf[1024] = {0};
|
||||||
|
int readBytes = 0;
|
||||||
|
while ((readBytes = ::recv(clientSocket, buf, sizeof(buf), 0)) > 0)
|
||||||
|
{
|
||||||
|
buf[readBytes] = '\0';
|
||||||
|
// TRACE_DEBUGGER_SERVER("debug server : received command >%s", buf);
|
||||||
|
|
||||||
|
// no other thread is using this
|
||||||
|
inData.append(buf);
|
||||||
|
// process any input, send any output
|
||||||
|
clearBuffers();
|
||||||
|
} // while(read)
|
||||||
|
|
||||||
|
close(clientSocket);
|
||||||
|
}
|
||||||
|
} // while(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
JSBool JSBDebug_BufferWrite(JSContext* cx, unsigned argc, jsval* vp)
|
||||||
|
{
|
||||||
|
if (argc == 1) {
|
||||||
|
jsval* argv = JS_ARGV(cx, vp);
|
||||||
|
JSStringWrapper strWrapper(argv[0]);
|
||||||
|
// this is safe because we're already inside a lock (from clearBuffers)
|
||||||
|
outData.append(strWrapper.get());
|
||||||
|
_clientSocketWriteAndClearString(outData);
|
||||||
|
}
|
||||||
|
return JS_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptingCore::enableDebugger()
|
||||||
|
{
|
||||||
|
JS_SetDebugMode(cx_, JS_TRUE);
|
||||||
|
|
||||||
|
if (debugGlobal_ == NULL)
|
||||||
|
{
|
||||||
|
JSAutoCompartment ac0(cx_, global_);
|
||||||
debugGlobal_ = NewGlobalObject(cx_, true);
|
debugGlobal_ = NewGlobalObject(cx_, true);
|
||||||
JS_WrapObject(cx_, &debugGlobal_);
|
JS_WrapObject(cx_, &debugGlobal_);
|
||||||
JSAutoCompartment ac(cx_, debugGlobal_);
|
JSAutoCompartment ac(cx_, debugGlobal_);
|
||||||
// these are used in the debug program
|
// these are used in the debug program
|
||||||
JS_DefineFunction(cx_, debugGlobal_, "log", ScriptingCore::log, 0, JSPROP_READONLY | JSPROP_PERMANENT);
|
JS_DefineFunction(cx_, debugGlobal_, "log", ScriptingCore::log, 0, JSPROP_READONLY | JSPROP_PERMANENT);
|
||||||
JS_DefineFunction(cx_, debugGlobal_, "_bufferWrite", JSBDebug_BufferWrite, 1, JSPROP_READONLY | JSPROP_PERMANENT);
|
JS_DefineFunction(cx_, debugGlobal_, "_bufferWrite", JSBDebug_BufferWrite, 1, JSPROP_READONLY | JSPROP_PERMANENT);
|
||||||
JS_DefineFunction(cx_, debugGlobal_, "_bufferRead", JSBDebug_BufferRead, 0, JSPROP_READONLY | JSPROP_PERMANENT);
|
JS_DefineFunction(cx_, debugGlobal_, "_enterNestedEventLoop", JSBDebug_enterNestedEventLoop, 0, JSPROP_READONLY | JSPROP_PERMANENT);
|
||||||
JS_DefineFunction(cx_, debugGlobal_, "_lockVM", JSBDebug_LockExecution, 2, JSPROP_READONLY | JSPROP_PERMANENT);
|
JS_DefineFunction(cx_, debugGlobal_, "_exitNestedEventLoop", JSBDebug_exitNestedEventLoop, 0, JSPROP_READONLY | JSPROP_PERMANENT);
|
||||||
JS_DefineFunction(cx_, debugGlobal_, "_unlockVM", JSBDebug_UnlockExecution, 0, JSPROP_READONLY | JSPROP_PERMANENT);
|
JS_DefineFunction(cx_, debugGlobal_, "_getEventLoopNestLevel", JSBDebug_getEventLoopNestLevel, 0, JSPROP_READONLY | JSPROP_PERMANENT);
|
||||||
|
|
||||||
|
|
||||||
runScript("jsb_debugger.js", debugGlobal_);
|
runScript("jsb_debugger.js", debugGlobal_);
|
||||||
|
|
||||||
|
@ -1946,10 +2171,8 @@ void ScriptingCore::enableDebugger() {
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
JS_ReportPendingException(cx_);
|
JS_ReportPendingException(cx_);
|
||||||
}
|
}
|
||||||
// define the start debugger function
|
|
||||||
JS_DefineFunction(cx_, global_, "startDebugger", JSBDebug_StartDebugger, 3, JSPROP_READONLY | JSPROP_PERMANENT);
|
|
||||||
// start bg thread
|
|
||||||
|
|
||||||
|
// start bg thread
|
||||||
auto t = std::thread(&serverEntryPoint);
|
auto t = std::thread(&serverEntryPoint);
|
||||||
t.detach();
|
t.detach();
|
||||||
|
|
||||||
|
@ -1958,36 +2181,6 @@ void ScriptingCore::enableDebugger() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JSBool jsStartDebugger(JSContext* cx, unsigned argc, jsval* vp)
|
|
||||||
{
|
|
||||||
JSObject* debugGlobal = ScriptingCore::getInstance()->getDebugGlobal();
|
|
||||||
if (argc >= 2) {
|
|
||||||
jsval* argv = JS_ARGV(cx, vp);
|
|
||||||
jsval out;
|
|
||||||
JS_WrapObject(cx, &debugGlobal);
|
|
||||||
JSAutoCompartment ac(cx, debugGlobal);
|
|
||||||
JS_CallFunctionName(cx, debugGlobal, "_startDebugger", argc, argv, &out);
|
|
||||||
return JS_TRUE;
|
|
||||||
}
|
|
||||||
return JS_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSBool jsGetScript(JSContext* cx, unsigned argc, jsval* vp)
|
|
||||||
{
|
|
||||||
jsval* argv = JS_ARGV(cx, vp);
|
|
||||||
if (argc == 1 && argv[0].isString()) {
|
|
||||||
JSString* str = argv[0].toString();
|
|
||||||
JSStringWrapper wrapper(str);
|
|
||||||
JSScript* script = filename_script[(char *)wrapper];
|
|
||||||
if (script) {
|
|
||||||
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL((JSObject*)script));
|
|
||||||
} else {
|
|
||||||
JS_SET_RVAL(cx, vp, JSVAL_NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return JS_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSObject* NewGlobalObject(JSContext* cx, bool debug)
|
JSObject* NewGlobalObject(JSContext* cx, bool debug)
|
||||||
{
|
{
|
||||||
JSObject* glob = JS_NewGlobalObject(cx, &global_class, NULL);
|
JSObject* glob = JS_NewGlobalObject(cx, &global_class, NULL);
|
||||||
|
@ -2057,191 +2250,6 @@ void jsb_remove_proxy(js_proxy_t* nativeProxy, js_proxy_t* jsProxy)
|
||||||
JS_REMOVE_PROXY(nativeProxy, jsProxy);
|
JS_REMOVE_PROXY(nativeProxy, jsProxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
//#pragma mark - Debugger
|
|
||||||
|
|
||||||
JSBool JSBDebug_StartDebugger(JSContext* cx, unsigned argc, jsval* vp)
|
|
||||||
{
|
|
||||||
JSObject* debugGlobal = ScriptingCore::getInstance()->getDebugGlobal();
|
|
||||||
if (argc >= 2) {
|
|
||||||
jsval* argv = JS_ARGV(cx, vp);
|
|
||||||
jsval out;
|
|
||||||
JS_WrapObject(cx, &debugGlobal);
|
|
||||||
JSAutoCompartment ac(cx, debugGlobal);
|
|
||||||
JS_CallFunctionName(cx, debugGlobal, "_startDebugger", argc, argv, &out);
|
|
||||||
return JS_TRUE;
|
|
||||||
}
|
|
||||||
return JS_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSBool JSBDebug_BufferRead(JSContext* cx, unsigned argc, jsval* vp)
|
|
||||||
{
|
|
||||||
if (argc == 0) {
|
|
||||||
JSString* str;
|
|
||||||
// this is safe because we're already inside a lock (from clearBuffers)
|
|
||||||
if (vmLock) {
|
|
||||||
g_rwMutex.lock();
|
|
||||||
}
|
|
||||||
str = JS_NewStringCopyZ(cx, inData.c_str());
|
|
||||||
inData.clear();
|
|
||||||
if (vmLock) {
|
|
||||||
g_rwMutex.unlock();
|
|
||||||
}
|
|
||||||
JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(str));
|
|
||||||
} else {
|
|
||||||
JS_SET_RVAL(cx, vp, JSVAL_NULL);
|
|
||||||
}
|
|
||||||
return JS_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _clientSocketWriteAndClearString(std::string& s) {
|
|
||||||
#if JSB_DEBUGGER_OUTPUT_STDOUT
|
|
||||||
write(STDOUT_FILENO, s.c_str(), s.length());
|
|
||||||
#endif
|
|
||||||
write(clientSocket, s.c_str(), s.length());
|
|
||||||
s.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
JSBool JSBDebug_BufferWrite(JSContext* cx, unsigned argc, jsval* vp)
|
|
||||||
{
|
|
||||||
if (argc == 1) {
|
|
||||||
jsval* argv = JS_ARGV(cx, vp);
|
|
||||||
JSStringWrapper strWrapper(argv[0]);
|
|
||||||
// this is safe because we're already inside a lock (from clearBuffers)
|
|
||||||
outData.append(strWrapper.get());
|
|
||||||
_clientSocketWriteAndClearString(outData);
|
|
||||||
}
|
|
||||||
return JS_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// this should lock the execution of the running thread, waiting for a signal
|
|
||||||
JSBool JSBDebug_LockExecution(JSContext* cx, unsigned argc, jsval* vp)
|
|
||||||
{
|
|
||||||
if (argc == 2) {
|
|
||||||
printf("locking vm\n");
|
|
||||||
jsval* argv = JS_ARGV(cx, vp);
|
|
||||||
frame = argv[0];
|
|
||||||
script = argv[1];
|
|
||||||
vmLock = true;
|
|
||||||
while (vmLock) {
|
|
||||||
// try to read the input, if there's anything
|
|
||||||
g_qMutex.lock();
|
|
||||||
while (g_queue.size() > 0) {
|
|
||||||
vector<string>::iterator first = g_queue.begin();
|
|
||||||
string str = *first;
|
|
||||||
ScriptingCore::getInstance()->debugProcessInput(str);
|
|
||||||
g_queue.erase(first);
|
|
||||||
}
|
|
||||||
g_qMutex.unlock();
|
|
||||||
std::this_thread::yield();
|
|
||||||
}
|
|
||||||
printf("vm unlocked\n");
|
|
||||||
frame = JSVAL_NULL;
|
|
||||||
script = JSVAL_NULL;
|
|
||||||
return JS_TRUE;
|
|
||||||
}
|
|
||||||
JS_ReportError(cx, "invalid call to _lockVM");
|
|
||||||
return JS_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSBool JSBDebug_UnlockExecution(JSContext* cx, unsigned argc, jsval* vp)
|
|
||||||
{
|
|
||||||
vmLock = false;
|
|
||||||
return JS_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void processInput(string data) {
|
|
||||||
std::lock_guard<std::mutex> lk(g_qMutex);
|
|
||||||
g_queue.push_back(string(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void clearBuffers() {
|
|
||||||
std::lock_guard<std::mutex> lk(g_rwMutex);
|
|
||||||
// only process input if there's something and we're not locked
|
|
||||||
if (inData.length() > 0) {
|
|
||||||
processInput(inData);
|
|
||||||
inData.clear();
|
|
||||||
}
|
|
||||||
if (outData.length() > 0) {
|
|
||||||
_clientSocketWriteAndClearString(outData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void serverEntryPoint(void)
|
|
||||||
{
|
|
||||||
// start a server, accept the connection and keep reading data from it
|
|
||||||
struct addrinfo hints, *result, *rp;
|
|
||||||
int s;
|
|
||||||
memset(&hints, 0, sizeof(struct addrinfo));
|
|
||||||
hints.ai_family = AF_INET; // IPv4
|
|
||||||
hints.ai_socktype = SOCK_STREAM; // TCP stream sockets
|
|
||||||
hints.ai_flags = AI_PASSIVE; // fill in my IP for me
|
|
||||||
|
|
||||||
stringstream portstr;
|
|
||||||
portstr << JSB_DEBUGGER_PORT;
|
|
||||||
|
|
||||||
int err;
|
|
||||||
if ((err = getaddrinfo(NULL, portstr.str().c_str(), &hints, &result)) != 0) {
|
|
||||||
LOGD("getaddrinfo error : %s\n", gai_strerror(err));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
|
||||||
if ((s = socket(rp->ai_family, rp->ai_socktype, 0)) < 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int optval = 1;
|
|
||||||
if ((setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&optval, sizeof(optval))) < 0) {
|
|
||||||
close(s);
|
|
||||||
TRACE_DEBUGGER_SERVER("debug server : error setting socket option SO_REUSEADDR");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
||||||
if ((setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, &optval, sizeof(optval))) < 0) {
|
|
||||||
close(s);
|
|
||||||
TRACE_DEBUGGER_SERVER("debug server : error setting socket option SO_NOSIGPIPE");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif //(CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
||||||
|
|
||||||
if ((::bind(s, rp->ai_addr, rp->ai_addrlen)) == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
close(s);
|
|
||||||
s = -1;
|
|
||||||
}
|
|
||||||
if (s < 0 || rp == NULL) {
|
|
||||||
TRACE_DEBUGGER_SERVER("debug server : error creating/binding socket");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
freeaddrinfo(result);
|
|
||||||
|
|
||||||
listen(s, 1);
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
clientSocket = accept(s, NULL, NULL);
|
|
||||||
if (clientSocket < 0)
|
|
||||||
{
|
|
||||||
TRACE_DEBUGGER_SERVER("debug server : error on accept");
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
// read/write data
|
|
||||||
TRACE_DEBUGGER_SERVER("debug server : client connected");
|
|
||||||
char buf[256];
|
|
||||||
int readBytes;
|
|
||||||
while ((readBytes = read(clientSocket, buf, 256)) > 0) {
|
|
||||||
buf[readBytes] = '\0';
|
|
||||||
TRACE_DEBUGGER_SERVER("debug server : received command >%s", buf);
|
|
||||||
// no other thread is using this
|
|
||||||
inData.append(buf);
|
|
||||||
// process any input, send any output
|
|
||||||
clearBuffers();
|
|
||||||
} // while(read)
|
|
||||||
close(clientSocket);
|
|
||||||
}
|
|
||||||
} // while(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
static Color3B getColorFromJSObject(JSContext *cx, JSObject *colorObject)
|
static Color3B getColorFromJSObject(JSContext *cx, JSObject *colorObject)
|
||||||
{
|
{
|
||||||
jsval jsr;
|
jsval jsr;
|
||||||
|
|
|
@ -245,14 +245,6 @@ jsval ccaffinetransform_to_jsval(JSContext* cx, const AffineTransform& t);
|
||||||
jsval FontDefinition_to_jsval(JSContext* cx, const FontDefinition& t);
|
jsval FontDefinition_to_jsval(JSContext* cx, const FontDefinition& t);
|
||||||
|
|
||||||
JSObject* NewGlobalObject(JSContext* cx, bool debug = false);
|
JSObject* NewGlobalObject(JSContext* cx, bool debug = false);
|
||||||
JSBool jsStartDebugger(JSContext* cx, unsigned argc, jsval* vp);
|
|
||||||
JSBool jsGetScript(JSContext* cx, unsigned argc, jsval* vp);
|
|
||||||
|
|
||||||
JSBool JSBDebug_StartDebugger(JSContext* cx, unsigned argc, jsval* vp);
|
|
||||||
JSBool JSBDebug_BufferRead(JSContext* cx, unsigned argc, jsval* vp);
|
|
||||||
JSBool JSBDebug_BufferWrite(JSContext* cx, unsigned argc, jsval* vp);
|
|
||||||
JSBool JSBDebug_LockExecution(JSContext* cx, unsigned argc, jsval* vp);
|
|
||||||
JSBool JSBDebug_UnlockExecution(JSContext* cx, unsigned argc, jsval* vp);
|
|
||||||
|
|
||||||
// just a simple utility to avoid mem leaking when using JSString
|
// just a simple utility to avoid mem leaking when using JSString
|
||||||
class JSStringWrapper
|
class JSStringWrapper
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
db6aaa41d0756117258eebb759cd6420f66071e0
|
ceb78008acf831592a416d7dfa85a9dfd0ddae75
|
|
@ -0,0 +1,133 @@
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
function utf16to8(str) {
|
||||||
|
var out, i, len, c;
|
||||||
|
|
||||||
|
out = "";
|
||||||
|
len = str.length;
|
||||||
|
for(i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
c = str.charCodeAt(i);
|
||||||
|
if ((c >= 0x0001) && (c <= 0x007F))
|
||||||
|
{
|
||||||
|
out += str.charAt(i);
|
||||||
|
}
|
||||||
|
else if (c > 0x07FF)
|
||||||
|
{
|
||||||
|
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
|
||||||
|
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
|
||||||
|
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
|
||||||
|
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function utf8to16(str) {
|
||||||
|
var out, i, len, c;
|
||||||
|
var char2, char3;
|
||||||
|
|
||||||
|
out = "";
|
||||||
|
len = str.length;
|
||||||
|
i = 0;
|
||||||
|
while(i < len) { c = str.charCodeAt(i++); switch(c >> 4)
|
||||||
|
{
|
||||||
|
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
|
||||||
|
// 0xxxxxxx
|
||||||
|
out += str.charAt(i-1);
|
||||||
|
break;
|
||||||
|
case 12: case 13:
|
||||||
|
// 110x xxxx 10xx xxxx
|
||||||
|
char2 = str.charCodeAt(i++);
|
||||||
|
out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
|
||||||
|
break;
|
||||||
|
case 14:
|
||||||
|
// 1110 xxxx 10xx xxxx 10xx xxxx
|
||||||
|
char2 = str.charCodeAt(i++);
|
||||||
|
char3 = str.charCodeAt(i++);
|
||||||
|
out += String.fromCharCode(((c & 0x0F) << 12) |
|
||||||
|
((char2 & 0x3F) << 6) |
|
||||||
|
((char3 & 0x3F) << 0));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
var dump = function(msg) {
|
||||||
|
log(msg);
|
||||||
|
};
|
||||||
|
|
||||||
|
/* General utilities used throughout devtools. */
|
||||||
|
|
||||||
|
/* Turn the error e into a string, without fail. */
|
||||||
|
this.safeErrorString = function safeErrorString(aError) {
|
||||||
|
try {
|
||||||
|
var s = aError.toString();
|
||||||
|
if (typeof s === "string")
|
||||||
|
return s;
|
||||||
|
} catch (ee) { }
|
||||||
|
|
||||||
|
return "<failed trying to find error description>";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report that |aWho| threw an exception, |aException|.
|
||||||
|
*/
|
||||||
|
this.reportException = function reportException(aWho, aException) {
|
||||||
|
let msg = aWho + " threw an exception: " + safeErrorString(aException);
|
||||||
|
if (aException.stack) {
|
||||||
|
msg += "\nCall stack:\n" + aException.stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
dump(msg + "\n");
|
||||||
|
|
||||||
|
// if (Components.utils.reportError) {
|
||||||
|
// /*
|
||||||
|
// * Note that the xpcshell test harness registers an observer for
|
||||||
|
// * console messages, so when we're running tests, this will cause
|
||||||
|
// * the test to quit.
|
||||||
|
// */
|
||||||
|
// Components.utils.reportError(msg);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a handler function that may throw, return an infallible handler
|
||||||
|
* function that calls the fallible handler, and logs any exceptions it
|
||||||
|
* throws.
|
||||||
|
*
|
||||||
|
* @param aHandler function
|
||||||
|
* A handler function, which may throw.
|
||||||
|
* @param aName string
|
||||||
|
* A name for aHandler, for use in error messages. If omitted, we use
|
||||||
|
* aHandler.name.
|
||||||
|
*
|
||||||
|
* (SpiderMonkey does generate good names for anonymous functions, but we
|
||||||
|
* don't have a way to get at them from JavaScript at the moment.)
|
||||||
|
*/
|
||||||
|
this.makeInfallible = function makeInfallible(aHandler, aName) {
|
||||||
|
if (!aName)
|
||||||
|
aName = aHandler.name;
|
||||||
|
|
||||||
|
return function (/* arguments */) {
|
||||||
|
try {
|
||||||
|
return aHandler.apply(this, arguments);
|
||||||
|
} catch (ex) {
|
||||||
|
let who = "Handler function";
|
||||||
|
if (aName) {
|
||||||
|
who += " " + aName;
|
||||||
|
}
|
||||||
|
reportException(who, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
Remote Debugging By Using FireFox
|
||||||
|
=================================
|
||||||
|
|
||||||
|
Requirement
|
||||||
|
-----------
|
||||||
|
|
||||||
|
* Firefox: From v24
|
||||||
|
|
||||||
|
How To Use
|
||||||
|
----------
|
||||||
|
|
||||||
|
TO BE DONE ...
|
|
@ -0,0 +1,329 @@
|
||||||
|
/* -*- tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/* Root actor for the remote debugging protocol. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Methods shared between RootActor and BrowserTabActor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populate |this._extraActors| as specified by |aFactories|, reusing whatever
|
||||||
|
* actors are already there. Add all actors in the final extra actors table to
|
||||||
|
* |aPool|.
|
||||||
|
*
|
||||||
|
* The root actor and the tab actor use this to instantiate actors that other
|
||||||
|
* parts of the browser have specified with DebuggerServer.addTabActor antd
|
||||||
|
* DebuggerServer.addGlobalActor.
|
||||||
|
*
|
||||||
|
* @param aFactories
|
||||||
|
* An object whose own property names are the names of properties to add to
|
||||||
|
* some reply packet (say, a tab actor grip or the "listTabs" response
|
||||||
|
* form), and whose own property values are actor constructor functions, as
|
||||||
|
* documented for addTabActor and addGlobalActor.
|
||||||
|
*
|
||||||
|
* @param this
|
||||||
|
* The BrowserRootActor or BrowserTabActor with which the new actors will
|
||||||
|
* be associated. It should support whatever API the |aFactories|
|
||||||
|
* constructor functions might be interested in, as it is passed to them.
|
||||||
|
* For the sake of CommonCreateExtraActors itself, it should have at least
|
||||||
|
* the following properties:
|
||||||
|
*
|
||||||
|
* - _extraActors
|
||||||
|
* An object whose own property names are factory table (and packet)
|
||||||
|
* property names, and whose values are no-argument actor constructors,
|
||||||
|
* of the sort that one can add to an ActorPool.
|
||||||
|
*
|
||||||
|
* - conn
|
||||||
|
* The DebuggerServerConnection in which the new actors will participate.
|
||||||
|
*
|
||||||
|
* - actorID
|
||||||
|
* The actor's name, for use as the new actors' parentID.
|
||||||
|
*/
|
||||||
|
function CommonCreateExtraActors(aFactories, aPool) {
|
||||||
|
// Walk over global actors added by extensions.
|
||||||
|
for (let name in aFactories) {
|
||||||
|
let actor = this._extraActors[name];
|
||||||
|
if (!actor) {
|
||||||
|
actor = aFactories[name].bind(null, this.conn, this);
|
||||||
|
actor.prototype = aFactories[name].prototype;
|
||||||
|
actor.parentID = this.actorID;
|
||||||
|
this._extraActors[name] = actor;
|
||||||
|
}
|
||||||
|
aPool.addActor(actor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append the extra actors in |this._extraActors|, constructed by a prior call
|
||||||
|
* to CommonCreateExtraActors, to |aObject|.
|
||||||
|
*
|
||||||
|
* @param aObject
|
||||||
|
* The object to which the extra actors should be added, under the
|
||||||
|
* property names given in the |aFactories| table passed to
|
||||||
|
* CommonCreateExtraActors.
|
||||||
|
*
|
||||||
|
* @param this
|
||||||
|
* The BrowserRootActor or BrowserTabActor whose |_extraActors| table we
|
||||||
|
* should use; see above.
|
||||||
|
*/
|
||||||
|
function CommonAppendExtraActors(aObject) {
|
||||||
|
for (let name in this._extraActors) {
|
||||||
|
let actor = this._extraActors[name];
|
||||||
|
aObject[name] = actor.actorID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a remote debugging protocol root actor.
|
||||||
|
*
|
||||||
|
* @param aConnection
|
||||||
|
* The DebuggerServerConnection whose root actor we are constructing.
|
||||||
|
*
|
||||||
|
* @param aParameters
|
||||||
|
* The properties of |aParameters| provide backing objects for the root
|
||||||
|
* actor's requests; if a given property is omitted from |aParameters|, the
|
||||||
|
* root actor won't implement the corresponding requests or notifications.
|
||||||
|
* Supported properties:
|
||||||
|
*
|
||||||
|
* - tabList: a live list (see below) of tab actors. If present, the
|
||||||
|
* new root actor supports the 'listTabs' request, providing the live
|
||||||
|
* list's elements as its tab actors, and sending 'tabListChanged'
|
||||||
|
* notifications when the live list's contents change. One actor in
|
||||||
|
* this list must have a true '.selected' property.
|
||||||
|
*
|
||||||
|
* - globalActorFactories: an object |A| describing further actors to
|
||||||
|
* attach to the 'listTabs' reply. This is the type accumulated by
|
||||||
|
* DebuggerServer.addGlobalActor. For each own property |P| of |A|,
|
||||||
|
* the root actor adds a property named |P| to the 'listTabs'
|
||||||
|
* reply whose value is the name of an actor constructed by
|
||||||
|
* |A[P]|.
|
||||||
|
*
|
||||||
|
* - onShutdown: a function to call when the root actor is disconnected.
|
||||||
|
*
|
||||||
|
* Instance properties:
|
||||||
|
*
|
||||||
|
* - applicationType: the string the root actor will include as the
|
||||||
|
* "applicationType" property in the greeting packet. By default, this
|
||||||
|
* is "browser".
|
||||||
|
*
|
||||||
|
* Live lists:
|
||||||
|
*
|
||||||
|
* A "live list", as used for the |tabList|, is an object that presents a
|
||||||
|
* list of actors, and also notifies its clients of changes to the list. A
|
||||||
|
* live list's interface is two properties:
|
||||||
|
*
|
||||||
|
* - iterator: a method that returns an iterator. A for-of loop will call
|
||||||
|
* this method to obtain an iterator for the loop, so if LL is
|
||||||
|
* a live list, one can simply write 'for (i of LL) ...'.
|
||||||
|
*
|
||||||
|
* - onListChanged: a handler called, with no arguments, when the set of
|
||||||
|
* values the iterator would produce has changed since the last
|
||||||
|
* time 'iterator' was called. This may only be set to null or a
|
||||||
|
* callable value (one for which the typeof operator returns
|
||||||
|
* 'function'). (Note that the live list will not call the
|
||||||
|
* onListChanged handler until the list has been iterated over
|
||||||
|
* once; if nobody's seen the list in the first place, nobody
|
||||||
|
* should care if its contents have changed!)
|
||||||
|
*
|
||||||
|
* When the list changes, the list implementation should ensure that any
|
||||||
|
* actors yielded in previous iterations whose referents (tabs) still exist
|
||||||
|
* get yielded again in subsequent iterations. If the underlying referent
|
||||||
|
* is the same, the same actor should be presented for it.
|
||||||
|
*
|
||||||
|
* The root actor registers an 'onListChanged' handler on the appropriate
|
||||||
|
* list when it may need to send the client 'tabListChanged' notifications,
|
||||||
|
* and is careful to remove the handler whenever it does not need to send
|
||||||
|
* such notifications (including when it is disconnected). This means that
|
||||||
|
* live list implementations can use the state of the handler property (set
|
||||||
|
* or null) to install and remove observers and event listeners.
|
||||||
|
*
|
||||||
|
* Note that, as the only way for the root actor to see the members of the
|
||||||
|
* live list is to begin an iteration over the list, the live list need not
|
||||||
|
* actually produce any actors until they are reached in the course of
|
||||||
|
* iteration: alliterative lazy live lists.
|
||||||
|
*/
|
||||||
|
function RootActor(aConnection, aParameters) {
|
||||||
|
this.conn = aConnection;
|
||||||
|
this._parameters = aParameters;
|
||||||
|
this._onTabListChanged = this.onTabListChanged.bind(this);
|
||||||
|
this._extraActors = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
RootActor.prototype = {
|
||||||
|
constructor: RootActor,
|
||||||
|
applicationType: "browser",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a 'hello' packet as specified by the Remote Debugging Protocol.
|
||||||
|
*/
|
||||||
|
sayHello: function() {
|
||||||
|
return {
|
||||||
|
from: "root",
|
||||||
|
applicationType: this.applicationType,
|
||||||
|
/* This is not in the spec, but it's used by tests. */
|
||||||
|
testConnectionPrefix: this.conn.prefix,
|
||||||
|
traits: {
|
||||||
|
sources: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disconnects the actor from the browser window.
|
||||||
|
*/
|
||||||
|
disconnect: function() {
|
||||||
|
/* Tell the live lists we aren't watching any more. */
|
||||||
|
if (this._parameters.tabList) {
|
||||||
|
this._parameters.tabList.onListChanged = null;
|
||||||
|
}
|
||||||
|
if (typeof this._parameters.onShutdown === 'function') {
|
||||||
|
this._parameters.onShutdown();
|
||||||
|
}
|
||||||
|
this._extraActors = null;
|
||||||
|
},
|
||||||
|
|
||||||
|
/* The 'listTabs' request and the 'tabListChanged' notification. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the listTabs request. The actors will survive until at least
|
||||||
|
* the next listTabs request.
|
||||||
|
*/
|
||||||
|
onListTabs: function() {
|
||||||
|
|
||||||
|
let tabList = this._parameters.tabList;
|
||||||
|
if (!tabList) {
|
||||||
|
return { from: "root", error: "noTabs",
|
||||||
|
message: "This root actor has no browser tabs." };
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Walk the tab list, accumulating the array of tab actors for the
|
||||||
|
* reply, and moving all the actors to a new ActorPool. We'll
|
||||||
|
* replace the old tab actor pool with the one we build here, thus
|
||||||
|
* retiring any actors that didn't get listed again, and preparing any
|
||||||
|
* new actors to receive packets.
|
||||||
|
*/
|
||||||
|
let newActorPool = new ActorPool(this.conn);
|
||||||
|
let tabActorList = [];
|
||||||
|
let selected;
|
||||||
|
for (let tabActor of tabList) {
|
||||||
|
if (tabActor.selected) {
|
||||||
|
selected = tabActorList.length;
|
||||||
|
}
|
||||||
|
tabActor.parentID = this.actorID;
|
||||||
|
newActorPool.addActor(tabActor);
|
||||||
|
tabActorList.push(tabActor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* DebuggerServer.addGlobalActor support: create actors. */
|
||||||
|
this._createExtraActors(this._parameters.globalActorFactories, newActorPool);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Drop the old actorID -> actor map. Actors that still mattered were
|
||||||
|
* added to the new map; others will go away.
|
||||||
|
*/
|
||||||
|
if (this._tabActorPool) {
|
||||||
|
this.conn.removeActorPool(this._tabActorPool);
|
||||||
|
}
|
||||||
|
this._tabActorPool = newActorPool;
|
||||||
|
this.conn.addActorPool(this._tabActorPool);
|
||||||
|
|
||||||
|
let reply = {
|
||||||
|
"from": "root",
|
||||||
|
"selected": selected || 0,
|
||||||
|
"tabs": [actor.grip() for (actor of tabActorList)]
|
||||||
|
};
|
||||||
|
|
||||||
|
/* DebuggerServer.addGlobalActor support: name actors in 'listTabs' reply. */
|
||||||
|
this._appendExtraActors(reply);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Now that we're actually going to report the contents of tabList to
|
||||||
|
* the client, we're responsible for letting the client know if it
|
||||||
|
* changes.
|
||||||
|
*/
|
||||||
|
tabList.onListChanged = this._onTabListChanged;
|
||||||
|
|
||||||
|
return reply;
|
||||||
|
},
|
||||||
|
|
||||||
|
onTabListChanged: function () {
|
||||||
|
this.conn.send({ from:"root", type:"tabListChanged" });
|
||||||
|
/* It's a one-shot notification; no need to watch any more. */
|
||||||
|
this._parameters.tabList.onListChanged = null;
|
||||||
|
},
|
||||||
|
|
||||||
|
/* This is not in the spec, but it's used by tests. */
|
||||||
|
onEcho: (aRequest) => aRequest,
|
||||||
|
|
||||||
|
/* Support for DebuggerServer.addGlobalActor. */
|
||||||
|
_createExtraActors: CommonCreateExtraActors,
|
||||||
|
_appendExtraActors: CommonAppendExtraActors,
|
||||||
|
|
||||||
|
/* ThreadActor hooks. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare to enter a nested event loop by disabling debuggee events.
|
||||||
|
*/
|
||||||
|
preNest: function() {
|
||||||
|
// Disable events in all open windows.
|
||||||
|
let e = windowMediator.getEnumerator(null);
|
||||||
|
while (e.hasMoreElements()) {
|
||||||
|
let win = e.getNext();
|
||||||
|
let windowUtils = win.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindowUtils);
|
||||||
|
windowUtils.suppressEventHandling(true);
|
||||||
|
windowUtils.suspendTimeouts();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare to exit a nested event loop by enabling debuggee events.
|
||||||
|
*/
|
||||||
|
postNest: function(aNestData) {
|
||||||
|
// Enable events in all open windows.
|
||||||
|
let e = windowMediator.getEnumerator(null);
|
||||||
|
while (e.hasMoreElements()) {
|
||||||
|
let win = e.getNext();
|
||||||
|
let windowUtils = win.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindowUtils);
|
||||||
|
windowUtils.resumeTimeouts();
|
||||||
|
windowUtils.suppressEventHandling(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/* ChromeDebuggerActor hooks. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the specified actor to the default actor pool connection, in order to
|
||||||
|
* keep it alive as long as the server is. This is used by breakpoints in the
|
||||||
|
* thread and chrome debugger actors.
|
||||||
|
*
|
||||||
|
* @param actor aActor
|
||||||
|
* The actor object.
|
||||||
|
*/
|
||||||
|
addToParentPool: function(aActor) {
|
||||||
|
this.conn.addActor(aActor);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified actor from the default actor pool.
|
||||||
|
*
|
||||||
|
* @param BreakpointActor aActor
|
||||||
|
* The actor object.
|
||||||
|
*/
|
||||||
|
removeFromParentPool: function(aActor) {
|
||||||
|
this.conn.removeActor(aActor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RootActor.prototype.requestTypes = {
|
||||||
|
"listTabs": RootActor.prototype.onListTabs,
|
||||||
|
"echo": RootActor.prototype.onEcho
|
||||||
|
};
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,294 @@
|
||||||
|
/* vim:set ts=2 sw=2 sts=2 expandtab */
|
||||||
|
/*jshint undef: true es5: true node: true browser: true devel: true
|
||||||
|
forin: true latedef: false */
|
||||||
|
/*global define: true, Cu: true, __URI__: true */
|
||||||
|
//;(function(id, factory) { // Module boilerplate :(
|
||||||
|
// if (typeof(define) === 'function') { // RequireJS
|
||||||
|
// define(factory);
|
||||||
|
// } else if (typeof(require) === 'function') { // CommonJS
|
||||||
|
// factory.call(this, require, exports, module);
|
||||||
|
// } else if (String(this).indexOf('BackstagePass') >= 0) { // JSM
|
||||||
|
// this[factory.name] = {};
|
||||||
|
// try {
|
||||||
|
// this.console = this['Components'].utils
|
||||||
|
// .import('resource://gre/modules/devtools/Console.jsm', {}).console;
|
||||||
|
// }
|
||||||
|
// catch (ex) {
|
||||||
|
// // Avoid failures on different toolkit configurations.
|
||||||
|
// }
|
||||||
|
// factory(function require(uri) {
|
||||||
|
// var imports = {};
|
||||||
|
// this['Components'].utils.import(uri, imports);
|
||||||
|
// return imports;
|
||||||
|
// }, this[factory.name], { uri: __URI__, id: id });
|
||||||
|
// this.EXPORTED_SYMBOLS = [factory.name];
|
||||||
|
// } else { // Browser or alike
|
||||||
|
// var globals = this;
|
||||||
|
// factory(function require(id) {
|
||||||
|
// return globals[id];
|
||||||
|
// }, (globals[id] = {}), { uri: document.location.href + '#' + id, id: id });
|
||||||
|
// }
|
||||||
|
//}).call(this, 'promise/core', function Promise(require, exports, module) {
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var exports = exports || {};
|
||||||
|
|
||||||
|
//module.metadata = {
|
||||||
|
// "stability": "unstable"
|
||||||
|
//};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal utility: Wraps given `value` into simplified promise, successfully
|
||||||
|
* fulfilled to a given `value`. Note the result is not a complete promise
|
||||||
|
* implementation, as its method `then` does not returns anything.
|
||||||
|
*/
|
||||||
|
function fulfilled(value) {
|
||||||
|
return { then: function then(fulfill) { fulfill(value); } };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal utility: Wraps given input into simplified promise, pre-rejected
|
||||||
|
* with a given `reason`. Note the result is not a complete promise
|
||||||
|
* implementation, as its method `then` does not returns anything.
|
||||||
|
*/
|
||||||
|
function rejected(reason) {
|
||||||
|
return { then: function then(fulfill, reject) { reject(reason); } };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal utility: Returns `true` if given `value` is a promise. Value is
|
||||||
|
* assumed to be a promise if it implements method `then`.
|
||||||
|
*/
|
||||||
|
function isPromise(value) {
|
||||||
|
return value && typeof(value.then) === 'function';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates deferred object containing fresh promise & methods to either resolve
|
||||||
|
* or reject it. The result is an object with the following properties:
|
||||||
|
* - `promise` Eventual value representation implementing CommonJS [Promises/A]
|
||||||
|
* (http://wiki.commonjs.org/wiki/Promises/A) API.
|
||||||
|
* - `resolve` Single shot function that resolves enclosed `promise` with a
|
||||||
|
* given `value`.
|
||||||
|
* - `reject` Single shot function that rejects enclosed `promise` with a given
|
||||||
|
* `reason`.
|
||||||
|
*
|
||||||
|
* An optional `prototype` argument is used as a prototype of the returned
|
||||||
|
* `promise` allowing one to implement additional API. If prototype is not
|
||||||
|
* passed then it falls back to `Object.prototype`.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* function fetchURI(uri, type) {
|
||||||
|
* var deferred = defer();
|
||||||
|
* var request = new XMLHttpRequest();
|
||||||
|
* request.open("GET", uri, true);
|
||||||
|
* request.responseType = type;
|
||||||
|
* request.onload = function onload() {
|
||||||
|
* deferred.resolve(request.response);
|
||||||
|
* }
|
||||||
|
* request.onerror = function(event) {
|
||||||
|
* deferred.reject(event);
|
||||||
|
* }
|
||||||
|
* request.send();
|
||||||
|
*
|
||||||
|
* return deferred.promise;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
function defer(prototype) {
|
||||||
|
// Define FIFO queue of observer pairs. Once promise is resolved & all queued
|
||||||
|
// observers are forwarded to `result` and variable is set to `null`.
|
||||||
|
var observers = [];
|
||||||
|
|
||||||
|
// Promise `result`, which will be assigned a resolution value once promise
|
||||||
|
// is resolved. Note that result will always be assigned promise (or alike)
|
||||||
|
// object to take care of propagation through promise chains. If result is
|
||||||
|
// `null` promise is not resolved yet.
|
||||||
|
var result = null;
|
||||||
|
|
||||||
|
prototype = (prototype || prototype === null) ? prototype : Object.prototype;
|
||||||
|
|
||||||
|
// Create an object implementing promise API.
|
||||||
|
var promise = Object.create(prototype, {
|
||||||
|
then: { value: function then(onFulfill, onError) {
|
||||||
|
var deferred = defer(prototype);
|
||||||
|
|
||||||
|
function resolve(value) {
|
||||||
|
// If `onFulfill` handler is provided resolve `deferred.promise` with
|
||||||
|
// result of invoking it with a resolution value. If handler is not
|
||||||
|
// provided propagate value through.
|
||||||
|
try {
|
||||||
|
deferred.resolve(onFulfill ? onFulfill(value) : value);
|
||||||
|
}
|
||||||
|
// `onFulfill` may throw exception in which case resulting promise
|
||||||
|
// is rejected with thrown exception.
|
||||||
|
catch(error) {
|
||||||
|
if (exports._reportErrors && typeof(console) === 'object')
|
||||||
|
console.error(error);
|
||||||
|
// Note: Following is equivalent of `deferred.reject(error)`,
|
||||||
|
// we use this shortcut to reduce a stack.
|
||||||
|
deferred.resolve(rejected(error));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function reject(reason) {
|
||||||
|
try {
|
||||||
|
if (onError) deferred.resolve(onError(reason));
|
||||||
|
else deferred.resolve(rejected(reason));
|
||||||
|
}
|
||||||
|
catch(error) {
|
||||||
|
if (exports._reportErrors && typeof(console) === 'object')
|
||||||
|
console.error(error);
|
||||||
|
deferred.resolve(rejected(error));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If enclosed promise (`this.promise`) observers queue is still alive
|
||||||
|
// enqueue a new observer pair into it. Note that this does not
|
||||||
|
// necessary means that promise is pending, it may already be resolved,
|
||||||
|
// but we still have to queue observers to guarantee an order of
|
||||||
|
// propagation.
|
||||||
|
if (observers) {
|
||||||
|
observers.push({ resolve: resolve, reject: reject });
|
||||||
|
}
|
||||||
|
// Otherwise just forward observer pair right to a `result` promise.
|
||||||
|
else {
|
||||||
|
result.then(resolve, reject);
|
||||||
|
}
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
|
}}
|
||||||
|
})
|
||||||
|
|
||||||
|
var deferred = {
|
||||||
|
promise: promise,
|
||||||
|
/**
|
||||||
|
* Resolves associated `promise` to a given `value`, unless it's already
|
||||||
|
* resolved or rejected. Note that resolved promise is not necessary a
|
||||||
|
* successfully fulfilled. Promise may be resolved with a promise `value`
|
||||||
|
* in which case `value` promise's fulfillment / rejection will propagate
|
||||||
|
* up to a promise resolved with `value`.
|
||||||
|
*/
|
||||||
|
resolve: function resolve(value) {
|
||||||
|
if (!result) {
|
||||||
|
// Store resolution `value` in a `result` as a promise, so that all
|
||||||
|
// the subsequent handlers can be simply forwarded to it. Since
|
||||||
|
// `result` will be a promise all the value / error propagation will
|
||||||
|
// be uniformly taken care of.
|
||||||
|
result = isPromise(value) ? value : fulfilled(value);
|
||||||
|
|
||||||
|
// Forward already registered observers to a `result` promise in the
|
||||||
|
// order they were registered. Note that we intentionally dequeue
|
||||||
|
// observer at a time until queue is exhausted. This makes sure that
|
||||||
|
// handlers registered as side effect of observer forwarding are
|
||||||
|
// queued instead of being invoked immediately, guaranteeing FIFO
|
||||||
|
// order.
|
||||||
|
while (observers.length) {
|
||||||
|
var observer = observers.shift();
|
||||||
|
result.then(observer.resolve, observer.reject);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Once `observers` queue is exhausted we `null`-ify it, so that
|
||||||
|
// new handlers are forwarded straight to the `result`.
|
||||||
|
observers = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Rejects associated `promise` with a given `reason`, unless it's already
|
||||||
|
* resolved / rejected. This is just a (better performing) convenience
|
||||||
|
* shortcut for `deferred.resolve(reject(reason))`.
|
||||||
|
*/
|
||||||
|
reject: function reject(reason) {
|
||||||
|
// Note that if promise is resolved that does not necessary means that it
|
||||||
|
// is successfully fulfilled. Resolution value may be a promise in which
|
||||||
|
// case its result propagates. In other words if promise `a` is resolved
|
||||||
|
// with promise `b`, `a` is either fulfilled or rejected depending
|
||||||
|
// on weather `b` is fulfilled or rejected. Here `deferred.promise` is
|
||||||
|
// resolved with a promise pre-rejected with a given `reason`, there for
|
||||||
|
// `deferred.promise` is rejected with a given `reason`. This may feel
|
||||||
|
// little awkward first, but doing it this way greatly simplifies
|
||||||
|
// propagation through promise chains.
|
||||||
|
deferred.resolve(rejected(reason));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return deferred;
|
||||||
|
}
|
||||||
|
exports.defer = defer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a promise resolved to a given `value`. Optionally a second
|
||||||
|
* `prototype` argument may be provided to be used as a prototype for the
|
||||||
|
* returned promise.
|
||||||
|
*/
|
||||||
|
function resolve(value, prototype) {
|
||||||
|
var deferred = defer(prototype);
|
||||||
|
deferred.resolve(value);
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
exports.resolve = resolve;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a promise rejected with a given `reason`. Optionally a second
|
||||||
|
* `prototype` argument may be provided to be used as a prototype for the
|
||||||
|
* returned promise.
|
||||||
|
*/
|
||||||
|
function reject(reason, prototype) {
|
||||||
|
var deferred = defer(prototype);
|
||||||
|
deferred.reject(reason);
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
exports.reject = reject;
|
||||||
|
|
||||||
|
var promised = (function() {
|
||||||
|
// Note: Define shortcuts and utility functions here in order to avoid
|
||||||
|
// slower property accesses and unnecessary closure creations on each
|
||||||
|
// call of this popular function.
|
||||||
|
|
||||||
|
var call = Function.call;
|
||||||
|
var concat = Array.prototype.concat;
|
||||||
|
|
||||||
|
// Utility function that does following:
|
||||||
|
// execute([ f, self, args...]) => f.apply(self, args)
|
||||||
|
function execute(args) { return call.apply(call, args) }
|
||||||
|
|
||||||
|
// Utility function that takes promise of `a` array and maybe promise `b`
|
||||||
|
// as arguments and returns promise for `a.concat(b)`.
|
||||||
|
function promisedConcat(promises, unknown) {
|
||||||
|
return promises.then(function(values) {
|
||||||
|
return resolve(unknown).then(function(value) {
|
||||||
|
return values.concat([ value ]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return function promised(f, prototype) {
|
||||||
|
/**
|
||||||
|
Returns a wrapped `f`, which when called returns a promise that resolves to
|
||||||
|
`f(...)` passing all the given arguments to it, which by the way may be
|
||||||
|
promises. Optionally second `prototype` argument may be provided to be used
|
||||||
|
a prototype for a returned promise.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
var promise = promised(Array)(1, promise(2), promise(3))
|
||||||
|
promise.then(console.log) // => [ 1, 2, 3 ]
|
||||||
|
**/
|
||||||
|
|
||||||
|
return function promised() {
|
||||||
|
// create array of [ f, this, args... ]
|
||||||
|
return concat.apply([ f, this ], arguments).
|
||||||
|
// reduce it via `promisedConcat` to get promised array of fulfillments
|
||||||
|
reduce(promisedConcat, resolve([], prototype)).
|
||||||
|
// finally map that to promise of `f.apply(this, args...)`
|
||||||
|
then(execute);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
exports.promised = promised;
|
||||||
|
//
|
||||||
|
var all = promised(Array);
|
||||||
|
exports.all = all;
|
||||||
|
//
|
||||||
|
//});
|
|
@ -0,0 +1,928 @@
|
||||||
|
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
/**
|
||||||
|
* Toolkit glue for the remote debugging protocol, loaded into the
|
||||||
|
* debugging global.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//const Ci = Components.interfaces;
|
||||||
|
//const Cc = Components.classes;
|
||||||
|
//const CC = Components.Constructor;
|
||||||
|
//const Cu = Components.utils;
|
||||||
|
//const Cr = Components.results;
|
||||||
|
//const DBG_STRINGS_URI = "chrome://global/locale/devtools/debugger.properties";
|
||||||
|
//
|
||||||
|
//Cu.import("resource://gre/modules/Services.jsm");
|
||||||
|
//Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
|
//let wantLogging = Services.prefs.getBoolPref("devtools.debugger.log");
|
||||||
|
//
|
||||||
|
//Cu.import("resource://gre/modules/jsdebugger.jsm");
|
||||||
|
//addDebuggerToGlobal(this);
|
||||||
|
//
|
||||||
|
//Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
|
||||||
|
//const { defer, resolve, reject, all } = Promise;
|
||||||
|
//
|
||||||
|
//Cu.import("resource://gre/modules/devtools/SourceMap.jsm");
|
||||||
|
//
|
||||||
|
//loadSubScript.call(this, "resource://gre/modules/devtools/DevToolsUtils.js");
|
||||||
|
|
||||||
|
let wantLogging = true;
|
||||||
|
let debuggerServer = null;
|
||||||
|
|
||||||
|
function dumpn(str) {
|
||||||
|
if (wantLogging) {
|
||||||
|
log("DBG-SERVER: " + str + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function dbg_assert(cond, e) {
|
||||||
|
if (!cond) {
|
||||||
|
log("assert >>>> " + cond.toString());
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function XPCInspector() {
|
||||||
|
this.exitNestedEventLoop = _exitNestedEventLoop;
|
||||||
|
this.enterNestedEventLoop = _enterNestedEventLoop;
|
||||||
|
this.eventLoopNestLevel = _getEventLoopNestLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
//loadSubScript.call(this, "resource://gre/modules/devtools/server/transport.js");
|
||||||
|
|
||||||
|
// XPCOM constructors
|
||||||
|
// const ServerSocket = CC("@mozilla.org/network/server-socket;1",
|
||||||
|
// "nsIServerSocket",
|
||||||
|
// "initSpecialConnection");
|
||||||
|
|
||||||
|
function ServerSocket(aPort, flags, c){
|
||||||
|
this.asyncListen = function(server){
|
||||||
|
log("asyncListen....");
|
||||||
|
debuggerServer = server;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
var gRegisteredModules = Object.create(null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ModuleAPI object is passed to modules loaded using the
|
||||||
|
* DebuggerServer.registerModule() API. Modules can use this
|
||||||
|
* object to register actor factories.
|
||||||
|
* Factories registered through the module API will be removed
|
||||||
|
* when the module is unregistered or when the server is
|
||||||
|
* destroyed.
|
||||||
|
*/
|
||||||
|
function ModuleAPI() {
|
||||||
|
let activeTabActors = new Set();
|
||||||
|
let activeGlobalActors = new Set();
|
||||||
|
|
||||||
|
return {
|
||||||
|
// See DebuggerServer.addGlobalActor for a description.
|
||||||
|
addGlobalActor: function(factory, name) {
|
||||||
|
DebuggerServer.addGlobalActor(factory, name);
|
||||||
|
activeGlobalActors.add(factory);
|
||||||
|
},
|
||||||
|
// See DebuggerServer.removeGlobalActor for a description.
|
||||||
|
removeGlobalActor: function(factory) {
|
||||||
|
DebuggerServer.removeGlobalActor(factory);
|
||||||
|
activeGlobalActors.delete(factory);
|
||||||
|
},
|
||||||
|
|
||||||
|
// See DebuggerServer.addTabActor for a description.
|
||||||
|
addTabActor: function(factory, name) {
|
||||||
|
DebuggerServer.addTabActor(factory, name);
|
||||||
|
activeTabActors.add(factory);
|
||||||
|
},
|
||||||
|
// See DebuggerServer.removeTabActor for a description.
|
||||||
|
removeTabActor: function(factory) {
|
||||||
|
DebuggerServer.removeTabActor(factory);
|
||||||
|
activeTabActors.delete(factory);
|
||||||
|
},
|
||||||
|
|
||||||
|
// Destroy the module API object, unregistering any
|
||||||
|
// factories registered by the module.
|
||||||
|
destroy: function() {
|
||||||
|
for (let factory of activeTabActors) {
|
||||||
|
DebuggerServer.removeTabActor(factory);
|
||||||
|
}
|
||||||
|
activeTabActors = null;
|
||||||
|
for (let factory of activeGlobalActors) {
|
||||||
|
DebuggerServer.removeGlobalActor(factory);
|
||||||
|
}
|
||||||
|
activeGlobalActors = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Public API
|
||||||
|
*/
|
||||||
|
var DebuggerServer = {
|
||||||
|
_listener: null,
|
||||||
|
_initialized: false,
|
||||||
|
_transportInitialized: false,
|
||||||
|
xpcInspector: null,
|
||||||
|
_transport: null,
|
||||||
|
// Number of currently open TCP connections.
|
||||||
|
_socketConnections: 0,
|
||||||
|
// Map of global actor names to actor constructors provided by extensions.
|
||||||
|
globalActorFactories: {},
|
||||||
|
// Map of tab actor names to actor constructors provided by extensions.
|
||||||
|
tabActorFactories: {},
|
||||||
|
|
||||||
|
LONG_STRING_LENGTH: 10000,
|
||||||
|
LONG_STRING_INITIAL_LENGTH: 1000,
|
||||||
|
LONG_STRING_READ_LENGTH: 1000,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A handler function that prompts the user to accept or decline the incoming
|
||||||
|
* connection.
|
||||||
|
*/
|
||||||
|
_allowConnection: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prompt the user to accept or decline the incoming connection. This is the
|
||||||
|
* default implementation that products embedding the debugger server may
|
||||||
|
* choose to override.
|
||||||
|
*
|
||||||
|
* @return true if the connection should be permitted, false otherwise
|
||||||
|
*/
|
||||||
|
_defaultAllowConnection: function DS__defaultAllowConnection() {
|
||||||
|
// let title = L10N.getStr("remoteIncomingPromptTitle");
|
||||||
|
// let msg = L10N.getStr("remoteIncomingPromptMessage");
|
||||||
|
// let disableButton = L10N.getStr("remoteIncomingPromptDisable");
|
||||||
|
// let prompt = Services.prompt;
|
||||||
|
// let flags = prompt.BUTTON_POS_0 * prompt.BUTTON_TITLE_OK +
|
||||||
|
// prompt.BUTTON_POS_1 * prompt.BUTTON_TITLE_CANCEL +
|
||||||
|
// prompt.BUTTON_POS_2 * prompt.BUTTON_TITLE_IS_STRING +
|
||||||
|
// prompt.BUTTON_POS_1_DEFAULT;
|
||||||
|
// let result = prompt.confirmEx(null, title, msg, flags, null, null,
|
||||||
|
// disableButton, null, { value: false });
|
||||||
|
// if (result == 0) {
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// if (result == 2) {
|
||||||
|
// DebuggerServer.closeListener(true);
|
||||||
|
// Services.prefs.setBoolPref("devtools.debugger.remote-enabled", false);
|
||||||
|
// }
|
||||||
|
// return false;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the debugger server.
|
||||||
|
*
|
||||||
|
* @param function aAllowConnectionCallback
|
||||||
|
* The embedder-provider callback, that decides whether an incoming
|
||||||
|
* remote protocol conection should be allowed or refused.
|
||||||
|
*/
|
||||||
|
init: function DS_init(aAllowConnectionCallback) {
|
||||||
|
if (this.initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.xpcInspector = new XPCInspector();//Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector);
|
||||||
|
this.initTransport(aAllowConnectionCallback);
|
||||||
|
this.addActors("resource://gre/modules/devtools/server/actors/root.js");
|
||||||
|
|
||||||
|
this._initialized = true;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the debugger server's transport variables. This can be
|
||||||
|
* in place of init() for cases where the jsdebugger isn't needed.
|
||||||
|
*
|
||||||
|
* @param function aAllowConnectionCallback
|
||||||
|
* The embedder-provider callback, that decides whether an incoming
|
||||||
|
* remote protocol conection should be allowed or refused.
|
||||||
|
*/
|
||||||
|
initTransport: function DS_initTransport(aAllowConnectionCallback) {
|
||||||
|
if (this._transportInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._connections = {};
|
||||||
|
this._nextConnID = 0;
|
||||||
|
this._transportInitialized = true;
|
||||||
|
this._allowConnection = aAllowConnectionCallback ?
|
||||||
|
aAllowConnectionCallback :
|
||||||
|
this._defaultAllowConnection;
|
||||||
|
},
|
||||||
|
|
||||||
|
get initialized() this._initialized,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs cleanup tasks before shutting down the debugger server, if no
|
||||||
|
* connections are currently open. Such tasks include clearing any actor
|
||||||
|
* constructors added at runtime. This method should be called whenever a
|
||||||
|
* debugger server is no longer useful, to avoid memory leaks. After this
|
||||||
|
* method returns, the debugger server must be initialized again before use.
|
||||||
|
*/
|
||||||
|
destroy: function DS_destroy() {
|
||||||
|
if (!this._initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let connID of Object.getOwnPropertyNames(this._connections)) {
|
||||||
|
this._connections[connID].close();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let id of Object.getOwnPropertyNames(gRegisteredModules)) {
|
||||||
|
let mod = gRegisteredModules[id];
|
||||||
|
mod.module.unregister(mod.api);
|
||||||
|
}
|
||||||
|
gRegisteredModules = {};
|
||||||
|
|
||||||
|
this.closeListener();
|
||||||
|
this.globalActorFactories = {};
|
||||||
|
this.tabActorFactories = {};
|
||||||
|
delete this._allowConnection;
|
||||||
|
this._transportInitialized = false;
|
||||||
|
this._initialized = false;
|
||||||
|
dumpn("Debugger server is shut down.");
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a subscript into the debugging global.
|
||||||
|
*
|
||||||
|
* @param aURL string A url that will be loaded as a subscript into the
|
||||||
|
* debugging global. The user must load at least one script
|
||||||
|
* that implements a createRootActor() function to create the
|
||||||
|
* server's root actor.
|
||||||
|
*/
|
||||||
|
addActors: function DS_addActors(aURL) {
|
||||||
|
//loadSubScript.call(this, aURL);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a CommonJS module with the debugger server.
|
||||||
|
* @param id string
|
||||||
|
* The ID of a CommonJS module. This module must export
|
||||||
|
* 'register' and 'unregister' functions.
|
||||||
|
*/
|
||||||
|
registerModule: function(id) {
|
||||||
|
if (id in gRegisteredModules) {
|
||||||
|
throw new Error("Tried to register a module twice: " + id + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
let moduleAPI = ModuleAPI();
|
||||||
|
|
||||||
|
let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
|
||||||
|
let mod = devtools.require(id);
|
||||||
|
mod.register(moduleAPI);
|
||||||
|
gRegisteredModules[id] = { module: mod, api: moduleAPI };
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if a module id has been registered.
|
||||||
|
*/
|
||||||
|
isModuleRegistered: function(id) {
|
||||||
|
return (id in gRegisteredModules);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregister a previously-loaded CommonJS module from the debugger server.
|
||||||
|
*/
|
||||||
|
unregisterModule: function(id) {
|
||||||
|
let mod = gRegisteredModules[id];
|
||||||
|
if (!mod) {
|
||||||
|
throw new Error("Tried to unregister a module that was not previously registered.");
|
||||||
|
}
|
||||||
|
mod.module.unregister(mod.api);
|
||||||
|
mod.api.destroy();
|
||||||
|
delete gRegisteredModules[id];
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install Firefox-specific actors.
|
||||||
|
*/
|
||||||
|
addBrowserActors: function DS_addBrowserActors() {
|
||||||
|
this.addActors("resource://gre/modules/devtools/server/actors/webbrowser.js");
|
||||||
|
this.addActors("resource://gre/modules/devtools/server/actors/script.js");
|
||||||
|
this.addGlobalActor(this.ChromeDebuggerActor, "chromeDebugger");
|
||||||
|
this.addActors("resource://gre/modules/devtools/server/actors/webconsole.js");
|
||||||
|
this.addActors("resource://gre/modules/devtools/server/actors/gcli.js");
|
||||||
|
if ("nsIProfiler" in Ci)
|
||||||
|
this.addActors("resource://gre/modules/devtools/server/actors/profiler.js");
|
||||||
|
|
||||||
|
this.addActors("resource://gre/modules/devtools/server/actors/styleeditor.js");
|
||||||
|
this.addActors("resource://gre/modules/devtools/server/actors/webapps.js");
|
||||||
|
this.registerModule("devtools/server/actors/inspector");
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listens on the given port for remote debugger connections.
|
||||||
|
*
|
||||||
|
* @param aPort int
|
||||||
|
* The port to listen on.
|
||||||
|
*/
|
||||||
|
openListener: function DS_openListener(aPort) {
|
||||||
|
// if (!Services.prefs.getBoolPref("devtools.debugger.remote-enabled")) {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
this._checkInit();
|
||||||
|
|
||||||
|
// Return early if the server is already listening.
|
||||||
|
if (this._listener) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// let flags = Ci.nsIServerSocket.KeepWhenOffline;
|
||||||
|
// A preference setting can force binding on the loopback interface.
|
||||||
|
// if (Services.prefs.getBoolPref("devtools.debugger.force-local")) {
|
||||||
|
// flags |= Ci.nsIServerSocket.LoopbackOnly;
|
||||||
|
// }
|
||||||
|
|
||||||
|
let flags = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let socket = new ServerSocket(aPort, flags, 4);
|
||||||
|
socket.asyncListen(this);
|
||||||
|
this._listener = socket;
|
||||||
|
} catch (e) {
|
||||||
|
dumpn("Could not start debugging listener on port " + aPort + ": " + e);
|
||||||
|
throw "Cr.NS_ERROR_NOT_AVAILABLE";
|
||||||
|
}
|
||||||
|
this._socketConnections++;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close a previously-opened TCP listener.
|
||||||
|
*
|
||||||
|
* @param aForce boolean [optional]
|
||||||
|
* If set to true, then the socket will be closed, regardless of the
|
||||||
|
* number of open connections.
|
||||||
|
*/
|
||||||
|
closeListener: function DS_closeListener(aForce) {
|
||||||
|
if (!this._listener || this._socketConnections == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only close the listener when the last connection is closed, or if the
|
||||||
|
// aForce flag is passed.
|
||||||
|
if (--this._socketConnections == 0 || aForce) {
|
||||||
|
this._listener.close();
|
||||||
|
this._listener = null;
|
||||||
|
this._socketConnections = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new connection to the local debugger speaking over a fake
|
||||||
|
* transport. This connection results in straightforward calls to the onPacket
|
||||||
|
* handlers of each side.
|
||||||
|
*
|
||||||
|
* @returns a client-side DebuggerTransport for communicating with
|
||||||
|
* the newly-created connection.
|
||||||
|
*/
|
||||||
|
connectPipe: function DS_connectPipe() {
|
||||||
|
this._checkInit();
|
||||||
|
|
||||||
|
let serverTransport = new LocalDebuggerTransport;
|
||||||
|
let clientTransport = new LocalDebuggerTransport(serverTransport);
|
||||||
|
serverTransport.other = clientTransport;
|
||||||
|
let connection = this._onConnection(serverTransport);
|
||||||
|
|
||||||
|
// I'm putting this here because I trust you.
|
||||||
|
//
|
||||||
|
// There are times, when using a local connection, when you're going
|
||||||
|
// to be tempted to just get direct access to the server. Resist that
|
||||||
|
// temptation! If you succumb to that temptation, you will make the
|
||||||
|
// fine developers that work on Fennec and Firefox OS sad. They're
|
||||||
|
// professionals, they'll try to act like they understand, but deep
|
||||||
|
// down you'll know that you hurt them.
|
||||||
|
//
|
||||||
|
// This reference allows you to give in to that temptation. There are
|
||||||
|
// times this makes sense: tests, for example, and while porting a
|
||||||
|
// previously local-only codebase to the remote protocol.
|
||||||
|
//
|
||||||
|
// But every time you use this, you will feel the shame of having
|
||||||
|
// used a property that starts with a '_'.
|
||||||
|
clientTransport._serverConnection = connection;
|
||||||
|
|
||||||
|
return clientTransport;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// nsIServerSocketListener implementation
|
||||||
|
|
||||||
|
onSocketAccepted:
|
||||||
|
makeInfallible(function DS_onSocketAccepted(aSocket, aTransport) {
|
||||||
|
if (!this._allowConnection()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dumpn("New debugging connection on " + aTransport.host + ":" + aTransport.port);
|
||||||
|
|
||||||
|
let input = aTransport.openInputStream(0, 0, 0);
|
||||||
|
let output = aTransport.openOutputStream(0, 0, 0);
|
||||||
|
let transport = new DebuggerTransport(input, output);
|
||||||
|
DebuggerServer._onConnection(transport);
|
||||||
|
}, "DebuggerServer.onSocketAccepted"),
|
||||||
|
|
||||||
|
onStopListening: function DS_onStopListening(aSocket, status) {
|
||||||
|
dumpn("onStopListening, status: " + status);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Raises an exception if the server has not been properly initialized.
|
||||||
|
*/
|
||||||
|
_checkInit: function DS_checkInit() {
|
||||||
|
if (!this._transportInitialized) {
|
||||||
|
throw "DebuggerServer has not been initialized.";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.createRootActor) {
|
||||||
|
throw "Use DebuggerServer.addActors() to add a root actor implementation.";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new debugger connection for the given transport. Called
|
||||||
|
* after connectPipe() or after an incoming socket connection.
|
||||||
|
*/
|
||||||
|
_onConnection: function DS_onConnection(aTransport) {
|
||||||
|
log("DebuggerServer._onConnection....");
|
||||||
|
|
||||||
|
this._transport = aTransport;
|
||||||
|
|
||||||
|
let connID = "conn" + this._nextConnID++ + '.';
|
||||||
|
let conn = new DebuggerServerConnection(connID, aTransport);
|
||||||
|
this._connections[connID] = conn;
|
||||||
|
|
||||||
|
// Create a root actor for the connection and send the hello packet.
|
||||||
|
conn.rootActor = this.createRootActor(conn);
|
||||||
|
conn.addActor(conn.rootActor);
|
||||||
|
|
||||||
|
aTransport.send(conn.rootActor.sayHello());
|
||||||
|
aTransport.ready();
|
||||||
|
|
||||||
|
return conn;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the connection from the debugging server.
|
||||||
|
*/
|
||||||
|
_connectionClosed: function DS_connectionClosed(aConnection) {
|
||||||
|
delete this._connections[aConnection.prefix];
|
||||||
|
},
|
||||||
|
|
||||||
|
// DebuggerServer extension API.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers handlers for new tab-scoped request types defined dynamically.
|
||||||
|
* This is used for example by add-ons to augment the functionality of the tab
|
||||||
|
* actor. Note that the name or actorPrefix of the request type is not allowed
|
||||||
|
* to clash with existing protocol packet properties, like 'title', 'url' or
|
||||||
|
* 'actor', since that would break the protocol.
|
||||||
|
*
|
||||||
|
* @param aFunction function
|
||||||
|
* The constructor function for this request type. This expects to be
|
||||||
|
* called as a constructor (i.e. with 'new'), and passed two
|
||||||
|
* arguments: the DebuggerServerConnection, and the BrowserTabActor
|
||||||
|
* with which it will be associated.
|
||||||
|
*
|
||||||
|
* @param aName string [optional]
|
||||||
|
* The name of the new request type. If this is not present, the
|
||||||
|
* actorPrefix property of the constructor prototype is used.
|
||||||
|
*/
|
||||||
|
addTabActor: function DS_addTabActor(aFunction, aName) {
|
||||||
|
let name = aName ? aName : aFunction.prototype.actorPrefix;
|
||||||
|
if (["title", "url", "actor"].indexOf(name) != -1) {
|
||||||
|
throw Error(name + " is not allowed");
|
||||||
|
}
|
||||||
|
if (DebuggerServer.tabActorFactories.hasOwnProperty(name)) {
|
||||||
|
throw Error(name + " already exists");
|
||||||
|
}
|
||||||
|
DebuggerServer.tabActorFactories[name] = aFunction;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregisters the handler for the specified tab-scoped request type.
|
||||||
|
* This may be used for example by add-ons when shutting down or upgrading.
|
||||||
|
*
|
||||||
|
* @param aFunction function
|
||||||
|
* The constructor function for this request type.
|
||||||
|
*/
|
||||||
|
removeTabActor: function DS_removeTabActor(aFunction) {
|
||||||
|
for (let name in DebuggerServer.tabActorFactories) {
|
||||||
|
let handler = DebuggerServer.tabActorFactories[name];
|
||||||
|
if (handler.name == aFunction.name) {
|
||||||
|
delete DebuggerServer.tabActorFactories[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers handlers for new browser-scoped request types defined
|
||||||
|
* dynamically. This is used for example by add-ons to augment the
|
||||||
|
* functionality of the root actor. Note that the name or actorPrefix of the
|
||||||
|
* request type is not allowed to clash with existing protocol packet
|
||||||
|
* properties, like 'from', 'tabs' or 'selected', since that would break the
|
||||||
|
* protocol.
|
||||||
|
*
|
||||||
|
* @param aFunction function
|
||||||
|
* The constructor function for this request type. This expects to be
|
||||||
|
* called as a constructor (i.e. with 'new'), and passed two
|
||||||
|
* arguments: the DebuggerServerConnection, and the BrowserRootActor
|
||||||
|
* with which it will be associated.
|
||||||
|
*
|
||||||
|
* @param aName string [optional]
|
||||||
|
* The name of the new request type. If this is not present, the
|
||||||
|
* actorPrefix property of the constructor prototype is used.
|
||||||
|
*/
|
||||||
|
addGlobalActor: function DS_addGlobalActor(aFunction, aName) {
|
||||||
|
let name = aName ? aName : aFunction.prototype.actorPrefix;
|
||||||
|
if (["from", "tabs", "selected"].indexOf(name) != -1) {
|
||||||
|
throw Error(name + " is not allowed");
|
||||||
|
}
|
||||||
|
if (DebuggerServer.globalActorFactories.hasOwnProperty(name)) {
|
||||||
|
throw Error(name + " already exists");
|
||||||
|
}
|
||||||
|
DebuggerServer.globalActorFactories[name] = aFunction;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregisters the handler for the specified browser-scoped request type.
|
||||||
|
* This may be used for example by add-ons when shutting down or upgrading.
|
||||||
|
*
|
||||||
|
* @param aFunction function
|
||||||
|
* The constructor function for this request type.
|
||||||
|
*/
|
||||||
|
removeGlobalActor: function DS_removeGlobalActor(aFunction) {
|
||||||
|
for (let name in DebuggerServer.globalActorFactories) {
|
||||||
|
let handler = DebuggerServer.globalActorFactories[name];
|
||||||
|
if (handler.name == aFunction.name) {
|
||||||
|
delete DebuggerServer.globalActorFactories[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct an ActorPool.
|
||||||
|
*
|
||||||
|
* ActorPools are actorID -> actor mapping and storage. These are
|
||||||
|
* used to accumulate and quickly dispose of groups of actors that
|
||||||
|
* share a lifetime.
|
||||||
|
*/
|
||||||
|
function ActorPool(aConnection)
|
||||||
|
{
|
||||||
|
this.conn = aConnection;
|
||||||
|
this._cleanups = {};
|
||||||
|
this._actors = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
ActorPool.prototype = {
|
||||||
|
/**
|
||||||
|
* Add an actor to the actor pool. If the actor doesn't have an ID,
|
||||||
|
* allocate one from the connection.
|
||||||
|
*
|
||||||
|
* @param aActor object
|
||||||
|
* The actor implementation. If the object has a
|
||||||
|
* 'disconnect' property, it will be called when the actor
|
||||||
|
* pool is cleaned up.
|
||||||
|
*/
|
||||||
|
addActor: function AP_addActor(aActor) {
|
||||||
|
aActor.conn = this.conn;
|
||||||
|
if (!aActor.actorID) {
|
||||||
|
let prefix = aActor.actorPrefix;
|
||||||
|
if (typeof aActor == "function") {
|
||||||
|
prefix = aActor.prototype.actorPrefix;
|
||||||
|
}
|
||||||
|
aActor.actorID = this.conn.allocID(prefix || undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aActor.registeredPool) {
|
||||||
|
aActor.registeredPool.removeActor(aActor);
|
||||||
|
}
|
||||||
|
aActor.registeredPool = this;
|
||||||
|
|
||||||
|
this._actors[aActor.actorID] = aActor;
|
||||||
|
if (aActor.disconnect) {
|
||||||
|
this._cleanups[aActor.actorID] = aActor;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
get: function AP_get(aActorID) {
|
||||||
|
return this._actors[aActorID];
|
||||||
|
},
|
||||||
|
|
||||||
|
has: function AP_has(aActorID) {
|
||||||
|
return aActorID in this._actors;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the pool is empty.
|
||||||
|
*/
|
||||||
|
isEmpty: function AP_isEmpty() {
|
||||||
|
return Object.keys(this._actors).length == 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove an actor from the actor pool.
|
||||||
|
*/
|
||||||
|
removeActor: function AP_remove(aActor) {
|
||||||
|
delete this._actors[aActor.actorID];
|
||||||
|
delete this._cleanups[aActor.actorID];
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Match the api expected by the protocol library.
|
||||||
|
*/
|
||||||
|
unmanage: function(aActor) {
|
||||||
|
return this.removeActor(aActor);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run all actor cleanups.
|
||||||
|
*/
|
||||||
|
cleanup: function AP_cleanup() {
|
||||||
|
for each (let actor in this._cleanups) {
|
||||||
|
actor.disconnect();
|
||||||
|
}
|
||||||
|
this._cleanups = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a DebuggerServerConnection.
|
||||||
|
*
|
||||||
|
* Represents a connection to this debugging global from a client.
|
||||||
|
* Manages a set of actors and actor pools, allocates actor ids, and
|
||||||
|
* handles incoming requests.
|
||||||
|
*
|
||||||
|
* @param aPrefix string
|
||||||
|
* All actor IDs created by this connection should be prefixed
|
||||||
|
* with aPrefix.
|
||||||
|
* @param aTransport transport
|
||||||
|
* Packet transport for the debugging protocol.
|
||||||
|
*/
|
||||||
|
function DebuggerServerConnection(aPrefix, aTransport)
|
||||||
|
{
|
||||||
|
this._prefix = aPrefix;
|
||||||
|
this._transport = aTransport;
|
||||||
|
this._transport.hooks = this;
|
||||||
|
this._nextID = 1;
|
||||||
|
|
||||||
|
this._actorPool = new ActorPool(this);
|
||||||
|
this._extraPools = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
DebuggerServerConnection.prototype = {
|
||||||
|
_prefix: null,
|
||||||
|
get prefix() { return this._prefix },
|
||||||
|
|
||||||
|
_transport: null,
|
||||||
|
get transport() { return this._transport },
|
||||||
|
|
||||||
|
close: function() {
|
||||||
|
this._transport.close();
|
||||||
|
},
|
||||||
|
|
||||||
|
send: function DSC_send(aPacket) {
|
||||||
|
this.transport.send(aPacket);
|
||||||
|
},
|
||||||
|
|
||||||
|
allocID: function DSC_allocID(aPrefix) {
|
||||||
|
return this.prefix + (aPrefix || '') + this._nextID++;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a map of actor IDs to the connection.
|
||||||
|
*/
|
||||||
|
addActorPool: function DSC_addActorPool(aActorPool) {
|
||||||
|
this._extraPools.push(aActorPool);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a previously-added pool of actors to the connection.
|
||||||
|
*
|
||||||
|
* @param ActorPool aActorPool
|
||||||
|
* The ActorPool instance you want to remove.
|
||||||
|
* @param boolean aCleanup
|
||||||
|
* True if you want to disconnect each actor from the pool, false
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
removeActorPool: function DSC_removeActorPool(aActorPool, aCleanup) {
|
||||||
|
let index = this._extraPools.lastIndexOf(aActorPool);
|
||||||
|
if (index > -1) {
|
||||||
|
let pool = this._extraPools.splice(index, 1);
|
||||||
|
if (aCleanup) {
|
||||||
|
pool.map(function(p) { p.cleanup(); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an actor to the default actor pool for this connection.
|
||||||
|
*/
|
||||||
|
addActor: function DSC_addActor(aActor) {
|
||||||
|
this._actorPool.addActor(aActor);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove an actor to the default actor pool for this connection.
|
||||||
|
*/
|
||||||
|
removeActor: function DSC_removeActor(aActor) {
|
||||||
|
this._actorPool.removeActor(aActor);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Match the api expected by the protocol library.
|
||||||
|
*/
|
||||||
|
unmanage: function(aActor) {
|
||||||
|
return this.removeActor(aActor);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Look up an actor implementation for an actorID. Will search
|
||||||
|
* all the actor pools registered with the connection.
|
||||||
|
*
|
||||||
|
* @param aActorID string
|
||||||
|
* Actor ID to look up.
|
||||||
|
*/
|
||||||
|
getActor: function DSC_getActor(aActorID) {
|
||||||
|
let pool = this.poolFor(aActorID);
|
||||||
|
if (pool) {
|
||||||
|
return pool.get(aActorID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aActorID === "root") {
|
||||||
|
return this.rootActor;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
|
poolFor: function DSC_actorPool(aActorID) {
|
||||||
|
if (this._actorPool && this._actorPool.has(aActorID)) {
|
||||||
|
return this._actorPool;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let pool of this._extraPools) {
|
||||||
|
if (pool.has(aActorID)) {
|
||||||
|
return pool;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
|
_unknownError: function DSC__unknownError(aPrefix, aError) {
|
||||||
|
let errorString = safeErrorString(aError);
|
||||||
|
errorString += "\n" + aError.stack;
|
||||||
|
// Cu.reportError(errorString);
|
||||||
|
dumpn(errorString);
|
||||||
|
return {
|
||||||
|
error: "unknownError",
|
||||||
|
message: (aPrefix + "': " + errorString)
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
// Transport hooks.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by DebuggerTransport to dispatch incoming packets as appropriate.
|
||||||
|
*
|
||||||
|
* @param aPacket object
|
||||||
|
* The incoming packet.
|
||||||
|
*/
|
||||||
|
onPacket: function DSC_onPacket(aPacket) {
|
||||||
|
let actor = this.getActor(aPacket.to);
|
||||||
|
if (!actor) {
|
||||||
|
this.transport.send({ from: aPacket.to ? aPacket.to : "root",
|
||||||
|
error: "noSuchActor" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dyamically-loaded actors have to be created lazily.
|
||||||
|
if (typeof actor == "function") {
|
||||||
|
let instance;
|
||||||
|
try {
|
||||||
|
instance = new actor();
|
||||||
|
} catch (e) {
|
||||||
|
this.transport.send(this._unknownError(
|
||||||
|
"Error occurred while creating actor '" + actor.name,
|
||||||
|
e));
|
||||||
|
}
|
||||||
|
instance.parentID = actor.parentID;
|
||||||
|
// We want the newly-constructed actor to completely replace the factory
|
||||||
|
// actor. Reusing the existing actor ID will make sure ActorPool.addActor
|
||||||
|
// does the right thing.
|
||||||
|
instance.actorID = actor.actorID;
|
||||||
|
actor.registeredPool.addActor(instance);
|
||||||
|
actor = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ret = null;
|
||||||
|
// log("actor.requestTypes: "+actor.requestTypes+", cb: "+actor.requestTypes[aPacket.type]);
|
||||||
|
// Dispatch the request to the actor.
|
||||||
|
if (actor.requestTypes && actor.requestTypes[aPacket.type]) {
|
||||||
|
try {
|
||||||
|
this.currentPacket = aPacket;
|
||||||
|
ret = actor.requestTypes[aPacket.type].bind(actor)(aPacket, this);
|
||||||
|
} catch(e) {
|
||||||
|
this.transport.send(this._unknownError(
|
||||||
|
"error occurred while processing '" + aPacket.type,
|
||||||
|
e));
|
||||||
|
} finally {
|
||||||
|
delete this.currentPacket;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret = { error: "unrecognizedPacketType",
|
||||||
|
message: ('Actor "' + actor.actorID +
|
||||||
|
'" does not recognize the packet type "' +
|
||||||
|
aPacket.type + '"') };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
// This should become an error once we've converted every user
|
||||||
|
// of this to promises in bug 794078.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(ret)
|
||||||
|
.then(null, (e) => {
|
||||||
|
return this._unknownError(
|
||||||
|
"error occurred while processing '" + aPacket.type,
|
||||||
|
e);
|
||||||
|
})
|
||||||
|
.then(function (aResponse) {
|
||||||
|
if (!aResponse.from) {
|
||||||
|
aResponse.from = aPacket.to;
|
||||||
|
}
|
||||||
|
return aResponse;
|
||||||
|
})
|
||||||
|
.then(this.transport.send.bind(this.transport));
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by DebuggerTransport when the underlying stream is closed.
|
||||||
|
*
|
||||||
|
* @param aStatus nsresult
|
||||||
|
* The status code that corresponds to the reason for closing
|
||||||
|
* the stream.
|
||||||
|
*/
|
||||||
|
onClosed: function DSC_onClosed(aStatus) {
|
||||||
|
dumpn("Cleaning up connection.");
|
||||||
|
|
||||||
|
this._actorPool.cleanup();
|
||||||
|
this._actorPool = null;
|
||||||
|
this._extraPools.map(function(p) { p.cleanup(); });
|
||||||
|
this._extraPools = null;
|
||||||
|
|
||||||
|
DebuggerServer._connectionClosed(this);
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Debugging helper for inspecting the state of the actor pools.
|
||||||
|
*/
|
||||||
|
_dumpPools: function DSC_dumpPools() {
|
||||||
|
dumpn("/-------------------- dumping pools:");
|
||||||
|
if (this._actorPool) {
|
||||||
|
dumpn("--------------------- actorPool actors: " +
|
||||||
|
uneval(Object.keys(this._actorPool._actors)));
|
||||||
|
}
|
||||||
|
for each (let pool in this._extraPools)
|
||||||
|
dumpn("--------------------- extraPool actors: " +
|
||||||
|
uneval(Object.keys(pool._actors)));
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Debugging helper for inspecting the state of an actor pool.
|
||||||
|
*/
|
||||||
|
_dumpPool: function DSC_dumpPools(aPool) {
|
||||||
|
dumpn("/-------------------- dumping pool:");
|
||||||
|
dumpn("--------------------- actorPool actors: " +
|
||||||
|
uneval(Object.keys(aPool._actors)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Localization convenience methods.
|
||||||
|
*/
|
||||||
|
// let L10N = {
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * L10N shortcut function.
|
||||||
|
// *
|
||||||
|
// * @param string aName
|
||||||
|
// * @return string
|
||||||
|
// */
|
||||||
|
// getStr: function L10N_getStr(aName) {
|
||||||
|
// return this.stringBundle.GetStringFromName(aName);
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// XPCOMUtils.defineLazyGetter(L10N, "stringBundle", function() {
|
||||||
|
// return Services.strings.createBundle(DBG_STRINGS_URI);
|
||||||
|
// });
|
|
@ -0,0 +1,288 @@
|
||||||
|
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
// Components.utils.import("resource://gre/modules/NetUtil.jsm");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An adapter that handles data transfers between the debugger client and
|
||||||
|
* server. It can work with both nsIPipe and nsIServerSocket transports so
|
||||||
|
* long as the properly created input and output streams are specified.
|
||||||
|
*
|
||||||
|
* @param aInput nsIInputStream
|
||||||
|
* The input stream.
|
||||||
|
* @param aOutput nsIAsyncOutputStream
|
||||||
|
* The output stream.
|
||||||
|
*
|
||||||
|
* Given a DebuggerTransport instance dt:
|
||||||
|
* 1) Set dt.hooks to a packet handler object (described below).
|
||||||
|
* 2) Call dt.ready() to begin watching for input packets.
|
||||||
|
* 3) Send packets as you please, and handle incoming packets passed to
|
||||||
|
* hook.onPacket.
|
||||||
|
* 4) Call dt.close() to close the connection, and disengage from the event
|
||||||
|
* loop.
|
||||||
|
*
|
||||||
|
* A packet handler object is an object with two methods:
|
||||||
|
*
|
||||||
|
* - onPacket(packet) - called when we have received a complete packet.
|
||||||
|
* |Packet| is the parsed form of the packet --- a JavaScript value, not
|
||||||
|
* a JSON-syntax string.
|
||||||
|
*
|
||||||
|
* - onClosed(status) - called when the connection is closed. |Status| is
|
||||||
|
* an nsresult, of the sort passed to nsIRequestObserver.
|
||||||
|
*
|
||||||
|
* Data is transferred as a JSON packet serialized into a string, with the
|
||||||
|
* string length prepended to the packet, followed by a colon
|
||||||
|
* ([length]:[packet]). The contents of the JSON packet are specified in
|
||||||
|
* the Remote Debugging Protocol specification.
|
||||||
|
*/
|
||||||
|
this.DebuggerTransport = function DebuggerTransport(aInput, aOutput)
|
||||||
|
{
|
||||||
|
this._input = aInput;
|
||||||
|
this._output = aOutput;
|
||||||
|
|
||||||
|
this._converter = null;//Cc["@mozilla.org/intl/scriptableunicodeconverter"]
|
||||||
|
// .createInstance(Ci.nsIScriptableUnicodeConverter);
|
||||||
|
// this._converter.charset = "UTF-8";
|
||||||
|
|
||||||
|
this._outgoing = "";
|
||||||
|
this._incoming = "";
|
||||||
|
|
||||||
|
this.hooks = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
DebuggerTransport.prototype = {
|
||||||
|
/**
|
||||||
|
* Transmit a packet.
|
||||||
|
*
|
||||||
|
* This method returns immediately, without waiting for the entire
|
||||||
|
* packet to be transmitted, registering event handlers as needed to
|
||||||
|
* transmit the entire packet. Packets are transmitted in the order
|
||||||
|
* they are passed to this method.
|
||||||
|
*/
|
||||||
|
send: function DT_send(aPacket) {
|
||||||
|
// TODO (bug 709088): remove pretty printing when the protocol is done.
|
||||||
|
let data = JSON.stringify(aPacket, null, 2);
|
||||||
|
// data = this._converter.ConvertFromUnicode(data);
|
||||||
|
|
||||||
|
let data_for_len = utf16to8(data);
|
||||||
|
|
||||||
|
this._outgoing = data_for_len.length + ':' + data;
|
||||||
|
|
||||||
|
this._flushOutgoing();
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the transport.
|
||||||
|
*/
|
||||||
|
close: function DT_close() {
|
||||||
|
this._input.close();
|
||||||
|
this._output.close();
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flush the outgoing stream.
|
||||||
|
*/
|
||||||
|
_flushOutgoing: function DT_flushOutgoing() {
|
||||||
|
if (this._outgoing.length > 0) {
|
||||||
|
// var threadManager = Cc["@mozilla.org/thread-manager;1"].getService();
|
||||||
|
// this._output.asyncWait(this, 0, 0, threadManager.currentThread);
|
||||||
|
log("outgoing: " + this._outgoing);//.substring(0, 200));
|
||||||
|
_bufferWrite(this._outgoing);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
onOutputStreamReady:
|
||||||
|
makeInfallible(function DT_onOutputStreamReady(aStream) {
|
||||||
|
let written = 0;
|
||||||
|
try {
|
||||||
|
written = aStream.write(this._outgoing, this._outgoing.length);
|
||||||
|
} catch(e if e.result == Components.results.NS_BASE_STREAM_CLOSED) {
|
||||||
|
dumpn("Connection closed.");
|
||||||
|
this.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._outgoing = this._outgoing.slice(written);
|
||||||
|
this._flushOutgoing();
|
||||||
|
}, "DebuggerTransport.prototype.onOutputStreamReady"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the input stream for reading. Once this method has been
|
||||||
|
* called, we watch for packets on the input stream, and pass them to
|
||||||
|
* this.hook.onPacket.
|
||||||
|
*/
|
||||||
|
ready: function DT_ready() {
|
||||||
|
// let pump = Cc["@mozilla.org/network/input-stream-pump;1"]
|
||||||
|
// .createInstance(Ci.nsIInputStreamPump);
|
||||||
|
// pump.init(this._input, -1, -1, 0, 0, false);
|
||||||
|
// pump.asyncRead(this, null);
|
||||||
|
},
|
||||||
|
|
||||||
|
// nsIStreamListener
|
||||||
|
onStartRequest:
|
||||||
|
makeInfallible(function DT_onStartRequest(aRequest, aContext) {},
|
||||||
|
"DebuggerTransport.prototype.onStartRequest"),
|
||||||
|
|
||||||
|
onStopRequest:
|
||||||
|
makeInfallible(function DT_onStopRequest(aRequest, aContext, aStatus) {
|
||||||
|
this.close();
|
||||||
|
if (this.hooks) {
|
||||||
|
this.hooks.onClosed(aStatus);
|
||||||
|
this.hooks = null;
|
||||||
|
}
|
||||||
|
}, "DebuggerTransport.prototype.onStopRequest"),
|
||||||
|
|
||||||
|
onDataAvailable: makeInfallible(function DT_onDataAvailable (incoming)
|
||||||
|
// makeInfallible(function DT_onDataAvailable(aRequest, aContext,
|
||||||
|
// aStream, aOffset, aCount)
|
||||||
|
{
|
||||||
|
this._incoming = incoming;//+= NetUtil.readInputStreamToString(aStream,
|
||||||
|
// aStream.available());
|
||||||
|
while (this._processIncoming()) {};
|
||||||
|
}, "DebuggerTransport.prototype.onDataAvailable"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process incoming packets. Returns true if a packet has been received, either
|
||||||
|
* if it was properly parsed or not. Returns false if the incoming stream does
|
||||||
|
* not contain a full packet yet. After a proper packet is parsed, the dispatch
|
||||||
|
* handler DebuggerTransport.hooks.onPacket is called with the packet as a
|
||||||
|
* parameter.
|
||||||
|
*/
|
||||||
|
_processIncoming: function DT__processIncoming() {
|
||||||
|
// Well this is ugly.
|
||||||
|
let sep = this._incoming.indexOf(':');
|
||||||
|
if (sep < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let count = parseInt(this._incoming.substring(0, sep));
|
||||||
|
if (this._incoming.length - (sep + 1) < count) {
|
||||||
|
// Don't have a complete request yet.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We have a complete request, pluck it out of the data and parse it.
|
||||||
|
this._incoming = this._incoming.substring(sep + 1);
|
||||||
|
let packet = this._incoming.substring(0, count);
|
||||||
|
this._incoming = this._incoming.substring(count);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// packet = this._converter.ConvertToUnicode(packet);
|
||||||
|
packet = utf8to16(packet);
|
||||||
|
var parsed = JSON.parse(packet);
|
||||||
|
} catch(e) {
|
||||||
|
let msg = "Error parsing incoming packet: " + packet + " (" + e + " - " + e.stack + ")";
|
||||||
|
// if (Cu.reportError) {
|
||||||
|
// Cu.reportError(msg);
|
||||||
|
// }
|
||||||
|
dump(msg + "\n");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
dumpn("Got: " + packet);
|
||||||
|
let self = this;
|
||||||
|
|
||||||
|
// Services.tm.currentThread.dispatch(makeInfallible(function() {
|
||||||
|
self.hooks.onPacket(parsed);
|
||||||
|
// }, "DebuggerTransport instance's this.hooks.onPacket"), 0);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An adapter that handles data transfers between the debugger client and
|
||||||
|
* server when they both run in the same process. It presents the same API as
|
||||||
|
* DebuggerTransport, but instead of transmitting serialized messages across a
|
||||||
|
* connection it merely calls the packet dispatcher of the other side.
|
||||||
|
*
|
||||||
|
* @param aOther LocalDebuggerTransport
|
||||||
|
* The other endpoint for this debugger connection.
|
||||||
|
*
|
||||||
|
* @see DebuggerTransport
|
||||||
|
*/
|
||||||
|
this.LocalDebuggerTransport = function LocalDebuggerTransport(aOther)
|
||||||
|
{
|
||||||
|
this.other = aOther;
|
||||||
|
this.hooks = null;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A packet number, shared between this and this.other. This isn't used
|
||||||
|
* by the protocol at all, but it makes the packet traces a lot easier to
|
||||||
|
* follow.
|
||||||
|
*/
|
||||||
|
this._serial = this.other ? this.other._serial : { count: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalDebuggerTransport.prototype = {
|
||||||
|
/**
|
||||||
|
* Transmit a message by directly calling the onPacket handler of the other
|
||||||
|
* endpoint.
|
||||||
|
*/
|
||||||
|
send: function LDT_send(aPacket) {
|
||||||
|
let serial = this._serial.count++;
|
||||||
|
if (wantLogging) {
|
||||||
|
if (aPacket.to) {
|
||||||
|
dumpn("Packet " + serial + " sent to " + uneval(aPacket.to));
|
||||||
|
} else if (aPacket.from) {
|
||||||
|
dumpn("Packet " + serial + " sent from " + uneval(aPacket.from));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._deepFreeze(aPacket);
|
||||||
|
let other = this.other;
|
||||||
|
if (other) {
|
||||||
|
Services.tm.currentThread.dispatch(makeInfallible(function() {
|
||||||
|
// Avoid the cost of JSON.stringify() when logging is disabled.
|
||||||
|
if (wantLogging) {
|
||||||
|
dumpn("Received packet " + serial + ": " + JSON.stringify(aPacket, null, 2));
|
||||||
|
}
|
||||||
|
if (other.hooks) {
|
||||||
|
other.hooks.onPacket(aPacket);
|
||||||
|
}
|
||||||
|
}, "LocalDebuggerTransport instance's this.other.hooks.onPacket"), 0);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the transport.
|
||||||
|
*/
|
||||||
|
close: function LDT_close() {
|
||||||
|
if (this.other) {
|
||||||
|
// Remove the reference to the other endpoint before calling close(), to
|
||||||
|
// avoid infinite recursion.
|
||||||
|
let other = this.other;
|
||||||
|
delete this.other;
|
||||||
|
other.close();
|
||||||
|
}
|
||||||
|
if (this.hooks) {
|
||||||
|
this.hooks.onClosed();
|
||||||
|
this.hooks = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An empty method for emulating the DebuggerTransport API.
|
||||||
|
*/
|
||||||
|
ready: function LDT_ready() {},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function that makes an object fully immutable.
|
||||||
|
*/
|
||||||
|
_deepFreeze: function LDT_deepFreeze(aObject) {
|
||||||
|
Object.freeze(aObject);
|
||||||
|
for (let prop in aObject) {
|
||||||
|
// Freeze the properties that are objects, not on the prototype, and not
|
||||||
|
// already frozen. Note that this might leave an unfrozen reference
|
||||||
|
// somewhere in the object if there is an already frozen object containing
|
||||||
|
// an unfrozen object.
|
||||||
|
if (aObject.hasOwnProperty(prop) && typeof aObject === "object" &&
|
||||||
|
!Object.isFrozen(aObject)) {
|
||||||
|
this._deepFreeze(o[prop]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,628 +1,135 @@
|
||||||
dbg = {};
|
require('debugger/DevToolsUtils.js', "debug");
|
||||||
dbg.log = log;
|
require('debugger/core/promise.js', "debug");
|
||||||
|
require('debugger/transport.js', "debug");
|
||||||
|
require('debugger/actors/root.js', "debug");
|
||||||
|
require('debugger/actors/script.js', "debug");
|
||||||
|
require('debugger/main.js', "debug");
|
||||||
|
|
||||||
var textCommandProcessor = {};
|
var globalDebuggee = null;
|
||||||
|
|
||||||
textCommandProcessor.break = function (str) {
|
function TestTabActor(aConnection, aGlobal)
|
||||||
var md = str.match(/^b(reak)?\s+([^:]+):(\d+)/);
|
{
|
||||||
|
this.conn = aConnection;
|
||||||
|
this._global = aGlobal;
|
||||||
|
this._threadActor = new ThreadActor(this, this._global);
|
||||||
|
this.conn.addActor(this._threadActor);
|
||||||
|
this._attached = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!md) {
|
TestTabActor.prototype = {
|
||||||
return ({commandname : "break",
|
constructor: TestTabActor,
|
||||||
success : false,
|
actorPrefix: "TestTabActor",
|
||||||
stringResult : "command could not be parsed"});
|
|
||||||
|
grip: function() {
|
||||||
|
return { actor: this.actorID, title: "Hello Cocos2d-X JSB", url: "http://cocos2d-x.org" };
|
||||||
|
},
|
||||||
|
|
||||||
|
onAttach: function(aRequest) {
|
||||||
|
this._attached = true;
|
||||||
|
return { type: "tabAttached", threadActor: this._threadActor.actorID };
|
||||||
|
},
|
||||||
|
|
||||||
|
onDetach: function(aRequest) {
|
||||||
|
if (!this._attached) {
|
||||||
|
return { "error":"wrongState" };
|
||||||
}
|
}
|
||||||
|
return { type: "detached" };
|
||||||
|
},
|
||||||
|
|
||||||
var scripts = dbg.scripts[md[2]],
|
// Hooks for use by TestTabActors.
|
||||||
tmpScript = null;
|
addToParentPool: function(aActor) {
|
||||||
if (scripts) {
|
this.conn.addActor(aActor);
|
||||||
var breakLine = parseInt(md[3], 10),
|
},
|
||||||
off = -1;
|
|
||||||
for (var n=0; n < scripts.length; n++) {
|
|
||||||
offsets = scripts[n].getLineOffsets(breakLine);
|
|
||||||
if (offsets.length > 0) {
|
|
||||||
off = offsets[0];
|
|
||||||
tmpScript = scripts[n];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (off >= 0) {
|
|
||||||
tmpScript.setBreakpoint(off, breakpointHandler);
|
|
||||||
return ({commandname : "break",
|
|
||||||
success : true,
|
|
||||||
jsfilename : md[2],
|
|
||||||
breakpointlinenumber : breakLine});
|
|
||||||
} else {
|
|
||||||
return ({commandname : "break",
|
|
||||||
success : false,
|
|
||||||
stringResult : "no valid offsets at that line"});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return ({commandname : "break",
|
|
||||||
success : false,
|
|
||||||
jsfilename : md[2],
|
|
||||||
stringResult : "Invalid script name"});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
textCommandProcessor.info = function (str) {
|
removeFromParentPool: function(aActor) {
|
||||||
var report = "";
|
this.conn.removeActor(aActor);
|
||||||
|
}
|
||||||
var md = str.match(/^info\s+(\S+)/);
|
|
||||||
if (md) {
|
|
||||||
report += "info - NYI";
|
|
||||||
report += "\nmd[0] = " + md[0];
|
|
||||||
report += "\nmd[1] = " + md[1];
|
|
||||||
|
|
||||||
return ({commandname : "info",
|
|
||||||
success : true,
|
|
||||||
stringResult : report});
|
|
||||||
} else {
|
|
||||||
return ({commandname : "info",
|
|
||||||
success : false,
|
|
||||||
stringResult : report});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
textCommandProcessor.clear = function (str) {
|
|
||||||
var report = "";
|
|
||||||
|
|
||||||
report += "clearing all breakpoints";
|
|
||||||
|
|
||||||
dbg.dbg.clearAllBreakpoints();
|
|
||||||
return ({commandname : "clear",
|
|
||||||
success : true,
|
|
||||||
stringResult : report});
|
|
||||||
}
|
|
||||||
|
|
||||||
textCommandProcessor.scripts = function (str) {
|
|
||||||
var report = "List of available scripts\n";
|
|
||||||
report += Object.keys(dbg.scripts).join("\n");
|
|
||||||
|
|
||||||
return ({commandname : "scripts",
|
|
||||||
success : true,
|
|
||||||
stringResult : report});
|
|
||||||
}
|
|
||||||
|
|
||||||
textCommandProcessor.step = function (str, frame, script) {
|
|
||||||
if (frame) {
|
|
||||||
dbg.breakLine = script.getOffsetLine(frame.offset) + 1;
|
|
||||||
frame.onStep = function () {
|
|
||||||
stepFunction(frame, frame.script);
|
|
||||||
return undefined;
|
|
||||||
};
|
|
||||||
stop = true;
|
|
||||||
_unlockVM();
|
|
||||||
|
|
||||||
return ({commandname : "step",
|
|
||||||
success : true,
|
|
||||||
stringResult : ""});
|
|
||||||
} else {
|
|
||||||
return ({commandname : "step",
|
|
||||||
success : false,
|
|
||||||
stringResult : ""});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
textCommandProcessor.continue = function (str, frame, script) {
|
|
||||||
if (frame) {
|
|
||||||
frame.onStep = undefined;
|
|
||||||
dbg.breakLine = 0;
|
|
||||||
}
|
|
||||||
stop = true;
|
|
||||||
_unlockVM();
|
|
||||||
|
|
||||||
return ({commandname : "continue",
|
|
||||||
success : true,
|
|
||||||
stringResult : ""});
|
|
||||||
}
|
|
||||||
|
|
||||||
textCommandProcessor.deval = function (str, frame, script) {
|
|
||||||
// debugger eval
|
|
||||||
var md = str.match(/^deval\s+(.+)/);
|
|
||||||
if (md[1]) {
|
|
||||||
try {
|
|
||||||
var devalReturn = eval(md[1]);
|
|
||||||
if (devalReturn) {
|
|
||||||
var stringreport = debugObject(devalReturn, true);
|
|
||||||
return ({commandname : "deval",
|
|
||||||
success : true,
|
|
||||||
stringResult : stringreport});
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
return ({commandname : "deval",
|
|
||||||
success : false,
|
|
||||||
stringResult : "exception:\n" + e.message});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return ({commandname : "deval",
|
|
||||||
success : false,
|
|
||||||
stringResult : "could not parse script to evaluate"});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
textCommandProcessor.eval = function (str, frame, script) {
|
|
||||||
if (!frame) {
|
|
||||||
return ({commandname : "eval",
|
|
||||||
success : false,
|
|
||||||
stringResult : "no frame to eval in"});
|
|
||||||
}
|
|
||||||
|
|
||||||
var stringToEval = str.substring(4);
|
|
||||||
|
|
||||||
if (stringToEval) {
|
|
||||||
try {
|
|
||||||
var evalResult = frame['eval']("JSON.stringify(eval(" + stringToEval + "));");
|
|
||||||
if (evalResult && evalResult['return']) {
|
|
||||||
var stringreport = evalResult['return'];
|
|
||||||
// var stringreport = debugObject(evalResult['return']);
|
|
||||||
return ({commandname : "eval",
|
|
||||||
success : true,
|
|
||||||
stringResult : stringreport});
|
|
||||||
} else if (evalResult && evalResult['throw']) {
|
|
||||||
return ({commandname : "eval",
|
|
||||||
success : false,
|
|
||||||
stringResult : "got exception: " + evalResult['throw'].message});
|
|
||||||
} else {
|
|
||||||
return ({commandname : "eval",
|
|
||||||
success : false,
|
|
||||||
stringResult : "invalid return from eval"});
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
dbg.log("exception = " + e);
|
|
||||||
return ({commandname : "eval",
|
|
||||||
success : false,
|
|
||||||
stringResult : "Exception : " + e});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
textCommandProcessor.line = function (str, frame, script) {
|
|
||||||
if (frame) {
|
|
||||||
try {
|
|
||||||
return ({commandname : "line",
|
|
||||||
success : true,
|
|
||||||
stringResult : script.getOffsetLine(frame.offset)});
|
|
||||||
} catch (e) {
|
|
||||||
return ({commandname : "line",
|
|
||||||
success : false,
|
|
||||||
stringResult : "exception " + e});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ({commandname : "line",
|
|
||||||
success : false,
|
|
||||||
// probably entering script
|
|
||||||
stringResult : "NOLINE"});
|
|
||||||
}
|
|
||||||
|
|
||||||
textCommandProcessor.backtrace = function (str, frame, script) {
|
|
||||||
if (!frame) {
|
|
||||||
return ({commandname : "backtrace",
|
|
||||||
success : false,
|
|
||||||
stringResult : "no valid frame"});
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = "";
|
|
||||||
var cur = frame,
|
|
||||||
stack = [cur.script.url + ":" + cur.script.getOffsetLine(cur.offset)];
|
|
||||||
while ((cur = cur.older)) {
|
|
||||||
stack.push(cur.script.url + ":" + cur.script.getOffsetLine(cur.offset));
|
|
||||||
}
|
|
||||||
result += stack.join("\n");
|
|
||||||
|
|
||||||
return ({commandname : "backtrace",
|
|
||||||
success : true,
|
|
||||||
stringResult : result});
|
|
||||||
}
|
|
||||||
|
|
||||||
textCommandProcessor.uiresponse = function (str) {
|
|
||||||
var subcommandstring = (str.substring("uiresponse".length)).replace(/\s+/g, '');
|
|
||||||
var response = "";
|
|
||||||
switch (subcommandstring) {
|
|
||||||
case "json":
|
|
||||||
dbg.responder = jsonResponder;
|
|
||||||
response += "DEBUGGER UI : responding with json messages";
|
|
||||||
break;
|
|
||||||
case "plaintext":
|
|
||||||
dbg.responder = textResponder;
|
|
||||||
response += "DEBUGGER UI : responding with plaintext messages";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// note : we return an empty string
|
|
||||||
// dbg.log(response);
|
|
||||||
return ({commandname : "uiresponse",
|
|
||||||
success : true,
|
|
||||||
stringResult : ""});
|
|
||||||
}
|
|
||||||
|
|
||||||
textCommandProcessor.help = function () {
|
|
||||||
_printHelp();
|
|
||||||
|
|
||||||
return ({commandname : "help",
|
|
||||||
success : true,
|
|
||||||
stringResult : ""});
|
|
||||||
}
|
|
||||||
|
|
||||||
textCommandProcessor.getCommandProcessor = function (str) {
|
|
||||||
// break
|
|
||||||
var md = str.match(/[a-z]*/);
|
|
||||||
if (!md) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
switch (md[0]) {
|
|
||||||
case "b" :
|
|
||||||
case "break" :
|
|
||||||
return textCommandProcessor.break;
|
|
||||||
case "info" :
|
|
||||||
return textCommandProcessor.info;
|
|
||||||
case "clear" :
|
|
||||||
return textCommandProcessor.clear;
|
|
||||||
case "scripts" :
|
|
||||||
return textCommandProcessor.scripts;
|
|
||||||
case "s" :
|
|
||||||
case "step" :
|
|
||||||
return textCommandProcessor.step;
|
|
||||||
case "c" :
|
|
||||||
case "continue" :
|
|
||||||
return textCommandProcessor.continue;
|
|
||||||
case "deval" :
|
|
||||||
return textCommandProcessor.deval;
|
|
||||||
case "eval" :
|
|
||||||
return textCommandProcessor.eval;
|
|
||||||
case "line" :
|
|
||||||
return textCommandProcessor.line;
|
|
||||||
case "bt" :
|
|
||||||
return textCommandProcessor.backtrace;
|
|
||||||
case "uiresponse" :
|
|
||||||
return textCommandProcessor.uiresponse;
|
|
||||||
case "help" :
|
|
||||||
return textCommandProcessor.help;
|
|
||||||
default :
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSON output
|
|
||||||
var jsonResponder = {};
|
|
||||||
|
|
||||||
jsonResponder.write = function (str) {
|
|
||||||
_bufferWrite(str);
|
|
||||||
_bufferWrite("\n");
|
|
||||||
_bufferWrite(String.fromCharCode(23));
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonResponder.onBreakpoint = function (filename, linenumber) {
|
|
||||||
var response = {"from" : "server",
|
|
||||||
"why" : "onBreakpoint",
|
|
||||||
"data" : {"jsfilename" : filename,
|
|
||||||
"linenumber" : linenumber}};
|
|
||||||
|
|
||||||
this.write(JSON.stringify(response));
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonResponder.onStep = function (filename, linenumber) {
|
|
||||||
var response = {"from" : "server",
|
|
||||||
"why" : "onStep",
|
|
||||||
"data" : {"jsfilename" : filename,
|
|
||||||
"linenumber" : linenumber}};
|
|
||||||
|
|
||||||
this.write(JSON.stringify(response));
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonResponder.commandResponse = function (commandresult) {
|
|
||||||
var response = {"from" : "server",
|
|
||||||
"why" : "commandresponse",
|
|
||||||
"data" : commandresult};
|
|
||||||
|
|
||||||
this.write(JSON.stringify(response));
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonResponder.commandNotFound = function () {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
// Plain Old Text output
|
|
||||||
var textResponder = {};
|
|
||||||
|
|
||||||
textResponder.write = function (str) {
|
|
||||||
_bufferWrite(str);
|
|
||||||
_bufferWrite("\n");
|
|
||||||
_bufferWrite(String.fromCharCode(23));
|
|
||||||
}
|
|
||||||
|
|
||||||
textResponder.onBreakpoint = function (filename, linenumber) {
|
|
||||||
var shortFilename = filename.substring(filename.lastIndexOf("/") + 1);
|
|
||||||
var response = "Breakpoint hit at " + shortFilename + " line number : " + linenumber;
|
|
||||||
this.write(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
textResponder.onStep = function (filename, linenumber) {
|
|
||||||
var shortFilename = filename.substring(filename.lastIndexOf("/") + 1);
|
|
||||||
var response = "Stopped at " + shortFilename + " line number : " + linenumber;
|
|
||||||
this.write(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
textResponder.commandResponse = function (commandresult) {
|
|
||||||
var response = "";
|
|
||||||
|
|
||||||
try {
|
|
||||||
switch (commandresult.commandname) {
|
|
||||||
case "break" :
|
|
||||||
if (!commandresult.success) {
|
|
||||||
response += "ERROR : " + commandresult.stringResult;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "info" :
|
|
||||||
if (!commandresult.success) {
|
|
||||||
response += "ERROR : " + commandresult.stringResult;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "clear" :
|
|
||||||
break;
|
|
||||||
case "scripts" :
|
|
||||||
if (true === commandresult.success) {
|
|
||||||
response += commandresult.stringResult;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "step" :
|
|
||||||
if (!commandresult.success) {
|
|
||||||
response += "ERROR : step failed " + commandresult.stringResult;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "continue" :
|
|
||||||
if (!commandresult.success) {
|
|
||||||
response += "ERROR : continue failed " + commandresult.stringResult;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "deval" :
|
|
||||||
if (true === commandresult.success) {
|
|
||||||
response += commandresult.stringResult;
|
|
||||||
} else {
|
|
||||||
response += "ERROR : deval failed " + commandresult.stringResult;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "eval" :
|
|
||||||
if (true === commandresult.success) {
|
|
||||||
response += commandresult.stringResult;
|
|
||||||
} else {
|
|
||||||
response += "ERROR : eval failed " + commandresult.stringResult;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "line" :
|
|
||||||
if (true === commandresult.success) {
|
|
||||||
response += commandresult.stringResult;
|
|
||||||
} else {
|
|
||||||
response += "ERROR : " + commandresult.stringResult;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "backtrace" :
|
|
||||||
if (true === commandresult.success) {
|
|
||||||
response += commandresult.stringResult;
|
|
||||||
} else {
|
|
||||||
response += "ERROR : " + commandresult.stringResult;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "help" :
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
response += "\nException logging response " + e;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.write(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
textResponder.commandNotFound = function () {
|
|
||||||
_printCommandNotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
var breakpointHandler = {
|
|
||||||
hit: function (frame) {
|
|
||||||
try {
|
|
||||||
dbg.responder.onBreakpoint(frame.script.url, frame.script.getOffsetLine(frame.offset));
|
|
||||||
} catch (e) {
|
|
||||||
dbg.log("exception " + e);
|
|
||||||
}
|
|
||||||
|
|
||||||
var script = frame.script;
|
|
||||||
_lockVM(frame, frame.script);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var stepFunction = function (frame, script) {
|
TestTabActor.prototype.requestTypes = {
|
||||||
if (dbg.breakLine > 0) {
|
"attach": TestTabActor.prototype.onAttach,
|
||||||
var curLine = script.getOffsetLine(frame.offset);
|
"detach": TestTabActor.prototype.onDetach
|
||||||
if (curLine < dbg.breakLine) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
dbg.responder.onStep(frame.script.url, frame.script.getOffsetLine(frame.offset));
|
|
||||||
} catch (e) {
|
|
||||||
dbg.log("exception " + e);
|
|
||||||
}
|
|
||||||
|
|
||||||
_lockVM(frame, script);
|
|
||||||
// dbg.breakLine = 0;
|
|
||||||
// frame.onStep = undefined;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dbg.log("invalid state onStep");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var debugObject = function (r, isNormal) {
|
function TestTabList(aConnection) {
|
||||||
var stringres = "";
|
this.conn = aConnection;
|
||||||
try {
|
|
||||||
stringres += "* " + (typeof r) + "\n";
|
|
||||||
if (typeof r != "object") {
|
|
||||||
stringres += "~> " + r + "\n";
|
|
||||||
} else {
|
|
||||||
var props;
|
|
||||||
if (isNormal) {
|
|
||||||
props = Object.keys(r);
|
|
||||||
} else {
|
|
||||||
props = r.getOwnPropertyNames();
|
|
||||||
}
|
|
||||||
for (k in props) {
|
|
||||||
var desc = r.getOwnPropertyDescriptor(props[k]);
|
|
||||||
stringres += "~> " + props[k] + " = ";
|
|
||||||
if (desc.value) {
|
|
||||||
stringres += "" + desc.value;
|
|
||||||
} else if (desc.get) {
|
|
||||||
stringres += "" + desc.get();
|
|
||||||
} else {
|
|
||||||
stringres += "undefined (no value or getter)";
|
|
||||||
}
|
|
||||||
stringres += "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return stringres;
|
// An array of actors for each global added with
|
||||||
} catch (e) {
|
// DebuggerServer.addTestGlobal.
|
||||||
return ("Exception when accessing object properties = " + e);
|
this._tabActors = [];
|
||||||
}
|
|
||||||
|
// A pool mapping those actors' names to the actors.
|
||||||
|
this._tabActorPool = new ActorPool(aConnection);
|
||||||
|
|
||||||
|
// for (let global of gTestGlobals) {
|
||||||
|
let actor = new TestTabActor(aConnection, globalDebuggee);
|
||||||
|
actor.selected = false;
|
||||||
|
this._tabActors.push(actor);
|
||||||
|
this._tabActorPool.addActor(actor);
|
||||||
|
// }
|
||||||
|
if (this._tabActors.length > 0) {
|
||||||
|
this._tabActors[0].selected = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
aConnection.addActorPool(this._tabActorPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
dbg.breakLine = 0;
|
TestTabList.prototype = {
|
||||||
|
constructor: TestTabList,
|
||||||
|
iterator: function() {
|
||||||
|
for (let actor of this._tabActors) {
|
||||||
|
yield actor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.processInput = function (inputstr, frame, script) {
|
this.processInput = function (inputstr) {
|
||||||
var command_func;
|
|
||||||
var command_return;
|
|
||||||
var commands_array = [];
|
|
||||||
var _command;
|
|
||||||
var i;
|
|
||||||
|
|
||||||
if (!inputstr) {
|
if (!inputstr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove Carriage Return's
|
if (inputstr === "connected")
|
||||||
inputstr = inputstr.replace(/\r+/, "");
|
{
|
||||||
|
|
||||||
// split into an array using Line Feed as the delimiter
|
DebuggerServer.createRootActor = (conn => {
|
||||||
commands_array = inputstr.split("\n");
|
return new RootActor(conn, { tabList: new TestTabList(conn) });
|
||||||
|
});
|
||||||
|
DebuggerServer.init(() => true);
|
||||||
|
DebuggerServer.openListener(5086);
|
||||||
|
|
||||||
// trace the commands received
|
if (debuggerServer && debuggerServer.onSocketAccepted)
|
||||||
// dbg.log("received " + commands_array.length + " commands:");
|
{
|
||||||
// for (i = 0; i < commands_array.length; i++) {
|
var aTransport = {
|
||||||
// if (i in commands_array) {
|
host: "127.0.0.1",
|
||||||
// dbg.log("~~~ commandstring =" + commands_array[i]);
|
port: 5086,
|
||||||
// dbg.log(" commandstring.length = " + commands_array[i].length);
|
openInputStream: function() {
|
||||||
// }
|
return {
|
||||||
// }
|
close: function(){}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
openOutputStream: function() {
|
||||||
|
return {
|
||||||
|
close: function(){},
|
||||||
|
write: function(){},
|
||||||
|
asyncWait: function(){}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
for (i = 0; i < commands_array.length; i++) {
|
debuggerServer.onSocketAccepted(null, aTransport);
|
||||||
if (i in commands_array) {
|
|
||||||
_command = commands_array[i];
|
|
||||||
|
|
||||||
if (_command === "") {
|
|
||||||
// dbg.log("Empty input. Ignoring.");
|
|
||||||
} else {
|
|
||||||
// dbg.log(_command);
|
|
||||||
|
|
||||||
command_func = dbg.getCommandProcessor(_command);
|
|
||||||
|
|
||||||
if (!command_func) {
|
|
||||||
dbg.log("did not find a command processor!");
|
|
||||||
dbg.responder.commandNotFound();
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
command_return = command_func(_command, frame, script);
|
|
||||||
if (true === command_return.success) {
|
|
||||||
dbg.responder.commandResponse(command_return);
|
|
||||||
} else {
|
|
||||||
dbg.log("command failed. return value = " + command_return.stringResult);
|
|
||||||
dbg.responder.commandResponse(command_return);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
dbg.log("Exception in command processing. e =\n" + e + "\n");
|
|
||||||
var _output = {success : false,
|
|
||||||
commandname : command_func.name,
|
|
||||||
stringResult : e};
|
|
||||||
dbg.responder.commandResponse(_output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DebuggerServer && DebuggerServer._transport && DebuggerServer._transport.onDataAvailable)
|
||||||
|
{
|
||||||
|
DebuggerServer._transport.onDataAvailable(inputstr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_printCommandNotFound = function() {
|
|
||||||
var str = "ERROR : command not found!\n";
|
|
||||||
_bufferWrite(str);
|
|
||||||
};
|
|
||||||
|
|
||||||
_printHelp = function() {
|
|
||||||
var help = "break filename:numer\tAdds a breakpoint at a given filename and line number\n" +
|
|
||||||
"clear\tClear all breakpoints\n" +
|
|
||||||
"c / continue\tContinues the execution\n" +
|
|
||||||
"s / step\tStep\n" +
|
|
||||||
"bt\tBacktrace\n" +
|
|
||||||
"scripts\tShow the scripts\n" +
|
|
||||||
"line\tShows current line\n" +
|
|
||||||
"eval js_command\tEvaluates JS code\n" +
|
|
||||||
"deval js_command\tEvaluates JS Debugger command\n" +
|
|
||||||
"uiresponse [json|plaintext] Switch between JSON and plaintext output from the debugger\n";
|
|
||||||
_bufferWrite(help);
|
|
||||||
};
|
|
||||||
|
|
||||||
dbg.scripts = [];
|
|
||||||
|
|
||||||
dbg.onNewScript = function (script) {
|
|
||||||
// skip if the url is this script
|
|
||||||
var last = script.url.split("/").pop();
|
|
||||||
|
|
||||||
var children = script.getChildScripts(),
|
|
||||||
arr = [script].concat(children);
|
|
||||||
/**
|
|
||||||
* just dumping all the offsets from the scripts
|
|
||||||
for (var i in arr) {
|
|
||||||
dbg.log("script: " + arr[i].url);
|
|
||||||
for (var start=arr[i].startLine, j=start; j < start+arr[i].lineCount; j++) {
|
|
||||||
var offsets = arr[i].getLineOffsets(j);
|
|
||||||
dbg.log(" off: " + offsets.join(",") + "; line: " + j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
dbg.scripts[last] = arr;
|
|
||||||
};
|
|
||||||
|
|
||||||
dbg.onError = function (frame, report) {
|
|
||||||
if (dbg.socket && report) {
|
|
||||||
_socketWrite(dbg.socket, "!! exception @ " + report.file + ":" + report.line);
|
|
||||||
}
|
|
||||||
dbg.log("!! exception");
|
|
||||||
};
|
|
||||||
|
|
||||||
this._prepareDebugger = function (global) {
|
this._prepareDebugger = function (global) {
|
||||||
var tmp = new Debugger(global);
|
|
||||||
tmp.onNewScript = dbg.onNewScript;
|
|
||||||
tmp.onDebuggerStatement = dbg.onDebuggerStatement;
|
|
||||||
tmp.onError = dbg.onError;
|
|
||||||
dbg.dbg = tmp;
|
|
||||||
|
|
||||||
// use the text command processor at startup
|
globalDebuggee = global;
|
||||||
dbg.getCommandProcessor = textCommandProcessor.getCommandProcessor;
|
|
||||||
|
|
||||||
// use the text responder at startup
|
|
||||||
dbg.responder = textResponder;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this._startDebugger = function (global, files, startFunc) {
|
|
||||||
// dbg.log("[DBG] starting debug session");
|
|
||||||
for (var i in files) {
|
|
||||||
try {
|
|
||||||
global['eval']("require('" + files[i] + "');");
|
|
||||||
} catch (e) {
|
|
||||||
dbg.log("[DBG] error evaluating file: " + files[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// dbg.log("[DBG] all files required");
|
|
||||||
if (startFunc) {
|
|
||||||
// dbg.log("executing start func: " + startFunc);
|
|
||||||
global['eval'](startFunc);
|
|
||||||
}
|
|
||||||
// beginDebug();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
/**
|
|
||||||
* bootstrap for the debugger. You can test to see if the debugger is loaded by checking the type of
|
|
||||||
* `startDebugger`. If that function is defined, then you should call it with the global object,
|
|
||||||
* which at this point is `this`, the array of files that you need to load (usually is just your
|
|
||||||
* main javascript), and the function that needs to be called to start your game, as a string.
|
|
||||||
* If the `startDebugger` function is not defined, then you just require your files and start your
|
|
||||||
* game :)
|
|
||||||
*/
|
|
||||||
var files = ['MoonWarriors-jsb.js'];
|
|
||||||
if (typeof startDebugger !== "undefined") {
|
|
||||||
cc.log("**** will start debugger ****");
|
|
||||||
startDebugger(this, files);
|
|
||||||
} else {
|
|
||||||
cc.log("**** no debugger loaded ****");
|
|
||||||
for (var i in files) {
|
|
||||||
require(files[i]);
|
|
||||||
}
|
|
||||||
// run();
|
|
||||||
}
|
|
|
@ -137,13 +137,6 @@
|
||||||
#define JSB_INCLUDE_COCOSDENSHION 1
|
#define JSB_INCLUDE_COCOSDENSHION 1
|
||||||
#endif // JSB_INCLUDE_COCOSDENSHION
|
#endif // JSB_INCLUDE_COCOSDENSHION
|
||||||
|
|
||||||
/** @def JSB_ENABLE_DEBUGGER
|
|
||||||
Set this to 1 to enable the debugger
|
|
||||||
*/
|
|
||||||
#ifndef JSB_ENABLE_DEBUGGER
|
|
||||||
#define JSB_ENABLE_DEBUGGER 0
|
|
||||||
#endif // JSB_ENABLE_DEBUGGER
|
|
||||||
|
|
||||||
#if JSB_ENABLE_DEBUGGER
|
#if JSB_ENABLE_DEBUGGER
|
||||||
#define JSB_ENSURE_AUTOCOMPARTMENT(cx, obj) \
|
#define JSB_ENSURE_AUTOCOMPARTMENT(cx, obj) \
|
||||||
JSAutoCompartment ac(cx, obj)
|
JSAutoCompartment ac(cx, obj)
|
||||||
|
|
Loading…
Reference in New Issue