From 3339406dd72936a643889b26b234d4f7d3002394 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Thu, 21 Apr 2016 10:57:28 -0400 Subject: [PATCH] Add tests for TypedArrays every --- .../callbackfn-arguments-with-thisarg.js | 55 +++++++++++++++ .../callbackfn-arguments-without-thisarg.js | 53 ++++++++++++++ .../every/callbackfn-detachbuffer.js | 43 ++++++++++++ ...lbackfn-no-interaction-over-non-integer.js | 41 +++++++++++ .../every/callbackfn-not-callable-throws.js | 69 +++++++++++++++++++ .../every/callbackfn-not-called-on-empty.js | 35 ++++++++++ ...lbackfn-return-does-not-change-instance.js | 37 ++++++++++ .../every/callbackfn-returns-abrupt.js | 34 +++++++++ ...callbackfn-set-value-during-interaction.js | 58 ++++++++++++++++ .../prototype/every/callbackfn-this.js | 58 ++++++++++++++++ .../get-length-uses-internal-arraylength.js | 46 +++++++++++++ .../returns-false-if-any-cb-returns-false.js | 45 ++++++++++++ .../returns-true-if-every-cb-returns-true.js | 46 +++++++++++++ .../prototype/every/values-are-not-cached.js | 42 +++++++++++ 14 files changed, 662 insertions(+) create mode 100644 test/built-ins/TypedArray/prototype/every/callbackfn-arguments-with-thisarg.js create mode 100644 test/built-ins/TypedArray/prototype/every/callbackfn-arguments-without-thisarg.js create mode 100644 test/built-ins/TypedArray/prototype/every/callbackfn-detachbuffer.js create mode 100644 test/built-ins/TypedArray/prototype/every/callbackfn-no-interaction-over-non-integer.js create mode 100644 test/built-ins/TypedArray/prototype/every/callbackfn-not-callable-throws.js create mode 100644 test/built-ins/TypedArray/prototype/every/callbackfn-not-called-on-empty.js create mode 100644 test/built-ins/TypedArray/prototype/every/callbackfn-return-does-not-change-instance.js create mode 100644 test/built-ins/TypedArray/prototype/every/callbackfn-returns-abrupt.js create mode 100644 test/built-ins/TypedArray/prototype/every/callbackfn-set-value-during-interaction.js create mode 100644 test/built-ins/TypedArray/prototype/every/callbackfn-this.js create mode 100644 test/built-ins/TypedArray/prototype/every/get-length-uses-internal-arraylength.js create mode 100644 test/built-ins/TypedArray/prototype/every/returns-false-if-any-cb-returns-false.js create mode 100644 test/built-ins/TypedArray/prototype/every/returns-true-if-every-cb-returns-true.js create mode 100644 test/built-ins/TypedArray/prototype/every/values-are-not-cached.js diff --git a/test/built-ins/TypedArray/prototype/every/callbackfn-arguments-with-thisarg.js b/test/built-ins/TypedArray/prototype/every/callbackfn-arguments-with-thisarg.js new file mode 100644 index 0000000000..63d8ba8a10 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/callbackfn-arguments-with-thisarg.js @@ -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.every +description: > + thisArg does not affect callbackfn arguments +info: > + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( 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 results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.every(function() { + results.push(arguments); + return true; + }, 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"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/callbackfn-arguments-without-thisarg.js b/test/built-ins/TypedArray/prototype/every/callbackfn-arguments-without-thisarg.js new file mode 100644 index 0000000000..2fba59f03a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/callbackfn-arguments-without-thisarg.js @@ -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.every +description: > + callbackfn arguments +info: > + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( 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 results = []; + + sample.every(function() { + results.push(arguments); + return true; + }); + + 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"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/callbackfn-detachbuffer.js b/test/built-ins/TypedArray/prototype/every/callbackfn-detachbuffer.js new file mode 100644 index 0000000000..3d7ce3215b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/callbackfn-detachbuffer.js @@ -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.every +description: > + Instance buffer can be detached during loop +info: > + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( 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.every(function() { + if (loops === 1) { + throw new Test262Error("callbackfn called twice"); + } + $DETACHBUFFER(sample.buffer); + loops++; + return true; + }); + }); + + assert.sameValue(loops, 1); +}); diff --git a/test/built-ins/TypedArray/prototype/every/callbackfn-no-interaction-over-non-integer.js b/test/built-ins/TypedArray/prototype/every/callbackfn-no-interaction-over-non-integer.js new file mode 100644 index 0000000000..1fcb162b8c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/callbackfn-no-interaction-over-non-integer.js @@ -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.every +description: > + Does not interact over non-integer properties +info: > + 22.2.3.7 %TypedArray%.prototype.every ( 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.every(function() { + results.push(arguments); + return true; + }); + + 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"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/callbackfn-not-callable-throws.js b/test/built-ins/TypedArray/prototype/every/callbackfn-not-callable-throws.js new file mode 100644 index 0000000000..bfee4bef04 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/callbackfn-not-callable-throws.js @@ -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.every +description: Throws a TypeError if callbackfn is not callable +info: > + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( 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.every(); + }, "no args"); + + assert.throws(TypeError, function() { + sample.every(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.every(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.every("abc"); + }, "string"); + + assert.throws(TypeError, function() { + sample.every(1); + }, "number"); + + assert.throws(TypeError, function() { + sample.every(NaN); + }, "NaN"); + + assert.throws(TypeError, function() { + sample.every(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.every(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.every({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.every(sample); + }, "same typedArray instance"); + + assert.throws(TypeError, function() { + sample.every(Symbol("1")); + }, "symbol"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/callbackfn-not-called-on-empty.js b/test/built-ins/TypedArray/prototype/every/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000..7f399ac9a7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/callbackfn-not-called-on-empty.js @@ -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.every +description: > + callbackfn is not called on empty instances +info: > + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( 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().every(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/every/callbackfn-return-does-not-change-instance.js b/test/built-ins/TypedArray/prototype/every/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000..61c067316c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/callbackfn-return-does-not-change-instance.js @@ -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.every +description: > + The callbackfn return does not change the instance +info: > + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( 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.every(function() { + return 43; + }); + + assert.sameValue(sample[0], 40, "[0] == 40"); + assert.sameValue(sample[1], 41, "[1] == 41"); + assert.sameValue(sample[2], 42, "[2] == 42"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/callbackfn-returns-abrupt.js b/test/built-ins/TypedArray/prototype/every/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000..fdd4bbf288 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/callbackfn-returns-abrupt.js @@ -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.every +description: Returns abrupt from callbackfn +info: > + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( 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.every(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/every/callbackfn-set-value-during-interaction.js b/test/built-ins/TypedArray/prototype/every/callbackfn-set-value-during-interaction.js new file mode 100644 index 0000000000..340b3c4385 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/callbackfn-set-value-during-interaction.js @@ -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.every +description: > + Integer indexed values changed during iteration +info: > + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( 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.every(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++; + + return true; + }); + + 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"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/callbackfn-this.js b/test/built-ins/TypedArray/prototype/every/callbackfn-this.js new file mode 100644 index 0000000000..b9baf849a1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/callbackfn-this.js @@ -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.every +description: > + callbackfn `this` value +info: > + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( 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.every(function() { + results1.push(this); + return true; + }); + + 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.every(function() { + results2.push(this); + return true; + }, 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]"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/get-length-uses-internal-arraylength.js b/test/built-ins/TypedArray/prototype/every/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000..1e57c468ab --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/get-length-uses-internal-arraylength.js @@ -0,0 +1,46 @@ +// 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.every +description: Get "length" uses internal ArrayLength +info: > + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( 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.every(function() { + calls++; + return true; + }); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 2, "interactions are not affected by custom length"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/returns-false-if-any-cb-returns-false.js b/test/built-ins/TypedArray/prototype/every/returns-false-if-any-cb-returns-false.js new file mode 100644 index 0000000000..6b984db40d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/returns-false-if-any-cb-returns-false.js @@ -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.every +description: > + Returns false if any callbackfn call returns a coerced false. +info: > + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( 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.every(function() { + called++; + if (called === 1) { + return true; + } + return val; + }); + assert.sameValue(called, 2, "callbackfn called until it returned " + val); + assert.sameValue(result, false, "result is false when it returned " + val); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/every/returns-true-if-every-cb-returns-true.js b/test/built-ins/TypedArray/prototype/every/returns-true-if-every-cb-returns-true.js new file mode 100644 index 0000000000..51ff9612ed --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/returns-true-if-every-cb-returns-true.js @@ -0,0 +1,46 @@ +// 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.every +description: > + Returns true if every callbackfn returns a coerced true. +info: > + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 7. Return true. +includes: [testTypedArray.js] +features: [Symbol] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + var values = [ + true, + 1, + "test262", + Symbol("1"), + {}, + [], + -1, + Infinity, + -Infinity, + 0.1, + -0.1 + ]; + var sample = new TA(values.length); + var result = sample.every(function() { + called++; + return values.unshift(); + }); + + assert.sameValue(called, sample.length, "callbackfn called for each index"); + assert.sameValue(result, true, "return is true"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/values-are-not-cached.js b/test/built-ins/TypedArray/prototype/every/values-are-not-cached.js new file mode 100644 index 0000000000..091ae6a35e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/values-are-not-cached.js @@ -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.every +description: > + Integer indexed values are not cached before interaction +info: > + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( 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.every(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42; + } + + assert.sameValue( + v, 42, "method does not cache values before callbackfn calls" + ); + return true; + }); +});