99#include < chrono>
1010#include < iomanip>
1111#include < sstream>
12+ #include < string>
13+ #include < vector>
1214#include < V8GlobalHelpers.h>
1315#include < NativeScriptException.h>
16+
17+ #include " ArgConverter.h"
1418#include " Console.h"
1519
1620namespace tns {
@@ -66,10 +70,27 @@ void Console::sendToADBLogcat(const std::string& message, android_LogPriority lo
6670 }
6771}
6872
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 ;
7276 }
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);
7394}
7495
7596std::string transformJSObject (v8::Isolate* isolate, v8::Local<v8::Object> object) {
@@ -170,7 +191,7 @@ void Console::assertCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
170191
171192 std::string log = assertionError.str ();
172193 sendToADBLogcat (log, ANDROID_LOG_ERROR);
173- sendToDevToolsFrontEnd (isolate, log, " error " );
194+ sendToDevToolsFrontEnd (isolate, ConsoleAPIType:: kAssert , info );
174195 }
175196 } catch (NativeScriptException& e) {
176197 e.ReThrowToV8 ();
@@ -191,7 +212,7 @@ void Console::errorCallback(const v8::FunctionCallbackInfo <v8::Value>& info) {
191212 log += buildLogString (info);
192213
193214 sendToADBLogcat (log, ANDROID_LOG_ERROR);
194- sendToDevToolsFrontEnd (info.GetIsolate (), log, " error " );
215+ sendToDevToolsFrontEnd (info.GetIsolate (), ConsoleAPIType:: kError , info );
195216 } catch (NativeScriptException& e) {
196217 e.ReThrowToV8 ();
197218 } catch (std::exception e) {
@@ -211,7 +232,7 @@ void Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
211232 log += buildLogString (info);
212233
213234 sendToADBLogcat (log, ANDROID_LOG_INFO);
214- sendToDevToolsFrontEnd (info.GetIsolate (), log, " info" );
235+ sendToDevToolsFrontEnd (info.GetIsolate (), ConsoleAPIType:: kInfo , info);
215236 } catch (NativeScriptException& e) {
216237 e.ReThrowToV8 ();
217238 } catch (std::exception e) {
@@ -231,7 +252,7 @@ void Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
231252 log += buildLogString (info);
232253
233254 sendToADBLogcat (log, ANDROID_LOG_INFO);
234- sendToDevToolsFrontEnd (info.GetIsolate (), log, " info" );
255+ sendToDevToolsFrontEnd (info.GetIsolate (), ConsoleAPIType:: kLog , info);
235256 } catch (NativeScriptException& e) {
236257 e.ReThrowToV8 ();
237258 } catch (std::exception e) {
@@ -251,7 +272,7 @@ void Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
251272 log += buildLogString (info);
252273
253274 sendToADBLogcat (log, ANDROID_LOG_WARN);
254- sendToDevToolsFrontEnd (info.GetIsolate (), log, " warning " );
275+ sendToDevToolsFrontEnd (info.GetIsolate (), ConsoleAPIType:: kWarning , info );
255276 } catch (NativeScriptException& e) {
256277 e.ReThrowToV8 ();
257278 } catch (std::exception e) {
@@ -325,7 +346,7 @@ void Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
325346 std::string log = ss.str ();
326347
327348 sendToADBLogcat (log, ANDROID_LOG_INFO);
328- sendToDevToolsFrontEnd (isolate, log, " info" );
349+ sendToDevToolsFrontEnd (isolate, ConsoleAPIType:: kDir , info);
329350 } catch (NativeScriptException& e) {
330351 e.ReThrowToV8 ();
331352 } catch (std::exception e) {
@@ -406,7 +427,7 @@ void Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
406427
407428 std::string log = ss.str ();
408429 __android_log_write (ANDROID_LOG_ERROR, LOG_TAG, log.c_str ());
409- sendToDevToolsFrontEnd (isolate, log, " error " );
430+ sendToDevToolsFrontEnd (isolate, ConsoleAPIType:: kTrace , info );
410431 } catch (NativeScriptException& e) {
411432 e.ReThrowToV8 ();
412433 } catch (std::exception e) {
@@ -480,7 +501,7 @@ void Console::timeEndCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
480501 std::string warning = std::string (" No such label '" + label + " ' for console.timeEnd()" );
481502
482503 __android_log_write (ANDROID_LOG_WARN, LOG_TAG, warning.c_str ());
483- sendToDevToolsFrontEnd (isolate, warning, " warning" );
504+ sendToDevToolsFrontEnd (isolate, ConsoleAPIType:: kWarning , warning);
484505
485506 return ;
486507 }
@@ -499,7 +520,7 @@ void Console::timeEndCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
499520 std::string log = ss.str ();
500521
501522 __android_log_write (ANDROID_LOG_INFO, LOG_TAG, log.c_str ());
502- sendToDevToolsFrontEnd (isolate, log, " info " );
523+ sendToDevToolsFrontEnd (isolate, ConsoleAPIType:: kTimeEnd , log );
503524 } catch (NativeScriptException& e) {
504525 e.ReThrowToV8 ();
505526 } catch (std::exception e) {
0 commit comments