22#include " Runtime.h"
33#include " NativeScriptException.h"
44#include " CallbackHandlers.h"
5+ #include " WorkerWrapper.h"
56#include < sstream>
67#include < android/log.h>
78
@@ -352,69 +353,6 @@ extern "C" JNIEXPORT jint Java_com_tns_Runtime_getCurrentRuntimeIdLegacy(JNIEnv*
352353 return getCurrentRuntimeIdCritical_impl ();
353354}
354355
355- extern " C" JNIEXPORT void Java_com_tns_Runtime_WorkerGlobalOnMessageCallback (JNIEnv* env, jobject obj, jint runtimeId, jstring msg) {
356- // Worker Thread runtime
357- auto runtime = TryGetRuntime (runtimeId);
358- if (runtime == nullptr ) {
359- // TODO: Pete: Log message informing the developer of the failure
360- return ;
361- }
362-
363- auto isolate = runtime->GetIsolate ();
364-
365- v8::Locker locker (isolate);
366- v8::Isolate::Scope isolate_scope (isolate);
367- v8::HandleScope handleScope (isolate);
368- auto context = runtime->GetContext ();
369- v8::Context::Scope context_scope (context);
370-
371- CallbackHandlers::WorkerGlobalOnMessageCallback (isolate, msg);
372- }
373-
374- extern " C" JNIEXPORT void Java_com_tns_Runtime_WorkerObjectOnMessageCallback (JNIEnv* env, jobject obj, jint runtimeId, jint workerId, jstring msg) {
375- // Main Thread runtime
376- auto runtime = TryGetRuntime (runtimeId);
377- if (runtime == nullptr ) {
378- // TODO: Pete: Log message informing the developer of the failure
379- return ;
380- }
381-
382- auto isolate = runtime->GetIsolate ();
383-
384- v8::Locker locker (isolate);
385- v8::Isolate::Scope isolate_scope (isolate);
386- v8::HandleScope handleScope (isolate);
387- auto context = runtime->GetContext ();
388- v8::Context::Scope context_scope (context);
389-
390- CallbackHandlers::WorkerObjectOnMessageCallback (isolate, workerId, msg);
391- }
392-
393- extern " C" JNIEXPORT void Java_com_tns_Runtime_TerminateWorkerCallback (JNIEnv* env, jobject obj, jint runtimeId) {
394- // Worker Thread runtime
395- auto runtime = TryGetRuntime (runtimeId);
396- if (runtime == nullptr ) {
397- // TODO: Pete: Log message informing the developer of the failure
398- return ;
399- }
400-
401- auto isolate = runtime->GetIsolate ();
402-
403- {
404- v8::Locker locker (isolate);
405- v8::Isolate::Scope isolate_scope (isolate);
406- v8::HandleScope handleScope (isolate);
407-
408- CallbackHandlers::TerminateWorkerThread (isolate);
409-
410- runtime->DestroyRuntime ();
411- }
412-
413- isolate->Dispose ();
414-
415- delete runtime;
416- }
417-
418356extern " C" JNIEXPORT void Java_com_tns_Runtime_TerminateRuntimeCallback (JNIEnv* env, jobject obj, jint runtimeId) {
419357 auto runtime = TryGetRuntime (runtimeId);
420358 if (runtime == nullptr ) {
@@ -424,6 +362,11 @@ extern "C" JNIEXPORT void Java_com_tns_Runtime_TerminateRuntimeCallback(JNIEnv*
424362
425363 auto isolate = runtime->GetIsolate ();
426364
365+ // Terminate this runtime's child workers before disposing the isolate. Their
366+ // Worker object persistents live in this isolate, so they must be released
367+ // first - mirrors WorkerWrapper::BackgroundLooper's nested-worker teardown.
368+ WorkerWrapper::TerminateChildren (isolate);
369+
427370 {
428371 v8::Locker locker (isolate);
429372 v8::Isolate::Scope isolate_scope (isolate);
@@ -437,46 +380,6 @@ extern "C" JNIEXPORT void Java_com_tns_Runtime_TerminateRuntimeCallback(JNIEnv*
437380 delete runtime;
438381}
439382
440- extern " C" JNIEXPORT void Java_com_tns_Runtime_ClearWorkerPersistent (JNIEnv* env, jobject obj, jint runtimeId, jint workerId) {
441- // Worker Thread runtime
442- auto runtime = TryGetRuntime (runtimeId);
443- if (runtime == nullptr ) {
444- // TODO: Pete: Log message informing the developer of the failure
445- return ;
446- }
447-
448- auto isolate = runtime->GetIsolate ();
449-
450- v8::Locker locker (isolate);
451- v8::Isolate::Scope isolate_scope (isolate);
452- v8::HandleScope handleScope (isolate);
453- auto context = runtime->GetContext ();
454- v8::Context::Scope context_scope (context);
455-
456- CallbackHandlers::ClearWorkerPersistent (workerId);
457- }
458-
459- extern " C" JNIEXPORT void Java_com_tns_Runtime_CallWorkerObjectOnErrorHandleMain (JNIEnv* env, jobject obj, jint runtimeId, jint workerId, jstring message, jstring stackTrace, jstring filename, jint lineno, jstring threadName) {
460- // Main Thread runtime
461- auto runtime = TryGetRuntime (runtimeId);
462- if (runtime == nullptr ) {
463- // TODO: Pete: Log message informing the developer of the failure
464- return ;
465- }
466-
467- auto isolate = runtime->GetIsolate ();
468- v8::Locker locker (isolate);
469- v8::Isolate::Scope isolate_scope (isolate);
470- v8::HandleScope handleScope (isolate);
471- auto context = runtime->GetContext ();
472- v8::Context::Scope context_scope (context);
473-
474- try {
475- CallbackHandlers::CallWorkerObjectOnErrorHandle (isolate, workerId, message, stackTrace, filename, lineno, threadName);
476- } catch (NativeScriptException& e) {
477- e.ReThrowToJava ();
478- }
479- }
480383extern " C" JNIEXPORT void Java_com_tns_Runtime_ResetDateTimeConfigurationCache (JNIEnv* _env, jobject obj, jint runtimeId) {
481384 auto runtime = TryGetRuntime (runtimeId);
482385 if (runtime == nullptr ) {
0 commit comments