Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-13662] iOS Fixed property order in proxies and webview setUrl() #5971

Merged
merged 1 commit into from Jun 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion iphone/Classes/TiProxy.h
Expand Up @@ -111,7 +111,8 @@ void DoProxyDelegateReadValuesWithKeysFromProxy(UIView<TiProxyDelegate> * target
pthread_rwlock_t listenerLock;
BOOL reproxying;
@protected
NSMutableDictionary *dynprops;
NSMutableDictionary *dynprops;
NSMutableArray *dynpropnames;
pthread_rwlock_t dynpropsLock; // NOTE: You must respect the dynprops lock when accessing dynprops elsewhere!

int bridgeCount;
Expand Down
29 changes: 26 additions & 3 deletions iphone/Classes/TiProxy.m
Expand Up @@ -231,9 +231,10 @@ -(void)initializeProperty:(NSString*)name defaultValue:(id)value
pthread_rwlock_wrlock(&dynpropsLock);
if (dynprops == nil) {
dynprops = [[NSMutableDictionary alloc] init];
dynpropnames = [[NSMutableArray alloc] init];
}
if ([dynprops valueForKey:name] == nil) {
[dynprops setValue:((value == nil) ? [NSNull null] : value) forKey:name];
[self addKey:name toValue:((value == nil) ? [NSNull null] : value)];
}
pthread_rwlock_unlock(&dynpropsLock);
}
Expand Down Expand Up @@ -423,6 +424,7 @@ -(void)_destroy

pthread_rwlock_wrlock(&dynpropsLock);
RELEASE_TO_NIL(dynprops);
RELEASE_TO_NIL(dynpropnames);
pthread_rwlock_unlock(&dynpropsLock);

RELEASE_TO_NIL(baseURL);
Expand Down Expand Up @@ -580,10 +582,12 @@ -(id)_proxy:(TiProxyBridgeType)type

#pragma mark Public


-(id<NSFastEnumeration>)allKeys
{
pthread_rwlock_rdlock(&dynpropsLock);
id<NSFastEnumeration> keys = [dynprops allKeys];
// Make sure the keys are in the same order as they were added in the JS
id<NSFastEnumeration> keys = dynpropnames;
pthread_rwlock_unlock(&dynpropsLock);

return keys;
Expand Down Expand Up @@ -1065,6 +1069,18 @@ - (void)setValuesForKeysWithDictionary:(NSDictionary *)keyedValues

DEFINE_EXCEPTIONS

-(void)addKey:(NSString*)key toValue:(id)val
{
[dynprops setValue:val forKey:key];
for (NSInteger i = 0, len = [dynpropnames count]; i < len; i++) {
if([[dynpropnames objectAtIndex:i] isEqualToString:key]) {
[dynpropnames removeObjectAtIndex:i];
break;
}
}
[dynpropnames addObject:key];
}

- (id) valueForUndefinedKey: (NSString *) key
{
if ([key isEqualToString:@"toString"] || [key isEqualToString:@"valueOf"])
Expand Down Expand Up @@ -1123,6 +1139,7 @@ - (void)replaceValue:(id)value forKey:(NSString*)key notification:(BOOL)notify
else
{
dynprops = [[NSMutableDictionary alloc] init];
dynpropnames = [[NSMutableArray alloc] init];
}

// TODO: Clarify internal difference between nil/NSNull
Expand All @@ -1142,7 +1159,7 @@ - (void)replaceValue:(id)value forKey:(NSString*)key notification:(BOOL)notify
if ([propvalue isKindOfClass:[TiProxy class]]) {
[self rememberProxy:propvalue];
}
[dynprops setValue:propvalue forKey:key];
[self addKey:key toValue:propvalue];
}
pthread_rwlock_unlock(&dynpropsLock);

Expand All @@ -1168,6 +1185,12 @@ - (void) deleteKey:(NSString*)key
if (dynprops!=nil)
{
[dynprops removeObjectForKey:key];
for(NSInteger i = 0, len = [dynpropnames count]; i < len; i++) {
if([[dynpropnames objectAtIndex:i] isEqualToString:key]) {
[dynpropnames removeObjectAtIndex:i];
break;
}
}
}
pthread_rwlock_unlock(&dynpropsLock);
}
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiUIWebViewProxy.h
Expand Up @@ -13,6 +13,7 @@
@private
NSString *pageToken;
NSString *evalResult;
NSArray *webKeySequence;
BOOL inKJSThread;
}
-(void)setPageToken:(NSString*)pageToken;
Expand Down
16 changes: 9 additions & 7 deletions iphone/Classes/TiUIWebViewProxy.m
Expand Up @@ -14,11 +14,10 @@

@implementation TiUIWebViewProxy

static NSArray* webKeySequence;

#ifdef DEBUG_MEMORY
-(void)dealloc
{
RELEASE_TO_NIL(webKeySequence);
[super dealloc];
}

Expand All @@ -35,11 +34,14 @@ -(void)release

-(NSArray *)keySequence
{
if (webKeySequence == nil)
{
//URL has to be processed first since the spinner depends on URL being remote
webKeySequence = [[NSArray arrayWithObjects:@"url",nil] retain];
}
RELEASE_TO_NIL(webKeySequence)
// if "html" is not set, the URL has to be processed first since the spinner depends on URL being remote
if ([self valueForUndefinedKey:@"html"] == nil) {
webKeySequence = [[NSArray arrayWithObjects:@"url",nil] retain];
} else {
webKeySequence = [[NSArray array] retain];
}

return webKeySequence;
}

Expand Down