Skip to content

Commit

Permalink
[TIMOB-26062] iOS: Fix all Xcode Analyzer warnings & possible leaks (#…
Browse files Browse the repository at this point in the history
…10072)

* Fix all Xcode Analyzer warnings & possible leaks

* Add missing zoomLevel unit test

* Update ti.ui.webview.addontest.js
  • Loading branch information
hansemannn authored and sgtcoolguy committed May 25, 2018
1 parent 70d5c3c commit 546468b
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 8 deletions.
2 changes: 1 addition & 1 deletion iphone/Classes/AppModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ - (void)fireEvent:(NSArray *)args
// fire application level event
[host fireEvent:[entry listener] withObject:jsonObject remove:NO context:[entry context] thisObject:nil];
}
[array release];
}
[array release];
}
}

Expand Down
4 changes: 2 additions & 2 deletions iphone/Classes/GeolocationModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ - (void)requestLocationPermissions:(id)args
+ (BOOL)hasAlwaysPermissionKeys
{
if (![TiUtils isIOS11OrGreater]) {
return [[NSBundle mainBundle] objectForInfoDictionaryKey:kTiGeolocationUsageDescriptionAlways];
return [[NSBundle mainBundle] objectForInfoDictionaryKey:kTiGeolocationUsageDescriptionAlways] != nil;
}

return [[NSBundle mainBundle] objectForInfoDictionaryKey:kTiGeolocationUsageDescriptionWhenInUse] &&
Expand All @@ -892,7 +892,7 @@ + (BOOL)hasAlwaysPermissionKeys

+ (BOOL)hasWhenInUsePermissionKeys
{
return [[NSBundle mainBundle] objectForInfoDictionaryKey:kTiGeolocationUsageDescriptionWhenInUse];
return [[NSBundle mainBundle] objectForInfoDictionaryKey:kTiGeolocationUsageDescriptionWhenInUse] != nil;
}
- (void)executeAndReleaseCallbackWithCode:(NSInteger)code andMessage:(NSString *)message
{
Expand Down
3 changes: 3 additions & 0 deletions iphone/Classes/TiFilesystemFileProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ - (TiFilesystemFileStreamProxy *)open:(id)args
return [[[TiFilesystemFileStreamProxy alloc] _initWithPageContext:[self executionContext] args:payload] autorelease];
}

// Xcode complains about the "copy" method naming, but in this case it's a proxy method so we are fine
#ifndef __clang_analyzer__
- (NSNumber *)copy:(id)args
{
ENSURE_TYPE(args, NSArray);
Expand All @@ -240,6 +242,7 @@ - (NSNumber *)copy:(id)args
}
return NUMBOOL(result);
}
#endif

- (NSNumber *)createFile:(id)args
{
Expand Down
2 changes: 2 additions & 0 deletions iphone/Classes/TiUIView.m
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ - (void)setHorizontalMotionEffect_:(id)motionEffect
effect.maximumRelativeValue = @(max);

[self addMotionEffect:effect];
RELEASE_TO_NIL(effect);
}

- (void)setVerticalMotionEffect_:(id)motionEffect
Expand All @@ -814,6 +815,7 @@ - (void)setVerticalMotionEffect_:(id)motionEffect
effect.maximumRelativeValue = @(max);

[self addMotionEffect:effect];
RELEASE_TO_NIL(effect);
}

- (void)updateViewShadowPath
Expand Down
8 changes: 7 additions & 1 deletion iphone/Classes/TiUIWebViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ - (id)loading

- (NSNumber *)zoomLevel
{
return [[(TiUIWebView *)[self view] webview] stringByEvaluatingJavaScriptFromString:@"document.body.style.zoom"];
NSString *zoomLevel = [[(TiUIWebView *)[self view] webview] stringByEvaluatingJavaScriptFromString:@"document.body.style.zoom"];

if (zoomLevel == nil || zoomLevel.length == 0) {
return @(1.0);
}

return @([zoomLevel doubleValue]);
}

- (void)goBack:(id)args
Expand Down
6 changes: 3 additions & 3 deletions iphone/Classes/TiUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ + (id)valueFromDimension:(TiDimension)dimension
case TiDimensionTypeDip:
return @(dimension.value);
case TiDimensionTypePercent:
return [NSString stringWithFormat:@"%li%%", (NSInteger)(dimension.value * 100)];
return [NSString stringWithFormat:@"%li%%", (long)(dimension.value * 100)];
default: {
break;
}
Expand Down Expand Up @@ -2074,7 +2074,7 @@ + (id)stripInvalidJSONPayload:(id)jsonPayload
DebugLog(@"[WARN] Found invalid attribute \"%@\" that cannot be serialized, skipping it ...", key)
}
}
return result;
return [result autorelease];
} else if ([jsonPayload isKindOfClass:[NSArray class]]) {
NSMutableArray *result = [NSMutableArray new];
for (id value in [jsonPayload allObjects]) {
Expand All @@ -2087,7 +2087,7 @@ + (id)stripInvalidJSONPayload:(id)jsonPayload
DebugLog(@"[WARN] Found invalid value \"%@\" that cannot be serialized, skipping it ...", value);
}
}
return result;
return [result autorelease];
} else {
DebugLog(@"[ERROR] Unhandled JSON type: %@", NSStringFromClass([jsonPayload class]));
}
Expand Down
2 changes: 1 addition & 1 deletion iphone/Classes/TiViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -2931,7 +2931,7 @@ + (TiViewProxy *)unarchiveFromTemplate:(id)viewTemplate_ inContext:(id<TiEvaluat
{
TiViewTemplate *viewTemplate = [TiViewTemplate templateFromViewTemplate:viewTemplate_];
if (viewTemplate == nil) {
return;
return nil;
}

if (viewTemplate.type != nil) {
Expand Down
60 changes: 60 additions & 0 deletions tests/Resources/ti.ui.webview.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2011-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* global Ti */
/* eslint no-unused-expressions: "off" */
'use strict';
var should = require('./utilities/assertions');

describe('Titanium.UI.WebView', function () {
var win;
this.slow(2000);
this.timeout(10000);

afterEach(function () {
if (win) {
win.close();
}
win = null;
});

it.windowsMissing('.zoomLevel', function (finish) {
var webView;

this.slow(5000);
this.timeout(10000);

win = Ti.UI.createWindow();

webView = Ti.UI.createWebView({
html: '<!DOCTYPE html><html><body><p>HELLO WORLD</p></body></html>'
});

webView.addEventListener('load', function () {
should(webView.zoomLevel).be.a.Number;
should(webView.getZoomLevel).be.a.Function;
should(webView.setZoomLevel).be.a.Function;

should(webView.zoomLevel).eql(1.0);
should(webView.getZoomLevel()).eql(1.0);

setTimeout(function () {
webView.zoomLevel = 3.0;
should(webView.zoomLevel).eql(3.0);
should(webView.getZoomLevel()).eql(3.0);
setTimeout(function () {
webView.setZoomLevel(1.0);
should(webView.zoomLevel).eql(1.0);
finish();
}, 500);
}, 500);
});

win.add(webView);
win.open();
});
});

0 comments on commit 546468b

Please sign in to comment.