Diff
Modified: trunk/LayoutTests/ChangeLog (181870 => 181871)
--- trunk/LayoutTests/ChangeLog 2015-03-23 21:32:38 UTC (rev 181870)
+++ trunk/LayoutTests/ChangeLog 2015-03-23 21:37:53 UTC (rev 181871)
@@ -1,3 +1,16 @@
+2015-03-23 Dean Jackson <d...@apple.com>
+
+ ES7: Implement Array.prototype.includes
+ https://bugs.webkit.org/show_bug.cgi?id=142707
+
+ Reviewed by Geoffrey Garen.
+
+ * 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'.
+
2015-03-23 Joseph Pecoraro <pecor...@apple.com>
__defineGetter__/__defineSetter__ should throw exceptions
Modified: trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt (181870 => 181871)
--- trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt 2015-03-23 21:32:38 UTC (rev 181870)
+++ trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt 2015-03-23 21:37:53 UTC (rev 181871)
@@ -45,7 +45,7 @@
PASS getSortedOwnPropertyNames(Function) is ['length', 'name', 'prototype']
PASS getSortedOwnPropertyNames(Function.prototype) is ['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']
PASS getSortedOwnPropertyNames(Array) is ['from', 'isArray', 'length', 'name', 'of', 'prototype']
-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']
+PASS 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']
PASS getSortedOwnPropertyNames(String) is ['fromCharCode', 'length', 'name', 'prototype']
PASS 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']
PASS getSortedOwnPropertyNames(Boolean) is ['length', 'name', 'prototype']
Added: trunk/LayoutTests/js/array-includes-expected.txt (0 => 181871)
--- trunk/LayoutTests/js/array-includes-expected.txt (rev 0)
+++ trunk/LayoutTests/js/array-includes-expected.txt 2015-03-23 21:37:53 UTC (rev 181871)
@@ -0,0 +1,35 @@
+Tests for Array.prototype.includes
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS [].includes.length is 1
+PASS [1, 2, 3].includes(2) is true
+PASS [1, 2, 3].includes(4) is false
+PASS [].includes(1) is false
+PASS [1, 2, 3].includes(1, 2) is false
+PASS [1, 2, 3].includes(3, 3) is false
+PASS [1, 2, 3].includes(2, undefined) is true
+PASS [1, 2, 3].includes(2, null) is true
+PASS [1, 2, 3].includes(2, 1, 2) is true
+PASS [1, 2, 3].includes(2, Number) is true
+PASS [1, 2, 3].includes(2, Number(2)) is false
+PASS [1, 2, 3].includes(2, 'egg') is true
+PASS [1, 2, 3].includes(2, '3') is false
+PASS [1, 2, 3].includes(3, -1) is true
+PASS [1, 2, 3].includes(1, -2) is false
+PASS [1, 2, 3].includes(1, -3) is true
+PASS [1, 2, NaN, 4].includes(NaN) is true
+PASS ['egg', 'bacon', 'sausage'].includes('egg') is true
+PASS ['egg', 'bacon', 'sausage'].includes('spinach') is false
+Array with holes
+PASS a.includes('egg') is true
+PASS a.includes('sausage') is true
+PASS a.includes('hashbrown') is false
+PASS a.includes('toast') is false
+PASS Array.prototype.includes.call(undefined, 1) threw exception TypeError: Array.prototype.includes requires that |this| not be undefined.
+PASS Array.prototype.includes.call(null, 1) threw exception TypeError: Array.prototype.includes requires that |this| not be null.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Property changes on: trunk/LayoutTests/js/array-includes-expected.txt
___________________________________________________________________
Added: svn:mime-type
Added: svn:keywords
Added: svn:eol-style
Added: trunk/LayoutTests/js/array-includes.html (0 => 181871)
--- trunk/LayoutTests/js/array-includes.html (rev 0)
+++ trunk/LayoutTests/js/array-includes.html 2015-03-23 21:37:53 UTC (rev 181871)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>
Property changes on: trunk/LayoutTests/js/array-includes.html
___________________________________________________________________
Added: svn:mime-type
Added: svn:keywords
Added: svn:eol-style
Modified: trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js (181870 => 181871)
--- trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js 2015-03-23 21:32:38 UTC (rev 181870)
+++ trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js 2015-03-23 21:37:53 UTC (rev 181871)
@@ -53,7 +53,7 @@
"Function": "['length', 'name', 'prototype']",
"Function.prototype": "['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']",
"Array": "['from', 'isArray', 'length', 'name', 'of', 'prototype']",
- "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']",
+ "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']",
"String": "['fromCharCode', 'length', 'name', 'prototype']",
"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']",
"Boolean": "['length', 'name', 'prototype']",
Added: trunk/LayoutTests/js/script-tests/array-includes.js (0 => 181871)
--- trunk/LayoutTests/js/script-tests/array-includes.js (rev 0)
+++ trunk/LayoutTests/js/script-tests/array-includes.js 2015-03-23 21:37:53 UTC (rev 181871)
@@ -0,0 +1,45 @@
+description("Tests for Array.prototype.includes");
+
+shouldBe("[].includes.length", "1");
+
+shouldBeTrue("[1, 2, 3].includes(2)");
+shouldBeFalse("[1, 2, 3].includes(4)");
+shouldBeFalse("[].includes(1)");
+
+shouldBeFalse("[1, 2, 3].includes(1, 2)");
+shouldBeFalse("[1, 2, 3].includes(3, 3)");
+shouldBeTrue("[1, 2, 3].includes(2, undefined)");
+shouldBeTrue("[1, 2, 3].includes(2, null)");
+shouldBeTrue("[1, 2, 3].includes(2, 1, 2)");
+shouldBeTrue("[1, 2, 3].includes(2, Number)");
+shouldBeFalse("[1, 2, 3].includes(2, Number(2))");
+shouldBeTrue("[1, 2, 3].includes(2, 'egg')");
+shouldBeFalse("[1, 2, 3].includes(2, '3')");
+
+shouldBeTrue("[1, 2, 3].includes(3, -1)");
+shouldBeFalse("[1, 2, 3].includes(1, -2)");
+shouldBeTrue("[1, 2, 3].includes(1, -3)");
+
+shouldBeTrue("[1, 2, NaN, 4].includes(NaN)");
+
+shouldBeTrue("['egg', 'bacon', 'sausage'].includes('egg')");
+shouldBeFalse("['egg', 'bacon', 'sausage'].includes('spinach')");
+
+debug("Array with holes");
+
+var a = [];
+a[0] = 'egg';
+a[1] = 'bacon';
+a[5] = 'sausage';
+a[6] = 'spinach';
+a[-2] = 'toast';
+
+shouldBeTrue("a.includes('egg')");
+shouldBeTrue("a.includes('sausage')");
+shouldBeFalse("a.includes('hashbrown')");
+shouldBeFalse("a.includes('toast')");
+
+shouldThrow("Array.prototype.includes.call(undefined, 1)");
+shouldThrow("Array.prototype.includes.call(null, 1)");
+
+
Property changes on: trunk/LayoutTests/js/script-tests/array-includes.js
___________________________________________________________________
Added: svn:mime-type
Added: svn:keywords
Added: svn:eol-style
Modified: trunk/Source/_javascript_Core/ChangeLog (181870 => 181871)
--- trunk/Source/_javascript_Core/ChangeLog 2015-03-23 21:32:38 UTC (rev 181870)
+++ trunk/Source/_javascript_Core/ChangeLog 2015-03-23 21:37:53 UTC (rev 181871)
@@ -1,3 +1,17 @@
+2015-03-23 Dean Jackson <d...@apple.com>
+
+ ES7: Implement Array.prototype.includes
+ https://bugs.webkit.org/show_bug.cgi?id=142707
+
+ Reviewed by Geoffrey Garen.
+
+ 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.
+
2015-03-23 Joseph Pecoraro <pecor...@apple.com>
__defineGetter__/__defineSetter__ should throw exceptions
Modified: trunk/Source/_javascript_Core/builtins/Array.prototype.js (181870 => 181871)
--- trunk/Source/_javascript_Core/builtins/Array.prototype.js 2015-03-23 21:32:38 UTC (rev 181870)
+++ trunk/Source/_javascript_Core/builtins/Array.prototype.js 2015-03-23 21:37:53 UTC (rev 181871)
@@ -236,3 +236,40 @@
}
return -1;
}
+
+function includes(searchElement /*, fromIndex*/) {
+ "use strict";
+ if (this === null)
+ throw new @TypeError("Array.prototype.includes requires that |this| not be null");
+
+ if (this === undefined)
+ throw new @TypeError("Array.prototype.includes requires that |this| not be undefined");
+
+ var array = @Object(this);
+ var length = array.length >>> 0;
+
+ if (length === 0)
+ return false;
+
+ var fromIndex = 0;
+ if (arguments.length > 1 && arguments[1] !== undefined)
+ fromIndex = arguments[1] | 0;
+
+ var index;
+ if (fromIndex >= 0)
+ index = fromIndex;
+ else
+ index = length + fromIndex;
+
+ if (index < 0)
+ index = 0;
+
+ var currentElement;
+ for (; index < length; ++index) {
+ currentElement = array[index];
+ // Use SameValueZero comparison, rather than just StrictEquals.
+ if (searchElement === currentElement || (searchElement !== searchElement && currentElement !== currentElement))
+ return true;
+ }
+ return false;
+}
Modified: trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp (181870 => 181871)
--- trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp 2015-03-23 21:32:38 UTC (rev 181870)
+++ trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp 2015-03-23 21:37:53 UTC (rev 181871)
@@ -117,6 +117,7 @@
keys arrayProtoFuncKeys DontEnum|Function 0
find arrayProtoFuncFind DontEnum|Function 1
findIndex arrayProtoFuncFindIndex DontEnum|Function 1
+ includes arrayProtoFuncIncludes DontEnum|Function 1
@end
*/