Skip to content

Commit

Permalink
fix(ios): properly detect when optional callback is not supplied
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sgtcoolguy committed Jul 20, 2020
1 parent 47d7ae9 commit b5bb437
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions iphone/Classes/PlatformModule.m
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions iphone/Classes/TiNetworkBonjourServiceProxy.m
Expand Up @@ -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];
Expand Down Expand Up @@ -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];
}

Expand All @@ -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];
Expand Down

0 comments on commit b5bb437

Please sign in to comment.