From bf0f370aae53ab45962bc9381711ef1a175f5028 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Thu, 14 Jan 2016 15:15:27 +0100 Subject: [PATCH] Remove the use of Array.map --- AppKit/CPCompatibility.j | 4 +--- Foundation/CPArray/_CPJavaScriptArray.j | 13 +++++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/AppKit/CPCompatibility.j b/AppKit/CPCompatibility.j index 8c71828019..1a48ab7ff4 100644 --- a/AppKit/CPCompatibility.j +++ b/AppKit/CPCompatibility.j @@ -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 @@ -272,8 +272,6 @@ if (typeof document != "undefined") } else PLATFORM_FEATURES[CPFileAPIFeature] = NO; - - PLATFORM_FEATURES[CPJavascriptMapFeature] = (typeof Array.map === "function"); } function CPFeatureIsCompatible(aFeature) diff --git a/Foundation/CPArray/_CPJavaScriptArray.j b/Foundation/CPArray/_CPJavaScriptArray.j index 800c1a5c16..6d36a8586f 100644 --- a/Foundation/CPArray/_CPJavaScriptArray.j +++ b/Foundation/CPArray/_CPJavaScriptArray.j @@ -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