mirror of https://github.com/tc39/test262.git
Merge branch 'bocoup/ta-indexof'
This commit is contained in:
commit
c26ef14ae0
|
@ -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-%typedarray%.prototype.indexof
|
||||
description: Return -1 if fromIndex >= ArrayLength
|
||||
info: >
|
||||
22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.indexOf is a distinct function that implements the same
|
||||
algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
|
||||
produces the value 0.)
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample;
|
||||
|
||||
sample = new TA(42);
|
||||
assert.sameValue(sample.indexOf(0, 42), -1);
|
||||
assert.sameValue(sample.indexOf(0, 43), -1);
|
||||
});
|
|
@ -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-%typedarray%.prototype.indexof
|
||||
description: handle Infinity values for fromIndex
|
||||
info: >
|
||||
22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.indexOf is a distinct function that implements the same
|
||||
algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
6. If n ≥ 0, then
|
||||
a. If n is -0, let k be +0; else let k be n.
|
||||
7. Else n < 0,
|
||||
a. Let k be len + n.
|
||||
b. If k < 0, let k be 0.
|
||||
8. Repeat, while k < len
|
||||
a. Let kPresent be ? HasProperty(O, ! ToString(k)).
|
||||
b. If kPresent is true, then
|
||||
i. Let elementK be ? Get(O, ! ToString(k)).
|
||||
ii. Let same be the result of performing Strict Equality Comparison
|
||||
searchElement === elementK.
|
||||
iii. If same is true, return k.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 43, 41]);
|
||||
|
||||
assert.sameValue(sample.indexOf(43, Infinity), -1, "indexOf(43, Infinity)");
|
||||
assert.sameValue(sample.indexOf(43, -Infinity), 1, "indexOf(43, -Infinity)");
|
||||
});
|
|
@ -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-%typedarray%.prototype.indexof
|
||||
description: -0 fromIndex becomes 0
|
||||
info: >
|
||||
22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.indexOf is a distinct function that implements the same
|
||||
algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
6. If n ≥ 0, then
|
||||
a. If n is -0, let k be +0; else let k be n.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample;
|
||||
|
||||
sample = new TA([42, 43]);
|
||||
assert.sameValue(sample.indexOf(42, -0), 0, "-0 [0]");
|
||||
assert.sameValue(sample.indexOf(43, -0), 1, "-0 [1]");
|
||||
});
|
31
test/built-ins/TypedArray/prototype/indexOf/get-length-uses-internal-arraylength.js
vendored
Normal file
31
test/built-ins/TypedArray/prototype/indexOf/get-length-uses-internal-arraylength.js
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
// 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-%typedarray%.prototype.indexof
|
||||
description: Get "length" uses internal ArrayLength
|
||||
info: >
|
||||
22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.indexOf is a distinct function that implements the same
|
||||
algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
2. Let len be ? ToLength(? Get(O, "length")).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
Object.defineProperty(TypedArray.prototype, "length", {value: 0});
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([7]);
|
||||
|
||||
Object.defineProperty(TA.prototype, "length", {value: 0});
|
||||
Object.defineProperty(sample, "length", {value: 0});
|
||||
|
||||
assert.sameValue(sample.indexOf(7), 0);
|
||||
});
|
36
test/built-ins/TypedArray/prototype/indexOf/length-zero-returns-minus-one.js
vendored
Normal file
36
test/built-ins/TypedArray/prototype/indexOf/length-zero-returns-minus-one.js
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
// 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-%typedarray%.prototype.indexof
|
||||
description: Returns -1 if length is 0
|
||||
info: >
|
||||
22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.indexOf is a distinct function that implements the same
|
||||
algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
2. Let len be ? ToLength(? Get(O, "length")).
|
||||
3. If len is 0, return -1.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var fromIndex = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
assert.sameValue(sample.indexOf(0), -1, "returns -1");
|
||||
assert.sameValue(
|
||||
sample.indexOf(0, fromIndex), -1,
|
||||
"length is checked before ToInteger(fromIndex)"
|
||||
);
|
||||
});
|
32
test/built-ins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex-symbol.js
vendored
Normal file
32
test/built-ins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex-symbol.js
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
// 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-%typedarray%.prototype.indexof
|
||||
description: Return abrupt from ToInteger(fromIndex) - using symbol
|
||||
info: >
|
||||
22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.indexOf is a distinct function that implements the same
|
||||
algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
|
||||
produces the value 0.)
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var fromIndex = Symbol("1");
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(1);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.indexOf(7, fromIndex);
|
||||
})
|
||||
});
|
35
test/built-ins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex.js
vendored
Normal file
35
test/built-ins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex.js
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
// 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-%typedarray%.prototype.indexof
|
||||
description: Return abrupt from ToInteger(fromIndex)
|
||||
info: >
|
||||
22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.indexOf is a distinct function that implements the same
|
||||
algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
|
||||
produces the value 0.)
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var fromIndex = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(1);
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
sample.indexOf(7, fromIndex);
|
||||
})
|
||||
});
|
|
@ -0,0 +1,45 @@
|
|||
// 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-%typedarray%.prototype.indexof
|
||||
description: returns index for the first found element
|
||||
info: >
|
||||
22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.indexOf is a distinct function that implements the same
|
||||
algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
6. If n ≥ 0, then
|
||||
a. If n is -0, let k be +0; else let k be n.
|
||||
7. Else n < 0,
|
||||
a. Let k be len + n.
|
||||
b. If k < 0, let k be 0.
|
||||
8. Repeat, while k < len
|
||||
a. Let kPresent be ? HasProperty(O, ! ToString(k)).
|
||||
b. If kPresent is true, then
|
||||
i. Let elementK be ? Get(O, ! ToString(k)).
|
||||
ii. Let same be the result of performing Strict Equality Comparison
|
||||
searchElement === elementK.
|
||||
iii. If same is true, return k.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 42, 41]);
|
||||
assert.sameValue(sample.indexOf(42), 0, "indexOf(42)");
|
||||
assert.sameValue(sample.indexOf(43), 1, "indexOf(43)");
|
||||
assert.sameValue(sample.indexOf(43, 1), 1, "indexOf(43, 1)");
|
||||
assert.sameValue(sample.indexOf(42, 1), 2, "indexOf(42, 1)");
|
||||
assert.sameValue(sample.indexOf(42, 2), 2, "indexOf(42, 2)");
|
||||
|
||||
assert.sameValue(sample.indexOf(42, -4), 0, "indexOf(42, -4)");
|
||||
assert.sameValue(sample.indexOf(42, -3), 2, "indexOf(42, -3)");
|
||||
assert.sameValue(sample.indexOf(42, -2), 2, "indexOf(42, -2)");
|
||||
assert.sameValue(sample.indexOf(42, -5), 0, "indexOf(42, -5)");
|
||||
});
|
37
test/built-ins/TypedArray/prototype/indexOf/search-not-found-returns-minus-one.js
vendored
Normal file
37
test/built-ins/TypedArray/prototype/indexOf/search-not-found-returns-minus-one.js
vendored
Normal file
|
@ -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-%typedarray%.prototype.indexof
|
||||
description: returns -1 if the element if not found
|
||||
info: >
|
||||
22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.indexOf is a distinct function that implements the same
|
||||
algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
6. If n ≥ 0, then
|
||||
a. If n is -0, let k be +0; else let k be n.
|
||||
7. Else n < 0,
|
||||
a. Let k be len + n.
|
||||
b. If k < 0, let k be 0.
|
||||
...
|
||||
9. Return -1.
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample;
|
||||
|
||||
sample = new TA([42, 43, 42, 41]);
|
||||
assert.sameValue(sample.indexOf(44), -1, "indexOf(44)");
|
||||
assert.sameValue(sample.indexOf(43, 2), -1, "indexOf(43, 2)");
|
||||
assert.sameValue(sample.indexOf(42, 3), -1, "indexOf(42, 3)");
|
||||
assert.sameValue(sample.indexOf(44, -4), -1, "indexOf(44, -4)");
|
||||
assert.sameValue(sample.indexOf(44, -5), -1, "indexOf(44, -5)");
|
||||
assert.sameValue(sample.indexOf(42, -1), -1, "indexOf(42, -1)");
|
||||
});
|
|
@ -0,0 +1,40 @@
|
|||
// 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-%typedarray%.prototype.indexof
|
||||
description: search element is compared using strict comparing (===)
|
||||
info: >
|
||||
22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.indexOf is a distinct function that implements the same
|
||||
algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
8. Repeat, while k < len
|
||||
...
|
||||
b. If kPresent is true, then
|
||||
i. Let elementK be ? Get(O, ! ToString(k)).
|
||||
ii. Let same be the result of performing Strict Equality Comparison
|
||||
searchElement === elementK.
|
||||
iii. If same is true, return k.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 0, 1, undefined, NaN]);
|
||||
assert.sameValue(sample.indexOf("42"), -1, "'42'");
|
||||
assert.sameValue(sample.indexOf([42]), -1, "[42]");
|
||||
assert.sameValue(sample.indexOf(42.0), 0, "42.0");
|
||||
assert.sameValue(sample.indexOf(-0), 1, "-0");
|
||||
assert.sameValue(sample.indexOf(true), -1, "true");
|
||||
assert.sameValue(sample.indexOf(false), -1, "false");
|
||||
assert.sameValue(sample.indexOf(NaN), -1, "NaN === NaN is false");
|
||||
assert.sameValue(sample.indexOf(null), -1, "null");
|
||||
assert.sameValue(sample.indexOf(undefined), -1, "undefined");
|
||||
assert.sameValue(sample.indexOf(""), -1, "empty string");
|
||||
});
|
|
@ -0,0 +1,56 @@
|
|||
// 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-%typedarray%.prototype.indexof
|
||||
description: Return -1 if fromIndex >= ArrayLength - converted values
|
||||
info: >
|
||||
22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.indexOf is a distinct function that implements the same
|
||||
algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step
|
||||
produces the value 0.)
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
valueOf: function() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample;
|
||||
|
||||
sample = new TA([42, 43]);
|
||||
assert.sameValue(sample.indexOf(42, "1"), -1, "string [0]");
|
||||
assert.sameValue(sample.indexOf(43, "1"), 1, "string [1]");
|
||||
|
||||
assert.sameValue(sample.indexOf(42, true), -1, "true [0]");
|
||||
assert.sameValue(sample.indexOf(43, true), 1, "true [1]");
|
||||
|
||||
assert.sameValue(sample.indexOf(42, false), 0, "false [0]");
|
||||
assert.sameValue(sample.indexOf(43, false), 1, "false [1]");
|
||||
|
||||
assert.sameValue(sample.indexOf(42, NaN), 0, "NaN [0]");
|
||||
assert.sameValue(sample.indexOf(43, NaN), 1, "NaN [1]");
|
||||
|
||||
assert.sameValue(sample.indexOf(42, null), 0, "null [0]");
|
||||
assert.sameValue(sample.indexOf(43, null), 1, "null [1]");
|
||||
|
||||
assert.sameValue(sample.indexOf(42, undefined), 0, "undefined [0]");
|
||||
assert.sameValue(sample.indexOf(43, undefined), 1, "undefined [1]");
|
||||
|
||||
assert.sameValue(sample.indexOf(42, null), 0, "null [0]");
|
||||
assert.sameValue(sample.indexOf(43, null), 1, "null [1]");
|
||||
|
||||
assert.sameValue(sample.indexOf(42, obj), -1, "object [0]");
|
||||
assert.sameValue(sample.indexOf(43, obj), 1, "object [1]");
|
||||
});
|
|
@ -0,0 +1,31 @@
|
|||
// 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-%typedarray%.prototype.lastindexof
|
||||
description: handle Infinity values for fromIndex
|
||||
info: >
|
||||
22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.lastIndexOf is a distinct function that implements the
|
||||
same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except
|
||||
that the this object's [[ArrayLength]] internal slot is accessed in place of
|
||||
performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
5. If n ≥ 0, then
|
||||
a. If n is -0, let k be +0; else let k be min(n, len - 1).
|
||||
6. Else n < 0,
|
||||
a. Let k be len + n.
|
||||
7. Repeat, while k ≥ 0
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 43, 41]);
|
||||
|
||||
assert.sameValue(sample.lastIndexOf(43, Infinity), 2, "lastIndexOf(43, Infinity)");
|
||||
assert.sameValue(sample.lastIndexOf(43, -Infinity), -1, "lastIndexOf(43, -Infinity)");
|
||||
});
|
|
@ -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-%typedarray%.prototype.lastindexof
|
||||
description: -0 fromIndex becomes 0
|
||||
info: >
|
||||
22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.lastIndexOf is a distinct function that implements the
|
||||
same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except
|
||||
that the this object's [[ArrayLength]] internal slot is accessed in place of
|
||||
performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
5. If n ≥ 0, then
|
||||
a. If n is -0, let k be +0; else let k be min(n, len - 1).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample;
|
||||
|
||||
sample = new TA([42, 43]);
|
||||
assert.sameValue(sample.lastIndexOf(42, -0), 0, "-0 [0]");
|
||||
assert.sameValue(sample.lastIndexOf(43, -0), -1, "-0 [1]");
|
||||
});
|
31
test/built-ins/TypedArray/prototype/lastIndexOf/get-length-uses-internal-arraylength.js
vendored
Normal file
31
test/built-ins/TypedArray/prototype/lastIndexOf/get-length-uses-internal-arraylength.js
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
// 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-%typedarray%.prototype.lastindexof
|
||||
description: Get "length" uses internal ArrayLength
|
||||
info: >
|
||||
22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.lastIndexOf is a distinct function that implements the
|
||||
same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except
|
||||
that the this object's [[ArrayLength]] internal slot is accessed in place of
|
||||
performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
2. Let len be ? ToLength(? Get(O, "length")).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
Object.defineProperty(TypedArray.prototype, "length", {value: 0});
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([7]);
|
||||
|
||||
Object.defineProperty(TA.prototype, "length", {value: 0});
|
||||
Object.defineProperty(sample, "length", {value: 0});
|
||||
|
||||
assert.sameValue(sample.lastIndexOf(7), 0);
|
||||
});
|
36
test/built-ins/TypedArray/prototype/lastIndexOf/length-zero-returns-minus-one.js
vendored
Normal file
36
test/built-ins/TypedArray/prototype/lastIndexOf/length-zero-returns-minus-one.js
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
// 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-%typedarray%.prototype.lastindexof
|
||||
description: Returns -1 if length is 0
|
||||
info: >
|
||||
22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.lastIndexOf is a distinct function that implements the
|
||||
same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except
|
||||
that the this object's [[ArrayLength]] internal slot is accessed in place of
|
||||
performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
2. Let len be ? ToLength(? Get(O, "length")).
|
||||
3. If len is 0, return -1.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var fromIndex = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
assert.sameValue(sample.lastIndexOf(0), -1, "returns -1");
|
||||
assert.sameValue(
|
||||
sample.lastIndexOf(0, fromIndex), -1,
|
||||
"length is checked before ToInteger(fromIndex)"
|
||||
);
|
||||
});
|
32
test/built-ins/TypedArray/prototype/lastIndexOf/return-abrupt-tointeger-fromindex-symbol.js
vendored
Normal file
32
test/built-ins/TypedArray/prototype/lastIndexOf/return-abrupt-tointeger-fromindex-symbol.js
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
// 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-%typedarray%.prototype.lastindexof
|
||||
description: Return abrupt from ToInteger(fromIndex) - using symbol
|
||||
info: >
|
||||
22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.lastIndexOf is a distinct function that implements the
|
||||
same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except
|
||||
that the this object's [[ArrayLength]] internal slot is accessed in place of
|
||||
performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
4. If argument fromIndex was passed, let n be ? ToInteger(fromIndex); else let
|
||||
n be len-1.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var fromIndex = Symbol("1");
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(1);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.lastIndexOf(7, fromIndex);
|
||||
})
|
||||
});
|
35
test/built-ins/TypedArray/prototype/lastIndexOf/return-abrupt-tointeger-fromindex.js
vendored
Normal file
35
test/built-ins/TypedArray/prototype/lastIndexOf/return-abrupt-tointeger-fromindex.js
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
// 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-%typedarray%.prototype.lastindexof
|
||||
description: Return abrupt from ToInteger(fromIndex)
|
||||
info: >
|
||||
22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.lastIndexOf is a distinct function that implements the
|
||||
same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except
|
||||
that the this object's [[ArrayLength]] internal slot is accessed in place of
|
||||
performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
4. If argument fromIndex was passed, let n be ? ToInteger(fromIndex); else let
|
||||
n be len-1.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var fromIndex = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(1);
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
sample.lastIndexOf(7, fromIndex);
|
||||
})
|
||||
});
|
56
test/built-ins/TypedArray/prototype/lastIndexOf/search-found-returns-index.js
vendored
Normal file
56
test/built-ins/TypedArray/prototype/lastIndexOf/search-found-returns-index.js
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
// 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-%typedarray%.prototype.lastindexof
|
||||
description: returns index for the first found element
|
||||
info: >
|
||||
22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.lastIndexOf is a distinct function that implements the
|
||||
same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except
|
||||
that the this object's [[ArrayLength]] internal slot is accessed in place of
|
||||
performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
5. If n ≥ 0, then
|
||||
a. If n is -0, let k be +0; else let k be min(n, len - 1).
|
||||
6. Else n < 0,
|
||||
a. Let k be len + n.
|
||||
7. Repeat, while k ≥ 0
|
||||
a. Let kPresent be ? HasProperty(O, ! ToString(k)).
|
||||
b. If kPresent is true, then
|
||||
i. Let elementK be ? Get(O, ! ToString(k)).
|
||||
ii. Let same be the result of performing Strict Equality Comparison
|
||||
searchElement === elementK.
|
||||
iii. If same is true, return k.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 42, 41]);
|
||||
assert.sameValue(sample.lastIndexOf(42), 2, "lastIndexOf(42)");
|
||||
assert.sameValue(sample.lastIndexOf(43), 1, "lastIndexOf(43)");
|
||||
assert.sameValue(sample.lastIndexOf(41), 3, "lastIndexOf(41)");
|
||||
assert.sameValue(sample.lastIndexOf(41, 3), 3, "lastIndexOf(41, 3)");
|
||||
assert.sameValue(sample.lastIndexOf(41, 4), 3, "lastIndexOf(41, 4)");
|
||||
assert.sameValue(sample.lastIndexOf(43, 1), 1, "lastIndexOf(43, 1)");
|
||||
assert.sameValue(sample.lastIndexOf(43, 2), 1, "lastIndexOf(43, 2)");
|
||||
assert.sameValue(sample.lastIndexOf(43, 3), 1, "lastIndexOf(43, 3)");
|
||||
assert.sameValue(sample.lastIndexOf(43, 4), 1, "lastIndexOf(43, 4)");
|
||||
assert.sameValue(sample.lastIndexOf(42, 0), 0, "lastIndexOf(42, 0)");
|
||||
assert.sameValue(sample.lastIndexOf(42, 1), 0, "lastIndexOf(42, 1)");
|
||||
assert.sameValue(sample.lastIndexOf(42, 2), 2, "lastIndexOf(42, 2)");
|
||||
assert.sameValue(sample.lastIndexOf(42, 3), 2, "lastIndexOf(42, 3)");
|
||||
assert.sameValue(sample.lastIndexOf(42, 4), 2, "lastIndexOf(42, 4)");
|
||||
assert.sameValue(sample.lastIndexOf(42, -4), 0, "lastIndexOf(42, -4)");
|
||||
assert.sameValue(sample.lastIndexOf(42, -3), 0, "lastIndexOf(42, -3)");
|
||||
assert.sameValue(sample.lastIndexOf(42, -2), 2, "lastIndexOf(42, -2)");
|
||||
assert.sameValue(sample.lastIndexOf(42, -1), 2, "lastIndexOf(42, -1)");
|
||||
assert.sameValue(sample.lastIndexOf(43, -3), 1, "lastIndexOf(43, -3)");
|
||||
assert.sameValue(sample.lastIndexOf(43, -2), 1, "lastIndexOf(43, -2)");
|
||||
assert.sameValue(sample.lastIndexOf(43, -1), 1, "lastIndexOf(43, -1)");
|
||||
assert.sameValue(sample.lastIndexOf(41, -1), 3, "lastIndexOf(41, -1)");
|
||||
});
|
41
test/built-ins/TypedArray/prototype/lastIndexOf/search-not-found-returns-minus-one.js
vendored
Normal file
41
test/built-ins/TypedArray/prototype/lastIndexOf/search-not-found-returns-minus-one.js
vendored
Normal file
|
@ -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-%typedarray%.prototype.lastindexof
|
||||
description: returns -1 if the element if not found
|
||||
info: >
|
||||
22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.lastIndexOf is a distinct function that implements the
|
||||
same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except
|
||||
that the this object's [[ArrayLength]] internal slot is accessed in place of
|
||||
performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
5. If n ≥ 0, then
|
||||
a. If n is -0, let k be +0; else let k be min(n, len - 1).
|
||||
6. Else n < 0,
|
||||
a. Let k be len + n.
|
||||
7. Repeat, while k ≥ 0
|
||||
...
|
||||
8. Return -1.
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample;
|
||||
|
||||
sample = new TA([42, 43, 42, 41]);
|
||||
assert.sameValue(sample.lastIndexOf(44), -1, "lastIndexOf(44)");
|
||||
assert.sameValue(sample.lastIndexOf(44, -4), -1, "lastIndexOf(44, -4)");
|
||||
assert.sameValue(sample.lastIndexOf(44, -5), -1, "lastIndexOf(44, -5)");
|
||||
assert.sameValue(sample.lastIndexOf(42, -5), -1, "lastIndexOf(42, -5)");
|
||||
assert.sameValue(sample.lastIndexOf(43, -4), -1, "lastIndexOf(43, -4)");
|
||||
assert.sameValue(sample.lastIndexOf(43, -5), -1, "lastIndexOf(43, -5)");
|
||||
assert.sameValue(sample.lastIndexOf(41, 0), -1, "lastIndexOf(41, 0)");
|
||||
assert.sameValue(sample.lastIndexOf(41, 1), -1, "lastIndexOf(41, 1)");
|
||||
assert.sameValue(sample.lastIndexOf(41, 2), -1, "lastIndexOf(41, 2)");
|
||||
assert.sameValue(sample.lastIndexOf(43, 0), -1, "lastIndexOf(43, 0)");
|
||||
});
|
|
@ -0,0 +1,40 @@
|
|||
// 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-%typedarray%.prototype.lastindexof
|
||||
description: search element is compared using strict comparing (===)
|
||||
info: >
|
||||
22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.lastIndexOf is a distinct function that implements the
|
||||
same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except
|
||||
that the this object's [[ArrayLength]] internal slot is accessed in place of
|
||||
performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
7. Repeat, while k ≥ 0
|
||||
...
|
||||
b. If kPresent is true, then
|
||||
i. Let elementK be ? Get(O, ! ToString(k)).
|
||||
ii. Let same be the result of performing Strict Equality Comparison
|
||||
searchElement === elementK.
|
||||
iii. If same is true, return k.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, undefined, NaN, 0, 1]);
|
||||
assert.sameValue(sample.lastIndexOf("42"), -1, "'42'");
|
||||
assert.sameValue(sample.lastIndexOf([42]), -1, "[42]");
|
||||
assert.sameValue(sample.lastIndexOf(42.0), 0, "42.0");
|
||||
assert.sameValue(sample.lastIndexOf(-0), 3, "-0");
|
||||
assert.sameValue(sample.lastIndexOf(true), -1, "true");
|
||||
assert.sameValue(sample.lastIndexOf(false), -1, "false");
|
||||
assert.sameValue(sample.lastIndexOf(NaN), -1, "NaN === NaN is false");
|
||||
assert.sameValue(sample.lastIndexOf(null), -1, "null");
|
||||
assert.sameValue(sample.lastIndexOf(undefined), -1, "undefined");
|
||||
assert.sameValue(sample.lastIndexOf(""), -1, "empty string");
|
||||
});
|
|
@ -0,0 +1,56 @@
|
|||
// 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-%typedarray%.prototype.lastindexof
|
||||
description: Return -1 if fromIndex >= ArrayLength - converted values
|
||||
info: >
|
||||
22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
%TypedArray%.prototype.lastIndexOf is a distinct function that implements the
|
||||
same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except
|
||||
that the this object's [[ArrayLength]] internal slot is accessed in place of
|
||||
performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
|
||||
|
||||
...
|
||||
4. If argument fromIndex was passed, let n be ? ToInteger(fromIndex); else let
|
||||
n be len-1.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
valueOf: function() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample;
|
||||
|
||||
sample = new TA([42, 43]);
|
||||
assert.sameValue(sample.lastIndexOf(42, "1"), 0, "string [0]");
|
||||
assert.sameValue(sample.lastIndexOf(43, "1"), 1, "string [1]");
|
||||
|
||||
assert.sameValue(sample.lastIndexOf(42, true), 0, "true [0]");
|
||||
assert.sameValue(sample.lastIndexOf(43, true), 1, "true [1]");
|
||||
|
||||
assert.sameValue(sample.lastIndexOf(42, false), 0, "false [0]");
|
||||
assert.sameValue(sample.lastIndexOf(43, false), -1, "false [1]");
|
||||
|
||||
assert.sameValue(sample.lastIndexOf(42, NaN), 0, "NaN [0]");
|
||||
assert.sameValue(sample.lastIndexOf(43, NaN), -1, "NaN [1]");
|
||||
|
||||
assert.sameValue(sample.lastIndexOf(42, null), 0, "null [0]");
|
||||
assert.sameValue(sample.lastIndexOf(43, null), -1, "null [1]");
|
||||
|
||||
assert.sameValue(sample.lastIndexOf(42, undefined), 0, "undefined [0]");
|
||||
assert.sameValue(sample.lastIndexOf(43, undefined), -1, "undefined [1]");
|
||||
|
||||
assert.sameValue(sample.lastIndexOf(42, null), 0, "null [0]");
|
||||
assert.sameValue(sample.lastIndexOf(43, null), -1, "null [1]");
|
||||
|
||||
assert.sameValue(sample.lastIndexOf(42, obj), 0, "object [0]");
|
||||
assert.sameValue(sample.lastIndexOf(43, obj), 1, "object [1]");
|
||||
});
|
Loading…
Reference in New Issue