From 7ce713c6fb0a6d8e2b6b4de29b131095ca80f16b Mon Sep 17 00:00:00 2001 From: Christopher Williams Date: Tue, 15 Dec 2020 15:53:07 -0500 Subject: [PATCH] fix(android): explicitly define Ti.Android.currentService to be null when not a service --- common/Resources/ti.internal/kernel/module.js | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/common/Resources/ti.internal/kernel/module.js b/common/Resources/ti.internal/kernel/module.js index 1e0d9d71019..dbf46dd4c4f 100644 --- a/common/Resources/ti.internal/kernel/module.js +++ b/common/Resources/ti.internal/kernel/module.js @@ -598,12 +598,20 @@ function bootstrap (global, kroll) { // On iOS, we don't yet pass in the value, but we do set Ti.App.currentService property beforehand! // Can we remove the preload stuff in KrollBridge.m to pass along the service instance into this like we do on Andorid? module.isService = OS_ANDROID ? (activityOrService instanceof Titanium.Service) : Ti.App.currentService !== null; - if (OS_ANDROID && module.isService) { - Object.defineProperty(Ti.Android, 'currentService', { - value: activityOrService, - writable: false, - configurable: true - }); + if (OS_ANDROID) { + if (module.isService) { + Object.defineProperty(Ti.Android, 'currentService', { + value: activityOrService, + writable: false, + configurable: true + }); + } else { + Object.defineProperty(Ti.Android, 'currentService', { + value: null, + writable: false, + configurable: true + }); + } } if (!Module.main) { @@ -612,9 +620,9 @@ function bootstrap (global, kroll) { filename = filename.replace('Resources/', '/'); // normalize back to absolute paths (which really are relative to Resources under the hood) module.load(filename, source); - if (OS_ANDROID && module.isService) { + if (OS_ANDROID) { Object.defineProperty(Ti.Android, 'currentService', { - value: undefined, + value: null, writable: false, configurable: true });