From afd44fc87af1d72f3468db4a05fcdf7e0e51f4b5 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Fri, 22 Apr 2016 18:22:49 -0400 Subject: [PATCH] Update tests for TypedArrays foreach and map Based on the feedback from gh-593 --- ...lbackfn-no-interaction-over-non-integer.js | 4 +-- .../forEach/values-are-not-cached.js | 30 +++++++++++++++++++ ...interaction-over-non-integer-properties.js | 4 +-- .../prototype/map/values-are-not-cached.js | 25 ++++++++++++++++ 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 test/built-ins/TypedArray/prototype/forEach/values-are-not-cached.js create mode 100644 test/built-ins/TypedArray/prototype/map/values-are-not-cached.js diff --git a/test/built-ins/TypedArray/prototype/forEach/callbackfn-no-interaction-over-non-integer.js b/test/built-ins/TypedArray/prototype/forEach/callbackfn-no-interaction-over-non-integer.js index f83b8b055e..4ee3c8a21f 100644 --- a/test/built-ins/TypedArray/prototype/forEach/callbackfn-no-interaction-over-non-integer.js +++ b/test/built-ins/TypedArray/prototype/forEach/callbackfn-no-interaction-over-non-integer.js @@ -27,8 +27,8 @@ testWithTypedArrayConstructors(function(TA) { sample.foo = 42; sample[Symbol("1")] = 43; - sample.forEach(function(v, i) { - results.push([v, i]); + sample.forEach(function() { + results.push(arguments); }); assert.sameValue(results.length, 2, "results.length"); diff --git a/test/built-ins/TypedArray/prototype/forEach/values-are-not-cached.js b/test/built-ins/TypedArray/prototype/forEach/values-are-not-cached.js new file mode 100644 index 0000000000..a18c999837 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/values-are-not-cached.js @@ -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.foreach +description: > + Integer indexed values are not cached before interaction +info: > + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + sample.forEach(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42; + } + + assert.sameValue( + v, 42, "method does not cache values before callbackfn calls" + ); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/map/callbackfn-no-interaction-over-non-integer-properties.js b/test/built-ins/TypedArray/prototype/map/callbackfn-no-interaction-over-non-integer-properties.js index fb3ebba661..972cbeb1d8 100644 --- a/test/built-ins/TypedArray/prototype/map/callbackfn-no-interaction-over-non-integer-properties.js +++ b/test/built-ins/TypedArray/prototype/map/callbackfn-no-interaction-over-non-integer-properties.js @@ -26,8 +26,8 @@ testWithTypedArrayConstructors(function(TA) { sample.foo = 42; sample[Symbol("1")] = 43; - sample.map(function(v, i) { - results.push([v, i]); + sample.map(function() { + results.push(arguments); }); assert.sameValue(results.length, 2, "results.length"); diff --git a/test/built-ins/TypedArray/prototype/map/values-are-not-cached.js b/test/built-ins/TypedArray/prototype/map/values-are-not-cached.js new file mode 100644 index 0000000000..f3b2a52740 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/values-are-not-cached.js @@ -0,0 +1,25 @@ +// 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.map +description: > + Integer indexed values changed during iteration +info: > + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + sample.map(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42; + } + + assert.sameValue( + v, 42, "method does not cache values before callbackfn calls" + ); + }); +});