Skip to content

Commit 29fdbc7

Browse files
kulcsaradamksh8281
authored andcommitted
Improve eval in devtools
Fix accidental deadlock possible inside the debugger and improve formatting when inspecting arrays. Signed-off-by: Ádám László Kulcsár <adam.kulcsar@szteszoftver.hu>
1 parent ebe3761 commit 29fdbc7

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

src/debugger/DebuggerDevtools.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static void computeEndLocation(const char* src, size_t length, uint32_t& endLine
138138

139139
void DebuggerDevtools::parseCompleted(String* source, String* srcName, const size_t originLineOffset, String* error)
140140
{
141-
if (!enabled()) {
141+
if (!enabled() || m_stopState == ESCARGOT_DEBUGGER_IN_EVAL_MODE) {
142142
return;
143143
}
144144

@@ -440,6 +440,10 @@ void DebuggerDevtools::exceptionCaught(String* message, SavedStackTraceDataVecto
440440

441441
void DebuggerDevtools::consoleOut(String* output)
442442
{
443+
if (m_stopState != ESCARGOT_DEBUGGER_IN_EVAL_MODE) {
444+
return;
445+
}
446+
443447
rapidjson::Document message;
444448
message.SetObject();
445449

@@ -1000,15 +1004,17 @@ bool DebuggerDevtools::evaluate(rapidjson::Document& jsonMessage, ExecutionState
10001004
return true;
10011005
}
10021006

1007+
m_stopState = ESCARGOT_DEBUGGER_IN_EVAL_MODE;
10031008
const char* source = jsonMessage["params"]["expression"].GetString();
10041009
size_t sourceLen = jsonMessage["params"]["expression"].GetStringLength();
1005-
Value evalExpression = Value(String::fromUTF8(source, sourceLen, false));
1010+
Value evalExpression = Value(new Latin1String(source, sourceLen));
10061011
Value result = Value(Value::Undefined);
10071012
try {
10081013
result = state->context()->globalObject()->eval(*state, evalExpression);
10091014
} catch (const Value& val) {
10101015
result = val;
10111016
}
1017+
m_stopState = ESCARGOT_DEBUGGER_IN_WAIT_MODE;
10121018

10131019
rapidjson::Document reply;
10141020
reply.SetObject();
@@ -1044,9 +1050,25 @@ bool DebuggerDevtools::evaluate(rapidjson::Document& jsonMessage, ExecutionState
10441050
description.SetString(temp.c_str(), temp.length(), reply.GetAllocator());
10451051
resultObj.AddMember("description", description, reply.GetAllocator());
10461052
} else if (result.isObject()) {
1047-
resultObj.AddMember("type", "object", reply.GetAllocator());
1048-
resultObj.AddMember("className", "Object", reply.GetAllocator());
1049-
resultObj.AddMember("description", "Object", reply.GetAllocator());
1053+
Object* resObj = result.asObject();
1054+
1055+
if (resObj->isArray(*state)) {
1056+
rapidjson::Value description;
1057+
1058+
if (result.toStringWithoutException(*state) != nullptr) {
1059+
UTF8StringDataNonGCStd arrayStr = result.toStringWithoutException(*state)->toNonGCUTF8StringData();
1060+
std::string temp = "Array: [" + std::string(arrayStr.c_str(), arrayStr.length()) + "]";
1061+
description.SetString(temp.c_str(), temp.length(), reply.GetAllocator());
1062+
}
1063+
1064+
resultObj.AddMember("type", "array", reply.GetAllocator());
1065+
resultObj.AddMember("className", "Array", reply.GetAllocator());
1066+
resultObj.AddMember("description", description, reply.GetAllocator());
1067+
} else {
1068+
resultObj.AddMember("type", "object", reply.GetAllocator());
1069+
resultObj.AddMember("className", "Object", reply.GetAllocator());
1070+
resultObj.AddMember("description", "Object", reply.GetAllocator());
1071+
}
10501072
} else if (result.isBigInt()) {
10511073
std::string temp = std::string(result.asBigInt()->toString()->toNonGCUTF8StringData().data());
10521074
rapidjson::Value description;

0 commit comments

Comments
 (0)