Skip to content

Commit

Permalink
Remove the use of Array.map
Browse files Browse the repository at this point in the history
  • Loading branch information
cacaodev committed Jan 14, 2016
1 parent 4ed65f8 commit bf0f370
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 1 addition & 3 deletions AppKit/CPCompatibility.j
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ CPFileAPIFeature = 31;

CPAltEnterTextAreaFeature = 32;

CPJavascriptMapFeature = 33;


/*
When an absolutely positioned div (CPView) with an absolutely positioned canvas in it (CPView with drawRect:) moves things on top of the canvas (subviews) don't redraw correctly. E.g. if you have a bunch of text fields in a CPBox in a sheet which animates in, some of the text fields might not be visible because the CPBox has a canvas at the bottom and the box moved form offscreen to onscreen. This bug is probably very related: https://bugs.webkit.org/show_bug.cgi?id=67203
Expand Down Expand Up @@ -272,8 +272,6 @@ if (typeof document != "undefined")
}
else
PLATFORM_FEATURES[CPFileAPIFeature] = NO;

PLATFORM_FEATURES[CPJavascriptMapFeature] = (typeof Array.map === "function");
}

function CPFeatureIsCompatible(aFeature)
Expand Down
13 changes: 9 additions & 4 deletions Foundation/CPArray/_CPJavaScriptArray.j
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,17 @@ var concat = Array.prototype.concat,
return join.call(self, aString);
}

- (CPArray)arrayByApplyingBlock:(Function)aFunction
- (CPArray)arrayByApplyingBlock:(Function/*element, index*/)aFunction
{
if (CPFeatureIsCompatible(CPJavascriptMapFeature))
return self.map(aFunction);
var result = [];

return [super arrayByApplyingBlock:aFunction];
for (var idx = 0; idx < self.length; idx++)
{
var obj = aFunction(self[idx], idx);
result.push(obj);
}

return result;
}

- (void)insertObject:(id)anObject atIndex:(CPUInteger)anIndex
Expand Down

0 comments on commit bf0f370

Please sign in to comment.