From 31424c6c2e85ad5d18c5d45c156221545e8a0e22 Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Mon, 20 Jul 2020 10:09:41 -0400 Subject: [PATCH] fix(ios): properly detect when optional callback is not supplied The new JSC API will give us a JSValue* that represents undefined. We only checked the pointer/value was nil. We need to guard for nil and verify the JSValue is a function (or not use/call the callback) Fixes TIMOB-27846 --- iphone/Classes/PlatformModule.m | 6 ++++++ iphone/Classes/TiNetworkBonjourServiceProxy.m | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/iphone/Classes/PlatformModule.m b/iphone/Classes/PlatformModule.m index ae8bba87381..62a6ca4dff1 100644 --- a/iphone/Classes/PlatformModule.m +++ b/iphone/Classes/PlatformModule.m @@ -309,6 +309,12 @@ - (BOOL)openURL:(NSString *)url withOptions:(JSValue *)options andCallback:(JSVa } else if ([options isObject]) { optionsDict = [options toDictionary]; } + // Ensure callback is actually a function. If not, make it nil so we don't fire it + // Since callback is optional, this may be a JSValue representing 'undefined' here wich is not nil + // So we need this special guard + if (![callback isFunction]) { + callback = nil; + } if (newUrl != nil) { [[UIApplication sharedApplication] openURL:newUrl diff --git a/iphone/Classes/TiNetworkBonjourServiceProxy.m b/iphone/Classes/TiNetworkBonjourServiceProxy.m index a7879a7aa92..61f28f863dd 100644 --- a/iphone/Classes/TiNetworkBonjourServiceProxy.m +++ b/iphone/Classes/TiNetworkBonjourServiceProxy.m @@ -227,7 +227,7 @@ - (void)publish:(JSValue *)socketProxy withCallback:(JSValue *)callback port:[port intValue]]; [service setDelegate:self]; - if (callback != nil) { + if (callback != nil && [callback isFunction]) { publishCallback = [callback retain]; } [service publish]; @@ -261,7 +261,7 @@ - (void)resolve:(NSTimeInterval)timeout withCallback:(JSValue *)callback timeout = 120.0; } - if (callback != nil) { + if (callback != nil && [callback isFunction]) { resolveCallback = [callback retain]; } @@ -270,7 +270,7 @@ - (void)resolve:(NSTimeInterval)timeout withCallback:(JSValue *)callback - (void)stop:(JSValue *)callback { - if (callback != nil) { + if (callback != nil && [callback isFunction]) { stopCallback = [callback retain]; } [service stop];