Title: [228012] trunk/Source/_javascript_Core
Revision
228012
Author
utatane....@gmail.com
Date
2018-02-02 09:12:23 -0800 (Fri, 02 Feb 2018)

Log Message

[JSC] Clean up ArraySpeciesCreate
https://bugs.webkit.org/show_bug.cgi?id=182434

Reviewed by Saam Barati.

We have duplicate code in filter, map, concatSlowPath.
This patch creates a new global private function @arraySpeciesCreate,
and use it.

* builtins/ArrayPrototype.js:
(globalPrivate.arraySpeciesCreate):
(filter):
(map):
(globalPrivate.concatSlowPath):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (228011 => 228012)


--- trunk/Source/_javascript_Core/ChangeLog	2018-02-02 16:38:55 UTC (rev 228011)
+++ trunk/Source/_javascript_Core/ChangeLog	2018-02-02 17:12:23 UTC (rev 228012)
@@ -1,3 +1,20 @@
+2018-02-02  Yusuke Suzuki  <utatane....@gmail.com>
+
+        [JSC] Clean up ArraySpeciesCreate
+        https://bugs.webkit.org/show_bug.cgi?id=182434
+
+        Reviewed by Saam Barati.
+
+        We have duplicate code in filter, map, concatSlowPath.
+        This patch creates a new global private function @arraySpeciesCreate,
+        and use it.
+
+        * builtins/ArrayPrototype.js:
+        (globalPrivate.arraySpeciesCreate):
+        (filter):
+        (map):
+        (globalPrivate.concatSlowPath):
+
 2018-02-01  Mark Lam  <mark....@apple.com>
 
         Fix broken bounds check in FTL's compileGetMyArgumentByVal().

Modified: trunk/Source/_javascript_Core/builtins/ArrayPrototype.js (228011 => 228012)


--- trunk/Source/_javascript_Core/builtins/ArrayPrototype.js	2018-02-02 16:38:55 UTC (rev 228011)
+++ trunk/Source/_javascript_Core/builtins/ArrayPrototype.js	2018-02-02 17:12:23 UTC (rev 228012)
@@ -164,39 +164,45 @@
     }
 }
 
-function filter(callback /*, thisArg */)
+@globalPrivate
+function arraySpeciesCreate(array, length)
 {
     "use strict";
 
-    var array = @toObject(this, "Array.prototype.filter requires that |this| not be null or undefined");
-    var length = @toLength(array.length);
-
-    if (typeof callback !== "function")
-        @throwTypeError("Array.prototype.filter callback must be a function");
-    
-    var thisArg = @argument(1);
-
-    // Do 9.4.2.3 ArraySpeciesCreate
-    var result;
     var constructor;
+    var arrayConstructorInRealm = @Array;
     if (@isArray(array)) {
         constructor = array.constructor;
         // We have this check so that if some array from a different global object
         // calls this map they don't get an array with the Array.prototype of the
         // other global object.
-        if (@isArrayConstructor(constructor) && @Array !== constructor)
+        if (@isArrayConstructor(constructor) && arrayConstructorInRealm !== constructor)
             constructor = @undefined;
-        if (@isObject(constructor)) {
+        else if (@isObject(constructor)) {
             constructor = constructor.@speciesSymbol;
             if (constructor === null)
                 constructor = @undefined;
         }
     }
-    if (constructor === @Array || constructor === @undefined)
-        result = @newArrayWithSize(0);
-    else
-        result = new constructor(0);
+    if (constructor === arrayConstructorInRealm || constructor === @undefined)
+        return @newArrayWithSize(length);
+    return new constructor(length);
+}
 
+function filter(callback /*, thisArg */)
+{
+    "use strict";
+
+    var array = @toObject(this, "Array.prototype.filter requires that |this| not be null or undefined");
+    var length = @toLength(array.length);
+
+    if (typeof callback !== "function")
+        @throwTypeError("Array.prototype.filter callback must be a function");
+    
+    var thisArg = @argument(1);
+
+    var result = @arraySpeciesCreate(array, 0);
+
     var nextIndex = 0;
     for (var i = 0; i < length; i++) {
         if (!(i in array))
@@ -222,26 +228,7 @@
     
     var thisArg = @argument(1);
 
-    // Do 9.4.2.3 ArraySpeciesCreate
-    var result;
-    var constructor;
-    if (@isArray(array)) {
-        constructor = array.constructor;
-        // We have this check so that if some array from a different global object
-        // calls this map they don't get an array with the Array.prototype of the
-        // other global object.
-        if (@isArrayConstructor(constructor) && @Array !== constructor)
-            constructor = @undefined;
-        if (@isObject(constructor)) {
-            constructor = constructor.@speciesSymbol;
-            if (constructor === null)
-                constructor = @undefined;
-        }
-    }
-    if (constructor === @Array || constructor === @undefined)
-        result = @newArrayWithSize(length);
-    else
-        result = new constructor(length);
+    var result = @arraySpeciesCreate(array, length);
 
     for (var i = 0; i < length; i++) {
         if (!(i in array))
@@ -617,28 +604,10 @@
 
     var currentElement = @toObject(this, "Array.prototype.concat requires that |this| not be null or undefined");
 
-    var constructor;
-    if (@isArray(currentElement)) {
-        constructor = currentElement.constructor;
-        // We have this check so that if some array from a different global object
-        // calls this map they don't get an array with the Array.prototype of the
-        // other global object.
-        if (@isArrayConstructor(constructor) && @Array !== constructor)
-            constructor = @undefined;
-        else if (@isObject(constructor)) {
-            constructor = constructor.@speciesSymbol;
-            if (constructor === null)
-                constructor = @Array;
-        }
-    }
+    var result = @arraySpeciesCreate(currentElement, 0);
+    var resultIsArray = @isJSArray(result);
 
     var argCount = arguments.length;
-    var result;
-    if (constructor === @Array || constructor === @undefined)
-        result = @newArrayWithSize(0);
-    else
-        result = new constructor(0);
-    var resultIsArray = @isJSArray(result);
 
     var resultIndex = 0;
     var argIndex = 0;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to