⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 181871 in webkit


Ignore:
Timestamp:
Mar 23, 2015, 2:37:53 PM (11 years ago)
Author:
dino@apple.com
Message:

ES7: Implement Array.prototype.includes
https://bugs.webkit.org/show_bug.cgi?id=142707

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

Add support for the ES7 includes method on Arrays.
https://github.com/tc39/Array.prototype.includes

  • builtins/Array.prototype.js:

(includes): Implementation in JS.

  • runtime/ArrayPrototype.cpp: Add 'includes' to the lookup table.

LayoutTests:

  • js/array-includes-expected.txt: Added.
  • js/array-includes.html: Added.
  • js/script-tests/array-includes.js: Added.
  • js/script-tests/Object-getOwnPropertyNames.js: Add 'includes'.
  • js/Object-getOwnPropertyNames-expected.txt: Add 'includes'.
Location:
trunk
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r181868 r181871  
     12015-03-23  Dean Jackson  <dino@apple.com>
     2
     3        ES7: Implement Array.prototype.includes
     4        https://bugs.webkit.org/show_bug.cgi?id=142707
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * js/array-includes-expected.txt: Added.
     9        * js/array-includes.html: Added.
     10        * js/script-tests/array-includes.js: Added.
     11        * js/script-tests/Object-getOwnPropertyNames.js: Add 'includes'.
     12        * js/Object-getOwnPropertyNames-expected.txt: Add 'includes'.
     13
    1142015-03-23  Joseph Pecoraro  <pecoraro@apple.com>
    215
  • trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt

    r180370 r181871  
    4646PASS getSortedOwnPropertyNames(Function.prototype) is ['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']
    4747PASS getSortedOwnPropertyNames(Array) is ['from', 'isArray', 'length', 'name', 'of', 'prototype']
    48 PASS 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']
     48PASS getSortedOwnPropertyNames(Array.prototype) is ['concat', 'constructor', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'forEach', 'includes', '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', 'endsWith', 'fixed', 'fontcolor', 'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'repeat', 'replace', 'search', 'slice', 'small', 'split', 'startsWith', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']
  • trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js

    r180370 r181871  
    5454    "Function.prototype": "['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']",
    5555    "Array": "['from', 'isArray', 'length', 'name', 'of', 'prototype']",
    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']",
     56    "Array.prototype": "['concat', 'constructor', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'forEach', 'includes', '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', 'endsWith', 'fixed', 'fontcolor', 'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'repeat', 'replace', 'search', 'slice', 'small', 'split', 'startsWith', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']",
  • trunk/Source/JavaScriptCore/ChangeLog

    r181868 r181871  
     12015-03-23  Dean Jackson  <dino@apple.com>
     2
     3        ES7: Implement Array.prototype.includes
     4        https://bugs.webkit.org/show_bug.cgi?id=142707
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Add support for the ES7 includes method on Arrays.
     9        https://github.com/tc39/Array.prototype.includes
     10
     11        * builtins/Array.prototype.js:
     12        (includes): Implementation in JS.
     13        * runtime/ArrayPrototype.cpp: Add 'includes' to the lookup table.
     14
    1152015-03-23  Joseph Pecoraro  <pecoraro@apple.com>
    216
  • trunk/Source/JavaScriptCore/builtins/Array.prototype.js

    r169162 r181871  
    237237    return -1;
    238238}
     239
     240function includes(searchElement /*, fromIndex*/) {
     241    "use strict";
     242    if (this === null)
     243        throw new @TypeError("Array.prototype.includes requires that |this| not be null");
     244
     245    if (this === undefined)
     246        throw new @TypeError("Array.prototype.includes requires that |this| not be undefined");
     247
     248    var array = @Object(this);
     249    var length = array.length >>> 0;
     250
     251    if (length === 0)
     252        return false;
     253
     254    var fromIndex = 0;
     255    if (arguments.length > 1 && arguments[1] !== undefined)
     256        fromIndex = arguments[1] | 0;
     257
     258    var index;
     259    if (fromIndex >= 0)
     260        index = fromIndex;
     261    else
     262        index = length + fromIndex;
     263
     264    if (index < 0)
     265        index = 0;
     266
     267    var currentElement;
     268    for (; index < length; ++index) {
     269        currentElement = array[index];
     270        // Use SameValueZero comparison, rather than just StrictEquals.
     271        if (searchElement === currentElement || (searchElement !== searchElement && currentElement !== currentElement))
     272            return true;
     273    }
     274    return false;
     275}
  • trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp

    r180506 r181871  
    118118  find           arrayProtoFuncFind           DontEnum|Function 1
    119119  findIndex      arrayProtoFuncFindIndex      DontEnum|Function 1
     120  includes       arrayProtoFuncIncludes       DontEnum|Function 1
    120121@end
    121122*/
Note: See TracChangeset for help on using the changeset viewer.