diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_array-modified.js b/test/built-ins/Array/prototype/find/Array.prototype.find_array-modified.js deleted file mode 100644 index 0aa20aa5ed..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_array-modified.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.8 -description: > - The find() method returns a value in the array, if an - element in the array satisfies the provided testing function. - Otherwise undefined is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find -includes: [compareArray.js] ----*/ - -var a = [1, 2, 3]; -var found = a.find(function(val) { a.push(val); return false; }); -assert(compareArray(a, [1, 2, 3, 1, 2, 3])); -assert.sameValue(a.length, 6); -assert.sameValue(found, undefined); - -a = [1, 2, 3]; -found = a.find(function(val, key) { a[key] = ++val; return false; }); -assert(compareArray(a, [2, 3, 4])); -assert.sameValue(a.length, 3); -assert.sameValue(found, undefined); diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_basic.js b/test/built-ins/Array/prototype/find/Array.prototype.find_basic.js deleted file mode 100644 index 24ae800e60..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_basic.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/*--- -es6id: 22.1.3.8 -description: > - The find() method returns a value in the array, if an - element in the array satisfies the provided testing function. - Otherwise undefined is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find ----*/ - - -assert.sameValue(1, Array.prototype.find.length); - -var a = [21, 22, 23, 24]; -assert.sameValue(a.find(function() { return false; }), undefined); -assert.sameValue(a.find(function() { return true; }), 21); -assert.sameValue(a.find(function(val) { return 121 === val; }), undefined); -assert.sameValue(a.find(function(val) { return 24 === val; }), 24); -assert.sameValue(a.find(function(val) { return 23 === val; }), 23); -assert.sameValue(a.find(function(val) { return 22 === val; }), 22); diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_callable-Proxy-1.js b/test/built-ins/Array/prototype/find/Array.prototype.find_callable-Proxy-1.js deleted file mode 100644 index a205bc2caa..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_callable-Proxy-1.js +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: > - Array.prototype.find shouldn't throw a TypeError if - IsCallable(predicate) is true; Proxy is callable -features: [Array#find, Proxy] ----*/ - - -[].find(Proxy); - diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_callable-Proxy-2.js b/test/built-ins/Array/prototype/find/Array.prototype.find_callable-Proxy-2.js deleted file mode 100644 index d6d49649d7..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_callable-Proxy-2.js +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: > - Array.prototype.find shouldn't throw a TypeError if - IsCallable(predicate) is true; a new Proxy object is callable -features: [Array#find, Proxy] ----*/ - - -[].find(new Proxy(function () {}, function () {})); - diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_callable-arrowfunction.js b/test/built-ins/Array/prototype/find/Array.prototype.find_callable-arrowfunction.js deleted file mode 100644 index 4f63feb5a9..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_callable-arrowfunction.js +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: > - Array.prototype.find shouldn't throw a TypeError if - IsCallable(predicate) is true; arrow functions are callable -features: [Array#find, arrow-function] ----*/ - - -[].find(x => x); - diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_callable-forEach.js b/test/built-ins/Array/prototype/find/Array.prototype.find_callable-forEach.js deleted file mode 100644 index 16ad7713ce..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_callable-forEach.js +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: > - Array.prototype.find shouldn't throw a TypeError if - IsCallable(predicate) is true; Array#forEach is callable -features: [Array#find] ----*/ - - -[].find(Array.prototype.forEach); - diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_callable-predicate.js b/test/built-ins/Array/prototype/find/Array.prototype.find_callable-predicate.js deleted file mode 100644 index 4b3b47eb8e..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_callable-predicate.js +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: > - Array.prototype.find shouldn't throw a TypeError if - IsCallable(predicate) is true; a function is callable -features: [Array#find] ----*/ - - -[].find(function () {}); - diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_called-length-times.js b/test/built-ins/Array/prototype/find/Array.prototype.find_called-length-times.js deleted file mode 100644 index 9e9e1a1767..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_called-length-times.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/*--- -es6id: 22.1.3.8 -description: > - The find() method returns a value in the array, if an - element in the array satisfies the provided testing function. - Otherwise undefined is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find ----*/ - -var a = [1, 2, 3, 4, 5]; -var l = 0; -var found = a.find(function() { - l++; - return false; -}); - -assert.sameValue(l, a.length); -assert.sameValue(found, undefined); diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_empty-array-undefined.js b/test/built-ins/Array/prototype/find/Array.prototype.find_empty-array-undefined.js deleted file mode 100644 index 28edaf5ac4..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_empty-array-undefined.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: Find on empty array should return undefined -features: [Array#find] ----*/ - -var a = [].find(function () { - return true; -}); - -if (a !== undefined) { - $ERROR('#1: a !== undefined. Actual: ' + typeof a); -} diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_exceptions.js b/test/built-ins/Array/prototype/find/Array.prototype.find_exceptions.js deleted file mode 100644 index 0dba5e7fa2..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_exceptions.js +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.8 -description: > - The find() method returns a value in the array, if an - element in the array satisfies the provided testing function. - Otherwise undefined is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find -includes: [compareArray.js] ----*/ - - -// Test exceptions -assert.throws(TypeError, function() { - Array.prototype.find.call(null, function() { }); -}); -assert.throws(TypeError, function() { - Array.prototype.find.call(undefined, function() { }); -}); -assert.throws(TypeError, function() { - Array.prototype.find.apply(null, function() { }, []); -}); -assert.throws(TypeError, function() { - Array.prototype.find.apply(undefined, function() { }, []); -}); - -assert.throws(TypeError, function() { - [].find(null); -}); -assert.throws(TypeError, function() { - [].find(undefined); -}); -assert.throws(TypeError, function() { - [].find(0); -}); -assert.throws(TypeError, function() { - [].find(true); -}); -assert.throws(TypeError, function() { - [].find(false); -}); -assert.throws(TypeError, function() { - [].find(""); -}); -assert.throws(TypeError, function() { - [].find({}); -}); -assert.throws(TypeError, function() { - [].find([]); -}); -assert.throws(TypeError, function() { - [].find(/\d+/); -}); - -assert.throws(TypeError, function() { - Array.prototype.find.call({}, null); -}); -assert.throws(TypeError, function() { - Array.prototype.find.call({}, undefined); -}); -assert.throws(TypeError, function() { - Array.prototype.find.call({}, 0); -}); -assert.throws(TypeError, function() { - Array.prototype.find.call({}, true); -}); -assert.throws(TypeError, function() { - Array.prototype.find.call({}, false); -}); -assert.throws(TypeError, function() { - Array.prototype.find.call({}, ""); -}); -assert.throws(TypeError, function() { - Array.prototype.find.call({}, {}); -}); -assert.throws(TypeError, function() { - Array.prototype.find.call({}, []); -}); -assert.throws(TypeError, function() { - Array.prototype.find.call({}, /\d+/); -}); - -assert.throws(TypeError, function() { - Array.prototype.find.apply({}, null, []); -}); -assert.throws(TypeError, function() { - Array.prototype.find.apply({}, undefined, []); -}); -assert.throws(TypeError, function() { - Array.prototype.find.apply({}, 0, []); -}); -assert.throws(TypeError, function() { - Array.prototype.find.apply({}, true, []); -}); -assert.throws(TypeError, function() { - Array.prototype.find.apply({}, false, []); -}); -assert.throws(TypeError, function() { - Array.prototype.find.apply({}, "", []); -}); -assert.throws(TypeError, function() { - Array.prototype.find.apply({}, {}, []); -}); -assert.throws(TypeError, function() { - Array.prototype.find.apply({}, [], []); -}); -assert.throws(TypeError, function() { - Array.prototype.find.apply({}, /\d+/, []); -}); diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_exotic-object.js b/test/built-ins/Array/prototype/find/Array.prototype.find_exotic-object.js deleted file mode 100644 index 4b210581c6..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_exotic-object.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.8 -description: > - The find() method returns a value in the array, if an - element in the array satisfies the provided testing function. - Otherwise undefined is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find -includes: [compareArray.js] ----*/ - -var l = -1; -var o = -1; -var v = -1; -var k = -1; -var a = { - prop1: "val1", - prop2: "val2", - isValid: function() { - return this.prop1 === "val1" && this.prop2 === "val2"; - } -}; - -Array.prototype.push.apply(a, [30, 31, 32]); -var found = Array.prototype.find.call(a, function(val, key, obj) { - o = obj; - l = obj.length; - v = val; - k = key; - - return !obj.isValid(); -}); - -assert(compareArray(o, a)); -assert.sameValue(l, 3); -assert.sameValue(v, 32); -assert.sameValue(k, 2); -assert.sameValue(found, undefined); diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_length-property.js b/test/built-ins/Array/prototype/find/Array.prototype.find_length-property.js deleted file mode 100644 index 275f929225..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_length-property.js +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: The length property of the find method is 1 -features: [Array#find] ----*/ - -if ([].find.length !== 1) { - $ERROR('1: [].find.length !== 1. Actual: ' + [].find.length); -} diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_modify-after-start.js b/test/built-ins/Array/prototype/find/Array.prototype.find_modify-after-start.js deleted file mode 100644 index 1c64122e39..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_modify-after-start.js +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: Array may be mutated by calls to the predicate -features: [Array#find] ----*/ - -[1, 2, 3].find(function (v, i, arr) { - arr[i + 1] = arr[i + 1] + 1; - switch (i) { - case 0: - if (arr[i] !== 1) { - $ERROR('#1: arr[0] !== 1. Actual: ' + arr[i]); - } - break; - case 1: - if (arr[i] !== 3) { - $ERROR('#2: arr[1] !== 3. Actual: ' + arr[i]); - } - break; - case 2: - if (arr[i] !== 4) { - $ERROR('#3: arr[1] !== 4. Actual: ' + arr[i]); - } - break; - } -}); diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_non-returning-predicate.js b/test/built-ins/Array/prototype/find/Array.prototype.find_non-returning-predicate.js deleted file mode 100644 index edbf75a232..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_non-returning-predicate.js +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: Find with a predicate with no return value should return undefined -features: [Array#find] ----*/ - -var a = [1, 2, 3].find(function () {}); - -if (a !== undefined) { - $ERROR('#1: a !== undefined. Actual: ' + typeof a); -} diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_noncallable-predicate.js b/test/built-ins/Array/prototype/find/Array.prototype.find_noncallable-predicate.js deleted file mode 100644 index 7c5109319f..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_noncallable-predicate.js +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: > - Array.prototype.find should throw a TypeError if - IsCallable(predicate) is false -includes: [runTestCase.js] -features: [Array#find] ----*/ - -var uncallableValues = [ - undefined, - null, - true, - this, - {}, - 'string', - 0 -]; - -function testcase() { - for (var i = 0, len = uncallableValues.length; i < len; i++) { - try { - [].find(uncallableValues[i]); - return false; - } catch (e) { - if (!(e instanceof TypeError)) { - return false; - } - } - } - return true; -} - -runTestCase(testcase); diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_not-called-on-empty-array.js b/test/built-ins/Array/prototype/find/Array.prototype.find_not-called-on-empty-array.js deleted file mode 100644 index 11c7df7175..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_not-called-on-empty-array.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.8 -description: > - The find() method returns a value in the array, if an - element in the array satisfies the provided testing function. - Otherwise undefined is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find -includes: [compareArray.js] ----*/ - -var a = []; -var l = -1; -var o = -1; -var v = -1; -var k = -1; - -a.find(function(val, key, obj) { - o = obj; - l = obj.length; - v = val; - k = key; - - return false; -}); - -assert.sameValue(-1, l); -assert.sameValue(-1, o); -assert.sameValue(-1, v); -assert.sameValue(-1, k); - diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_predicate-arguments.js b/test/built-ins/Array/prototype/find/Array.prototype.find_predicate-arguments.js deleted file mode 100644 index 6e3fe14306..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_predicate-arguments.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: > - predicate is called with three arguments: the value of the - element, the index of the element, and the object being traversed. -features: [Array#find] ----*/ - -var a = [1]; - -var b = a.find(function (v, i, arr) { - if (arguments.length !== 3) { - $ERROR('#1: arguments.length !== 3. Actual: ' + arguments.length); - } - if (v !== 1) { - $ERROR('#2: element value !== 1. Actual: ' + v); - } - if (i !== 0) { - $ERROR('#3: index !== 0. Actual: ' + i); - } - if (arr !== a) { - $ERROR('#4: object being traversed !== a'); - } -}); diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_predicate-called-correct-arguments.js b/test/built-ins/Array/prototype/find/Array.prototype.find_predicate-called-correct-arguments.js deleted file mode 100644 index 9368853375..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_predicate-called-correct-arguments.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.8 -description: > - The find() method returns a value in the array, if an - element in the array satisfies the provided testing function. - Otherwise undefined is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find -includes: [compareArray.js] ----*/ - -var a = ["b"]; -var l = -1; -var o = -1; -var v = -1; -var k = -1; - -var found = a.find(function(val, key, obj) { - o = obj; - l = obj.length; - v = val; - k = key; - - return false; -}); - -assert(compareArray(o, a)); -assert.sameValue(a.length, l); -assert.sameValue(v, "b"); -assert.sameValue(k, 0); -assert.sameValue(found, undefined); diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_push-after-start.js b/test/built-ins/Array/prototype/find/Array.prototype.find_push-after-start.js deleted file mode 100644 index 2cf73cc532..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_push-after-start.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: > - Elements added to array after find has been called should not be - visited -features: [Array#find] ----*/ - -[1].find(function (v, i, arr) { - arr.push('string'); - if (v === 'string') { - $ERROR('#' + i + ': \'string\' should not be visited'); - } -}); diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_remove-after-start.js b/test/built-ins/Array/prototype/find/Array.prototype.find_remove-after-start.js deleted file mode 100644 index bd4dca31e6..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_remove-after-start.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: > - Elements removed from array after find has been called should be - visited -features: [Array#find] ----*/ - -var elementsVisited; - -elementsVisited = 0; - -[1, 'string', 2].find(function (v, i, arr) { - elementsVisited++; - var stringIndex = arr.indexOf('string'); - if (stringIndex !== -1) delete arr[stringIndex]; - if (v === 'string') { - $ERROR('#1: \'string\' should not exist, it has been deleted'); - } -}); - -if (elementsVisited !== 3) { - $ERROR('#2: deleted elements should be visited'); -} - -elementsVisited = 0; - -[1, 'string', 2].find(function (v, i, arr) { - elementsVisited++; - var stringIndex = arr.indexOf('string'); - if (stringIndex !== -1) arr.splice(stringIndex, 1); - if (v === 'string') { - $ERROR('#3: \'string\' should not exist, it has been deleted'); - } -}); - -if (elementsVisited !== 3) { - $ERROR('#4: deleted elements should be visited'); -} diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_return-found-value.js b/test/built-ins/Array/prototype/find/Array.prototype.find_return-found-value.js deleted file mode 100644 index 31cbfcb0db..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_return-found-value.js +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: Find should return value if predicate returns true -features: [Array#find] ----*/ - -var testVals = [ - undefined, - null, - 0, - 'string', - String, - this, - true, - [1,2,3] -]; - -var a; - -for (var i = 0, len = testVals.length; i < len; i++) { - a = testVals.find(function (v) { - return v === testVals[i]; - }); - if (a !== testVals[i]) { - $ERROR('#' + (i + 1) + ': a !== testVals[' + i + ']. Actual: ' + a); - } -} diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_this-arg-receiver-primitive.js b/test/built-ins/Array/prototype/find/Array.prototype.find_this-arg-receiver-primitive.js deleted file mode 100644 index 19ad7a3440..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_this-arg-receiver-primitive.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.8 -description: > - Create a new object in each function call when receiver is a - primitive value. See ECMA-262, Annex C. -flags: [noStrict] -includes: [compareArray.js] ----*/ - -// Create a new object in each function call when receiver is a -// primitive value. See ECMA-262, Annex C. -var a = []; -[1, 2].find(function() { a.push(this) }, ""); -assert(a[0] !== a[1]); diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_this-arg.js b/test/built-ins/Array/prototype/find/Array.prototype.find_this-arg.js deleted file mode 100644 index 1c162ea4bd..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_this-arg.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.8 -description: > - The find() method returns a value in the array, if an - element in the array satisfies the provided testing function. - Otherwise undefined is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find -includes: [compareArray.js] ----*/ - - -// Test String as a thisArg -var found = [1, 2, 3].find(function(val, key) { - return this.charAt(Number(key)) === String(val); -}, "321"); -assert.sameValue(2, found); - -// Test object as a thisArg -var thisArg = { - elementAt: function(key) { - return this[key]; - } -}; -Array.prototype.push.apply(thisArg, ["c", "b", "a"]); - -found = ["a", "b", "c"].find(function(val, key) { - return this.elementAt(key) === val; -}, thisArg); -assert.sameValue("b", found); - -// Check thisArg parameter does not change. -var a = []; -[1, 2].find(function() { a.push(this) }, {}); -assert.sameValue(a[0], a[1]); - -// In strict mode primitive values should not be coerced to an object. -a = []; -[1, 2].find(function() { "use strict"; a.push(this); }, ""); -assert.sameValue("", a[0]); -assert.sameValue(a[0], a[1]); diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_this-defined.js b/test/built-ins/Array/prototype/find/Array.prototype.find_this-defined.js deleted file mode 100644 index aaf6b05206..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_this-defined.js +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: thisArg should be bound to this if provided -features: [Array#find] ----*/ - -var globalThis = this; - -[1].find(function () { - assert.sameValue(this, Array, 'this should equal Array'); - assert.notSameValue(this, globalThis, 'this should not equal globalThis'); -}, Array); diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_this-global.js b/test/built-ins/Array/prototype/find/Array.prototype.find_this-global.js deleted file mode 100644 index 174397e0ec..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_this-global.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: thisArg should be global object if not provided (not Strict mode) -flags: [noStrict] -includes: [fnGlobalObject.js] -features: [Array#find] ----*/ - - -[1].find(function () { - if (this !== fnGlobalObject()) { - $ERROR('#1: this !== global object'); - } -}); diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_this-is-object.js b/test/built-ins/Array/prototype/find/Array.prototype.find_this-is-object.js deleted file mode 100644 index 5bde2b99df..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_this-is-object.js +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: Array.prototype.find should convert thisArg into an object -flags: [noStrict] -features: [Array#find] ----*/ - -var dataTypes = [ - undefined, - null, - true, - this, - {}, - 'string', - 0, - function () {} -] - -for (var i = 0, len = dataTypes.length; i < len; i++) { - [1].find(function () { - if (!(this instanceof Object)) { - $ERROR('#' + i + ': !(this instanceof Object). Actual: ' + typeof this); - } - }, dataTypes[i]) -} diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_this-undefined.js b/test/built-ins/Array/prototype/find/Array.prototype.find_this-undefined.js deleted file mode 100644 index a8db0fa5f0..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_this-undefined.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2014 Matthew Meyers. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: thisArg should be undefined if not provided (Strict mode) -flags: [onlyStrict] -features: [Array#find] ----*/ - - -[1].find(function () { - if (this !== undefined) { - $ERROR('#1: this !== undefined'); - } -}); diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_treats-holes-as-undefined-not-skipped.js b/test/built-ins/Array/prototype/find/Array.prototype.find_treats-holes-as-undefined-not-skipped.js deleted file mode 100644 index b47a8c8612..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_treats-holes-as-undefined-not-skipped.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.8 -description: > - The find() method returns a value in the array, if an - element in the array satisfies the provided testing function. - Otherwise undefined is returned. - - Does not skip holes - - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find ----*/ - -var count = 0; -[,,,,,].find(function() { count++; return false; }); -assert.sameValue(count, 5); diff --git a/test/built-ins/Array/prototype/find/Array.prototype.find_with-string.js b/test/built-ins/Array/prototype/find/Array.prototype.find_with-string.js deleted file mode 100644 index 40a6163cbd..0000000000 --- a/test/built-ins/Array/prototype/find/Array.prototype.find_with-string.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.8 -description: > - The find() method returns a value in the array, if an - element in the array satisfies the provided testing function. - Otherwise undefined is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find -includes: [compareArray.js] ----*/ - -var a = "abcd"; -var l = -1; -var o = -1; -var v = -1; -var k = -1; -var found = Array.prototype.find.call(a, function(val, key, obj) { - o = obj.toString(); - l = obj.length; - v = val; - k = key; - - return false; -}); - -assert.sameValue(o, a); -assert.sameValue(l, a.length); -assert.sameValue(v, "d"); -assert.sameValue(k, 3); -assert.sameValue(found, undefined); - -found = Array.prototype.find.apply(a, [function(val, key, obj) { - o = obj.toString(); - l = obj.length; - v = val; - k = key; - - return true; -}]); - -assert.sameValue(o, a); -assert.sameValue(l, a.length); -assert.sameValue(v, "a"); -assert.sameValue(k, 0); -assert.sameValue(found, "a"); - diff --git a/test/built-ins/Array/prototype/find/array-altered-during-loop.js b/test/built-ins/Array/prototype/find/array-altered-during-loop.js new file mode 100644 index 0000000000..7a5a0e7c9a --- /dev/null +++ b/test/built-ins/Array/prototype/find/array-altered-during-loop.js @@ -0,0 +1,47 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: > + The range of elements processed is set before the first call to `predicate`. +info: > + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. If thisArg was supplied, let T be thisArg; else let T be undefined. + 7. Let k be 0. + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + ... +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var results = []; + +arr.find(function(kValue) { + if (results.length === 0) { + arr.splice(1, 1); + } + results.push(kValue); +}); + +assert.sameValue(results.length, 3, 'predicate called three times'); +assert.sameValue(results[0], 'Shoes'); +assert.sameValue(results[1], 'Bike'); +assert.sameValue(results[2], undefined); + +results = []; +arr = ['Skateboard', 'Barefoot']; +arr.find(function(kValue) { + if (results.length === 0) { + arr.push('Motorcycle'); + arr[1] = 'Magic Carpet'; + } + + results.push(kValue); +}); + +assert.sameValue(results.length, 2, 'predicate called twice'); +assert.sameValue(results[0], 'Skateboard'); +assert.sameValue(results[1], 'Magic Carpet'); diff --git a/test/built-ins/Array/prototype/find/find.js b/test/built-ins/Array/prototype/find/find.js new file mode 100644 index 0000000000..d67656ad86 --- /dev/null +++ b/test/built-ins/Array/prototype/find/find.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: Property type and descriptor. +info: > + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof Array.prototype.find, + 'function', + '`typeof Array.prototype.find` is `function`' +); + +verifyNotEnumerable(Array.prototype, 'find'); +verifyWritable(Array.prototype, 'find'); +verifyConfigurable(Array.prototype, 'find'); diff --git a/test/built-ins/Array/prototype/find/length.js b/test/built-ins/Array/prototype/find/length.js new file mode 100644 index 0000000000..3335a00ff6 --- /dev/null +++ b/test/built-ins/Array/prototype/find/length.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: Array.prototype.find.length value and descriptor. +info: > + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Array.prototype.find.length, 1, + 'The value of `Array.prototype.find.length` is `1`' +); + +verifyNotEnumerable(Array.prototype.find, 'length'); +verifyNotWritable(Array.prototype.find, 'length'); +verifyConfigurable(Array.prototype.find, 'length'); diff --git a/test/built-ins/Array/prototype/find/name.js b/test/built-ins/Array/prototype/find/name.js new file mode 100644 index 0000000000..4b75775757 --- /dev/null +++ b/test/built-ins/Array/prototype/find/name.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: > + Array.prototype.find.name value and descriptor. +info: > + 22.1.3.8 Array.prototype.find ( predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Array.prototype.find.name, 'find', + 'The value of `Array.prototype.find.name` is `"find"`' +); + +verifyNotEnumerable(Array.prototype.find, 'name'); +verifyNotWritable(Array.prototype.find, 'name'); +verifyConfigurable(Array.prototype.find, 'name'); diff --git a/test/built-ins/Array/prototype/find/predicate-call-parameters.js b/test/built-ins/Array/prototype/find/predicate-call-parameters.js new file mode 100644 index 0000000000..403ec09158 --- /dev/null +++ b/test/built-ins/Array/prototype/find/predicate-call-parameters.js @@ -0,0 +1,46 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +info: > + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. If thisArg was supplied, let T be thisArg; else let T be undefined. + 7. Let k be 0. + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + e. ReturnIfAbrupt(testResult). + ... +---*/ + +var arr = ['Mike', 'Rick', 'Leo']; + +var results = []; + +arr.find(function(kValue, k, O) { + results.push(arguments); +}); + +assert.sameValue(results.length, 3); + +var result = results[0]; +assert.sameValue(result[0], 'Mike'); +assert.sameValue(result[1], 0); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); + +result = results[1]; +assert.sameValue(result[0], 'Rick'); +assert.sameValue(result[1], 1); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); + +result = results[2]; +assert.sameValue(result[0], 'Leo'); +assert.sameValue(result[1], 2); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); diff --git a/test/built-ins/Array/prototype/find/predicate-call-this-non-strict.js b/test/built-ins/Array/prototype/find/predicate-call-this-non-strict.js new file mode 100644 index 0000000000..e533d2103a --- /dev/null +++ b/test/built-ins/Array/prototype/find/predicate-call-this-non-strict.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +info: > + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + e. ReturnIfAbrupt(testResult). + ... +flags: [noStrict] +---*/ + +var result; + +[1].find(function(kValue, k, O) { + result = this; +}); + +assert.sameValue(result, this); + +var o = {}; +[1].find(function() { + result = this; +}, o); + +assert.sameValue(result, o); diff --git a/test/built-ins/Array/prototype/find/predicate-call-this-strict.js b/test/built-ins/Array/prototype/find/predicate-call-this-strict.js new file mode 100644 index 0000000000..5a8726f2f1 --- /dev/null +++ b/test/built-ins/Array/prototype/find/predicate-call-this-strict.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +info: > + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + e. ReturnIfAbrupt(testResult). + ... +flags: [onlyStrict] +---*/ + +var result; + +[1].find(function(kValue, k, O) { + result = this; +}); + +assert.sameValue(result, undefined); + +var o = {}; +[1].find(function() { + result = this; +}, o); + +assert.sameValue(result, o); diff --git a/test/built-ins/Array/prototype/find/predicate-called-for-each-array-property.js b/test/built-ins/Array/prototype/find/predicate-called-for-each-array-property.js new file mode 100644 index 0000000000..0a140f9ea3 --- /dev/null +++ b/test/built-ins/Array/prototype/find/predicate-called-for-each-array-property.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: > + Predicate is called for each array property. +info: > + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. If thisArg was supplied, let T be thisArg; else let T be undefined. + 7. Let k be 0. + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + ... +---*/ + +var arr = [undefined, , , 'foo']; +var called = 0; + +arr.find(function() { + called++; +}); + +assert.sameValue(called, 4); diff --git a/test/built-ins/Array/prototype/find/predicate-is-not-callable-throws.js b/test/built-ins/Array/prototype/find/predicate-is-not-callable-throws.js new file mode 100644 index 0000000000..3aa4a58d1d --- /dev/null +++ b/test/built-ins/Array/prototype/find/predicate-is-not-callable-throws.js @@ -0,0 +1,49 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: > + Throws a TypeError exception if predicate is not callable. +info: > + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 5. If IsCallable(predicate) is false, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + [].find({}); +}); + +assert.throws(TypeError, function() { + [].find(null); +}); + +assert.throws(TypeError, function() { + [].find(undefined); +}); + +assert.throws(TypeError, function() { + [].find(true); +}); + +assert.throws(TypeError, function() { + [].find(1); +}); + +assert.throws(TypeError, function() { + [].find(''); +}); + +assert.throws(TypeError, function() { + [].find(1); +}); + +assert.throws(TypeError, function() { + [].find([]); +}); + +assert.throws(TypeError, function() { + [].find(/./); +}); diff --git a/test/built-ins/Array/prototype/find/predicate-not-called-on-empty-array.js b/test/built-ins/Array/prototype/find/predicate-not-called-on-empty-array.js new file mode 100644 index 0000000000..327293d2fc --- /dev/null +++ b/test/built-ins/Array/prototype/find/predicate-not-called-on-empty-array.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: > + Predicate is only called if this.length is > 0. +info: > + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 7. Let k be 0. + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + ... + 9. Return undefined. +---*/ + +var called = false; + +var predicate = function() { + called = true; + return true; +}; + +var result = [].find(predicate); + +assert.sameValue(called, false, '[].find(predicate) does not call predicate'); +assert.sameValue(result, undefined, '[].find(predicate) returned undefined'); diff --git a/test/built-ins/Array/prototype/find/return-abrupt-from-predicate-call.js b/test/built-ins/Array/prototype/find/return-abrupt-from-predicate-call.js new file mode 100644 index 0000000000..7a7fb605ad --- /dev/null +++ b/test/built-ins/Array/prototype/find/return-abrupt-from-predicate-call.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: > + Return abrupt from predicate call. +info: > + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 7. Let k be 0. + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + e. ReturnIfAbrupt(testResult). + ... +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + [1].find(predicate); +}); diff --git a/test/built-ins/Array/prototype/find/return-abrupt-from-property.js b/test/built-ins/Array/prototype/find/return-abrupt-from-property.js new file mode 100644 index 0000000000..c5dd97bd13 --- /dev/null +++ b/test/built-ins/Array/prototype/find/return-abrupt-from-property.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: > + Returns abrupt from getting property value from `this`. +info: > + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 7. Let k be 0. + 8. Repeat, while k < len + a. Let Pk be ToString(k). + b. Let kValue be Get(O, Pk). + c. ReturnIfAbrupt(kValue). + ... +---*/ + +var o = { + length: 1 +}; + +Object.defineProperty(o, 0, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + [].find.call(o, function() {}); +}); diff --git a/test/built-ins/Array/prototype/find/return-abrupt-from-this-length-as-symbol.js b/test/built-ins/Array/prototype/find/return-abrupt-from-this-length-as-symbol.js new file mode 100644 index 0000000000..78bc5bb290 --- /dev/null +++ b/test/built-ins/Array/prototype/find/return-abrupt-from-this-length-as-symbol.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: > + Return abrupt from ToLength(Get(O, "length")) where length is a Symbol. +info: > + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Let len be ToLength(Get(O, "length")). + 4. ReturnIfAbrupt(len). +features: [Symbol] +---*/ + +var o = {}; + +o.length = Symbol(1); + +// predicate fn is given to avoid false positives +assert.throws(TypeError, function() { + [].find.call(o, function() {}); +}); diff --git a/test/built-ins/Array/prototype/find/return-abrupt-from-this-length.js b/test/built-ins/Array/prototype/find/return-abrupt-from-this-length.js new file mode 100644 index 0000000000..a0dcc894b1 --- /dev/null +++ b/test/built-ins/Array/prototype/find/return-abrupt-from-this-length.js @@ -0,0 +1,38 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: > + Return abrupt from ToLength(Get(O, "length")). +info: > + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Let len be ToLength(Get(O, "length")). + 4. ReturnIfAbrupt(len). +---*/ + +var o1 = {}; + +Object.defineProperty(o1, 'length', { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); + +assert.throws(Test262Error, function() { + [].find.call(o1); +}); + +var o2 = { + length: { + valueOf: function() { + throw new Test262Error(); + } + } +}; +assert.throws(Test262Error, function() { + [].find.call(o2); +}); diff --git a/test/built-ins/Array/prototype/find/return-abrupt-from-this.js b/test/built-ins/Array/prototype/find/return-abrupt-from-this.js new file mode 100644 index 0000000000..298e100460 --- /dev/null +++ b/test/built-ins/Array/prototype/find/return-abrupt-from-this.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: > + Return abrupt from ToObject(this value). +info: > + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). +---*/ + +// predicate fn is given to avoid false positives +assert.throws(TypeError, function() { + Array.prototype.find.call(undefined, function() {}); +}); + +assert.throws(TypeError, function() { + Array.prototype.find.call(null, function() {}); +}); diff --git a/test/built-ins/Array/prototype/find/return-found-value-predicate-result-is-true.js b/test/built-ins/Array/prototype/find/return-found-value-predicate-result-is-true.js new file mode 100644 index 0000000000..7c8e8b63c6 --- /dev/null +++ b/test/built-ins/Array/prototype/find/return-found-value-predicate-result-is-true.js @@ -0,0 +1,53 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: > + Return found value if predicate return a boolean true value. +info: > + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + e. ReturnIfAbrupt(testResult). + f. If testResult is true, return kValue. + ... +features: [Symbol] +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var called = 0; + +var result = arr.find(function(val) { + called++; + return true; +}); + +assert.sameValue(result, 'Shoes'); +assert.sameValue(called, 1, 'predicate was called once'); + +called = 0; +result = arr.find(function(val) { + called++; + return val === 'Bike'; +}); + +assert.sameValue(called, 3, 'predicate was called three times'); +assert.sameValue(result, 'Bike'); + +result = arr.find(function(val) { return 'string'; }); +assert.sameValue(result, 'Shoes', 'coerced string'); + +result = arr.find(function(val) { return {}; }); +assert.sameValue(result, 'Shoes', 'coerced object'); + +result = arr.find(function(val) { return Symbol(''); }); +assert.sameValue(result, 'Shoes', 'coerced Symbol'); + +result = arr.find(function(val) { return 1; }); +assert.sameValue(result, 'Shoes', 'coerced number'); + +result = arr.find(function(val) { return -1; }); +assert.sameValue(result, 'Shoes', 'coerced negative number'); diff --git a/test/built-ins/Array/prototype/find/return-undefined-if-predicate-returns-false-value.js b/test/built-ins/Array/prototype/find/return-undefined-if-predicate-returns-false-value.js new file mode 100644 index 0000000000..cf665b8cb9 --- /dev/null +++ b/test/built-ins/Array/prototype/find/return-undefined-if-predicate-returns-false-value.js @@ -0,0 +1,43 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.8 +description: > + Return undefined if predicate always returns a boolean false value. +info: > + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + ... + 9. Return undefined. +features: [Symbol] +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var called = 0; + +var result = arr.find(function(val) { + called++; + return false; +}); + +assert.sameValue(called, 3, 'predicate was called three times'); +assert.sameValue(result, undefined); + +result = arr.find(function(val) { return ''; }); +assert.sameValue(result, undefined, 'coerced string'); + +result = arr.find(function(val) { return undefined; }); +assert.sameValue(result, undefined, 'coerced undefined'); + +result = arr.find(function(val) { return null; }); +assert.sameValue(result, undefined, 'coerced null'); + +result = arr.find(function(val) { return 0; }); +assert.sameValue(result, undefined, 'coerced 0'); + +result = arr.find(function(val) { return NaN; }); +assert.sameValue(result, undefined, 'coerced NaN'); diff --git a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_arity.js b/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_arity.js deleted file mode 100644 index 622ceb5623..0000000000 --- a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_arity.js +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.9 -description: > - The findIndex() method returns an index in the array, if an element - in the array satisfies the provided testing function. Otherwise -1 is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex ----*/ - -assert.sameValue(1, Array.prototype.findIndex.length); - diff --git a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_basic.js b/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_basic.js deleted file mode 100644 index 2b9db5c681..0000000000 --- a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_basic.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.9 -description: > - The findIndex() method returns an index in the array, if an element - in the array satisfies the provided testing function. Otherwise -1 is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex ----*/ -var a = [21, 22, 23, 24]; -assert.sameValue(a.findIndex(function() { return false; }), -1); -assert.sameValue(a.findIndex(function(val) { return 121 === val; }), -1); -assert.sameValue(a.findIndex(function() { return true; }), 0); -assert.sameValue(a.findIndex(function(val) { return 22 === val; }), 1); -assert.sameValue(a.findIndex(function(val) { return 23 === val; }), 2); -assert.sameValue(a.findIndex(function(val) { return 24 === val; }), 3); diff --git a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_called-length-times.js b/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_called-length-times.js deleted file mode 100644 index dc3cbe85e7..0000000000 --- a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_called-length-times.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.9 -description: > - The findIndex() method returns an index in the array, if an element - in the array satisfies the provided testing function. Otherwise -1 is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex ----*/ -// -// Test predicate is called array.length times -// -(function() { - var a = [1, 2, 3, 4, 5]; - var l = 0; - - a.findIndex(function() { - l++; - return false; - }); - - assert.sameValue(a.length, l); -})(); diff --git a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_exceptions.js b/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_exceptions.js deleted file mode 100644 index 11abc79b1c..0000000000 --- a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_exceptions.js +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.9 -description: > - The findIndex() method returns an index in the array, if an element - in the array satisfies the provided testing function. Otherwise -1 is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex ----*/ -// Test exceptions -assert.throws(TypeError, function() { - Array.prototype.findIndex.call(null, function() { }); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.call(undefined, function() { }); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.apply(null, function() { }, []); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.apply(undefined, function() { }, []); -}); - -assert.throws(TypeError, function() { - [].findIndex(null); -}); -assert.throws(TypeError, function() { - [].findIndex(undefined); -}); -assert.throws(TypeError, function() { - [].findIndex(0); -}); -assert.throws(TypeError, function() { - [].findIndex(true); -}); -assert.throws(TypeError, function() { - [].findIndex(false); -}); -assert.throws(TypeError, function() { - [].findIndex(""); -}); -assert.throws(TypeError, function() { - [].findIndex({}); -}); -assert.throws(TypeError, function() { - [].findIndex([]); -}); -assert.throws(TypeError, function() { - [].findIndex(/\d+/); -}); - -assert.throws(TypeError, function() { - Array.prototype.findIndex.call({}, null); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.call({}, undefined); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.call({}, 0); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.call({}, true); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.call({}, false); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.call({}, ""); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.call({}, {}); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.call({}, []); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.call({}, /\d+/); -}); - -assert.throws(TypeError, function() { - Array.prototype.findIndex.apply({}, null, []); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.apply({}, undefined, []); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.apply({}, 0, []); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.apply({}, true, []); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.apply({}, false, []); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.apply({}, "", []); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.apply({}, {}, []); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.apply({}, [], []); -}); -assert.throws(TypeError, function() { - Array.prototype.findIndex.apply({}, /\d+/, []); -}); diff --git a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_exotic-object.js b/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_exotic-object.js deleted file mode 100644 index 888b17e179..0000000000 --- a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_exotic-object.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.9 -description: > - The findIndex() method returns an index in the array, if an element - in the array satisfies the provided testing function. Otherwise -1 is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex -includes: [compareArray.js] ----*/ -// -// Test Array.prototype.findIndex works with exotic object -// -var l = -1; -var o = -1; -var v = -1; -var k = -1; -var a = { - prop1: "val1", - prop2: "val2", - isValid: function() { - return this.prop1 === "val1" && this.prop2 === "val2"; - } -}; - -Array.prototype.push.apply(a, [30, 31, 32]); - -var index = Array.prototype.findIndex.call(a, function(val, key, obj) { - o = obj; - l = obj.length; - v = val; - k = key; - - return !obj.isValid(); -}); - -assert(compareArray(o, a)); -assert.sameValue(l, 3); -assert.sameValue(v, 32); -assert.sameValue(k, 2); -assert.sameValue(index, -1); diff --git a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_modifications.js b/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_modifications.js deleted file mode 100644 index a1c8d28b41..0000000000 --- a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_modifications.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.9 -description: > - The findIndex() method returns an index in the array, if an element - in the array satisfies the provided testing function. Otherwise -1 is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex -includes: [compareArray.js] ----*/ -// -// Test array modifications -// -var a = [1, 2, 3]; -a.findIndex(function(val) { a.push(val); return false; }); -assert(compareArray(a, [1, 2, 3, 1, 2, 3])); -assert.sameValue(a.length, 6); - -a = [1, 2, 3]; -a.findIndex(function(val, key) { a[key] = ++val; return false; }); -assert(compareArray(a, [2, 3, 4])); -assert.sameValue(a.length, 3); diff --git a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_not-called-on-empty-array.js b/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_not-called-on-empty-array.js deleted file mode 100644 index 9f9db8b324..0000000000 --- a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_not-called-on-empty-array.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.9 -description: > - The findIndex() method returns an index in the array, if an element - in the array satisfies the provided testing function. Otherwise -1 is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex ----*/ -// -// Test predicate is not called when array is empty -// -var a = []; -var l = -1; -var o = -1; -var v = -1; -var k = -1; - -a.findIndex(function(val, key, obj) { - o = obj; - l = obj.length; - v = val; - k = key; - - return false; -}); - -assert.sameValue(-1, l); -assert.sameValue(-1, o); -assert.sameValue(-1, v); -assert.sameValue(-1, k); diff --git a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_predicate-arguments.js b/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_predicate-arguments.js deleted file mode 100644 index 08c4a7dee1..0000000000 --- a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_predicate-arguments.js +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.9 -description: > - The findIndex() method returns an index in the array, if an element - in the array satisfies the provided testing function. Otherwise -1 is returned. - - Test predicate is called with correct arguments - - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex -includes: [compareArray.js] ----*/ -var a = ["b"]; -var l = -1; -var o = -1; -var v = -1; -var k = -1; - -var index = a.findIndex(function(val, key, obj) { - o = obj; - l = obj.length; - v = val; - k = key; - - return false; -}); - -assert(compareArray(o, a)); -assert.sameValue(l, a.length); -assert.sameValue(v, "b"); -assert.sameValue(k, 0); -assert.sameValue(index, -1); diff --git a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_this-arg-receiver-coercion-strict.js b/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_this-arg-receiver-coercion-strict.js deleted file mode 100644 index f343507f0b..0000000000 --- a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_this-arg-receiver-coercion-strict.js +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.9 -description: > - In strict mode primitive value thisArg should not be coerced to an object. -flags: [onlyStrict] ----*/ -var a = []; -[1, 2].findIndex(function() { a.push(this); }, ""); -assert.sameValue(a[0], ""); -assert.sameValue(a[1], a[0]); diff --git a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_this-arg-receiver-primitive.js b/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_this-arg-receiver-primitive.js deleted file mode 100644 index 3f2c44f831..0000000000 --- a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_this-arg-receiver-primitive.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.9 -description: > - Create a new object in each function call when receiver is a - primitive value. See ECMA-262, Annex C. -flags: [noStrict] ----*/ -var a = []; -[1, 2].findIndex(function() { a.push(this) }, ""); -assert(a[0] !== a[1]); - -var b = []; -[1, 2].findIndex(function() { b.push(this) }, 1); -assert(b[0] !== b[1]); diff --git a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_this-arg-receiver-reference.js b/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_this-arg-receiver-reference.js deleted file mode 100644 index 4c89bd813b..0000000000 --- a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_this-arg-receiver-reference.js +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.9 -description: > - Do not create a new object in each function call when receiver is a - non-primitive value. See ECMA-262, Annex C. ----*/ -var a = []; -[1, 2].findIndex(function() { a.push(this) }, {}); -assert.sameValue(a[1], a[0]); diff --git a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_this-arg.js b/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_this-arg.js deleted file mode 100644 index d166f8592f..0000000000 --- a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_this-arg.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.9 -description: > - The findIndex() method returns an index in the array, if an element - in the array satisfies the provided testing function. Otherwise -1 is returned. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex ----*/ -// -// Test thisArg -// -// Test String as a thisArg -var index = [1, 2, 3].findIndex(function(val, key) { - return this.charAt(Number(key)) === String(val); -}, "321"); -assert.sameValue(index, 1); - -// Test object as a thisArg -var thisArg = { - elementAt: function(key) { - return this[key]; - } -}; -Array.prototype.push.apply(thisArg, ["c", "b", "a"]); - -index = ["a", "b", "c"].findIndex(function(val, key) { - return this.elementAt(key) === val; -}, thisArg); -assert.sameValue(index, 1); - -// Check thisArg parameter does not change. -var a = []; -[1, 2].findIndex(function() { a.push(this) }, {}); -assert.sameValue(a[1], a[0]); - -// In strict mode primitive values should not be coerced to an object. -a = []; -[1, 2].findIndex(function() { 'use strict'; a.push(this); }, ""); -assert.sameValue(a[0], ""); -assert.sameValue(a[1], a[0]); diff --git a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_treats-holes-as-undefined-not-skipped.js b/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_treats-holes-as-undefined-not-skipped.js deleted file mode 100644 index 489d41c02f..0000000000 --- a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_treats-holes-as-undefined-not-skipped.js +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.9 -description: > - Holes are not skipped ----*/ -var count = 0; -[,,,,,].find(function() { count++; return false; }); -assert.sameValue(count, 5); diff --git a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_with-string.js b/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_with-string.js deleted file mode 100644 index a48fc0504e..0000000000 --- a/test/built-ins/Array/prototype/findIndex/Array.prototype.findIndex_with-string.js +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2013 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -/*--- -es6id: 22.1.3.9 -description: > - The findIndex() method returns an index in the array, if an element - in the array satisfies the provided testing function. Otherwise -1 is returned. - - Test Array.prototype.findIndex works with String - - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex ----*/ -var a = "abcd"; -var l = -1; -var o = -1; -var v = -1; -var k = -1; - -var index = Array.prototype.findIndex.call(a, function(val, key, obj) { - o = obj.toString(); - l = obj.length; - v = val; - k = key; - - return false; -}); - -assert.sameValue(o, a); -assert.sameValue(l, a.length); -assert.sameValue(v, "d"); -assert.sameValue(k, 3); -assert.sameValue(index, -1); - -index = Array.prototype.findIndex.apply(a, [function(val, key, obj) { - o = obj.toString(); - l = obj.length; - v = val; - k = key; - - return true; -}]); - -assert.sameValue(o, a); -assert.sameValue(l, a.length); -assert.sameValue(v, "a"); -assert.sameValue(k, 0); -assert.sameValue(index, 0); - diff --git a/test/built-ins/Array/prototype/findIndex/array-altered-during-loop.js b/test/built-ins/Array/prototype/findIndex/array-altered-during-loop.js new file mode 100644 index 0000000000..e490021939 --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/array-altered-during-loop.js @@ -0,0 +1,47 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: > + The range of elements processed is set before the first call to `predicate`. +info: > + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 6. If thisArg was supplied, let T be thisArg; else let T be undefined. + 7. Let k be 0. + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + ... +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var results = []; + +arr.findIndex(function(kValue) { + if (results.length === 0) { + arr.splice(1, 1); + } + results.push(kValue); +}); + +assert.sameValue(results.length, 3, 'predicate called three times'); +assert.sameValue(results[0], 'Shoes'); +assert.sameValue(results[1], 'Bike'); +assert.sameValue(results[2], undefined); + +results = []; +arr = ['Skateboard', 'Barefoot']; +arr.findIndex(function(kValue) { + if (results.length === 0) { + arr.push('Motorcycle'); + arr[1] = 'Magic Carpet'; + } + + results.push(kValue); +}); + +assert.sameValue(results.length, 2, 'predicate called twice'); +assert.sameValue(results[0], 'Skateboard'); +assert.sameValue(results[1], 'Magic Carpet'); diff --git a/test/built-ins/Array/prototype/findIndex/findIndex.js b/test/built-ins/Array/prototype/findIndex/findIndex.js new file mode 100644 index 0000000000..69557fb7f9 --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/findIndex.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: Property type and descriptor. +info: > + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof Array.prototype.findIndex, + 'function', + '`typeof Array.prototype.findIndex` is `function`' +); + +verifyNotEnumerable(Array.prototype, 'findIndex'); +verifyWritable(Array.prototype, 'findIndex'); +verifyConfigurable(Array.prototype, 'findIndex'); diff --git a/test/built-ins/Array/prototype/findIndex/length.js b/test/built-ins/Array/prototype/findIndex/length.js new file mode 100644 index 0000000000..bdb946494e --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/length.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: Array.prototype.findIndex.length value and descriptor. +info: > + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Array.prototype.findIndex.length, 1, + 'The value of `Array.prototype.findIndex.length` is `1`' +); + +verifyNotEnumerable(Array.prototype.findIndex, 'length'); +verifyNotWritable(Array.prototype.findIndex, 'length'); +verifyConfigurable(Array.prototype.findIndex, 'length'); diff --git a/test/built-ins/Array/prototype/findIndex/name.js b/test/built-ins/Array/prototype/findIndex/name.js new file mode 100644 index 0000000000..6258ff467f --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/name.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: > + Array.prototype.findIndex.name value and descriptor. +info: > + 22.1.3.9 Array.prototype.findIndex ( predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Array.prototype.findIndex.name, 'findIndex', + 'The value of `Array.prototype.findIndex.name` is `"findIndex"`' +); + +verifyNotEnumerable(Array.prototype.findIndex, 'name'); +verifyNotWritable(Array.prototype.findIndex, 'name'); +verifyConfigurable(Array.prototype.findIndex, 'name'); diff --git a/test/built-ins/Array/prototype/findIndex/predicate-call-parameters.js b/test/built-ins/Array/prototype/findIndex/predicate-call-parameters.js new file mode 100644 index 0000000000..60a6dc1407 --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/predicate-call-parameters.js @@ -0,0 +1,45 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +info: > + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 6. If thisArg was supplied, let T be thisArg; else let T be undefined. + 7. Let k be 0. + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + ... +---*/ + +var arr = ['Mike', 'Rick', 'Leo']; + +var results = []; + +arr.findIndex(function(kValue, k, O) { + results.push(arguments); +}); + +assert.sameValue(results.length, 3); + +var result = results[0]; +assert.sameValue(result[0], 'Mike'); +assert.sameValue(result[1], 0); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); + +result = results[1]; +assert.sameValue(result[0], 'Rick'); +assert.sameValue(result[1], 1); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); + +result = results[2]; +assert.sameValue(result[0], 'Leo'); +assert.sameValue(result[1], 2); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); diff --git a/test/built-ins/Array/prototype/findIndex/predicate-call-this-non-strict.js b/test/built-ins/Array/prototype/findIndex/predicate-call-this-non-strict.js new file mode 100644 index 0000000000..0e702987eb --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/predicate-call-this-non-strict.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +info: > + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + e. ReturnIfAbrupt(testResult). + ... +flags: [noStrict] +---*/ + +var result; + +[1].find(function(kValue, k, O) { + result = this; +}); + +assert.sameValue(result, this); + +var o = {}; +[1].find(function() { + result = this; +}, o); + +assert.sameValue(result, o); diff --git a/test/built-ins/Array/prototype/findIndex/predicate-call-this-strict.js b/test/built-ins/Array/prototype/findIndex/predicate-call-this-strict.js new file mode 100644 index 0000000000..2febc6a41e --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/predicate-call-this-strict.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +info: > + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + e. ReturnIfAbrupt(testResult). + ... +flags: [onlyStrict] +---*/ + +var result; + +[1].find(function(kValue, k, O) { + result = this; +}); + +assert.sameValue(result, undefined); + +var o = {}; +[1].find(function() { + result = this; +}, o); + +assert.sameValue(result, o); diff --git a/test/built-ins/Array/prototype/findIndex/predicate-called-for-each-array-property.js b/test/built-ins/Array/prototype/findIndex/predicate-called-for-each-array-property.js new file mode 100644 index 0000000000..a9413f9544 --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/predicate-called-for-each-array-property.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: > + Predicate is called for each array property. +info: > + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 6. If thisArg was supplied, let T be thisArg; else let T be undefined. + 7. Let k be 0. + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + ... +---*/ + +var arr = [undefined, , , 'foo']; +var called = 0; + +arr.findIndex(function() { + called++; +}); + +assert.sameValue(called, 4); diff --git a/test/built-ins/Array/prototype/findIndex/predicate-is-not-callable-throws.js b/test/built-ins/Array/prototype/findIndex/predicate-is-not-callable-throws.js new file mode 100644 index 0000000000..e7da5795ed --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/predicate-is-not-callable-throws.js @@ -0,0 +1,49 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: > + Throws a TypeError exception if predicate is not callable. +info: > + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 5. If IsCallable(predicate) is false, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + [].findIndex({}); +}); + +assert.throws(TypeError, function() { + [].findIndex(null); +}); + +assert.throws(TypeError, function() { + [].findIndex(undefined); +}); + +assert.throws(TypeError, function() { + [].findIndex(true); +}); + +assert.throws(TypeError, function() { + [].findIndex(1); +}); + +assert.throws(TypeError, function() { + [].findIndex(''); +}); + +assert.throws(TypeError, function() { + [].findIndex(1); +}); + +assert.throws(TypeError, function() { + [].findIndex([]); +}); + +assert.throws(TypeError, function() { + [].findIndex(/./); +}); diff --git a/test/built-ins/Array/prototype/findIndex/predicate-not-called-on-empty-array.js b/test/built-ins/Array/prototype/findIndex/predicate-not-called-on-empty-array.js new file mode 100644 index 0000000000..58788f9385 --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/predicate-not-called-on-empty-array.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: > + Predicate is only called if this.length is > 0. +info: > + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 7. Let k be 0. + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + ... + 9. Return -1. +---*/ + +var called = false; + +var predicate = function() { + called = true; + return true; +}; + +var result = [].findIndex(predicate); + +assert.sameValue( + called, false, + '[].findIndex(predicate) does not call predicate' +); +assert.sameValue( + result, -1, + '[].findIndex(predicate) returned undefined' +); diff --git a/test/built-ins/Array/prototype/findIndex/return-abrupt-from-predicate-call.js b/test/built-ins/Array/prototype/findIndex/return-abrupt-from-predicate-call.js new file mode 100644 index 0000000000..c5b42e6ac2 --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/return-abrupt-from-predicate-call.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: > + Return abrupt from predicate call. +info: > + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 7. Let k be 0. + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + e. ReturnIfAbrupt(testResult). + ... +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + [1].findIndex(predicate); +}); diff --git a/test/built-ins/Array/prototype/findIndex/return-abrupt-from-property.js b/test/built-ins/Array/prototype/findIndex/return-abrupt-from-property.js new file mode 100644 index 0000000000..88c729b244 --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/return-abrupt-from-property.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: > + Returns abrupt from getting property value from `this`. +info: > + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 7. Let k be 0. + 8. Repeat, while k < len + a. Let Pk be ToString(k). + b. Let kValue be Get(O, Pk). + c. ReturnIfAbrupt(kValue). + ... +---*/ + +var o = { + length: 1 +}; + +Object.defineProperty(o, 0, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + [].findIndex.call(o, function() {}); +}); diff --git a/test/built-ins/Array/prototype/findIndex/return-abrupt-from-this-length-as-symbol.js b/test/built-ins/Array/prototype/findIndex/return-abrupt-from-this-length-as-symbol.js new file mode 100644 index 0000000000..0489657bb0 --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/return-abrupt-from-this-length-as-symbol.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: > + Return abrupt from ToLength(Get(O, "length")) where length is a Symbol. +info: > + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Let len be ToLength(Get(O, "length")). + 4. ReturnIfAbrupt(len). + ... +features: [Symbol] +---*/ + +var o = {}; + +o.length = Symbol(1); + +// predicate fn is given to avoid false positives +assert.throws(TypeError, function() { + [].findIndex.call(o, function() {}); +}); diff --git a/test/built-ins/Array/prototype/findIndex/return-abrupt-from-this-length.js b/test/built-ins/Array/prototype/findIndex/return-abrupt-from-this-length.js new file mode 100644 index 0000000000..294fbd9902 --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/return-abrupt-from-this-length.js @@ -0,0 +1,38 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: > + Return abrupt from ToLength(Get(O, "length")). +info: > + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Let len be ToLength(Get(O, "length")). + 4. ReturnIfAbrupt(len). +---*/ + +var o1 = {}; + +Object.defineProperty(o1, 'length', { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +// predicate fn is given to avoid false positives +assert.throws(Test262Error, function() { + [].findIndex.call(o1, function() {}); +}); + +var o2 = { + length: { + valueOf: function() { + throw new Test262Error(); + } + } +}; +assert.throws(Test262Error, function() { + [].findIndex.call(o2, function() {}); +}); diff --git a/test/built-ins/Array/prototype/findIndex/return-abrupt-from-this.js b/test/built-ins/Array/prototype/findIndex/return-abrupt-from-this.js new file mode 100644 index 0000000000..35853a8279 --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/return-abrupt-from-this.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: > + Return abrupt from ToObject(this value). +info: > + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). +---*/ + +// predicate fn is given to avoid false positives +assert.throws(TypeError, function() { + Array.prototype.findIndex.call(undefined, function() {}); +}); + +assert.throws(TypeError, function() { + Array.prototype.findIndex.call(null, function() {}); +}); diff --git a/test/built-ins/Array/prototype/findIndex/return-index-predicate-result-is-true.js b/test/built-ins/Array/prototype/findIndex/return-index-predicate-result-is-true.js new file mode 100644 index 0000000000..349559e048 --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/return-index-predicate-result-is-true.js @@ -0,0 +1,53 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: > + Return index if predicate return a boolean true value. +info: > + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + e. ReturnIfAbrupt(testResult). + f. If testResult is true, return k. + ... +features: [Symbol] +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var called = 0; + +var result = arr.findIndex(function(val) { + called++; + return true; +}); + +assert.sameValue(result, 0); +assert.sameValue(called, 1, 'predicate was called once'); + +called = 0; +result = arr.findIndex(function(val) { + called++; + return val === 'Bike'; +}); + +assert.sameValue(called, 3, 'predicate was called three times'); +assert.sameValue(result, 2); + +result = arr.findIndex(function(val) { return 'string'; }); +assert.sameValue(result, 0, 'coerced string'); + +result = arr.findIndex(function(val) { return {}; }); +assert.sameValue(result, 0, 'coerced object'); + +result = arr.findIndex(function(val) { return Symbol(''); }); +assert.sameValue(result, 0, 'coerced Symbol'); + +result = arr.findIndex(function(val) { return 1; }); +assert.sameValue(result, 0, 'coerced number'); + +result = arr.findIndex(function(val) { return -1; }); +assert.sameValue(result, 0, 'coerced negative number'); diff --git a/test/built-ins/Array/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js b/test/built-ins/Array/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js new file mode 100644 index 0000000000..f54e5bb496 --- /dev/null +++ b/test/built-ins/Array/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js @@ -0,0 +1,43 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.9 +description: > + Return -1 if predicate always returns a boolean false value. +info: > + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 8. Repeat, while k < len + ... + d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)). + ... + 9. Return -1. +features: [Symbol] +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var called = 0; + +var result = arr.findIndex(function(val) { + called++; + return false; +}); + +assert.sameValue(called, 3, 'predicate was called three times'); +assert.sameValue(result, -1); + +result = arr.findIndex(function(val) { return ''; }); +assert.sameValue(result, -1, 'coerced string'); + +result = arr.findIndex(function(val) { return undefined; }); +assert.sameValue(result, -1, 'coerced undefined'); + +result = arr.findIndex(function(val) { return null; }); +assert.sameValue(result, -1, 'coerced null'); + +result = arr.findIndex(function(val) { return 0; }); +assert.sameValue(result, -1, 'coerced 0'); + +result = arr.findIndex(function(val) { return NaN; }); +assert.sameValue(result, -1, 'coerced NaN');