Commit 85c91f63 authored by dehrenberg's avatar dehrenberg Committed by Commit bot

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}
parent 96ab3dce
......@@ -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]);
}
......@@ -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);
}
......@@ -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);
}
......@@ -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++) {
......
......@@ -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++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment