mirror of https://github.com/tc39/test262.git
Add tests for TypedArrays some
This commit is contained in:
parent
3339406dd7
commit
45ff661f75
56
test/built-ins/TypedArray/prototype/some/callbackfn-arguments-with-thisarg.js
vendored
Normal file
56
test/built-ins/TypedArray/prototype/some/callbackfn-arguments-with-thisarg.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.some
|
||||
description: >
|
||||
thisArg does not affect callbackfn arguments
|
||||
info: >
|
||||
22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
%TypedArray%.prototype.some is a distinct function that implements the same
|
||||
algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this
|
||||
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||
[[Get]] of "length".
|
||||
|
||||
22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
...
|
||||
4. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||
...
|
||||
6. Repeat, while k < len
|
||||
...
|
||||
c. If kPresent is true, then
|
||||
i. Let kValue be ? Get(O, Pk).
|
||||
ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 44]);
|
||||
|
||||
var results = [];
|
||||
var thisArg = ["test262", 0, "ecma262", 0];
|
||||
|
||||
sample.some(function() {
|
||||
results.push(arguments);
|
||||
}, thisArg);
|
||||
|
||||
assert.sameValue(results.length, 3, "results.length");
|
||||
assert.sameValue(thisArg.length, 4, "thisArg.length");
|
||||
|
||||
assert.sameValue(results[0].length, 3, "results[0].length");
|
||||
assert.sameValue(results[0][0], 42, "results[0][0] - kValue");
|
||||
assert.sameValue(results[0][1], 0, "results[0][1] - k");
|
||||
assert.sameValue(results[0][2], sample, "results[0][2] - this");
|
||||
|
||||
assert.sameValue(results[1].length, 3, "results[1].length");
|
||||
assert.sameValue(results[1][0], 43, "results[1][0] - kValue");
|
||||
assert.sameValue(results[1][1], 1, "results[1][1] - k");
|
||||
assert.sameValue(results[1][2], sample, "results[1][2] - this");
|
||||
|
||||
assert.sameValue(results[2].length, 3, "results[2].length");
|
||||
assert.sameValue(results[2][0], 44, "results[2][0] - kValue");
|
||||
assert.sameValue(results[2][1], 2, "results[2][1] - k");
|
||||
assert.sameValue(results[2][2], sample, "results[2][2] - this");
|
||||
});
|
54
test/built-ins/TypedArray/prototype/some/callbackfn-arguments-without-thisarg.js
vendored
Normal file
54
test/built-ins/TypedArray/prototype/some/callbackfn-arguments-without-thisarg.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.some
|
||||
description: >
|
||||
callbackfn arguments
|
||||
info: >
|
||||
22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
%TypedArray%.prototype.some is a distinct function that implements the same
|
||||
algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this
|
||||
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||
[[Get]] of "length".
|
||||
|
||||
22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
...
|
||||
4. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||
...
|
||||
6. Repeat, while k < len
|
||||
...
|
||||
c. If kPresent is true, then
|
||||
i. Let kValue be ? Get(O, Pk).
|
||||
ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 44]);
|
||||
|
||||
var results = [];
|
||||
|
||||
sample.some(function() {
|
||||
results.push(arguments);
|
||||
});
|
||||
|
||||
assert.sameValue(results.length, 3, "results.length");
|
||||
|
||||
assert.sameValue(results[0].length, 3, "results[0].length");
|
||||
assert.sameValue(results[0][0], 42, "results[0][0] - kValue");
|
||||
assert.sameValue(results[0][1], 0, "results[0][1] - k");
|
||||
assert.sameValue(results[0][2], sample, "results[0][2] - this");
|
||||
|
||||
assert.sameValue(results[1].length, 3, "results[1].length");
|
||||
assert.sameValue(results[1][0], 43, "results[1][0] - kValue");
|
||||
assert.sameValue(results[1][1], 1, "results[1][1] - k");
|
||||
assert.sameValue(results[1][2], sample, "results[1][2] - this");
|
||||
|
||||
assert.sameValue(results[2].length, 3, "results[2].length");
|
||||
assert.sameValue(results[2][0], 44, "results[2][0] - kValue");
|
||||
assert.sameValue(results[2][1], 2, "results[2][1] - k");
|
||||
assert.sameValue(results[2][2], sample, "results[2][2] - this");
|
||||
});
|
|
@ -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.some
|
||||
description: >
|
||||
Instance buffer can be detached during loop
|
||||
info: >
|
||||
22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
%TypedArray%.prototype.some is a distinct function that implements the same
|
||||
algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this
|
||||
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||
[[Get]] of "length".
|
||||
|
||||
22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
...
|
||||
6. Repeat, while k < len
|
||||
...
|
||||
c. If kPresent is true, then
|
||||
i. Let kValue be ? Get(O, Pk).
|
||||
ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
|
||||
...
|
||||
includes: [detachArrayBuffer.js, testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var loops = 0;
|
||||
var sample = new TA(2);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.some(function() {
|
||||
if (loops === 1) {
|
||||
throw new Test262Error("callbackfn called twice");
|
||||
}
|
||||
$DETACHBUFFER(sample.buffer);
|
||||
loops++;
|
||||
});
|
||||
});
|
||||
|
||||
assert.sameValue(loops, 1);
|
||||
});
|
40
test/built-ins/TypedArray/prototype/some/callbackfn-no-interaction-over-non-integer.js
vendored
Normal file
40
test/built-ins/TypedArray/prototype/some/callbackfn-no-interaction-over-non-integer.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.some
|
||||
description: >
|
||||
Does not interact over non-integer properties
|
||||
info: >
|
||||
22.2.3.7 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
...
|
||||
6. Repeat, while k < len
|
||||
...
|
||||
c. If kPresent is true, then
|
||||
i. Let kValue be ? Get(O, Pk).
|
||||
ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([7, 8]);
|
||||
|
||||
var results = [];
|
||||
|
||||
sample.foo = 42;
|
||||
sample[Symbol("1")] = 43;
|
||||
|
||||
sample.some(function() {
|
||||
results.push(arguments);
|
||||
});
|
||||
|
||||
assert.sameValue(results.length, 2, "results.length");
|
||||
|
||||
assert.sameValue(results[0][1], 0, "results[0][1] - key");
|
||||
assert.sameValue(results[1][1], 1, "results[1][1] - key");
|
||||
|
||||
assert.sameValue(results[0][0], 7, "results[0][0] - value");
|
||||
assert.sameValue(results[1][0], 8, "results[1][0] - value");
|
||||
});
|
|
@ -0,0 +1,69 @@
|
|||
// 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.some
|
||||
description: Throws a TypeError if callbackfn is not callable
|
||||
info: >
|
||||
22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
%TypedArray%.prototype.some is a distinct function that implements the same
|
||||
algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this
|
||||
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||
[[Get]] of "length".
|
||||
|
||||
22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
...
|
||||
3. If IsCallable(callbackfn) is false, throw a TypeError exception.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(2);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.some();
|
||||
}, "no args");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.some(null);
|
||||
}, "null");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.some(undefined);
|
||||
}, "undefined");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.some("abc");
|
||||
}, "string");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.some(1);
|
||||
}, "number");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.some(NaN);
|
||||
}, "NaN");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.some(false);
|
||||
}, "false");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.some(true);
|
||||
}, "true");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.some({});
|
||||
}, "{}");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.some(sample);
|
||||
}, "same typedArray instance");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.some(Symbol("1"));
|
||||
}, "symbol");
|
||||
});
|
|
@ -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.some
|
||||
description: >
|
||||
callbackfn is not called on empty instances
|
||||
info: >
|
||||
22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
%TypedArray%.prototype.some is a distinct function that implements the same
|
||||
algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this
|
||||
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||
[[Get]] of "length".
|
||||
|
||||
22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
...
|
||||
6. Repeat, while k < len
|
||||
..
|
||||
c. If kPresent is true, then
|
||||
i. Let kValue be ? Get(O, Pk).
|
||||
ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var called = 0;
|
||||
|
||||
new TA().some(function() {
|
||||
called++;
|
||||
});
|
||||
|
||||
assert.sameValue(called, 0);
|
||||
});
|
37
test/built-ins/TypedArray/prototype/some/callbackfn-return-does-not-change-instance.js
vendored
Normal file
37
test/built-ins/TypedArray/prototype/some/callbackfn-return-does-not-change-instance.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.some
|
||||
description: >
|
||||
The callbackfn return does not change the instance
|
||||
info: >
|
||||
22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
%TypedArray%.prototype.some is a distinct function that implements the same
|
||||
algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this
|
||||
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||
[[Get]] of "length".
|
||||
|
||||
22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
...
|
||||
6. Repeat, while k < len
|
||||
..
|
||||
c. If kPresent is true, then
|
||||
i. Let kValue be ? Get(O, Pk).
|
||||
ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([40, 41, 42]);
|
||||
|
||||
sample.some(function() {
|
||||
return 0;
|
||||
});
|
||||
|
||||
assert.sameValue(sample[0], 40, "[0] == 40");
|
||||
assert.sameValue(sample[1], 41, "[1] == 41");
|
||||
assert.sameValue(sample[2], 42, "[2] == 42");
|
||||
});
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.some
|
||||
description: Returns abrupt from callbackfn
|
||||
info: >
|
||||
22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
%TypedArray%.prototype.some is a distinct function that implements the same
|
||||
algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this
|
||||
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||
[[Get]] of "length".
|
||||
|
||||
22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
...
|
||||
6. Repeat, while k < len
|
||||
..
|
||||
c. If kPresent is true, then
|
||||
i. Let kValue be ? Get(O, Pk).
|
||||
ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(3);
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
sample.some(function() {
|
||||
throw new Test262Error();
|
||||
});
|
||||
});
|
||||
});
|
56
test/built-ins/TypedArray/prototype/some/callbackfn-set-value-during-interaction.js
vendored
Normal file
56
test/built-ins/TypedArray/prototype/some/callbackfn-set-value-during-interaction.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.some
|
||||
description: >
|
||||
Integer indexed values changed during iteration
|
||||
info: >
|
||||
22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
%TypedArray%.prototype.some is a distinct function that implements the same
|
||||
algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this
|
||||
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||
[[Get]] of "length".
|
||||
|
||||
22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
...
|
||||
6. Repeat, while k < len
|
||||
..
|
||||
c. If kPresent is true, then
|
||||
i. Let kValue be ? Get(O, Pk).
|
||||
ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Reflect.set]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 44]);
|
||||
var newVal = 0;
|
||||
|
||||
sample.some(function(val, i) {
|
||||
if (i > 0) {
|
||||
assert.sameValue(
|
||||
sample[i - 1], newVal - 1,
|
||||
"get the changed value during the loop"
|
||||
);
|
||||
assert.sameValue(
|
||||
Reflect.set(sample, 0, 7),
|
||||
true,
|
||||
"re-set a value for sample[0]"
|
||||
);
|
||||
}
|
||||
assert.sameValue(
|
||||
Reflect.set(sample, i, newVal),
|
||||
true,
|
||||
"set value during interaction"
|
||||
);
|
||||
|
||||
newVal++;
|
||||
});
|
||||
|
||||
assert.sameValue(sample[0], 7, "changed values after interaction [0] == 7");
|
||||
assert.sameValue(sample[1], 1, "changed values after interaction [1] == 1");
|
||||
assert.sameValue(sample[2], 2, "changed values after interaction [2] == 2");
|
||||
});
|
|
@ -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.some
|
||||
description: >
|
||||
callbackfn `this` value
|
||||
info: >
|
||||
22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
%TypedArray%.prototype.some is a distinct function that implements the same
|
||||
algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this
|
||||
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||
[[Get]] of "length".
|
||||
|
||||
22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
...
|
||||
4. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||
...
|
||||
6. Repeat, while k < len
|
||||
...
|
||||
c. If kPresent is true, then
|
||||
...
|
||||
ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var expected = (function() { return this; })();
|
||||
var thisArg = {};
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(3);
|
||||
|
||||
var results1 = [];
|
||||
|
||||
sample.some(function() {
|
||||
results1.push(this);
|
||||
});
|
||||
|
||||
assert.sameValue(results1.length, 3, "results1");
|
||||
assert.sameValue(results1[0], expected, "without thisArg - [0]");
|
||||
assert.sameValue(results1[1], expected, "without thisArg - [1]");
|
||||
assert.sameValue(results1[2], expected, "without thisArg - [2]");
|
||||
|
||||
var results2 = [];
|
||||
|
||||
sample.some(function() {
|
||||
results2.push(this);
|
||||
}, thisArg);
|
||||
|
||||
assert.sameValue(results2.length, 3, "results2");
|
||||
assert.sameValue(results2[0], thisArg, "using thisArg - [0]");
|
||||
assert.sameValue(results2[1], thisArg, "using thisArg - [1]");
|
||||
assert.sameValue(results2[2], thisArg, "using thisArg - [2]");
|
||||
});
|
45
test/built-ins/TypedArray/prototype/some/get-length-uses-internal-arraylength.js
vendored
Normal file
45
test/built-ins/TypedArray/prototype/some/get-length-uses-internal-arraylength.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.some
|
||||
description: Get "length" uses internal ArrayLength
|
||||
info: >
|
||||
22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
%TypedArray%.prototype.some is a distinct function that implements the same
|
||||
algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this
|
||||
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||
[[Get]] of "length".
|
||||
|
||||
22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
1. Let O be ? ToObject(this value).
|
||||
2. Let len be ? ToLength(? Get(O, "length")).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var getCalls = 0;
|
||||
var desc = {
|
||||
get: function getLen() {
|
||||
getCalls++;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
Object.defineProperty(TypedArray.prototype, "length", desc);
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43]);
|
||||
var calls = 0;
|
||||
|
||||
Object.defineProperty(TA.prototype, "length", desc);
|
||||
Object.defineProperty(sample, "length", desc);
|
||||
|
||||
sample.some(function() {
|
||||
calls++;
|
||||
});
|
||||
|
||||
assert.sameValue(getCalls, 0, "ignores length properties");
|
||||
assert.sameValue(calls, 2, "interactions are not affected by custom length");
|
||||
});
|
42
test/built-ins/TypedArray/prototype/some/returns-false-if-every-cb-returns-false.js
vendored
Normal file
42
test/built-ins/TypedArray/prototype/some/returns-false-if-every-cb-returns-false.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.some
|
||||
description: >
|
||||
Returns false if every callbackfn calls returns a coerced false.
|
||||
info: >
|
||||
22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
%TypedArray%.prototype.some is a distinct function that implements the same
|
||||
algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this
|
||||
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||
[[Get]] of "length".
|
||||
|
||||
22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
...
|
||||
7. Return true.
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(42);
|
||||
|
||||
[
|
||||
false,
|
||||
"",
|
||||
0,
|
||||
-0,
|
||||
NaN,
|
||||
undefined,
|
||||
null
|
||||
].forEach(function(val) {
|
||||
var called = 0;
|
||||
var result = sample.some(function() {
|
||||
called++;
|
||||
return val;
|
||||
});
|
||||
assert.sameValue(called, 42, "callbackfn called for each index property");
|
||||
assert.sameValue(result, false, "result is false - " + val);
|
||||
});
|
||||
});
|
60
test/built-ins/TypedArray/prototype/some/returns-true-if-any-cb-returns-true.js
vendored
Normal file
60
test/built-ins/TypedArray/prototype/some/returns-true-if-any-cb-returns-true.js
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
// 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.some
|
||||
description: >
|
||||
Returns true if any callbackfn returns a coerced true.
|
||||
info: >
|
||||
22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
%TypedArray%.prototype.some is a distinct function that implements the same
|
||||
algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this
|
||||
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||
[[Get]] of "length".
|
||||
|
||||
22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
...
|
||||
6. Repeat, while k < len
|
||||
...
|
||||
c. If kPresent is true, then
|
||||
i. Let kValue be ? Get(O, Pk).
|
||||
ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
|
||||
iii. If testResult is true, return true.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var s = Symbol("1");
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var called = 0;
|
||||
var sample = new TA(42);
|
||||
var values = [
|
||||
true,
|
||||
1,
|
||||
"test262",
|
||||
s,
|
||||
{},
|
||||
[],
|
||||
-1,
|
||||
Infinity,
|
||||
-Infinity,
|
||||
0.1,
|
||||
-0.1
|
||||
].forEach(function(val) {
|
||||
var called = 0;
|
||||
var result = sample.some(function() {
|
||||
called++;
|
||||
if (called == 1) {
|
||||
return false;
|
||||
}
|
||||
return val;
|
||||
});
|
||||
assert.sameValue(called, 2, "callbackfn called for each index property");
|
||||
|
||||
var msg = "result is true - " + (val === s ? "symbol" : val);
|
||||
assert.sameValue(result, true, msg);
|
||||
});
|
||||
});
|
|
@ -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.some
|
||||
description: >
|
||||
Integer indexed values are not cached before interaction
|
||||
info: >
|
||||
22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
%TypedArray%.prototype.some is a distinct function that implements the same
|
||||
algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this
|
||||
object's [[ArrayLength]] internal slot is accessed in place of performing a
|
||||
[[Get]] of "length".
|
||||
|
||||
22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] )
|
||||
|
||||
...
|
||||
6. Repeat, while k < len
|
||||
..
|
||||
c. If kPresent is true, then
|
||||
i. Let kValue be ? Get(O, Pk).
|
||||
ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 44]);
|
||||
var calls = 0;
|
||||
|
||||
sample.some(function(v, i) {
|
||||
if (i < sample.length - 1) {
|
||||
sample[i+1] = 42;
|
||||
}
|
||||
|
||||
assert.sameValue(
|
||||
v, 42, "method does not cache values before callbackfn calls"
|
||||
);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue