Changeset 167797 in webkit


Ignore:
Timestamp:
Apr 25, 2014 1:25:59 AM (10 years ago)
Author:
graouts@webkit.org
Message:

Implement Array.prototype.find()
https://bugs.webkit.org/show_bug.cgi?id=130966

Reviewed by Oliver Hunt.

Source/JavaScriptCore:
Implement Array.prototype.find() and Array.prototype.findIndex() as proposed in the Harmony spec.

  • builtins/Array.prototype.js:

(find):
(findIndex):

  • runtime/ArrayPrototype.cpp:

LayoutTests:

  • js/Object-getOwnPropertyNames-expected.txt:
  • js/array-find-expected.txt: Added.
  • js/array-find.html: Added.
  • js/array-findIndex-expected.txt: Added.
  • js/array-findIndex.html: Added.
  • js/script-tests/Object-getOwnPropertyNames.js:
  • js/script-tests/array-find.js: Added.
  • js/script-tests/array-findIndex.js: Added.
Location:
trunk
Files:
6 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r167796 r167797  
     12014-04-25  Antoine Quint  <graouts@webkit.org>
     2
     3        Implement Array.prototype.find()
     4        https://bugs.webkit.org/show_bug.cgi?id=130966
     5
     6        Reviewed by Oliver Hunt.
     7
     8        * js/Object-getOwnPropertyNames-expected.txt:
     9        * js/array-find-expected.txt: Added.
     10        * js/array-find.html: Added.
     11        * js/array-findIndex-expected.txt: Added.
     12        * js/array-findIndex.html: Added.
     13        * js/script-tests/Object-getOwnPropertyNames.js:
     14        * js/script-tests/array-find.js: Added.
     15        * js/script-tests/array-findIndex.js: Added.
     16
    1172014-04-25  Ion Rosca  <rosca@adobe.com>
    218
  • trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt

    r167380 r167797  
    4646PASS getSortedOwnPropertyNames(Function.prototype) is ['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']
    4747PASS getSortedOwnPropertyNames(Array) is ['isArray', 'length', 'name', 'prototype']
    48 PASS getSortedOwnPropertyNames(Array.prototype) is ['concat', 'constructor', 'entries', 'every', 'fill', 'filter', 'forEach', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift']
     48PASS getSortedOwnPropertyNames(Array.prototype) is ['concat', 'constructor', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'forEach', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift']
    4949PASS getSortedOwnPropertyNames(String) is ['fromCharCode', 'length', 'name', 'prototype']
    5050PASS getSortedOwnPropertyNames(String.prototype) is ['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'concat', 'constructor', 'fixed', 'fontcolor', 'fontsize', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'replace', 'search', 'slice', 'small', 'split', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']
  • trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js

    r167380 r167797  
    5454    "Function.prototype": "['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']",
    5555    "Array": "['isArray', 'length', 'name', 'prototype']",
    56     "Array.prototype": "['concat', 'constructor', 'entries', 'every', 'fill', 'filter', 'forEach', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift']",
     56    "Array.prototype": "['concat', 'constructor', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'forEach', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift']",
    5757    "String": "['fromCharCode', 'length', 'name', 'prototype']",
    5858    "String.prototype": "['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'concat', 'constructor', 'fixed', 'fontcolor', 'fontsize', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'replace', 'search', 'slice', 'small', 'split', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']",
  • trunk/Source/JavaScriptCore/ChangeLog

    r167786 r167797  
     12014-04-25  Antoine Quint  <graouts@webkit.org>
     2
     3        Implement Array.prototype.find()
     4        https://bugs.webkit.org/show_bug.cgi?id=130966
     5
     6        Reviewed by Oliver Hunt.
     7
     8        Implement Array.prototype.find() and Array.prototype.findIndex() as proposed in the Harmony spec.
     9
     10        * builtins/Array.prototype.js:
     11        (find):
     12        (findIndex):
     13        * runtime/ArrayPrototype.cpp:
     14
    1152014-04-24  Brady Eidson  <beidson@apple.com>
    216
  • trunk/Source/JavaScriptCore/builtins/Array.prototype.js

    r167380 r167797  
    190190}
    191191
     192function find(callback /*, thisArg */) {
     193    "use strict";
     194    if (this === null)
     195        throw new @TypeError("Array.prototype.find requires that |this| not be null");
     196   
     197    if (this === undefined)
     198        throw new @TypeError("Array.prototype.find requires that |this| not be undefined");
     199   
     200    var array = @Object(this);
     201    var length = array.length >>> 0;
     202   
     203    if (typeof callback !== "function")
     204        throw new @TypeError("Array.prototype.find callback must be a function");
     205   
     206    var thisArg = arguments.length > 1 ? arguments[1] : undefined;
     207    for (var i = 0; i < length; i++) {
     208        if (callback.@call(thisArg, array[i], i, array))
     209            return array[i];
     210    }
     211    return undefined;
     212}
     213
     214function findIndex(callback /*, thisArg */) {
     215    "use strict";
     216    if (this === null)
     217        throw new @TypeError("Array.prototype.findIndex requires that |this| not be null");
     218   
     219    if (this === undefined)
     220        throw new @TypeError("Array.prototype.findIndex requires that |this| not be undefined");
     221   
     222    var array = @Object(this);
     223    var length = array.length >>> 0;
     224   
     225    if (typeof callback !== "function")
     226        throw new @TypeError("Array.prototype.findIndex callback must be a function");
     227   
     228    var thisArg = arguments.length > 1 ? arguments[1] : undefined;
     229    for (var i = 0; i < length; i++) {
     230        if (callback.@call(thisArg, array[i], i, array))
     231            return i;
     232    }
     233    return -1;
     234}
  • trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp

    r167380 r167797  
    116116  entries        arrayProtoFuncEntries        DontEnum|Function 0
    117117  keys           arrayProtoFuncKeys           DontEnum|Function 0
     118  find           arrayProtoFuncFind           DontEnum|Function 1
     119  findIndex      arrayProtoFuncFindIndex      DontEnum|Function 1
    118120@end
    119121*/
Note: See TracChangeset for help on using the changeset viewer.