diff --git a/iphone/Classes/TiProxy.h b/iphone/Classes/TiProxy.h index 628c2827a3d..17a29db3343 100644 --- a/iphone/Classes/TiProxy.h +++ b/iphone/Classes/TiProxy.h @@ -111,7 +111,8 @@ void DoProxyDelegateReadValuesWithKeysFromProxy(UIView * 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; diff --git a/iphone/Classes/TiProxy.m b/iphone/Classes/TiProxy.m index 71602ebad69..5d5f2e96a24 100644 --- a/iphone/Classes/TiProxy.m +++ b/iphone/Classes/TiProxy.m @@ -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); } @@ -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); @@ -580,10 +582,12 @@ -(id)_proxy:(TiProxyBridgeType)type #pragma mark Public + -(id)allKeys { pthread_rwlock_rdlock(&dynpropsLock); - id keys = [dynprops allKeys]; + // Make sure the keys are in the same order as they were added in the JS + id keys = dynpropnames; pthread_rwlock_unlock(&dynpropsLock); return keys; @@ -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"]) @@ -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 @@ -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); @@ -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); } diff --git a/iphone/Classes/TiUIWebViewProxy.h b/iphone/Classes/TiUIWebViewProxy.h index 8cb59de5323..6d5730fa131 100644 --- a/iphone/Classes/TiUIWebViewProxy.h +++ b/iphone/Classes/TiUIWebViewProxy.h @@ -13,6 +13,7 @@ @private NSString *pageToken; NSString *evalResult; + NSArray *webKeySequence; BOOL inKJSThread; } -(void)setPageToken:(NSString*)pageToken; diff --git a/iphone/Classes/TiUIWebViewProxy.m b/iphone/Classes/TiUIWebViewProxy.m index b910865131c..57bb09aa940 100644 --- a/iphone/Classes/TiUIWebViewProxy.m +++ b/iphone/Classes/TiUIWebViewProxy.m @@ -14,11 +14,10 @@ @implementation TiUIWebViewProxy -static NSArray* webKeySequence; - #ifdef DEBUG_MEMORY -(void)dealloc { + RELEASE_TO_NIL(webKeySequence); [super dealloc]; } @@ -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; }