Skip to content

Commit 557e0f7

Browse files
committed
refactor console.assert to use console.log string building logic when assertion fails
1 parent 9eb9b7d commit 557e0f7

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

test-app/runtime/src/main/cpp/console/Console.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void Console::sendToDevToolsFrontEnd(v8::Isolate* isolate, const std::string& me
7272
v8_inspector::V8LogAgentImpl::EntryAdded(message, logLevel, ArgConverter::ConvertToString(frame->GetScriptNameOrSourceURL()), frame->GetLineNumber());
7373
}
7474

75-
const std::string buildLogString(const v8::FunctionCallbackInfo<v8::Value>& info) {
75+
const std::string buildLogString(const v8::FunctionCallbackInfo<v8::Value>& info, int startingIndex = 0) {
7676
auto isolate = info.GetIsolate();
7777

7878
v8::HandleScope scope(isolate);
@@ -81,7 +81,7 @@ const std::string buildLogString(const v8::FunctionCallbackInfo<v8::Value>& info
8181

8282
auto argLen = info.Length();
8383
if (argLen) {
84-
for (int i = 0; i < argLen; i++) {
84+
for (int i = startingIndex; i < argLen; i++) {
8585
v8::Local<v8::String> argString;
8686
if (info[i]->IsFunction()) {
8787
info[i]->ToDetailString(isolate->GetCurrentContext()).ToLocal(&argString);
@@ -120,10 +120,7 @@ void Console::assertCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
120120
assertionError << "Assertion failed: ";
121121

122122
if (argLen > 1) {
123-
v8::Local<v8::String> argString;
124-
info[1]->ToDetailString(isolate->GetCurrentContext()).ToLocal(&argString);
125-
126-
assertionError << ArgConverter::ConvertToString(argString);
123+
assertionError << buildLogString(info, 1);
127124
} else {
128125
assertionError << "console.assert";
129126
}
@@ -197,11 +194,12 @@ void Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
197194

198195
ss << "==== object dump end ====" << std::endl;
199196
} else {
200-
v8::Local<v8::String> argString;
201-
info[0]->ToString(isolate->GetCurrentContext()).ToLocal(&argString);
197+
std::string logString = buildLogString(info);
202198

203-
ss << ArgConverter::ConvertToString(argString);
199+
ss << logString;
204200
}
201+
} else {
202+
ss << std::endl;
205203
}
206204

207205
std::string log = ss.str();

0 commit comments

Comments
 (0)