mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-26 21:47:04 +00:00
Use stubbed out Array methods instead of relying on them existing on the object.
Reviewed by me.
This commit is contained in:
@@ -2,6 +2,13 @@
|
||||
@import "CPMutableArray.j"
|
||||
|
||||
|
||||
var indexOf = Array.prototype.indexOf,
|
||||
join = Array.prototype.join,
|
||||
pop = Array.prototype.pop,
|
||||
push = Array.prototype.push,
|
||||
slice = Array.prototype.slice,
|
||||
splice = Array.prototype.splice;
|
||||
|
||||
@implementation _CPJavaScriptArray : CPMutableArray
|
||||
{
|
||||
}
|
||||
@@ -28,13 +35,13 @@
|
||||
|
||||
- (id)initWithArray:(CPArray)anArray
|
||||
{
|
||||
return anArray.slice(0);
|
||||
return slice.call(anArray, 0);
|
||||
}
|
||||
|
||||
- (id)initWithArray:(CPArray)anArray copyItems:(BOOL)shouldCopyItems
|
||||
{
|
||||
if (!shouldCopyItems)
|
||||
return anArray.slice(0);
|
||||
return slice.call(anArray, 0);
|
||||
|
||||
self = [super init];
|
||||
|
||||
@@ -76,19 +83,19 @@
|
||||
if (arguments[index] === nil)
|
||||
break;
|
||||
|
||||
return Array.prototype.slice.call(arguments, 2, index);
|
||||
return slice.call(arguments, 2, index);
|
||||
}
|
||||
|
||||
- (id)initWithObjects:(CPArray)objects count:(CPUInteger)aCount
|
||||
{
|
||||
if (objects.isa === _CPJavaScriptArray)
|
||||
return objects.slice(0);
|
||||
return slice.call(objects, 0);
|
||||
|
||||
var array = [],
|
||||
index = 0;
|
||||
|
||||
for (; index < aCount; ++index)
|
||||
array.push([objects objectAtIndex:index]);
|
||||
push.call(array, [objects objectAtIndex:index]);
|
||||
|
||||
return array;
|
||||
}
|
||||
@@ -106,11 +113,6 @@
|
||||
return self[anIndex];
|
||||
}
|
||||
|
||||
- (CPUInteger)indexOfObject:(id)anObject
|
||||
{
|
||||
return [self indexOfObject:anObject inRange:nil];
|
||||
}
|
||||
|
||||
- (CPUInteger)indexOfObject:(id)anObject inRange:(CPRange)aRange
|
||||
{
|
||||
// Only use isEqual: if our object is a CPObject.
|
||||
@@ -129,15 +131,10 @@
|
||||
return [self indexOfObjectIdenticalTo:anObject inRange:aRange];
|
||||
}
|
||||
|
||||
- (CPUInteger)indexOfObjectIdenticalTo:(id)anObject
|
||||
{
|
||||
return [self indexOfObjectIdenticalTo:anObject inRange:nil];
|
||||
}
|
||||
|
||||
- (CPUInteger)indexOfObjectIdenticalTo:(id)anObject inRange:(CPRange)aRange
|
||||
{
|
||||
if (self.indexOf)
|
||||
return self.indexOf(anObject);
|
||||
if (indexOf && !aRange)
|
||||
return indexOf.call(self, anObject);
|
||||
|
||||
var index = aRange ? aRange.location : 0,
|
||||
count = aRange ? CPMaxRange(aRange) : self.length;
|
||||
@@ -179,32 +176,32 @@
|
||||
if (aRange.location < 0 || CPMaxRange(aRange) > self.length)
|
||||
[CPException raise:CPRangeException reason:"subarrayWithRange: aRange out of bounds"];
|
||||
|
||||
return self.slice(aRange.location, CPMaxRange(aRange));
|
||||
return slice.call(self, aRange.location, CPMaxRange(aRange));
|
||||
}
|
||||
|
||||
- (CPString)componentsJoinedByString:(CPString)aString
|
||||
{
|
||||
return self.join(aString);
|
||||
return join.call(self, aString);
|
||||
}
|
||||
|
||||
- (void)insertObject:(id)anObject atIndex:(CPUInteger)anIndex
|
||||
{
|
||||
self.splice(anIndex, 0, anObject);
|
||||
splice.call(self, anIndex, 0, anObject);
|
||||
}
|
||||
|
||||
- (void)removeObjectAtIndex:(CPUInteger)anIndex
|
||||
{
|
||||
self.splice(anIndex, 1);
|
||||
splice.call(self, anIndex, 1);
|
||||
}
|
||||
|
||||
- (void)addObject:(id)anObject
|
||||
{
|
||||
self.push(anObject);
|
||||
push.call(self, anObject);
|
||||
}
|
||||
|
||||
- (void)removeLastObject
|
||||
{
|
||||
self.pop();
|
||||
pop.call(self);
|
||||
}
|
||||
|
||||
- (void)replaceObjectAtIndex:(int)anIndex withObject:(id)anObject
|
||||
@@ -214,7 +211,7 @@
|
||||
|
||||
- (void)copy
|
||||
{
|
||||
return self.slice(0);
|
||||
return slice.call(self, 0);
|
||||
}
|
||||
|
||||
- (Class)classForCoder
|
||||
|
||||
Reference in New Issue
Block a user