mirror of
https://github.com/tc39/test262.git
synced 2025-07-20 20:44:43 +02:00
Add tests for TypedArrays find
This commit is contained in:
parent
bc8ae6e0ae
commit
9aa4dced8d
54
test/built-ins/TypedArray/prototype/find/get-length-ignores-length-prop.js
vendored
Normal file
54
test/built-ins/TypedArray/prototype/find/get-length-ignores-length-prop.js
vendored
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
// 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.find
|
||||||
|
es6id: 22.2.3.10
|
||||||
|
description: >
|
||||||
|
[[Get]] of "length" uses [[ArrayLength]]
|
||||||
|
info: >
|
||||||
|
22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
%TypedArray%.prototype.find is a distinct function that implements the same
|
||||||
|
algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this
|
||||||
|
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||||
|
[[Get]] of "length". The implementation of the algorithm may be optimized with
|
||||||
|
the knowledge that the this value is an object that has a fixed length and
|
||||||
|
whose integer indexed properties are not sparse.
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
2. Let len be ? ToLength(? Get(O, "length")).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
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.find(function() { return true; }),
|
||||||
|
42
|
||||||
|
);
|
||||||
|
});
|
78
test/built-ins/TypedArray/prototype/find/predicate-call-changes-value.js
vendored
Normal file
78
test/built-ins/TypedArray/prototype/find/predicate-call-changes-value.js
vendored
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
// 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.find
|
||||||
|
es6id: 22.2.3.10
|
||||||
|
description: >
|
||||||
|
Change values during predicate call
|
||||||
|
info: >
|
||||||
|
22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
%TypedArray%.prototype.find is a distinct function that implements the same
|
||||||
|
algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this
|
||||||
|
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||||
|
[[Get]] of "length". The implementation of the algorithm may be optimized with
|
||||||
|
the knowledge that the this value is an object that has a fixed length and
|
||||||
|
whose integer indexed properties are not sparse.
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||||
|
5. Let k be 0.
|
||||||
|
6. Repeat, while k < len
|
||||||
|
...
|
||||||
|
c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
|
||||||
|
...
|
||||||
|
includes: [compareArray.js, testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var arr = [1, 2, 3];
|
||||||
|
var sample;
|
||||||
|
var result;
|
||||||
|
|
||||||
|
sample = new TA(3);
|
||||||
|
sample.find(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.find(function(val, i) {
|
||||||
|
if ( i === 0 ) {
|
||||||
|
sample[2] = 7;
|
||||||
|
}
|
||||||
|
return val === 7;
|
||||||
|
});
|
||||||
|
assert.sameValue(result, 7, "value found");
|
||||||
|
|
||||||
|
sample = new TA(arr);
|
||||||
|
result = sample.find(function(val, i) {
|
||||||
|
if ( i === 0 ) {
|
||||||
|
sample[2] = 7;
|
||||||
|
}
|
||||||
|
return val === 3;
|
||||||
|
});
|
||||||
|
assert.sameValue(result, undefined, "value not found");
|
||||||
|
|
||||||
|
sample = new TA(arr);
|
||||||
|
result = sample.find(function(val, i) {
|
||||||
|
if ( i > 0 ) {
|
||||||
|
sample[0] = 7;
|
||||||
|
}
|
||||||
|
return val === 7;
|
||||||
|
});
|
||||||
|
assert.sameValue(result, undefined, "value not found - changed after call");
|
||||||
|
|
||||||
|
sample = new TA(arr);
|
||||||
|
result = sample.find(function() {
|
||||||
|
sample[0] = 7;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
assert.sameValue(result, 1, "find() returns previous found value");
|
||||||
|
});
|
62
test/built-ins/TypedArray/prototype/find/predicate-call-parameters.js
vendored
Normal file
62
test/built-ins/TypedArray/prototype/find/predicate-call-parameters.js
vendored
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// 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.find
|
||||||
|
es6id: 22.2.3.10
|
||||||
|
description: >
|
||||||
|
Predicate called as F.call( thisArg, kValue, k, O ) for each array entry.
|
||||||
|
info: >
|
||||||
|
22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
%TypedArray%.prototype.find is a distinct function that implements the same
|
||||||
|
algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this
|
||||||
|
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||||
|
[[Get]] of "length". The implementation of the algorithm may be optimized with
|
||||||
|
the knowledge that the this value is an object that has a fixed length and
|
||||||
|
whose integer indexed properties are not sparse.
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||||
|
5. Let k be 0.
|
||||||
|
6. Repeat, while k < len
|
||||||
|
...
|
||||||
|
c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA([39, 2, 62]);
|
||||||
|
var results = [];
|
||||||
|
var result;
|
||||||
|
|
||||||
|
sample.foo = "bar"; // Ignores non integer index properties
|
||||||
|
|
||||||
|
sample.find(function() {
|
||||||
|
results.push(arguments);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(results.length, 3, "predicate is called for each index");
|
||||||
|
|
||||||
|
result = results[0];
|
||||||
|
assert.sameValue(result[0], 39, "results[0][0] === 39, value");
|
||||||
|
assert.sameValue(result[1], 0, "results[0][1] === 0, 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], 62, "results[2][0] === 62, value");
|
||||||
|
assert.sameValue(result[1], 2, "results[2][1] === 2, index");
|
||||||
|
assert.sameValue(result[2], sample, "results[2][2] === sample, instance");
|
||||||
|
assert.sameValue(result.length, 3, "results[2].length === 3 arguments");
|
||||||
|
});
|
59
test/built-ins/TypedArray/prototype/find/predicate-call-this-non-strict.js
vendored
Normal file
59
test/built-ins/TypedArray/prototype/find/predicate-call-this-non-strict.js
vendored
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
// 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.find
|
||||||
|
es6id: 22.2.3.10
|
||||||
|
description: >
|
||||||
|
Verify predicate this on non-strict mode
|
||||||
|
info: >
|
||||||
|
22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
%TypedArray%.prototype.find is a distinct function that implements the same
|
||||||
|
algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this
|
||||||
|
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||||
|
[[Get]] of "length". The implementation of the algorithm may be optimized with
|
||||||
|
the knowledge that the this value is an object that has a fixed length and
|
||||||
|
whose integer indexed properties are not sparse.
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||||
|
...
|
||||||
|
6. Repeat, while k < len
|
||||||
|
...
|
||||||
|
c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
|
||||||
|
...
|
||||||
|
flags: [noStrict]
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var T = this;
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(1);
|
||||||
|
var result;
|
||||||
|
|
||||||
|
sample.find(function() {
|
||||||
|
result = this;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(result, T, "without thisArg, predicate this is the global");
|
||||||
|
|
||||||
|
result = null;
|
||||||
|
sample.find(function() {
|
||||||
|
result = this;
|
||||||
|
}, undefined);
|
||||||
|
|
||||||
|
assert.sameValue(result, T, "predicate this is the global when thisArg is undefined");
|
||||||
|
|
||||||
|
var o = {};
|
||||||
|
result = null;
|
||||||
|
sample.find(function() {
|
||||||
|
result = this;
|
||||||
|
}, o);
|
||||||
|
|
||||||
|
assert.sameValue(result, o, "thisArg becomes the predicate this");
|
||||||
|
});
|
53
test/built-ins/TypedArray/prototype/find/predicate-call-this-strict.js
vendored
Normal file
53
test/built-ins/TypedArray/prototype/find/predicate-call-this-strict.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.find
|
||||||
|
es6id: 22.2.3.10
|
||||||
|
description: >
|
||||||
|
Verify predicate this on strict mode
|
||||||
|
info: >
|
||||||
|
22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
%TypedArray%.prototype.find is a distinct function that implements the same
|
||||||
|
algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this
|
||||||
|
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||||
|
[[Get]] of "length". The implementation of the algorithm may be optimized with
|
||||||
|
the knowledge that the this value is an object that has a fixed length and
|
||||||
|
whose integer indexed properties are not sparse.
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||||
|
...
|
||||||
|
6. Repeat, while k < len
|
||||||
|
...
|
||||||
|
c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
|
||||||
|
...
|
||||||
|
flags: [onlyStrict]
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(1);
|
||||||
|
var result;
|
||||||
|
|
||||||
|
sample.find(function() {
|
||||||
|
result = this;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
result,
|
||||||
|
undefined,
|
||||||
|
"without thisArg, predicate this is undefined"
|
||||||
|
);
|
||||||
|
|
||||||
|
var o = {};
|
||||||
|
sample.find(function() {
|
||||||
|
result = this;
|
||||||
|
}, o);
|
||||||
|
|
||||||
|
assert.sameValue(result, o, "thisArg becomes the predicate this");
|
||||||
|
});
|
66
test/built-ins/TypedArray/prototype/find/predicate-is-not-callable-throws.js
vendored
Normal file
66
test/built-ins/TypedArray/prototype/find/predicate-is-not-callable-throws.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.find
|
||||||
|
es6id: 22.2.3.10
|
||||||
|
description: >
|
||||||
|
Throws a TypeError exception if predicate is not callable.
|
||||||
|
info: >
|
||||||
|
22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
%TypedArray%.prototype.find is a distinct function that implements the same
|
||||||
|
algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this
|
||||||
|
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||||
|
[[Get]] of "length". The implementation of the algorithm may be optimized with
|
||||||
|
the knowledge that the this value is an object that has a fixed length and
|
||||||
|
whose integer indexed properties are not sparse.
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. If IsCallable(predicate) is false, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA();
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.find({});
|
||||||
|
}, "object");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.find(null);
|
||||||
|
}, "null");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.find(undefined);
|
||||||
|
}, "undefined");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.find(false);
|
||||||
|
}, "false");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.find(true);
|
||||||
|
}, "true");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.find(1);
|
||||||
|
}, "number");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.find("");
|
||||||
|
}, "string");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.find([]);
|
||||||
|
}, "array");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.find(/./);
|
||||||
|
}, "regexp");
|
||||||
|
});
|
58
test/built-ins/TypedArray/prototype/find/predicate-may-detach-buffer.js
vendored
Normal file
58
test/built-ins/TypedArray/prototype/find/predicate-may-detach-buffer.js
vendored
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
// 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.find
|
||||||
|
es6id: 22.2.3.10
|
||||||
|
description: >
|
||||||
|
Predicate may detach the buffer
|
||||||
|
info: >
|
||||||
|
22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
%TypedArray%.prototype.find is a distinct function that implements the same
|
||||||
|
algorithm as Array.prototype.find as defined in 22.1.3.8
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||||
|
5. Let k be 0.
|
||||||
|
6. Repeat, while k < len
|
||||||
|
...
|
||||||
|
b. Let kValue be ? Get(O, Pk).
|
||||||
|
c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
|
||||||
|
...
|
||||||
|
|
||||||
|
9.4.5.8 IntegerIndexedElementGet ( O, index )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
|
||||||
|
4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(2);
|
||||||
|
var loops = 0;
|
||||||
|
var completion = false;
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
sample.find(function() {
|
||||||
|
loops++;
|
||||||
|
$DETACHBUFFER(sample.buffer);
|
||||||
|
completion = true;
|
||||||
|
});
|
||||||
|
}, "throws a TypeError getting a value from the detached buffer");
|
||||||
|
|
||||||
|
assert.sameValue(loops, 1, "predicate is called once");
|
||||||
|
assert(completion, "abrupt completion does not come from DETACHBUFFER");
|
||||||
|
});
|
49
test/built-ins/TypedArray/prototype/find/predicate-not-called-on-empty-array.js
vendored
Normal file
49
test/built-ins/TypedArray/prototype/find/predicate-not-called-on-empty-array.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.find
|
||||||
|
es6id: 22.2.3.10
|
||||||
|
description: >
|
||||||
|
Predicate is not called on empty instances
|
||||||
|
info: >
|
||||||
|
22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
%TypedArray%.prototype.find is a distinct function that implements the same
|
||||||
|
algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this
|
||||||
|
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||||
|
[[Get]] of "length". The implementation of the algorithm may be optimized with
|
||||||
|
the knowledge that the this value is an object that has a fixed length and
|
||||||
|
whose integer indexed properties are not sparse.
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
6. Repeat, while k < len
|
||||||
|
...
|
||||||
|
c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA();
|
||||||
|
var called = false;
|
||||||
|
|
||||||
|
var result = sample.find(function() {
|
||||||
|
called = true;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
called,
|
||||||
|
false,
|
||||||
|
"empty instance does not call predicate"
|
||||||
|
);
|
||||||
|
assert.sameValue(
|
||||||
|
result,
|
||||||
|
undefined,
|
||||||
|
"find returns undefined when predicate is not called"
|
||||||
|
);
|
||||||
|
});
|
40
test/built-ins/TypedArray/prototype/find/return-abrupt-from-predicate-call.js
vendored
Normal file
40
test/built-ins/TypedArray/prototype/find/return-abrupt-from-predicate-call.js
vendored
Normal file
@ -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.find
|
||||||
|
es6id: 22.2.3.10
|
||||||
|
description: >
|
||||||
|
Return abrupt from predicate call.
|
||||||
|
info: >
|
||||||
|
22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
%TypedArray%.prototype.find is a distinct function that implements the same
|
||||||
|
algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this
|
||||||
|
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||||
|
[[Get]] of "length". The implementation of the algorithm may be optimized with
|
||||||
|
the knowledge that the this value is an object that has a fixed length and
|
||||||
|
whose integer indexed properties are not sparse.
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
6. Repeat, while k < len
|
||||||
|
...
|
||||||
|
c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
|
||||||
|
...
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(1);
|
||||||
|
|
||||||
|
var predicate = function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
sample.find(predicate);
|
||||||
|
});
|
||||||
|
});
|
66
test/built-ins/TypedArray/prototype/find/return-found-value-predicate-result-is-true.js
vendored
Normal file
66
test/built-ins/TypedArray/prototype/find/return-found-value-predicate-result-is-true.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.find
|
||||||
|
es6id: 22.2.3.10
|
||||||
|
description: >
|
||||||
|
Return found value if predicate return a boolean true value.
|
||||||
|
info: >
|
||||||
|
22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
%TypedArray%.prototype.find is a distinct function that implements the same
|
||||||
|
algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this
|
||||||
|
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||||
|
[[Get]] of "length". The implementation of the algorithm may be optimized with
|
||||||
|
the knowledge that the this value is an object that has a fixed length and
|
||||||
|
whose integer indexed properties are not sparse.
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
6. Repeat, while k < len
|
||||||
|
...
|
||||||
|
c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
|
||||||
|
d. If testResult is true, return kValue.
|
||||||
|
...
|
||||||
|
features: [Symbol]
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA([39, 2, 62]);
|
||||||
|
var called, result;
|
||||||
|
|
||||||
|
called = 0;
|
||||||
|
result = sample.find(function() {
|
||||||
|
called++;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
assert.sameValue(result, 39, "returned true on sample[0]");
|
||||||
|
assert.sameValue(called, 1, "predicate was called once");
|
||||||
|
|
||||||
|
called = 0;
|
||||||
|
result = sample.find(function(val) {
|
||||||
|
called++;
|
||||||
|
return val === 62;
|
||||||
|
});
|
||||||
|
assert.sameValue(called, 3, "predicate was called three times");
|
||||||
|
assert.sameValue(result, 62, "returned true on sample[3]");
|
||||||
|
|
||||||
|
result = sample.find(function() { return "string"; });
|
||||||
|
assert.sameValue(result, 39, "ToBoolean(string)");
|
||||||
|
|
||||||
|
result = sample.find(function() { return {}; });
|
||||||
|
assert.sameValue(result, 39, "ToBoolean(object)");
|
||||||
|
|
||||||
|
result = sample.find(function() { return Symbol(""); });
|
||||||
|
assert.sameValue(result, 39, "ToBoolean(symbol)");
|
||||||
|
|
||||||
|
result = sample.find(function() { return 1; });
|
||||||
|
assert.sameValue(result, 39, "ToBoolean(number)");
|
||||||
|
|
||||||
|
result = sample.find(function() { return -1; });
|
||||||
|
assert.sameValue(result, 39, "ToBoolean(negative number)");
|
||||||
|
});
|
61
test/built-ins/TypedArray/prototype/find/return-undefined-if-predicate-returns-false-value.js
vendored
Normal file
61
test/built-ins/TypedArray/prototype/find/return-undefined-if-predicate-returns-false-value.js
vendored
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
// 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.find
|
||||||
|
es6id: 22.2.3.10
|
||||||
|
description: >
|
||||||
|
Return undefined if predicate always returns a boolean false value.
|
||||||
|
info: >
|
||||||
|
22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] )
|
||||||
|
|
||||||
|
%TypedArray%.prototype.find is a distinct function that implements the same
|
||||||
|
algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this
|
||||||
|
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||||
|
[[Get]] of "length". The implementation of the algorithm may be optimized with
|
||||||
|
the knowledge that the this value is an object that has a fixed length and
|
||||||
|
whose integer indexed properties are not sparse.
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
6. Repeat, while k < len
|
||||||
|
...
|
||||||
|
c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
|
||||||
|
...
|
||||||
|
7. Return undefined.
|
||||||
|
features: [Symbol]
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var sample = new TA(3);
|
||||||
|
var called = 0;
|
||||||
|
|
||||||
|
var result = sample.find(function(val) {
|
||||||
|
called++;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(called, 3, "predicate was called three times");
|
||||||
|
assert.sameValue(result, undefined);
|
||||||
|
|
||||||
|
result = sample.find(function(val) { return ""; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(empty string)");
|
||||||
|
|
||||||
|
result = sample.find(function(val) { return undefined; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(undefined)");
|
||||||
|
|
||||||
|
result = sample.find(function(val) { return null; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(null)");
|
||||||
|
|
||||||
|
result = sample.find(function(val) { return 0; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(0)");
|
||||||
|
|
||||||
|
result = sample.find(function(val) { return -0; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(-0)");
|
||||||
|
|
||||||
|
result = sample.find(function(val) { return NaN; });
|
||||||
|
assert.sameValue(result, undefined, "ToBoolean(NaN)");
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user