issue #2823: _lockVM take no arguments now.

This commit is contained in:
James Chen 2013-10-08 16:21:10 +08:00
parent a919fd5de1
commit adbb3585ac
3 changed files with 22 additions and 19 deletions

View File

@ -60,7 +60,6 @@ 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 bool vmLock = false;
static jsval frame = JSVAL_NULL, script = JSVAL_NULL;
static int clientSocket = -1; static int clientSocket = -1;
// server entry point for the bg thread // server entry point for the bg thread
@ -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)
{
std::string logBuf = _js_log_buf; std::string logBuf = _js_log_buf;
if (std::string::npos != logBuf.find("unknown (can't convert to") if (std::string::npos != logBuf.find("unknown (can't convert to")
|| std::string::npos != logBuf.find("too much recursion")) || std::string::npos != logBuf.find("too much recursion"))
@ -1949,14 +1952,12 @@ void ScriptingCore::debugProcessInput(string str) {
JSAutoCompartment ac(cx_, debugGlobal_); 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;
JS_CallFunctionName(cx_, debugGlobal_, "processInput", 3, argv, &outval); JS_CallFunctionName(cx_, debugGlobal_, "processInput", 1, argv, &outval);
} }
void ScriptingCore::enableDebugger() { void ScriptingCore::enableDebugger() {
@ -1969,7 +1970,7 @@ void ScriptingCore::enableDebugger() {
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_, "_bufferRead", JSBDebug_BufferRead, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx_, debugGlobal_, "_lockVM", JSBDebug_LockExecution, 2, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx_, debugGlobal_, "_lockVM", JSBDebug_LockExecution, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx_, debugGlobal_, "_unlockVM", JSBDebug_UnlockExecution, 0, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx_, debugGlobal_, "_unlockVM", JSBDebug_UnlockExecution, 0, JSPROP_READONLY | JSPROP_PERMANENT);
@ -2162,11 +2163,14 @@ JSBool JSBDebug_BufferWrite(JSContext* cx, unsigned argc, jsval* vp)
// this should lock the execution of the running thread, waiting for a signal // this should lock the execution of the running thread, waiting for a signal
JSBool JSBDebug_LockExecution(JSContext* cx, unsigned argc, jsval* vp) JSBool JSBDebug_LockExecution(JSContext* cx, unsigned argc, jsval* vp)
{ {
if (argc == 2) { if (argc == 0)
printf("locking vm\n"); {
jsval* argv = JS_ARGV(cx, vp); if (vmLock)
frame = argv[0]; {
script = argv[1]; CCLOG("%s", "vm has been locked.");
return JS_TRUE;
}
CCLOG("%s","locking vm\n");
vmLock = true; vmLock = true;
while (vmLock) { while (vmLock) {
// try to read the input, if there's anything // try to read the input, if there's anything
@ -2180,9 +2184,8 @@ JSBool JSBDebug_LockExecution(JSContext* cx, unsigned argc, jsval* vp)
g_qMutex.unlock(); g_qMutex.unlock();
std::this_thread::yield(); std::this_thread::yield();
} }
printf("vm unlocked\n"); CCLOG("%s","vm unlocked\n");
frame = JSVAL_NULL;
script = JSVAL_NULL;
return JS_TRUE; return JS_TRUE;
} }
JS_ReportError(cx, "invalid call to _lockVM"); JS_ReportError(cx, "invalid call to _lockVM");

View File

@ -278,7 +278,7 @@ ThreadActor.prototype = {
} }
packet.why = aReason; packet.why = aReason;
resolve(onPacket(packet)).then(this.conn.send.bind(this.conn)); resolve(onPacket(packet)).then(this.conn.send.bind(this.conn));
_lockVM(aFrame, aFrame.script); _lockVM();
return this._nest(); return this._nest();
} catch(e) { } catch(e) {
let msg = "Got an exception during TA__pauseAndRespond: " + e + let msg = "Got an exception during TA__pauseAndRespond: " + e +

View File

@ -84,7 +84,7 @@ TestTabList.prototype = {
} }
}; };
this.processInput = function (inputstr, frame, script) { this.processInput = function (inputstr) {
if (!inputstr) { if (!inputstr) {
return; return;