diff --git a/Foundation/CPArray/_CPJavaScriptArray.j b/Foundation/CPArray/_CPJavaScriptArray.j index 640a9bdf0..6785d8b14 100644 --- a/Foundation/CPArray/_CPJavaScriptArray.j +++ b/Foundation/CPArray/_CPJavaScriptArray.j @@ -35,12 +35,12 @@ var indexOf = Array.prototype.indexOf, - (id)initWithArray:(CPArray)anArray { - return slice.call(anArray, 0); + return [self initWithArray:anArray copyItems:NO]; } - (id)initWithArray:(CPArray)anArray copyItems:(BOOL)shouldCopyItems { - if (!shouldCopyItems) + if (!shouldCopyItems && anArray.isa === _CPJavaScriptArray) return slice.call(anArray, 0); self = [super init]; diff --git a/Foundation/CPKeyValueCoding.j b/Foundation/CPKeyValueCoding.j index c618e6d73..5bba5ffbf 100644 --- a/Foundation/CPKeyValueCoding.j +++ b/Foundation/CPKeyValueCoding.j @@ -347,8 +347,8 @@ var CPObjectAccessorsForClassKey = @"$CPObjectAccessorsForClassKey", - (id)copy { - var objects = [self objectsAtIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, [self count])]]; - return [[CPArray alloc] initWithArray:objects]; + // We do this to ensure we return a CPArray. + return [CPArray arrayWithArray:self]; } @end @@ -408,14 +408,8 @@ var CPObjectAccessorsForClassKey = @"$CPObjectAccessorsForClassKey", - (id)copy { - var objects = [], - object = nil, - objectEnumerator = [self objectEnumerator]; - - while ((object = [objectEnumerator nextObject]) !== nil) - objects.push(object); - - return [[CPSet alloc] initWithArray:objects]; + // We do this to ensure we return a CPSet. + return [CPSet setWithSet:self]; } @end diff --git a/Foundation/CPSet/CPSet.j b/Foundation/CPSet/CPSet.j index db19b8d56..1ae1fa5bc 100644 --- a/Foundation/CPSet/CPSet.j +++ b/Foundation/CPSet/CPSet.j @@ -383,7 +383,7 @@ - (id)copy { - return [[CPSet alloc] initWithSet:self]; + return [[self class] setWithSet:self]; } - (id)mutableCopy