Skip to content

Commit 31f8501

Browse files
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 <edusperoni@gmail.com>
1 parent fb30932 commit 31f8501

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

test-app/app/src/main/assets/internal/ts_helpers.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@
170170
Object.defineProperty(global, "__extends", { value: __extends });
171171
Object.defineProperty(global, "__decorate", { value: __decorate });
172172

173-
global.JavaProxy = JavaProxy;
173+
if (!global.__ns__worker) {
174+
global.JavaProxy = JavaProxy;
175+
}
174176
global.Interfaces = Interfaces;
175177
})()

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public static Runtime initRuntime(Context context) {
190190
waitForLiveSync(context);
191191
}
192192

193-
runtime.runScript(new File(appDir, "internal/ts_helpers.js"));
193+
// runtime.runScript(new File(appDir, "internal/ts_helpers.js"));
194194

195195
File javaClassesModule = new File(appDir, "app/tns-java-classes.js");
196196
if (javaClassesModule.exists()) {

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

+1
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native
577577
else {
578578
m_isMainThread = false;
579579
auto postMessageFuncTemplate = FunctionTemplate::New(isolate, CallbackHandlers::WorkerGlobalPostMessageCallback);
580+
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__ns__worker"), Boolean::New(isolate, true));
580581
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "postMessage"), postMessageFuncTemplate);
581582
auto closeFuncTemplate = FunctionTemplate::New(isolate, CallbackHandlers::WorkerGlobalCloseCallback);
582583
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "close"), closeFuncTemplate);

test-app/runtime/src/main/java/com/tns/Runtime.java

+1
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ public static void initWorker(String jsFileName, String callingJsDir, int id) {
605605
private static Runtime initRuntime(DynamicConfiguration dynamicConfiguration) {
606606
Runtime runtime = new Runtime(staticConfiguration, dynamicConfiguration);
607607
runtime.init();
608+
runtime.runScript(new File(staticConfiguration.appDir, "internal/ts_helpers.js"));
608609

609610
return runtime;
610611
}

0 commit comments

Comments
 (0)