9
9
#include < chrono>
10
10
#include < iomanip>
11
11
#include < sstream>
12
+ #include < string>
13
+ #include < vector>
12
14
#include < V8GlobalHelpers.h>
13
15
#include < NativeScriptException.h>
16
+
17
+ #include " ArgConverter.h"
14
18
#include " Console.h"
15
19
16
20
namespace tns {
@@ -66,10 +70,27 @@ void Console::sendToADBLogcat(const std::string& message, android_LogPriority lo
66
70
}
67
71
}
68
72
69
- void Console::sendToDevToolsFrontEnd (v8::Isolate* isolate, const std::string& message , const std::string& logLevel ) {
70
- if (m_callback != nullptr ) {
71
- m_callback (isolate, message, logLevel) ;
73
+ void Console::sendToDevToolsFrontEnd (v8::Isolate* isolate, ConsoleAPIType method , const v8::FunctionCallbackInfo<v8::Value>& args ) {
74
+ if (!m_callback ) {
75
+ return ;
72
76
}
77
+
78
+ std::vector<v8::Local<v8::Value>> arg_vector;
79
+ unsigned nargs = args.Length ();
80
+ arg_vector.reserve (nargs);
81
+ for (unsigned ix = 0 ; ix < nargs; ix++)
82
+ arg_vector.push_back (args[ix]);
83
+
84
+ m_callback (isolate, method, arg_vector);
85
+ }
86
+
87
+ void Console::sendToDevToolsFrontEnd (v8::Isolate* isolate, ConsoleAPIType method, const std::string& message) {
88
+ if (!m_callback) {
89
+ return ;
90
+ }
91
+
92
+ std::vector<v8::Local<v8::Value>> args{ArgConverter::ConvertToV8String (isolate, message)};
93
+ m_callback (isolate, method, args);
73
94
}
74
95
75
96
std::string transformJSObject (v8::Isolate* isolate, v8::Local<v8::Object> object) {
@@ -170,7 +191,7 @@ void Console::assertCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
170
191
171
192
std::string log = assertionError.str ();
172
193
sendToADBLogcat (log, ANDROID_LOG_ERROR);
173
- sendToDevToolsFrontEnd (isolate, log, " error " );
194
+ sendToDevToolsFrontEnd (isolate, ConsoleAPIType:: kAssert , info );
174
195
}
175
196
} catch (NativeScriptException& e) {
176
197
e.ReThrowToV8 ();
@@ -191,7 +212,7 @@ void Console::errorCallback(const v8::FunctionCallbackInfo <v8::Value>& info) {
191
212
log += buildLogString (info);
192
213
193
214
sendToADBLogcat (log, ANDROID_LOG_ERROR);
194
- sendToDevToolsFrontEnd (info.GetIsolate (), log, " error " );
215
+ sendToDevToolsFrontEnd (info.GetIsolate (), ConsoleAPIType:: kError , info );
195
216
} catch (NativeScriptException& e) {
196
217
e.ReThrowToV8 ();
197
218
} catch (std::exception e) {
@@ -211,7 +232,7 @@ void Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
211
232
log += buildLogString (info);
212
233
213
234
sendToADBLogcat (log, ANDROID_LOG_INFO);
214
- sendToDevToolsFrontEnd (info.GetIsolate (), log, " info" );
235
+ sendToDevToolsFrontEnd (info.GetIsolate (), ConsoleAPIType:: kInfo , info);
215
236
} catch (NativeScriptException& e) {
216
237
e.ReThrowToV8 ();
217
238
} catch (std::exception e) {
@@ -231,7 +252,7 @@ void Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
231
252
log += buildLogString (info);
232
253
233
254
sendToADBLogcat (log, ANDROID_LOG_INFO);
234
- sendToDevToolsFrontEnd (info.GetIsolate (), log, " info" );
255
+ sendToDevToolsFrontEnd (info.GetIsolate (), ConsoleAPIType:: kLog , info);
235
256
} catch (NativeScriptException& e) {
236
257
e.ReThrowToV8 ();
237
258
} catch (std::exception e) {
@@ -251,7 +272,7 @@ void Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
251
272
log += buildLogString (info);
252
273
253
274
sendToADBLogcat (log, ANDROID_LOG_WARN);
254
- sendToDevToolsFrontEnd (info.GetIsolate (), log, " warning " );
275
+ sendToDevToolsFrontEnd (info.GetIsolate (), ConsoleAPIType:: kWarning , info );
255
276
} catch (NativeScriptException& e) {
256
277
e.ReThrowToV8 ();
257
278
} catch (std::exception e) {
@@ -325,7 +346,7 @@ void Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
325
346
std::string log = ss.str ();
326
347
327
348
sendToADBLogcat (log, ANDROID_LOG_INFO);
328
- sendToDevToolsFrontEnd (isolate, log, " info" );
349
+ sendToDevToolsFrontEnd (isolate, ConsoleAPIType:: kDir , info);
329
350
} catch (NativeScriptException& e) {
330
351
e.ReThrowToV8 ();
331
352
} catch (std::exception e) {
@@ -406,7 +427,7 @@ void Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
406
427
407
428
std::string log = ss.str ();
408
429
__android_log_write (ANDROID_LOG_ERROR, LOG_TAG, log.c_str ());
409
- sendToDevToolsFrontEnd (isolate, log, " error " );
430
+ sendToDevToolsFrontEnd (isolate, ConsoleAPIType:: kTrace , info );
410
431
} catch (NativeScriptException& e) {
411
432
e.ReThrowToV8 ();
412
433
} catch (std::exception e) {
@@ -480,7 +501,7 @@ void Console::timeEndCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
480
501
std::string warning = std::string (" No such label '" + label + " ' for console.timeEnd()" );
481
502
482
503
__android_log_write (ANDROID_LOG_WARN, LOG_TAG, warning.c_str ());
483
- sendToDevToolsFrontEnd (isolate, warning, " warning" );
504
+ sendToDevToolsFrontEnd (isolate, ConsoleAPIType:: kWarning , warning);
484
505
485
506
return ;
486
507
}
@@ -499,7 +520,7 @@ void Console::timeEndCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
499
520
std::string log = ss.str ();
500
521
501
522
__android_log_write (ANDROID_LOG_INFO, LOG_TAG, log.c_str ());
502
- sendToDevToolsFrontEnd (isolate, log, " info " );
523
+ sendToDevToolsFrontEnd (isolate, ConsoleAPIType:: kTimeEnd , log );
503
524
} catch (NativeScriptException& e) {
504
525
e.ReThrowToV8 ();
505
526
} catch (std::exception e) {
0 commit comments