mirror of https://github.com/tc39/test262.git
Add typedarray find last tests
This commit is contained in:
parent
6c5e421806
commit
cb54d119e3
|
@ -0,0 +1,30 @@
|
||||||
|
// 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.findlast
|
||||||
|
description: Throws a TypeError if this has a detached buffer
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
2. Perform ? ValidateTypedArray(O).
|
||||||
|
|
||||||
|
22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
|
||||||
|
|
||||||
|
...
|
||||||
|
5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
|
||||||
|
features: [BigInt, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var predicate = function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
};
|
||||||
|
|
||||||
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(1);
|
||||||
|
$DETACHBUFFER(sample.buffer);
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast(predicate);
|
||||||
|
});
|
||||||
|
});
|
43
test/built-ins/TypedArray/prototype/findLast/BigInt/get-length-ignores-length-prop.js
vendored
Normal file
43
test/built-ins/TypedArray/prototype/findLast/BigInt/get-length-ignores-length-prop.js
vendored
Normal file
|
@ -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-%typedarray%.prototype.findlast
|
||||||
|
description: >
|
||||||
|
[[Get]] of "length" uses [[ArrayLength]]
|
||||||
|
info: |
|
||||||
|
22.2.3.10 %TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. Let len be O.[[ArrayLength]].
|
||||||
|
...
|
||||||
|
includes: [testBigIntTypedArray.js]
|
||||||
|
features: [BigInt, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
Object.defineProperty(TypedArray.prototype, "length", {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
|
Object.defineProperty(TA.prototype, "length", {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var sample = new TA([42n]);
|
||||||
|
|
||||||
|
Object.defineProperty(sample, "length", {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
},
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
sample.findLast(function() { return true; }),
|
||||||
|
42n
|
||||||
|
);
|
||||||
|
});
|
66
test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-call-changes-value.js
vendored
Normal file
66
test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-call-changes-value.js
vendored
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
// 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.findlast
|
||||||
|
description: >
|
||||||
|
Change values during predicate call
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
5. Let k be len - 1.
|
||||||
|
6. Repeat, while k ≥ 0
|
||||||
|
...
|
||||||
|
c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
|
||||||
|
...
|
||||||
|
includes: [compareArray.js, testBigIntTypedArray.js]
|
||||||
|
features: [BigInt, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
|
var arr = [1n, 2n, 3n];
|
||||||
|
var sample;
|
||||||
|
var result;
|
||||||
|
|
||||||
|
sample = new TA(3);
|
||||||
|
sample.findLast(function(val, i) {
|
||||||
|
sample[i] = arr[i];
|
||||||
|
|
||||||
|
assert.sameValue(val, 0n, "value is not mapped to instance");
|
||||||
|
});
|
||||||
|
assert(compareArray(sample, arr), "values set during each predicate call");
|
||||||
|
|
||||||
|
sample = new TA(arr);
|
||||||
|
result = sample.findLast(function(val, i) {
|
||||||
|
if ( i === 2 ) {
|
||||||
|
sample[0] = 7n;
|
||||||
|
}
|
||||||
|
return val === 7n;
|
||||||
|
});
|
||||||
|
assert.sameValue(result, 7n, "value found");
|
||||||
|
|
||||||
|
sample = new TA(arr);
|
||||||
|
result = sample.findLast(function(val, i) {
|
||||||
|
if ( i === 2 ) {
|
||||||
|
sample[0] = 7n;
|
||||||
|
}
|
||||||
|
return val === 3n;
|
||||||
|
});
|
||||||
|
assert.sameValue(result, undefined, "value not found");
|
||||||
|
|
||||||
|
sample = new TA(arr);
|
||||||
|
result = sample.findLast(function(val, i) {
|
||||||
|
if ( i <= 2 ) {
|
||||||
|
sample[2] = 7n;
|
||||||
|
}
|
||||||
|
return val === 7n;
|
||||||
|
});
|
||||||
|
assert.sameValue(result, undefined, "value not found - changed after call");
|
||||||
|
|
||||||
|
sample = new TA(arr);
|
||||||
|
result = sample.findLast(function() {
|
||||||
|
sample[2] = 7n;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
assert.sameValue(result, 1n, "findLast() returns previous found value");
|
||||||
|
});
|
49
test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-call-parameters.js
vendored
Normal file
49
test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-call-parameters.js
vendored
Normal file
|
@ -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-%typedarray%.prototype.findlast
|
||||||
|
description: >
|
||||||
|
Predicate called as F.call( thisArg, kValue, k, O ) for each array entry.
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
5. Let k be len - 1.
|
||||||
|
6. Repeat, while k ≥ 0,
|
||||||
|
...
|
||||||
|
c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
|
||||||
|
...
|
||||||
|
includes: [testBigIntTypedArray.js]
|
||||||
|
features: [BigInt, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA([39n, 2n, 62n]);
|
||||||
|
var results = [];
|
||||||
|
var result;
|
||||||
|
|
||||||
|
sample.foo = "bar"; // Ignores non integer index properties
|
||||||
|
|
||||||
|
sample.findLast(function() {
|
||||||
|
results.push(arguments);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(results.length, 3, "predicate is called for each index");
|
||||||
|
|
||||||
|
result = results[0];
|
||||||
|
assert.sameValue(result[0], 62n, "results[0][0] === 62, value");
|
||||||
|
assert.sameValue(result[1], 2, "results[0][1] === 2, index");
|
||||||
|
assert.sameValue(result[2], sample, "results[0][2] === sample, instance");
|
||||||
|
assert.sameValue(result.length, 3, "results[0].length === 3 arguments");
|
||||||
|
|
||||||
|
result = results[1];
|
||||||
|
assert.sameValue(result[0], 2n, "results[1][0] === 2, value");
|
||||||
|
assert.sameValue(result[1], 1, "results[1][1] === 1, index");
|
||||||
|
assert.sameValue(result[2], sample, "results[1][2] === sample, instance");
|
||||||
|
assert.sameValue(result.length, 3, "results[1].length === 3 arguments");
|
||||||
|
|
||||||
|
result = results[2];
|
||||||
|
assert.sameValue(result[0], 39n, "results[2][0] === 39, value");
|
||||||
|
assert.sameValue(result[1], 0, "results[2][1] === 0, index");
|
||||||
|
assert.sameValue(result[2], sample, "results[2][2] === sample, instance");
|
||||||
|
assert.sameValue(result.length, 3, "results[2].length === 3 arguments");
|
||||||
|
});
|
45
test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-call-this-non-strict.js
vendored
Normal file
45
test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-call-this-non-strict.js
vendored
Normal file
|
@ -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.findlast
|
||||||
|
description: >
|
||||||
|
Verify predicate this on non-strict mode
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
6. Repeat, while k ≥ 0,
|
||||||
|
...
|
||||||
|
c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
|
||||||
|
...
|
||||||
|
flags: [noStrict]
|
||||||
|
includes: [testBigIntTypedArray.js]
|
||||||
|
features: [BigInt, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var T = this;
|
||||||
|
|
||||||
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(1);
|
||||||
|
var result;
|
||||||
|
|
||||||
|
sample.findLast(function() {
|
||||||
|
result = this;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(result, T, "without thisArg, predicate this is the global");
|
||||||
|
|
||||||
|
result = null;
|
||||||
|
sample.findLast(function() {
|
||||||
|
result = this;
|
||||||
|
}, undefined);
|
||||||
|
|
||||||
|
assert.sameValue(result, T, "predicate this is the global when thisArg is undefined");
|
||||||
|
|
||||||
|
var o = {};
|
||||||
|
result = null;
|
||||||
|
sample.findLast(function() {
|
||||||
|
result = this;
|
||||||
|
}, o);
|
||||||
|
|
||||||
|
assert.sameValue(result, o, "thisArg becomes the predicate this");
|
||||||
|
});
|
39
test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-call-this-strict.js
vendored
Normal file
39
test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-call-this-strict.js
vendored
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
// 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.findlast
|
||||||
|
description: >
|
||||||
|
Verify predicate this on strict mode
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
6. Repeat, while k ≥ 0,
|
||||||
|
...
|
||||||
|
c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
|
||||||
|
...
|
||||||
|
flags: [onlyStrict]
|
||||||
|
includes: [testBigIntTypedArray.js]
|
||||||
|
features: [BigInt, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(1);
|
||||||
|
var result;
|
||||||
|
|
||||||
|
sample.findLast(function() {
|
||||||
|
result = this;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
result,
|
||||||
|
undefined,
|
||||||
|
"without thisArg, predicate this is undefined"
|
||||||
|
);
|
||||||
|
|
||||||
|
var o = {};
|
||||||
|
sample.findLast(function() {
|
||||||
|
result = this;
|
||||||
|
}, o);
|
||||||
|
|
||||||
|
assert.sameValue(result, o, "thisArg becomes the predicate this");
|
||||||
|
});
|
55
test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-is-not-callable-throws.js
vendored
Normal file
55
test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-is-not-callable-throws.js
vendored
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
// 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.findlast
|
||||||
|
description: >
|
||||||
|
Throws a TypeError exception if predicate is not callable.
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. If IsCallable(predicate) is false, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
includes: [testBigIntTypedArray.js]
|
||||||
|
features: [BigInt, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA();
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast({});
|
||||||
|
}, "object");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast(null);
|
||||||
|
}, "null");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast(undefined);
|
||||||
|
}, "undefined");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast(false);
|
||||||
|
}, "false");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast(true);
|
||||||
|
}, "true");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast(1);
|
||||||
|
}, "number");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast("");
|
||||||
|
}, "string");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast([]);
|
||||||
|
}, "array");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast(/./);
|
||||||
|
}, "regexp");
|
||||||
|
});
|
39
test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-may-detach-buffer.js
vendored
Normal file
39
test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-may-detach-buffer.js
vendored
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
// 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.findlast
|
||||||
|
description: >
|
||||||
|
Predicate may detach the buffer
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
However, such optimization must not introduce any observable changes in the
|
||||||
|
specified behaviour of the algorithm and must take into account the
|
||||||
|
possibility that calls to predicate may cause the this value to become
|
||||||
|
detached.
|
||||||
|
|
||||||
|
IntegerIndexedElementGet ( O, index )
|
||||||
|
|
||||||
|
...
|
||||||
|
Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
|
||||||
|
If IsDetachedBuffer(buffer) is true, return undefined.
|
||||||
|
|
||||||
|
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
|
||||||
|
features: [BigInt, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
|
var loops = 0;
|
||||||
|
var sample = new TA(2);
|
||||||
|
|
||||||
|
sample.findLast(function() {
|
||||||
|
if (loops === 0) {
|
||||||
|
$DETACHBUFFER(sample.buffer);
|
||||||
|
}
|
||||||
|
loops++;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(loops, 2);
|
||||||
|
});
|
37
test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-not-called-on-empty-array.js
vendored
Normal file
37
test/built-ins/TypedArray/prototype/findLast/BigInt/predicate-not-called-on-empty-array.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.findlast
|
||||||
|
description: >
|
||||||
|
Predicate is not called on empty instances
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
6. Repeat, while k ≥ 0,
|
||||||
|
...
|
||||||
|
c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
|
||||||
|
...
|
||||||
|
includes: [testBigIntTypedArray.js]
|
||||||
|
features: [BigInt, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA();
|
||||||
|
var called = false;
|
||||||
|
|
||||||
|
var result = sample.findLast(function() {
|
||||||
|
called = true;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
called,
|
||||||
|
false,
|
||||||
|
"empty instance does not call predicate"
|
||||||
|
);
|
||||||
|
assert.sameValue(
|
||||||
|
result,
|
||||||
|
undefined,
|
||||||
|
"findLast returns undefined when predicate is not called"
|
||||||
|
);
|
||||||
|
});
|
28
test/built-ins/TypedArray/prototype/findLast/BigInt/return-abrupt-from-predicate-call.js
vendored
Normal file
28
test/built-ins/TypedArray/prototype/findLast/BigInt/return-abrupt-from-predicate-call.js
vendored
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// 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.findlast
|
||||||
|
description: >
|
||||||
|
Return abrupt from predicate call.
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
6. Repeat, while k ≥ 0,
|
||||||
|
...
|
||||||
|
c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
|
||||||
|
...
|
||||||
|
includes: [testBigIntTypedArray.js]
|
||||||
|
features: [BigInt, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(1);
|
||||||
|
|
||||||
|
var predicate = function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
sample.findLast(predicate);
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,53 @@
|
||||||
|
// 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.findlast
|
||||||
|
description: >
|
||||||
|
Return found value if predicate return a boolean true value.
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
6. Repeat, while k ≥ 0,
|
||||||
|
...
|
||||||
|
c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
|
||||||
|
d. If testResult is true, return kValue.
|
||||||
|
...
|
||||||
|
includes: [testBigIntTypedArray.js]
|
||||||
|
features: [BigInt, Symbol, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA([39n, 2n, 62n]);
|
||||||
|
var called, result;
|
||||||
|
|
||||||
|
called = 0;
|
||||||
|
result = sample.findLast(function() {
|
||||||
|
called++;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
assert.sameValue(result, 62n, "returned true on sample[0]");
|
||||||
|
assert.sameValue(called, 1, "predicate was called once");
|
||||||
|
|
||||||
|
called = 0;
|
||||||
|
result = sample.findLast(function(val) {
|
||||||
|
called++;
|
||||||
|
return val === 62n;
|
||||||
|
});
|
||||||
|
assert.sameValue(called, 1, "predicate was called three times");
|
||||||
|
assert.sameValue(result, 62n, "returned true on sample[3]");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return "string"; });
|
||||||
|
assert.sameValue(result, 62n, "ToBoolean(string)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return {}; });
|
||||||
|
assert.sameValue(result, 62n, "ToBoolean(object)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return Symbol(""); });
|
||||||
|
assert.sameValue(result, 62n, "ToBoolean(symbol)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return 1; });
|
||||||
|
assert.sameValue(result, 62n, "ToBoolean(number)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return -1; });
|
||||||
|
assert.sameValue(result, 62n, "ToBoolean(negative number)");
|
||||||
|
});
|
|
@ -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-%typedarray%.prototype.findlast
|
||||||
|
description: >
|
||||||
|
Return undefined if predicate always returns a boolean false value.
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
6. 6. Repeat, while k ≥ 0
|
||||||
|
...
|
||||||
|
c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
|
||||||
|
...
|
||||||
|
7. Return undefined.
|
||||||
|
includes: [testBigIntTypedArray.js]
|
||||||
|
features: [BigInt, Symbol, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(3);
|
||||||
|
var called = 0;
|
||||||
|
|
||||||
|
var result = sample.findLast(function() {
|
||||||
|
called++;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(called, 3, "predicate was called three times");
|
||||||
|
assert.sameValue(result, undefined);
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return ""; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(empty string)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return undefined; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(undefined)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return null; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(null)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return 0; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(0)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return -0; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(-0)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return NaN; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(NaN)");
|
||||||
|
});
|
|
@ -0,0 +1,30 @@
|
||||||
|
// 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.findlast
|
||||||
|
description: Throws a TypeError if this has a detached buffer
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
2. Perform ? ValidateTypedArray(O).
|
||||||
|
|
||||||
|
22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
|
||||||
|
|
||||||
|
...
|
||||||
|
5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||||
|
features: [TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var predicate = function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
};
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(1);
|
||||||
|
$DETACHBUFFER(sample.buffer);
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast(predicate);
|
||||||
|
});
|
||||||
|
});
|
42
test/built-ins/TypedArray/prototype/findLast/get-length-ignores-length-prop.js
vendored
Normal file
42
test/built-ins/TypedArray/prototype/findLast/get-length-ignores-length-prop.js
vendored
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
// 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.findlast
|
||||||
|
description: >
|
||||||
|
[[Get]] of "length" uses [[ArrayLength]]
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
...
|
||||||
|
3. Let len be O.[[ArrayLength]].
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
Object.defineProperty(TypedArray.prototype, "length", {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
Object.defineProperty(TA.prototype, "length", {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var sample = new TA([42]);
|
||||||
|
|
||||||
|
Object.defineProperty(sample, "length", {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
},
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
sample.findLast(function() { return true; }),
|
||||||
|
42
|
||||||
|
);
|
||||||
|
});
|
|
@ -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-%typedarray%.prototype.findlast
|
||||||
|
description: Throws a TypeError exception when invoked as a function
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
2. Perform ? ValidateTypedArray(O).
|
||||||
|
|
||||||
|
22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
|
||||||
|
|
||||||
|
1. If Type(O) is not Object, throw a TypeError exception.
|
||||||
|
2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError
|
||||||
|
exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var findLast = TypedArray.prototype.findLast;
|
||||||
|
|
||||||
|
assert.sameValue(typeof findLast, 'function');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
findLast();
|
||||||
|
});
|
|
@ -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-%typedarray%.prototype.findlast
|
||||||
|
description: Requires a [[TypedArrayName]] internal slot.
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
2. Perform ? ValidateTypedArray(O).
|
||||||
|
|
||||||
|
22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
|
||||||
|
|
||||||
|
1. If Type(O) is not Object, throw a TypeError exception.
|
||||||
|
2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError
|
||||||
|
exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var TypedArrayPrototype = TypedArray.prototype;
|
||||||
|
|
||||||
|
assert.sameValue(typeof TypedArrayPrototype.findLast, 'function');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
TypedArrayPrototype.findLast();
|
||||||
|
});
|
|
@ -0,0 +1,30 @@
|
||||||
|
// Copyright (C) 2015 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-%typedarray%.prototype.findlast
|
||||||
|
description: >
|
||||||
|
%TypedArray%.prototype.findLast.length is 1.
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
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, testTypedArray.js]
|
||||||
|
features: [TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(TypedArray.prototype.findLast.length, 1);
|
||||||
|
|
||||||
|
verifyNotEnumerable(TypedArray.prototype.findLast, "length");
|
||||||
|
verifyNotWritable(TypedArray.prototype.findLast, "length");
|
||||||
|
verifyConfigurable(TypedArray.prototype.findLast, "length");
|
|
@ -0,0 +1,27 @@
|
||||||
|
// Copyright (C) 2015 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-%typedarray%.prototype.findlast
|
||||||
|
description: >
|
||||||
|
%TypedArray%.prototype.findLast.name is "findLast".
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
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, testTypedArray.js]
|
||||||
|
features: [TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(TypedArray.prototype.findLast.name, "findLast");
|
||||||
|
|
||||||
|
verifyNotEnumerable(TypedArray.prototype.findLast, "name");
|
||||||
|
verifyNotWritable(TypedArray.prototype.findLast, "name");
|
||||||
|
verifyConfigurable(TypedArray.prototype.findLast, "name");
|
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-ecmascript-standard-built-in-objects
|
||||||
|
description: >
|
||||||
|
TypedArray.prototype.findLast does not implement [[Construct]], is not new-able
|
||||||
|
info: |
|
||||||
|
ECMAScript Function Objects
|
||||||
|
|
||||||
|
Built-in function objects that are not identified as constructors do not
|
||||||
|
implement the [[Construct]] internal method unless otherwise specified in
|
||||||
|
the description of a particular function.
|
||||||
|
|
||||||
|
sec-evaluatenew
|
||||||
|
|
||||||
|
...
|
||||||
|
7. If IsConstructor(constructor) is false, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
includes: [isConstructor.js, testTypedArray.js]
|
||||||
|
features: [Reflect.construct, arrow-function, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
isConstructor(TypedArray.prototype.findLast),
|
||||||
|
false,
|
||||||
|
'isConstructor(TypedArray.prototype.findLast) must return false'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
let u8 = new Uint8Array(1); new u8.findLast(() => {});
|
||||||
|
}, '`let u8 = new Uint8Array(1); new u8.findLast(() => {})` throws TypeError');
|
||||||
|
|
66
test/built-ins/TypedArray/prototype/findLast/predicate-call-changes-value.js
vendored
Normal file
66
test/built-ins/TypedArray/prototype/findLast/predicate-call-changes-value.js
vendored
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
// 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.findlast
|
||||||
|
description: >
|
||||||
|
Change values during predicate call
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
5. Let k be len - 1.
|
||||||
|
6. Repeat, while k ≥ 0,
|
||||||
|
...
|
||||||
|
c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
|
||||||
|
...
|
||||||
|
|
||||||
|
includes: [compareArray.js, testTypedArray.js]
|
||||||
|
features: [TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var arr = [1, 2, 3];
|
||||||
|
var sample;
|
||||||
|
var result;
|
||||||
|
|
||||||
|
sample = new TA(3);
|
||||||
|
sample.findLast(function(val, i) {
|
||||||
|
sample[i] = arr[i];
|
||||||
|
|
||||||
|
assert.sameValue(val, 0, "value is not mapped to instance");
|
||||||
|
});
|
||||||
|
assert(compareArray(sample, arr), "values set during each predicate call");
|
||||||
|
|
||||||
|
sample = new TA(arr);
|
||||||
|
result = sample.findLast(function(val, i) {
|
||||||
|
if ( i === 2 ) {
|
||||||
|
sample[0] = 7;
|
||||||
|
}
|
||||||
|
return val === 7;
|
||||||
|
});
|
||||||
|
assert.sameValue(result, 7, "value found");
|
||||||
|
|
||||||
|
sample = new TA(arr);
|
||||||
|
result = sample.findLast(function(val, i) {
|
||||||
|
if ( i === 2 ) {
|
||||||
|
sample[0] = 7;
|
||||||
|
}
|
||||||
|
return val === 3;
|
||||||
|
});
|
||||||
|
assert.sameValue(result, undefined, "value not found");
|
||||||
|
|
||||||
|
sample = new TA(arr);
|
||||||
|
result = sample.findLast(function(val, i) {
|
||||||
|
if ( i <= 2 ) {
|
||||||
|
sample[2] = 7;
|
||||||
|
}
|
||||||
|
return val === 7;
|
||||||
|
});
|
||||||
|
assert.sameValue(result, undefined, "value not found - changed after call");
|
||||||
|
|
||||||
|
sample = new TA(arr);
|
||||||
|
result = sample.findLast(function() {
|
||||||
|
sample[2] = 7;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
assert.sameValue(result, 1, "findLast() returns previous found value");
|
||||||
|
});
|
|
@ -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-%typedarray%.prototype.findlast
|
||||||
|
description: >
|
||||||
|
Predicate called as F.call( thisArg, kValue, k, O ) for each array entry.
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
5. Let k be len - 1.
|
||||||
|
6. Repeat, while k ≥ 0,
|
||||||
|
...
|
||||||
|
c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA([39, 2, 62]);
|
||||||
|
var results = [];
|
||||||
|
var result;
|
||||||
|
|
||||||
|
sample.foo = "bar"; // Ignores non integer index properties
|
||||||
|
|
||||||
|
sample.findLast(function() {
|
||||||
|
results.push(arguments);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(results.length, 3, "predicate is called for each index");
|
||||||
|
|
||||||
|
result = results[0];
|
||||||
|
assert.sameValue(result[0], 62, "results[0][0] === 62, value");
|
||||||
|
assert.sameValue(result[1], 2, "results[0][1] === 2, index");
|
||||||
|
assert.sameValue(result[2], sample, "results[0][2] === sample, instance");
|
||||||
|
assert.sameValue(result.length, 3, "results[0].length === 3 arguments");
|
||||||
|
|
||||||
|
result = results[1];
|
||||||
|
assert.sameValue(result[0], 2, "results[1][0] === 2, value");
|
||||||
|
assert.sameValue(result[1], 1, "results[1][1] === 1, index");
|
||||||
|
assert.sameValue(result[2], sample, "results[1][2] === sample, instance");
|
||||||
|
assert.sameValue(result.length, 3, "results[1].length === 3 arguments");
|
||||||
|
|
||||||
|
result = results[2];
|
||||||
|
assert.sameValue(result[0], 39, "results[2][0] === 39, value");
|
||||||
|
assert.sameValue(result[1], 0, "results[2][1] === 0, index");
|
||||||
|
assert.sameValue(result[2], sample, "results[2][2] === sample, instance");
|
||||||
|
assert.sameValue(result.length, 3, "results[2].length === 3 arguments");
|
||||||
|
});
|
45
test/built-ins/TypedArray/prototype/findLast/predicate-call-this-non-strict.js
vendored
Normal file
45
test/built-ins/TypedArray/prototype/findLast/predicate-call-this-non-strict.js
vendored
Normal file
|
@ -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.findlast
|
||||||
|
description: >
|
||||||
|
Verify predicate this on non-strict mode
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
6. Repeat, while k ≥ 0,
|
||||||
|
...
|
||||||
|
c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
|
||||||
|
...
|
||||||
|
flags: [noStrict]
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var T = this;
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(1);
|
||||||
|
var result;
|
||||||
|
|
||||||
|
sample.findLast(function() {
|
||||||
|
result = this;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(result, T, "without thisArg, predicate this is the global");
|
||||||
|
|
||||||
|
result = null;
|
||||||
|
sample.findLast(function() {
|
||||||
|
result = this;
|
||||||
|
}, undefined);
|
||||||
|
|
||||||
|
assert.sameValue(result, T, "predicate this is the global when thisArg is undefined");
|
||||||
|
|
||||||
|
var o = {};
|
||||||
|
result = null;
|
||||||
|
sample.findLast(function() {
|
||||||
|
result = this;
|
||||||
|
}, o);
|
||||||
|
|
||||||
|
assert.sameValue(result, o, "thisArg becomes the predicate this");
|
||||||
|
});
|
|
@ -0,0 +1,39 @@
|
||||||
|
// 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.findlast
|
||||||
|
description: >
|
||||||
|
Verify predicate this on strict mode
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
6. Repeat, while k ≥ 0,
|
||||||
|
...
|
||||||
|
c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
|
||||||
|
...
|
||||||
|
flags: [onlyStrict]
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(1);
|
||||||
|
var result;
|
||||||
|
|
||||||
|
sample.findLast(function() {
|
||||||
|
result = this;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
result,
|
||||||
|
undefined,
|
||||||
|
"without thisArg, predicate this is undefined"
|
||||||
|
);
|
||||||
|
|
||||||
|
var o = {};
|
||||||
|
sample.findLast(function() {
|
||||||
|
result = this;
|
||||||
|
}, o);
|
||||||
|
|
||||||
|
assert.sameValue(result, o, "thisArg becomes the predicate this");
|
||||||
|
});
|
55
test/built-ins/TypedArray/prototype/findLast/predicate-is-not-callable-throws.js
vendored
Normal file
55
test/built-ins/TypedArray/prototype/findLast/predicate-is-not-callable-throws.js
vendored
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
// 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.findlast
|
||||||
|
description: >
|
||||||
|
Throws a TypeError exception if predicate is not callable.
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. If IsCallable(predicate) is false, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA();
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast({});
|
||||||
|
}, "object");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast(null);
|
||||||
|
}, "null");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast(undefined);
|
||||||
|
}, "undefined");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast(false);
|
||||||
|
}, "false");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast(true);
|
||||||
|
}, "true");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast(1);
|
||||||
|
}, "number");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast("");
|
||||||
|
}, "string");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast([]);
|
||||||
|
}, "array");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.findLast(/./);
|
||||||
|
}, "regexp");
|
||||||
|
});
|
|
@ -0,0 +1,39 @@
|
||||||
|
// 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.findlast
|
||||||
|
description: >
|
||||||
|
Predicate may detach the buffer
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
However, such optimization must not introduce any observable changes in the
|
||||||
|
specified behaviour of the algorithm and must take into account the
|
||||||
|
possibility that calls to predicate may cause the this value to become
|
||||||
|
detached.
|
||||||
|
|
||||||
|
IntegerIndexedElementGet ( O, index )
|
||||||
|
|
||||||
|
...
|
||||||
|
Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
|
||||||
|
If IsDetachedBuffer(buffer) is true, return undefined.
|
||||||
|
|
||||||
|
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||||
|
features: [TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var loops = 0;
|
||||||
|
var sample = new TA(2);
|
||||||
|
|
||||||
|
sample.findLast(function() {
|
||||||
|
if (loops === 0) {
|
||||||
|
$DETACHBUFFER(sample.buffer);
|
||||||
|
}
|
||||||
|
loops++;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(loops, 2);
|
||||||
|
});
|
37
test/built-ins/TypedArray/prototype/findLast/predicate-not-called-on-empty-array.js
vendored
Normal file
37
test/built-ins/TypedArray/prototype/findLast/predicate-not-called-on-empty-array.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.findlast
|
||||||
|
description: >
|
||||||
|
Predicate is not called on empty instances
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
6. Repeat, while k ≥ 0,
|
||||||
|
...
|
||||||
|
c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA();
|
||||||
|
var called = false;
|
||||||
|
|
||||||
|
var result = sample.findLast(function() {
|
||||||
|
called = true;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
called,
|
||||||
|
false,
|
||||||
|
"empty instance does not call predicate"
|
||||||
|
);
|
||||||
|
assert.sameValue(
|
||||||
|
result,
|
||||||
|
undefined,
|
||||||
|
"findLast returns undefined when predicate is not called"
|
||||||
|
);
|
||||||
|
});
|
|
@ -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-%typedarray%.prototype.findLast
|
||||||
|
description: >
|
||||||
|
"findLast" property of TypedArrayPrototype
|
||||||
|
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, testTypedArray.js]
|
||||||
|
features: [TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var TypedArrayPrototype = TypedArray.prototype;
|
||||||
|
|
||||||
|
verifyNotEnumerable(TypedArrayPrototype, 'findLast');
|
||||||
|
verifyWritable(TypedArrayPrototype, 'findLast');
|
||||||
|
verifyConfigurable(TypedArrayPrototype, 'findLast');
|
28
test/built-ins/TypedArray/prototype/findLast/return-abrupt-from-predicate-call.js
vendored
Normal file
28
test/built-ins/TypedArray/prototype/findLast/return-abrupt-from-predicate-call.js
vendored
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// 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.findlast
|
||||||
|
description: >
|
||||||
|
Return abrupt from predicate call.
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
6. Repeat, while k ≥ 0,
|
||||||
|
...
|
||||||
|
c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(1);
|
||||||
|
|
||||||
|
var predicate = function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
sample.findLast(predicate);
|
||||||
|
});
|
||||||
|
});
|
56
test/built-ins/TypedArray/prototype/findLast/return-abrupt-from-this-out-of-bounds.js
vendored
Normal file
56
test/built-ins/TypedArray/prototype/findLast/return-abrupt-from-this-out-of-bounds.js
vendored
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
// Copyright (C) 2021 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-%typedarray%.prototype.findlast
|
||||||
|
description: Return abrupt when "this" value fails buffer boundary checks
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray, resizable-arraybuffer]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
typeof TypedArray.prototype.findLast,
|
||||||
|
'function',
|
||||||
|
'implements TypedArray.prototype.findLast'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
typeof ArrayBuffer.prototype.resize,
|
||||||
|
'function',
|
||||||
|
'implements ArrayBuffer.prototype.resize'
|
||||||
|
);
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(TA => {
|
||||||
|
var BPE = TA.BYTES_PER_ELEMENT;
|
||||||
|
var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5});
|
||||||
|
var array = new TA(ab, BPE, 2);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 5);
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
// no error following grow:
|
||||||
|
array.findLast(() => {});
|
||||||
|
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 3);
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
// no error following shrink (within bounds):
|
||||||
|
array.findLast(() => {});
|
||||||
|
|
||||||
|
var expectedError;
|
||||||
|
try {
|
||||||
|
ab.resize(BPE * 3);
|
||||||
|
expectedError = TypeError;
|
||||||
|
} catch (_) {
|
||||||
|
// The host is permitted to fail any "resize" operation at its own
|
||||||
|
// discretion. If that occurs, the findLast operation should complete
|
||||||
|
// successfully.
|
||||||
|
expectedError = Test262Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(expectedError, () => {
|
||||||
|
array.findLast(() => {});
|
||||||
|
throw new Test262Error('findLast completed successfully');
|
||||||
|
});
|
||||||
|
});
|
53
test/built-ins/TypedArray/prototype/findLast/return-found-value-predicate-result-is-true.js
vendored
Normal file
53
test/built-ins/TypedArray/prototype/findLast/return-found-value-predicate-result-is-true.js
vendored
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
// 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.findlast
|
||||||
|
description: >
|
||||||
|
Return found value if predicate return a boolean true value.
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
6. Repeat, while k ≥ 0,
|
||||||
|
...
|
||||||
|
c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
|
||||||
|
d. If testResult is true, return kValue.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [Symbol, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA([39, 2, 62]);
|
||||||
|
var called, result;
|
||||||
|
|
||||||
|
called = 0;
|
||||||
|
result = sample.findLast(function() {
|
||||||
|
called++;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
assert.sameValue(result, 62, "returned true on sample[0]");
|
||||||
|
assert.sameValue(called, 1, "predicate was called once");
|
||||||
|
|
||||||
|
called = 0;
|
||||||
|
result = sample.findLast(function(val) {
|
||||||
|
called++;
|
||||||
|
return val === 62;
|
||||||
|
});
|
||||||
|
assert.sameValue(called, 1, "predicate was called three times");
|
||||||
|
assert.sameValue(result, 62, "returned true on sample[3]");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return "string"; });
|
||||||
|
assert.sameValue(result, 62, "ToBoolean(string)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return {}; });
|
||||||
|
assert.sameValue(result, 62, "ToBoolean(object)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return Symbol(""); });
|
||||||
|
assert.sameValue(result, 62, "ToBoolean(symbol)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return 1; });
|
||||||
|
assert.sameValue(result, 62, "ToBoolean(number)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return -1; });
|
||||||
|
assert.sameValue(result, 62, "ToBoolean(negative number)");
|
||||||
|
});
|
|
@ -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-%typedarray%.prototype.findlast
|
||||||
|
description: >
|
||||||
|
Return undefined if predicate always returns a boolean false value.
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
6. 6. Repeat, while k ≥ 0
|
||||||
|
...
|
||||||
|
c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
|
||||||
|
...
|
||||||
|
7. Return undefined.
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [Symbol, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(3);
|
||||||
|
var called = 0;
|
||||||
|
|
||||||
|
var result = sample.findLast(function() {
|
||||||
|
called++;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(called, 3, "predicate was called three times");
|
||||||
|
assert.sameValue(result, undefined);
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return ""; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(empty string)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return undefined; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(undefined)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return null; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(null)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return 0; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(0)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return -0; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(-0)");
|
||||||
|
|
||||||
|
result = sample.findLast(function() { return NaN; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(NaN)");
|
||||||
|
});
|
|
@ -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-%typedarray%.prototype.findlast
|
||||||
|
description: Throws a TypeError exception when `this` is not Object
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
2. Perform ? ValidateTypedArray(O).
|
||||||
|
|
||||||
|
22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
|
||||||
|
|
||||||
|
1. If Type(O) is not Object, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [Symbol, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var findLast = TypedArray.prototype.findLast;
|
||||||
|
var predicate = function() {};
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
findLast.call(undefined, predicate);
|
||||||
|
}, "this is undefined");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
findLast.call(null, predicate);
|
||||||
|
}, "this is null");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
findLast.call(42, predicate);
|
||||||
|
}, "this is 42");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
findLast.call("1", predicate);
|
||||||
|
}, "this is a string");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
findLast.call(true, predicate);
|
||||||
|
}, "this is true");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
findLast.call(false, predicate);
|
||||||
|
}, "this is false");
|
||||||
|
|
||||||
|
var s = Symbol("s");
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
findLast.call(s, predicate);
|
||||||
|
}, "this is a Symbol");
|
41
test/built-ins/TypedArray/prototype/findLast/this-is-not-typedarray-instance.js
vendored
Normal file
41
test/built-ins/TypedArray/prototype/findLast/this-is-not-typedarray-instance.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.findlast
|
||||||
|
description: >
|
||||||
|
Throws a TypeError exception when `this` is not a TypedArray instance
|
||||||
|
info: |
|
||||||
|
%TypedArray%.prototype.findLast (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
2. Perform ? ValidateTypedArray(O).
|
||||||
|
|
||||||
|
22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
|
||||||
|
|
||||||
|
1. If Type(O) is not Object, throw a TypeError exception.
|
||||||
|
2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError
|
||||||
|
exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var findlast = TypedArray.prototype.findlast;
|
||||||
|
var predicate = function() {};
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
findlast.call({}, predicate);
|
||||||
|
}, "this is an Object");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
findlast.call([], predicate);
|
||||||
|
}, "this is an Array");
|
||||||
|
|
||||||
|
var ab = new ArrayBuffer(8);
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
findlast.call(ab, predicate);
|
||||||
|
}, "this is an ArrayBuffer instance");
|
||||||
|
|
||||||
|
var dv = new DataView(new ArrayBuffer(8), 0, 1);
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
findlast.call(dv, predicate);
|
||||||
|
}, "this is a DataView instance");
|
Loading…
Reference in New Issue