From 85c91f639e6779b1e5b19b1766bc64ccbe9f00dc Mon Sep 17 00:00:00 2001 From: dehrenberg Date: Thu, 14 May 2015 19:03:47 -0700 Subject: [PATCH] Test that TypedArray methods don't read length ES6 specifies that methods on TypedArrays reference an internal length slot, rather than their length property. This patch tests that for the TypedArray methods that exist currently. R=arv@chromium.org BUG=v8:3578 LOG=Y Review URL: https://codereview.chromium.org/1130413010 Cr-Commit-Position: refs/heads/master@{#28409} --- test/mjsunit/harmony/typedarray-fill.js | 8 ++++++++ test/mjsunit/harmony/typedarray-find.js | 10 ++++++++++ test/mjsunit/harmony/typedarray-findindex.js | 10 ++++++++++ test/mjsunit/harmony/typedarrays-every.js | 10 ++++++++++ test/mjsunit/harmony/typedarrays-foreach.js | 10 ++++++++++ 5 files changed, 48 insertions(+) diff --git a/test/mjsunit/harmony/typedarray-fill.js b/test/mjsunit/harmony/typedarray-fill.js index 40605bb..4452bf6 100644 --- a/test/mjsunit/harmony/typedarray-fill.js +++ b/test/mjsunit/harmony/typedarray-fill.js @@ -36,4 +36,12 @@ for (var constructor of typedArrayConstructors) { assertThrows('constructor.prototype.fill.call(null)', TypeError); assertThrows('constructor.prototype.fill.call(undefined)', TypeError); assertThrows('constructor.prototype.fill.call([])', TypeError); + + // Shadowing length doesn't affect fill, unlike Array.prototype.fill + var a = new constructor([2, 2]); + Object.defineProperty(a, 'length', {value: 1}); + a.fill(3); + assertArrayEquals([a[0], a[1]], [3, 3]); + Array.prototype.fill.call(a, 4); + assertArrayEquals([a[0], a[1]], [4, 3]); } diff --git a/test/mjsunit/harmony/typedarray-find.js b/test/mjsunit/harmony/typedarray-find.js index 5e35125..3b7ba1e 100644 --- a/test/mjsunit/harmony/typedarray-find.js +++ b/test/mjsunit/harmony/typedarray-find.js @@ -176,4 +176,14 @@ assertThrows('new constructor([]).find({})', TypeError); assertThrows('new constructor([]).find([])', TypeError); assertThrows('new constructor([]).find(/\d+/)', TypeError); +// Shadowing length doesn't affect find, unlike Array.prototype.find +a = new constructor([1, 2]); +Object.defineProperty(a, 'length', {value: 1}); +var x = 0; +assertEquals(a.find(function(elt) { x += elt; return false; }), undefined); +assertEquals(x, 3); +assertEquals(Array.prototype.find.call(a, + function(elt) { x += elt; return false; }), undefined); +assertEquals(x, 4); + } diff --git a/test/mjsunit/harmony/typedarray-findindex.js b/test/mjsunit/harmony/typedarray-findindex.js index 5a0afb4..1634448 100644 --- a/test/mjsunit/harmony/typedarray-findindex.js +++ b/test/mjsunit/harmony/typedarray-findindex.js @@ -176,4 +176,14 @@ assertThrows('new constructor([]).findIndex({})', TypeError); assertThrows('new constructor([]).findIndex([])', TypeError); assertThrows('new constructor([]).findIndex(/\d+/)', TypeError); +// Shadowing length doesn't affect findIndex, unlike Array.prototype.findIndex +a = new constructor([1, 2]); +Object.defineProperty(a, 'length', {value: 1}); +var x = 0; +assertEquals(a.findIndex(function(elt) { x += elt; return false; }), -1); +assertEquals(x, 3); +assertEquals(Array.prototype.findIndex.call(a, + function(elt) { x += elt; return false; }), -1); +assertEquals(x, 4); + } diff --git a/test/mjsunit/harmony/typedarrays-every.js b/test/mjsunit/harmony/typedarrays-every.js index c81fd96..e6acb56 100644 --- a/test/mjsunit/harmony/typedarrays-every.js +++ b/test/mjsunit/harmony/typedarrays-every.js @@ -135,6 +135,16 @@ function TestTypedArrayForEach(constructor) { constructor.prototype.every.call(a, function (x) { count++; return true; }); assertEquals(a.length, count); } + + // Shadowing length doesn't affect every, unlike Array.prototype.every + a = new constructor([1, 2]); + Object.defineProperty(a, 'length', {value: 1}); + var x = 0; + assertEquals(a.every(function(elt) { x += elt; return true; }), true); + assertEquals(x, 3); + assertEquals(Array.prototype.every.call(a, + function(elt) { x += elt; return true; }), true); + assertEquals(x, 4); } for (i = 0; i < typedArrayConstructors.length; i++) { diff --git a/test/mjsunit/harmony/typedarrays-foreach.js b/test/mjsunit/harmony/typedarrays-foreach.js index 0d34c78..e1d375d 100644 --- a/test/mjsunit/harmony/typedarrays-foreach.js +++ b/test/mjsunit/harmony/typedarrays-foreach.js @@ -138,6 +138,16 @@ function TestTypedArrayForEach(constructor) { constructor.prototype.forEach.call(a, function (x) { count++ }); assertEquals(a.length, count); } + + // Shadowing length doesn't affect forEach, unlike Array.prototype.forEach + a = new constructor([1, 2]); + Object.defineProperty(a, 'length', {value: 1}); + var x = 0; + assertEquals(a.forEach(function(elt) { x += elt; }), undefined); + assertEquals(x, 3); + assertEquals(Array.prototype.forEach.call(a, + function(elt) { x += elt; }), undefined); + assertEquals(x, 4); } for (i = 0; i < typedArrayConstructors.length; i++) { -- 2.7.4