From 31f8501bb902815cfed8e1cd123fe8b6de2cb757 Mon Sep 17 00:00:00 2001 From: farfromrefuge Date: Fri, 21 Jun 2024 00:24:58 +0200 Subject: [PATCH] fix: correctly load ts_helpers.js in workers (#1798) * fix: correctly load ts_helpers.js in workers * chore: remove redundant arguments * feat: don't polyfill JavaProxy on worker * chore: remove unneeded appDir --------- Co-authored-by: farfromrefuge <> Co-authored-by: Eduardo Speroni --- test-app/app/src/main/assets/internal/ts_helpers.js | 4 +++- test-app/app/src/main/java/com/tns/RuntimeHelper.java | 2 +- test-app/runtime/src/main/cpp/Runtime.cpp | 1 + test-app/runtime/src/main/java/com/tns/Runtime.java | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test-app/app/src/main/assets/internal/ts_helpers.js b/test-app/app/src/main/assets/internal/ts_helpers.js index 1a0625f45..d1860dc47 100644 --- a/test-app/app/src/main/assets/internal/ts_helpers.js +++ b/test-app/app/src/main/assets/internal/ts_helpers.js @@ -170,6 +170,8 @@ Object.defineProperty(global, "__extends", { value: __extends }); Object.defineProperty(global, "__decorate", { value: __decorate }); - global.JavaProxy = JavaProxy; + if (!global.__ns__worker) { + global.JavaProxy = JavaProxy; + } global.Interfaces = Interfaces; })() \ No newline at end of file diff --git a/test-app/app/src/main/java/com/tns/RuntimeHelper.java b/test-app/app/src/main/java/com/tns/RuntimeHelper.java index 423cc44b1..90a64f16e 100644 --- a/test-app/app/src/main/java/com/tns/RuntimeHelper.java +++ b/test-app/app/src/main/java/com/tns/RuntimeHelper.java @@ -190,7 +190,7 @@ public static Runtime initRuntime(Context context) { waitForLiveSync(context); } - runtime.runScript(new File(appDir, "internal/ts_helpers.js")); +// runtime.runScript(new File(appDir, "internal/ts_helpers.js")); File javaClassesModule = new File(appDir, "app/tns-java-classes.js"); if (javaClassesModule.exists()) { diff --git a/test-app/runtime/src/main/cpp/Runtime.cpp b/test-app/runtime/src/main/cpp/Runtime.cpp index 6457527e4..8d831d9be 100644 --- a/test-app/runtime/src/main/cpp/Runtime.cpp +++ b/test-app/runtime/src/main/cpp/Runtime.cpp @@ -577,6 +577,7 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native else { m_isMainThread = false; auto postMessageFuncTemplate = FunctionTemplate::New(isolate, CallbackHandlers::WorkerGlobalPostMessageCallback); + globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__ns__worker"), Boolean::New(isolate, true)); globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "postMessage"), postMessageFuncTemplate); auto closeFuncTemplate = FunctionTemplate::New(isolate, CallbackHandlers::WorkerGlobalCloseCallback); globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "close"), closeFuncTemplate); diff --git a/test-app/runtime/src/main/java/com/tns/Runtime.java b/test-app/runtime/src/main/java/com/tns/Runtime.java index ad8caed91..17670e3dc 100644 --- a/test-app/runtime/src/main/java/com/tns/Runtime.java +++ b/test-app/runtime/src/main/java/com/tns/Runtime.java @@ -605,6 +605,7 @@ public static void initWorker(String jsFileName, String callingJsDir, int id) { private static Runtime initRuntime(DynamicConfiguration dynamicConfiguration) { Runtime runtime = new Runtime(staticConfiguration, dynamicConfiguration); runtime.init(); + runtime.runScript(new File(staticConfiguration.appDir, "internal/ts_helpers.js")); return runtime; }