mirror of https://github.com/tc39/test262.git
Add tests for Array.prototype.includes
This commit is contained in:
parent
2cf968cfad
commit
c7f9b12cc4
|
@ -1,20 +1,23 @@
|
|||
// Copyright (C) 2015 Mike Pennisi. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.31
|
||||
esid: sec-array.prototype-@@unscopables
|
||||
description: >
|
||||
Initial value of `Symbol.unscopables` property
|
||||
info: >
|
||||
1. Let blackList be ObjectCreate(null).
|
||||
2. Perform CreateDataProperty(blackList, "copyWithin", true).
|
||||
3. Perform CreateDataProperty(blackList, "entries", true).
|
||||
4. Perform CreateDataProperty(blackList, "fill", true).
|
||||
5. Perform CreateDataProperty(blackList, "find", true).
|
||||
6. Perform CreateDataProperty(blackList, "findIndex", true).
|
||||
7. Perform CreateDataProperty(blackList, "keys", true).
|
||||
8. Perform CreateDataProperty(blackList, "values", true).
|
||||
9. Assert: Each of the above calls will return true.
|
||||
10. Return blackList.
|
||||
info: |
|
||||
22.1.3.32 Array.prototype [ @@unscopables ]
|
||||
|
||||
1. Let unscopableList be ObjectCreate(null).
|
||||
2. Perform CreateDataProperty(unscopableList, "copyWithin", true).
|
||||
3. Perform CreateDataProperty(unscopableList, "entries", true).
|
||||
4. Perform CreateDataProperty(unscopableList, "fill", true).
|
||||
5. Perform CreateDataProperty(unscopableList, "find", true).
|
||||
6. Perform CreateDataProperty(unscopableList, "findIndex", true).
|
||||
7. Perform CreateDataProperty(unscopableList, "includes", true).
|
||||
8. Perform CreateDataProperty(unscopableList, "keys", true).
|
||||
9. Perform CreateDataProperty(unscopableList, "values", true).
|
||||
10. Assert: Each of the above calls will return true.
|
||||
11. Return unscopableList.
|
||||
includes: [propertyHelper.js]
|
||||
features: [Symbol.unscopables]
|
||||
---*/
|
||||
|
@ -48,6 +51,11 @@ verifyEnumerable(unscopables, 'findIndex');
|
|||
verifyWritable(unscopables, 'findIndex');
|
||||
verifyConfigurable(unscopables, 'findIndex');
|
||||
|
||||
assert.sameValue(unscopables.includes, true, '`includes` property value');
|
||||
verifyEnumerable(unscopables, 'includes');
|
||||
verifyWritable(unscopables, 'includes');
|
||||
verifyConfigurable(unscopables, 'includes');
|
||||
|
||||
assert.sameValue(unscopables.keys, true, '`keys` property value');
|
||||
verifyEnumerable(unscopables, 'keys');
|
||||
verifyWritable(unscopables, 'keys');
|
||||
|
|
23
test/built-ins/Array/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js
vendored
Normal file
23
test/built-ins/Array/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: Return false if fromIndex >= ArrayLength
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
|
||||
produces the value 0.)
|
||||
5. If n ≥ 0, then
|
||||
a. Let k be n.
|
||||
...
|
||||
7. Repeat, while k < len
|
||||
...
|
||||
8. Return false.
|
||||
---*/
|
||||
|
||||
var sample = [ 7, 7, 7, 7 ];
|
||||
assert.sameValue(sample.includes(7, 4), false, "length");
|
||||
assert.sameValue(sample.includes(7, 5), false, "length + 1");
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: handle Infinity values for fromIndex
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
|
||||
produces the value 0.)
|
||||
5. If n ≥ 0, then
|
||||
a. Let k be n.
|
||||
6. Else n < 0,
|
||||
a. Let k be len + n.
|
||||
b. If k < 0, let k be 0.
|
||||
7. Repeat, while k < len
|
||||
...
|
||||
8. Return false.
|
||||
---*/
|
||||
|
||||
var sample = [42, 43, 43, 41];
|
||||
|
||||
assert.sameValue(
|
||||
sample.includes(43, Infinity),
|
||||
false,
|
||||
"includes(43, Infinity)"
|
||||
);
|
||||
assert.sameValue(
|
||||
sample.includes(43, -Infinity),
|
||||
true,
|
||||
"includes(43, -Infinity)"
|
||||
);
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: -0 fromIndex becomes 0
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
5. If n ≥ 0, then
|
||||
a. Let k be n.
|
||||
...
|
||||
7. Repeat, while k < len
|
||||
...
|
||||
---*/
|
||||
|
||||
var sample = [42, 43];
|
||||
assert.sameValue(sample.includes(42, -0), true, "-0 [0]");
|
||||
assert.sameValue(sample.includes(43, -0), true, "-0 [1]");
|
||||
assert.sameValue(sample.includes(44, -0), false, "-0 [2]");
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: get array-like indexed properties
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
7. Repeat, while k < len
|
||||
a. Let elementK be the result of ? Get(O, ! ToString(k)).
|
||||
...
|
||||
includes: [compareArray.js]
|
||||
features: [Proxy]
|
||||
---*/
|
||||
|
||||
var calls;
|
||||
|
||||
var obj = {};
|
||||
|
||||
var p = new Proxy(obj, {
|
||||
get: function(_, key) {
|
||||
calls.push(key);
|
||||
|
||||
if (key === "length") {
|
||||
return 4;
|
||||
}
|
||||
|
||||
return key * 10;
|
||||
}
|
||||
});
|
||||
|
||||
calls = [];
|
||||
assert.sameValue([].includes.call(p, 42), false);
|
||||
assert(
|
||||
compareArray(calls, ["length", "0", "1", "2", "3"]),
|
||||
"loops through all indexes"
|
||||
);
|
||||
|
||||
calls = [];
|
||||
assert.sameValue([].includes.call(p, 10), true, "uses the returned value");
|
||||
assert(compareArray(calls, ["length", "0", "1"]), "loops until value is found");
|
|
@ -0,0 +1,82 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: length boundaries from ToLength operation
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
2. Let len be ? ToLength(? Get(O, "length")).
|
||||
...
|
||||
|
||||
7.1.15 ToLength ( argument )
|
||||
|
||||
1. Let len be ? ToInteger(argument).
|
||||
2. If len ≤ +0, return +0.
|
||||
3. If len is +∞, return 2**53-1.
|
||||
4. Return min(len, 2**53-1).
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
"0": "a",
|
||||
"1": "b",
|
||||
"9007199254740990": "c", // 2 ** 53 - 2
|
||||
"9007199254740991": "d", // 2 ** 53 - 1
|
||||
"9007199254740992": "e", // 2 ** 53
|
||||
};
|
||||
|
||||
obj.length = -0;
|
||||
assert.sameValue([].includes.call(obj, "a"), false, "-0");
|
||||
|
||||
obj.length = -1;
|
||||
assert.sameValue([].includes.call(obj, "a"), false, "-1");
|
||||
|
||||
obj.length = -0.1;
|
||||
assert.sameValue([].includes.call(obj, "a"), false, "-0.1");
|
||||
|
||||
obj.length = -Infinity;
|
||||
assert.sameValue([].includes.call(obj, "a"), false, "-Infinity");
|
||||
|
||||
var fromIndex = 9007199254740990;
|
||||
|
||||
obj.length = 9007199254740991;
|
||||
assert.sameValue(
|
||||
[].includes.call(obj, "c", fromIndex),
|
||||
true,
|
||||
"2**53-1, found value at 2**53-2"
|
||||
);
|
||||
|
||||
obj.length = 9007199254740991;
|
||||
assert.sameValue(
|
||||
[].includes.call(obj, "d", fromIndex),
|
||||
false,
|
||||
"2**53-1, ignores indexes >= 2**53-1"
|
||||
);
|
||||
|
||||
obj.length = 9007199254740992;
|
||||
assert.sameValue(
|
||||
[].includes.call(obj, "d", fromIndex),
|
||||
false,
|
||||
"2**53, ignores indexes >= 2**53-1"
|
||||
);
|
||||
|
||||
obj.length = 9007199254740993;
|
||||
assert.sameValue(
|
||||
[].includes.call(obj, "d", fromIndex),
|
||||
false,
|
||||
"2**53+1, ignores indexes >= 2**53-1"
|
||||
);
|
||||
|
||||
obj.length = Infinity;
|
||||
assert.sameValue(
|
||||
[].includes.call(obj, "c", fromIndex),
|
||||
true,
|
||||
"Infinity, found item"
|
||||
);
|
||||
assert.sameValue(
|
||||
[].includes.call(obj, "d", fromIndex),
|
||||
false,
|
||||
"Infinity, ignores indexes >= 2**53-1"
|
||||
);
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: Returns false if length is 0
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
2. Let len be ? ToLength(? Get(O, "length")).
|
||||
3. If len is 0, return false.
|
||||
...
|
||||
---*/
|
||||
|
||||
var calls = 0;
|
||||
var fromIndex = {
|
||||
valueOf: function() {
|
||||
calls++;
|
||||
}
|
||||
};
|
||||
|
||||
var sample = [];
|
||||
assert.sameValue(sample.includes(0), false, "returns false");
|
||||
assert.sameValue(sample.includes(), false, "returns false - no arg");
|
||||
assert.sameValue(sample.includes(0, fromIndex), false, "using fromIndex");
|
||||
assert.sameValue(calls, 0, "length is checked before ToInteger(fromIndex)");
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: >
|
||||
Array.prototype.includes.length is 1.
|
||||
info: |
|
||||
Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects:
|
||||
Every built-in Function object, including constructors, has a length
|
||||
property whose value is an integer. Unless otherwise specified, this
|
||||
value is equal to the largest number of named arguments shown in the
|
||||
subclause headings for the function description, including optional
|
||||
parameters. However, rest parameters shown using the form “...name”
|
||||
are not included in the default argument count.
|
||||
|
||||
Unless otherwise specified, the length property of a built-in Function
|
||||
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
|
||||
[[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(Array.prototype.includes.length, 1);
|
||||
|
||||
verifyNotEnumerable(Array.prototype.includes, "length");
|
||||
verifyNotWritable(Array.prototype.includes, "length");
|
||||
verifyConfigurable(Array.prototype.includes, "length");
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: >
|
||||
Array.prototype.includes.name is "includes".
|
||||
info: |
|
||||
Array.prototype.includes (searchElement [ , fromIndex ] )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects:
|
||||
Every built-in Function object, including constructors, that is not
|
||||
identified as an anonymous function has a name property whose value
|
||||
is a String.
|
||||
|
||||
Unless otherwise specified, the name property of a built-in Function
|
||||
object, if it exists, has the attributes { [[Writable]]: false,
|
||||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(Array.prototype.includes.name, "includes");
|
||||
|
||||
verifyNotEnumerable(Array.prototype.includes, "name");
|
||||
verifyNotWritable(Array.prototype.includes, "name");
|
||||
verifyConfigurable(Array.prototype.includes, "name");
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: no argument searches for a undefined value
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
7. Repeat, while k < len
|
||||
a. Let elementK be the result of ? Get(O, ! ToString(k)).
|
||||
b. If SameValueZero(searchElement, elementK) is true, return true.
|
||||
c. Increase k by 1.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.sameValue([0].includes(), false, "[0].includes()");
|
||||
assert.sameValue([undefined].includes(), true, "[undefined].includes()");
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: >
|
||||
"includes" property of Array.prototype
|
||||
info: |
|
||||
ES6 section 17: Every other data property described in clauses 18 through 26
|
||||
and in Annex B.2 has the attributes { [[Writable]]: true,
|
||||
[[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
verifyNotEnumerable(Array.prototype, "includes");
|
||||
verifyWritable(Array.prototype, "includes");
|
||||
verifyConfigurable(Array.prototype, "includes");
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: Return abrupt from Get(O, "length")
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
2. Let len be ? ToLength(? Get(O, "length")).
|
||||
...
|
||||
---*/
|
||||
|
||||
var obj = {};
|
||||
|
||||
Object.defineProperty(obj, "length", {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
[].includes.call(obj, 7);
|
||||
});
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: Return abrupt getting index properties
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
7. Repeat, while k < len
|
||||
a. Let elementK be the result of ? Get(O, ! ToString(k)).
|
||||
...
|
||||
---*/
|
||||
|
||||
var stopped = 0;
|
||||
|
||||
var obj = {
|
||||
length: 3
|
||||
};
|
||||
|
||||
Object.defineProperty(obj, "1", {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(obj, "2", {
|
||||
get: function() {
|
||||
stopped++;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
[].includes.call(obj, 7);
|
||||
});
|
||||
|
||||
assert.sameValue(stopped, 0, "It stops the loop after the abrupt completion");
|
23
test/built-ins/Array/prototype/includes/return-abrupt-tointeger-fromindex-symbol.js
vendored
Normal file
23
test/built-ins/Array/prototype/includes/return-abrupt-tointeger-fromindex-symbol.js
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: Return abrupt from ToInteger(fromIndex) - using symbol
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
|
||||
produces the value 0.)
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var fromIndex = Symbol("1");
|
||||
|
||||
var sample = [7];
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.includes(7, fromIndex);
|
||||
});
|
26
test/built-ins/Array/prototype/includes/return-abrupt-tointeger-fromindex.js
vendored
Normal file
26
test/built-ins/Array/prototype/includes/return-abrupt-tointeger-fromindex.js
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: Return abrupt from ToInteger(fromIndex)
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
|
||||
produces the value 0.)
|
||||
...
|
||||
---*/
|
||||
|
||||
var fromIndex = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
var sample = [7];
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
sample.includes(7, fromIndex);
|
||||
});
|
22
test/built-ins/Array/prototype/includes/return-abrupt-tonumber-length-symbol.js
vendored
Normal file
22
test/built-ins/Array/prototype/includes/return-abrupt-tonumber-length-symbol.js
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: Return abrupt from ToNumber(symbol "length")
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
2. Let len be ? ToLength(? Get(O, "length")).
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
length: Symbol("1")
|
||||
};
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
[].includes.call(obj, 7);
|
||||
});
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: Return abrupt from ToNumber("length")
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
2. Let len be ? ToLength(? Get(O, "length")).
|
||||
...
|
||||
---*/
|
||||
|
||||
var obj1 = {
|
||||
length: {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var obj2 = {
|
||||
length: {
|
||||
toString: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
[].includes.call(obj1);
|
||||
}, "valueOf");
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
[].includes.call(obj2);
|
||||
}, "toString");
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: search element is compared using SameValueZero
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
7. Repeat, while k < len
|
||||
a. Let elementK be the result of ? Get(O, ! ToString(k)).
|
||||
b. If SameValueZero(searchElement, elementK) is true, return true.
|
||||
c. Increase k by 1.
|
||||
...
|
||||
---*/
|
||||
|
||||
var sample = [42, 0, 1, NaN];
|
||||
assert.sameValue(sample.includes("42"), false, "'42'");
|
||||
assert.sameValue(sample.includes([42]), false, "[42]");
|
||||
assert.sameValue(sample.includes(42.0), true, "42.0");
|
||||
assert.sameValue(sample.includes(-0), true, "-0");
|
||||
assert.sameValue(sample.includes(true), false, "true");
|
||||
assert.sameValue(sample.includes(false), false, "false");
|
||||
assert.sameValue(sample.includes(null), false, "null");
|
||||
assert.sameValue(sample.includes(""), false, "empty string");
|
||||
assert.sameValue(sample.includes(NaN), true, "NaN");
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: returns true for found index
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
5. If n ≥ 0, then
|
||||
a. Let k be n.
|
||||
6. Else n < 0,
|
||||
a. Let k be len + n.
|
||||
b. If k < 0, let k be 0.
|
||||
7. Repeat, while k < len
|
||||
a. Let elementK be the result of ? Get(O, ! ToString(k)).
|
||||
b. If SameValueZero(searchElement, elementK) is true, return true.
|
||||
c. Increase k by 1.
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var symbol = Symbol("1");
|
||||
var obj = {};
|
||||
var array = [];
|
||||
|
||||
var sample = [42, "test262", null, undefined, true, false, 0, -1, "", symbol, obj, array];
|
||||
|
||||
assert.sameValue(sample.includes(42), true, "42");
|
||||
assert.sameValue(sample.includes("test262"), true, "'test262'");
|
||||
assert.sameValue(sample.includes(null), true, "null");
|
||||
assert.sameValue(sample.includes(undefined), true, "undefined");
|
||||
assert.sameValue(sample.includes(true), true, "true");
|
||||
assert.sameValue(sample.includes(false), true, "false");
|
||||
assert.sameValue(sample.includes(0), true, "0");
|
||||
assert.sameValue(sample.includes(-1), true, "-1");
|
||||
assert.sameValue(sample.includes(""), true, "the empty string");
|
||||
assert.sameValue(sample.includes(symbol), true, "symbol");
|
||||
assert.sameValue(sample.includes(obj), true, "obj");
|
||||
assert.sameValue(sample.includes(array), true, "array");
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: returns false if the element is not found
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
5. If n ≥ 0, then
|
||||
a. Let k be n.
|
||||
6. Else n < 0,
|
||||
a. Let k be len + n.
|
||||
b. If k < 0, let k be 0.
|
||||
7. Repeat, while k < len
|
||||
a. Let elementK be the result of ? Get(O, ! ToString(k)).
|
||||
b. If SameValueZero(searchElement, elementK) is true, return true.
|
||||
c. Increase k by 1.
|
||||
8. Return false.
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
assert.sameValue([42].includes(43), false, "43");
|
||||
|
||||
assert.sameValue(["test262"].includes("test"), false, "string");
|
||||
|
||||
assert.sameValue([0, "test262", undefined].includes(""), false, "the empty string");
|
||||
|
||||
assert.sameValue(["true", false].includes(true), false, "true");
|
||||
assert.sameValue(["", true].includes(false), false, "false");
|
||||
|
||||
assert.sameValue([undefined, false, 0, 1].includes(null), false, "null");
|
||||
assert.sameValue([null].includes(undefined), false, "undefined");
|
||||
|
||||
assert.sameValue([Symbol("1")].includes(Symbol("1")), false, "symbol");
|
||||
assert.sameValue([{}].includes({}), false, "object");
|
||||
assert.sameValue([[]].includes([]), false, "array");
|
||||
|
||||
var sample = [42];
|
||||
assert.sameValue(sample.includes(sample), false, "this");
|
|
@ -0,0 +1,51 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: Searches all indexes from a sparse array
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
5. If n ≥ 0, then
|
||||
a. Let k be n.
|
||||
6. Else n < 0,
|
||||
a. Let k be len + n.
|
||||
b. If k < 0, let k be 0.
|
||||
7. Repeat, while k < len
|
||||
a. Let elementK be the result of ? Get(O, ! ToString(k)).
|
||||
b. If SameValueZero(searchElement, elementK) is true, return true.
|
||||
c. Increase k by 1.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
[ , , , ].includes(undefined),
|
||||
true,
|
||||
"[ , , , ].includes(undefined)"
|
||||
);
|
||||
|
||||
assert.sameValue(
|
||||
[ , , , 42, ].includes(undefined, 4),
|
||||
false,
|
||||
"[ , , , 42, ].includes(undefined, 4)"
|
||||
);
|
||||
|
||||
var sample = [ , , , 42, , ];
|
||||
|
||||
assert.sameValue(
|
||||
sample.includes(undefined),
|
||||
true,
|
||||
"sample.includes(undefined)"
|
||||
);
|
||||
assert.sameValue(
|
||||
sample.includes(undefined, 4),
|
||||
true,
|
||||
"sample.includes(undefined, 4)"
|
||||
);
|
||||
assert.sameValue(
|
||||
sample.includes(42, 3),
|
||||
true,
|
||||
"sample.includes(42, 3)"
|
||||
);
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.2.3.14
|
||||
esid: sec-array.prototype.includes
|
||||
description: >
|
||||
Throws a TypeError exception when `this` cannot be coerced to Object
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
1. Let O be ? ToObject(this value).
|
||||
...
|
||||
---*/
|
||||
|
||||
var includes = Array.prototype.includes;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
includes.call(undefined, 42);
|
||||
}, "this is undefined");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
includes.call(null, 42);
|
||||
}, "this is null");
|
|
@ -0,0 +1,52 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: get the integer value from fromIndex
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
|
||||
produces the value 0.)
|
||||
5. If n ≥ 0, then
|
||||
a. Let k be n.
|
||||
...
|
||||
7. Repeat, while k < len
|
||||
a. Let elementK be the result of ? Get(O, ! ToString(k)).
|
||||
b. If SameValueZero(searchElement, elementK) is true, return true.
|
||||
c. Increase k by 1.
|
||||
8. Return false.
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
valueOf: function() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
var sample = [42, 43];
|
||||
assert.sameValue(sample.includes(42, "1"), false, "string [0]");
|
||||
assert.sameValue(sample.includes(43, "1"), true, "string [1]");
|
||||
|
||||
assert.sameValue(sample.includes(42, true), false, "true [0]");
|
||||
assert.sameValue(sample.includes(43, true), true, "true [1]");
|
||||
|
||||
assert.sameValue(sample.includes(42, false), true, "false [0]");
|
||||
assert.sameValue(sample.includes(43, false), true, "false [1]");
|
||||
|
||||
assert.sameValue(sample.includes(42, NaN), true, "NaN [0]");
|
||||
assert.sameValue(sample.includes(43, NaN), true, "NaN [1]");
|
||||
|
||||
assert.sameValue(sample.includes(42, null), true, "null [0]");
|
||||
assert.sameValue(sample.includes(43, null), true, "null [1]");
|
||||
|
||||
assert.sameValue(sample.includes(42, undefined), true, "undefined [0]");
|
||||
assert.sameValue(sample.includes(43, undefined), true, "undefined [1]");
|
||||
|
||||
assert.sameValue(sample.includes(42, null), true, "null [0]");
|
||||
assert.sameValue(sample.includes(43, null), true, "null [1]");
|
||||
|
||||
assert.sameValue(sample.includes(42, obj), false, "object [0]");
|
||||
assert.sameValue(sample.includes(43, obj), true, "object [1]");
|
|
@ -0,0 +1,79 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: length value coerced on ToLength
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
2. Let len be ? ToLength(? Get(O, "length")).
|
||||
...
|
||||
|
||||
7.1.15 ToLength ( argument )
|
||||
|
||||
1. Let len be ? ToInteger(argument).
|
||||
2. If len ≤ +0, return +0.
|
||||
3. If len is +∞, return 253-1.
|
||||
4. Return min(len, 253-1).
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
"0": "a",
|
||||
"1": "b"
|
||||
};
|
||||
|
||||
obj.length = 0.1;
|
||||
assert.sameValue([].includes.call(obj, "a"), false, "0.1");
|
||||
|
||||
obj.length = 0.99;
|
||||
assert.sameValue([].includes.call(obj, "a"), false, "0.99");
|
||||
|
||||
obj.length = 1.00001;
|
||||
assert.sameValue([].includes.call(obj, "a"), true, "1.00001");
|
||||
|
||||
obj.length = 1.1;
|
||||
assert.sameValue([].includes.call(obj, "a"), true, "1.1");
|
||||
|
||||
obj.length = "0";
|
||||
assert.sameValue([].includes.call(obj, "a"), false, "string '0'");
|
||||
|
||||
obj.length = "1";
|
||||
assert.sameValue([].includes.call(obj, "a"), true, "string '1', item found");
|
||||
|
||||
obj.length = "1";
|
||||
assert.sameValue([].includes.call(obj, "b"), false, "string '1', item not found");
|
||||
|
||||
obj.length = "2";
|
||||
assert.sameValue([].includes.call(obj, "b"), true, "string '2', item found");
|
||||
|
||||
obj.length = "";
|
||||
assert.sameValue([].includes.call(obj, "a"), false, "the empty string");
|
||||
|
||||
obj.length = undefined;
|
||||
assert.sameValue([].includes.call(obj, "a"), false, "undefined");
|
||||
|
||||
obj.length = NaN;
|
||||
assert.sameValue([].includes.call(obj, "a"), false, "NaN");
|
||||
|
||||
obj.length = [];
|
||||
assert.sameValue([].includes.call(obj, "a"), false, "[]");
|
||||
|
||||
obj.length = [1];
|
||||
assert.sameValue([].includes.call(obj, "a"), true, "[1]");
|
||||
|
||||
obj.length = null;
|
||||
assert.sameValue([].includes.call(obj, "a"), false, "null");
|
||||
|
||||
obj.length = false;
|
||||
assert.sameValue([].includes.call(obj, "a"), false, "false");
|
||||
|
||||
obj.length = true;
|
||||
assert.sameValue([].includes.call(obj, "a"), true, "true");
|
||||
|
||||
obj.length = { valueOf: function() { return 2; } };
|
||||
assert.sameValue([].includes.call(obj, "b"), true, "ordinary object.valueOf");
|
||||
|
||||
obj.length = { toString: function() { return 2; } };
|
||||
assert.sameValue([].includes.call(obj, "b"), true, "ordinary object.toString");
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: Searches using fromIndex
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
5. If n ≥ 0, then
|
||||
a. Let k be n.
|
||||
6. Else n < 0,
|
||||
a. Let k be len + n.
|
||||
b. If k < 0, let k be 0.
|
||||
7. Repeat, while k < len
|
||||
a. Let elementK be the result of ? Get(O, ! ToString(k)).
|
||||
b. If SameValueZero(searchElement, elementK) is true, return true.
|
||||
c. Increase k by 1.
|
||||
...
|
||||
---*/
|
||||
|
||||
var sample = ["a", "b", "c"];
|
||||
assert.sameValue(sample.includes("a", 0), true, "includes('a', 0)");
|
||||
assert.sameValue(sample.includes("a", 1), false, "includes('a', 1)");
|
||||
assert.sameValue(sample.includes("a", 2), false, "includes('a', 2)");
|
||||
|
||||
assert.sameValue(sample.includes("b", 0), true, "includes('b', 0)");
|
||||
assert.sameValue(sample.includes("b", 1), true, "includes('b', 1)");
|
||||
assert.sameValue(sample.includes("b", 2), false, "includes('b', 2)");
|
||||
|
||||
assert.sameValue(sample.includes("c", 0), true, "includes('c', 0)");
|
||||
assert.sameValue(sample.includes("c", 1), true, "includes('c', 1)");
|
||||
assert.sameValue(sample.includes("c", 2), true, "includes('c', 2)");
|
||||
|
||||
assert.sameValue(sample.includes("a", -1), false, "includes('a', -1)");
|
||||
assert.sameValue(sample.includes("a", -2), false, "includes('a', -2)");
|
||||
assert.sameValue(sample.includes("a", -3), true, "includes('a', -3)");
|
||||
assert.sameValue(sample.includes("a", -4), true, "includes('a', -4)");
|
||||
|
||||
assert.sameValue(sample.includes("b", -1), false, "includes('b', -1)");
|
||||
assert.sameValue(sample.includes("b", -2), true, "includes('b', -2)");
|
||||
assert.sameValue(sample.includes("b", -3), true, "includes('b', -3)");
|
||||
assert.sameValue(sample.includes("b", -4), true, "includes('b', -4)");
|
||||
|
||||
assert.sameValue(sample.includes("c", -1), true, "includes('c', -1)");
|
||||
assert.sameValue(sample.includes("c", -2), true, "includes('c', -2)");
|
||||
assert.sameValue(sample.includes("c", -3), true, "includes('c', -3)");
|
||||
assert.sameValue(sample.includes("c", -4), true, "includes('c', -4)");
|
|
@ -0,0 +1,44 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-array.prototype.includes
|
||||
description: indexed values are not cached
|
||||
info: |
|
||||
22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
7. Repeat, while k < len
|
||||
a. Let elementK be the result of ? Get(O, ! ToString(k)).
|
||||
...
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
function getCleanObj() {
|
||||
var obj = {};
|
||||
Object.defineProperty(obj, "length", {
|
||||
get: function() {
|
||||
Object.defineProperty(obj, "0", {
|
||||
get: function() {
|
||||
obj[1] = "ecma262";
|
||||
obj[2] = "cake";
|
||||
return "tc39";
|
||||
}
|
||||
});
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
var obj;
|
||||
obj = getCleanObj();
|
||||
assert.sameValue([].includes.call(obj, "tc39"), true, "'tc39' is true");
|
||||
|
||||
obj = getCleanObj();
|
||||
assert.sameValue([].includes.call(obj, "ecma262"), true, "'ecma262' is true");
|
||||
|
||||
obj = getCleanObj();
|
||||
assert.sameValue([].includes.call(obj, "cake"), false, "'cake' is false");
|
||||
assert.sameValue(obj[2], "cake", "'2' is set");
|
Loading…
Reference in New Issue