Skip to content

Commit de75287

Browse files
[Issue newyankeecodeshop#11] Fixed internal state management for NSFastEnumeration implementation.
1 parent 342377d commit de75287

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

Classes/GAScriptObject.m

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,8 @@ - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
255255
// or until we've provided as many items as the stack based buffer will hold.
256256
while((enumState->state < propCount) && (count < len))
257257
{
258-
// For this sample, we generate the contents on the fly.
259-
// A real implementation would likely just be copying objects from internal storage.
260-
enumState->itemsPtr[count] = [enumState->propNames objectAtIndex:count];
258+
enumState->itemsPtr[count++] = [enumState->propNames objectAtIndex:enumState->state];
261259
enumState->state++;
262-
count++;
263260
}
264261
}
265262
else

GAJavaScript.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@
282282
0867D690FE84028FC02AAC07 /* Project object */ = {
283283
isa = PBXProject;
284284
attributes = {
285-
LastUpgradeCheck = 0430;
285+
LastUpgradeCheck = 0450;
286286
};
287287
buildConfigurationList = 1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "GAJavaScript" */;
288288
compatibilityVersion = "Xcode 3.2";

Tests/TScriptObject.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,19 @@ - (void)testFastEnumeration
184184
}
185185

186186
GHAssertTrue(foundHostName, nil);
187+
188+
// Test that the enumeration does not return duplicate property names. It was doing that for objects with
189+
// more than 16 properties.
190+
//
191+
jsObject = [_engine scriptObjectWithReference:@"window"];
192+
NSMutableArray *keyNames = [NSMutableArray array];
193+
194+
for (id key in jsObject)
195+
{
196+
GHAssertFalse([keyNames containsObject:key], @"Enumeration is returning duplicates!");
197+
198+
[keyNames addObject:key];
199+
}
187200
}
188201

189202
- (void)testCallFunction

0 commit comments

Comments
 (0)