@@ -72,7 +72,7 @@ void Console::sendToDevToolsFrontEnd(v8::Isolate* isolate, const std::string& me
72
72
v8_inspector::V8LogAgentImpl::EntryAdded (message, logLevel, ArgConverter::ConvertToString (frame->GetScriptNameOrSourceURL ()), frame->GetLineNumber ());
73
73
}
74
74
75
- const std::string& buildLogString (const v8::FunctionCallbackInfo<v8::Value>& info) {
75
+ const std::string buildLogString (const v8::FunctionCallbackInfo<v8::Value>& info) {
76
76
auto isolate = info.GetIsolate ();
77
77
78
78
v8::HandleScope scope (isolate);
@@ -99,9 +99,13 @@ const std::string& buildLogString(const v8::FunctionCallbackInfo<v8::Value>& inf
99
99
100
100
ss << ArgConverter::ConvertToString (argString);
101
101
}
102
+ } else {
103
+ ss << std::endl;
102
104
}
103
105
104
- return ss.str ();
106
+ std::string stringResult = ss.str ();
107
+
108
+ return stringResult;
105
109
}
106
110
107
111
void Console::assertCallback (const v8::FunctionCallbackInfo<v8::Value>& info) {
@@ -111,20 +115,20 @@ void Console::assertCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
111
115
auto expressionPasses = argLen && info[0 ]->BooleanValue ();
112
116
113
117
if (!expressionPasses) {
114
- std::stringstream ss ;
118
+ std::stringstream assertionError ;
115
119
116
- ss << " Assertion failed: " ;
120
+ assertionError << " Assertion failed: " ;
117
121
118
122
if (argLen > 1 ) {
119
123
v8::Local<v8::String> argString;
120
124
info[1 ]->ToDetailString (isolate->GetCurrentContext ()).ToLocal (&argString);
121
125
122
- ss << ArgConverter::ConvertToString (argString);
126
+ assertionError << ArgConverter::ConvertToString (argString);
123
127
} else {
124
- ss << " console.assert" ;
128
+ assertionError << " console.assert" ;
125
129
}
126
130
127
- std::string log = ss .str ();
131
+ std::string log = assertionError .str ();
128
132
sendToADBLogcat (log , ANDROID_LOG_ERROR);
129
133
sendToDevToolsFrontEnd (isolate, log , " error" );
130
134
}
@@ -177,12 +181,12 @@ void Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
177
181
178
182
auto propertiesLen = propNames->Length ();
179
183
for (int i = 0 ; i < propertiesLen; i++) {
180
- auto propName = propNames->Get (context, i).ToLocalChecked ();
181
- auto property = argObject->Get (context, propName ).ToLocalChecked ();
184
+ auto propertyName = propNames->Get (context, i).ToLocalChecked ();
185
+ auto propertyValue = argObject->Get (context, propertyName ).ToLocalChecked ();
182
186
183
- auto propIsFunction = property ->IsFunction ();
187
+ auto propIsFunction = propertyValue ->IsFunction ();
184
188
185
- ss << ArgConverter::ConvertToString (propName ->ToString (isolate));
189
+ ss << ArgConverter::ConvertToString (propertyName ->ToString (isolate));
186
190
187
191
if (propIsFunction) {
188
192
ss << " ()" ;
@@ -206,41 +210,57 @@ void Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
206
210
sendToDevToolsFrontEnd (isolate, log , " info" );
207
211
}
208
212
209
- const std::string& buildStacktraceFrameLocationPart (v8::Local<v8::StackFrame> frame) {
213
+ const std::string buildStacktraceFrameLocationPart (v8::Local<v8::StackFrame> frame) {
210
214
std::stringstream ss;
211
215
212
- ss << ArgConverter::ConvertToString (frame->GetScriptNameOrSourceURL ()) << " :" << frame->GetLineNumber () << " :" << frame->GetColumn ();
216
+ auto scriptName = frame->GetScriptNameOrSourceURL ();
217
+ auto scriptNameConverted = ArgConverter::ConvertToString (scriptName);
218
+ if (scriptNameConverted.length () < 1 ) {
219
+ ss << " VM" ;
220
+ } else {
221
+ ss << scriptNameConverted << " :" << frame->GetLineNumber () << " :" << frame->GetColumn ();
222
+ }
223
+
224
+ std::string stringResult = ss.str ();
213
225
214
- return ss. str () ;
226
+ return stringResult ;
215
227
}
216
228
217
- const std::string& buildStacktraceFrameMessage (v8::Local<v8::StackFrame> frame) {
229
+ const std::string buildStacktraceFrameMessage (v8::Local<v8::StackFrame> frame) {
218
230
std::stringstream ss;
219
231
232
+ auto functionName = frame->GetFunctionName ();
233
+ auto functionNameConverted = ArgConverter::ConvertToString (functionName);
234
+ if (functionNameConverted.length () < 1 ) {
235
+ functionNameConverted = " <anonymous>" ;
236
+ }
237
+
220
238
if (frame->IsConstructor ()) {
221
- ss << " at new " << ArgConverter::ConvertToString (frame-> GetFunctionName ()) << " (" << buildStacktraceFrameLocationPart (frame) << " )" ;
239
+ ss << " at new " << functionNameConverted << " (" << buildStacktraceFrameLocationPart (frame) << " )" ;
222
240
} else if (frame->IsEval ()) {
223
241
ss << " eval at " << buildStacktraceFrameLocationPart (frame) << std::endl;
224
242
} else {
225
- ss << " at " << ArgConverter::ConvertToString (frame-> GetFunctionName ()) << " (" << buildStacktraceFrameLocationPart (frame) << " )" ;
243
+ ss << " at " << functionNameConverted << " (" << buildStacktraceFrameLocationPart (frame) << " )" ;
226
244
}
227
245
228
- return ss.str ();
246
+ std::string stringResult = ss.str ();
247
+
248
+ return stringResult;
229
249
}
230
250
231
251
void Console::traceCallback (const v8::FunctionCallbackInfo<v8::Value>& info) {
232
252
auto isolate = info.GetIsolate ();
233
253
std::stringstream ss;
234
254
235
255
std::string logString = buildLogString (info);
236
- ss << logString;
237
256
238
- // append a new line
239
- if (logString.length ()) {
240
- ss << std::endl;
257
+ if (logString.compare (" \n " ) == 0 ) {
258
+ ss << " Trace" ;
259
+ } else {
260
+ ss << " Trace: " << logString;
241
261
}
242
262
243
- ss << " Trace " << std::endl;
263
+ ss << std::endl;
244
264
245
265
v8::HandleScope scope (isolate);
246
266
0 commit comments