Skip to content

Commit c0f5514

Browse files
committed
fix: always log console messages and uncomment live sync
1 parent d243cf0 commit c0f5514

File tree

4 files changed

+9
-49
lines changed

4 files changed

+9
-49
lines changed

test-app/app/src/main/java/com/tns/RuntimeHelper.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public static Runtime initRuntime(Context context) {
162162
appDir, classLoader, dexDir, dexThumb, appConfig, isDebuggable);
163163

164164
runtime = Runtime.initializeRuntimeWithConfiguration(config);
165-
// if (isDebuggable) {
165+
if (isDebuggable) {
166166
// try {
167167
// v8Inspector = new AndroidJsV8Inspector(context.getFilesDir().getAbsolutePath(), context.getPackageName());
168168
// v8Inspector.start();
@@ -198,10 +198,10 @@ public static Runtime initRuntime(Context context) {
198198
//
199199
// // if app is in debuggable mode run livesync service
200200
// // runtime needs to be initialized before the NativeScriptSyncService is enabled because it uses runtime.runScript(...)
201-
// initLiveSync(runtime, logger, context);
202-
//
203-
// waitForLiveSync(context);
204-
// }
201+
initLiveSync(runtime, logger, context);
202+
203+
waitForLiveSync(context);
204+
}
205205

206206
runtime.runScript(new File(appDir, "internal/ts_helpers.js"));
207207

test-app/runtime/src/main/cpp/Runtime.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -711,16 +711,17 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native
711711
CallbackHandlers::CreateGlobalCastFunctions(isolate, globalTemplate);
712712

713713
Local<Context> context = Context::New(isolate, nullptr, globalTemplate);
714-
m_weakRef.Init(isolate,context, context->Global(), m_objectManager);
714+
715+
auto global = context->Global();
716+
717+
m_weakRef.Init(isolate,context, global, m_objectManager);
715718

716719
context->Enter();
717720

718721
m_objectManager->Init(isolate);
719722

720723
m_module.Init(isolate, callingDir);
721724

722-
auto global = context->Global();
723-
724725
Local<Value> gcFunc;
725726
global->Get(context, ArgConverter::ConvertToV8String(isolate, "gc")).ToLocal(&gcFunc);
726727
if (!gcFunc.IsEmpty() && gcFunc->IsFunction()) {

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

-35
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ namespace tns {
1818
v8::Local<v8::Object> Console::createConsole(v8::Local<v8::Context> context, ConsoleCallback callback, const int maxLogcatObjectSize, const bool forceLog) {
1919
m_callback = callback;
2020
m_maxLogcatObjectSize = maxLogcatObjectSize;
21-
m_forceLog = forceLog;
2221
v8::Context::Scope contextScope(context);
2322
v8::Isolate* isolate = context->GetIsolate();
2423

@@ -167,9 +166,6 @@ const std::string buildLogString(const v8::FunctionCallbackInfo<v8::Value>& info
167166
}
168167

169168
void Console::assertCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
170-
if (!shouldLog()) {
171-
return;
172-
}
173169
try {
174170
auto isolate = info.GetIsolate();
175171

@@ -206,9 +202,6 @@ void Console::assertCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
206202
}
207203

208204
void Console::errorCallback(const v8::FunctionCallbackInfo <v8::Value>& info) {
209-
if (!shouldLog()) {
210-
return;
211-
}
212205
try {
213206
std::string log = buildLogString(info);
214207

@@ -228,9 +221,6 @@ void Console::errorCallback(const v8::FunctionCallbackInfo <v8::Value>& info) {
228221
}
229222

230223
void Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
231-
if (!shouldLog()) {
232-
return;
233-
}
234224
try {
235225
std::string log = buildLogString(info);
236226

@@ -250,9 +240,6 @@ void Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
250240
}
251241

252242
void Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
253-
if (!shouldLog()) {
254-
return;
255-
}
256243
try {
257244
std::string log = buildLogString(info);
258245

@@ -272,9 +259,6 @@ void Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
272259
}
273260

274261
void Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
275-
if (!shouldLog()) {
276-
return;
277-
}
278262
try {
279263
std::string log = buildLogString(info);
280264

@@ -294,9 +278,6 @@ void Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
294278
}
295279

296280
void Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
297-
if (!shouldLog()) {
298-
return;
299-
}
300281
try {
301282
auto isolate = info.GetIsolate();
302283
auto context = isolate->GetCurrentContext();
@@ -411,9 +392,6 @@ const std::string buildStacktraceFrameMessage(v8::Local<v8::StackFrame> frame) {
411392
}
412393

413394
void Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
414-
if (!shouldLog()) {
415-
return;
416-
}
417395
try {
418396
auto isolate = info.GetIsolate();
419397
std::stringstream ss;
@@ -457,9 +435,6 @@ void Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
457435
}
458436

459437
void Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
460-
if (!shouldLog()) {
461-
return;
462-
}
463438
try {
464439
auto isolate = info.GetIsolate();
465440

@@ -496,9 +471,6 @@ void Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
496471
}
497472

498473
void Console::timeEndCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
499-
if (!shouldLog()) {
500-
return;
501-
}
502474
try {
503475
auto isolate = info.GetIsolate();
504476

@@ -563,11 +535,4 @@ const char* Console::LOG_TAG = "JS";
563535
std::map<v8::Isolate*, std::map<std::string, double>> Console::s_isolateToConsoleTimersMap;
564536
ConsoleCallback Console::m_callback = nullptr;
565537
int Console::m_maxLogcatObjectSize;
566-
bool Console::m_forceLog;
567-
568-
#ifdef APPLICATION_IN_DEBUG
569-
bool Console::isApplicationInDebug = true;
570-
#else
571-
bool Console::isApplicationInDebug = false;
572-
#endif
573538
}

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

-6
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,10 @@ class Console {
3232

3333
private:
3434
static int m_maxLogcatObjectSize;
35-
static bool m_forceLog;
3635
static ConsoleCallback m_callback;
3736
static const char* LOG_TAG;
3837
static std::map<v8::Isolate*, std::map<std::string, double>> s_isolateToConsoleTimersMap;
3938

40-
static bool isApplicationInDebug;
41-
static bool shouldLog() {
42-
return m_forceLog || isApplicationInDebug;
43-
}
44-
4539
// heavily inspired by 'createBoundFunctionProperty' of V8's v8-console.h
4640
static void bindFunctionProperty(v8::Local<v8::Context> context,
4741
v8::Local<v8::Object> consoleInstance,

0 commit comments

Comments
 (0)