Reviewers: arv,
Description:
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.
[email protected]
BUG=v8:3578
LOG=Y
Please review this at https://codereview.chromium.org/1130413010/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+48, -0 lines):
M test/mjsunit/harmony/typedarray-fill.js
M test/mjsunit/harmony/typedarray-find.js
M test/mjsunit/harmony/typedarray-findindex.js
M test/mjsunit/harmony/typedarrays-every.js
M test/mjsunit/harmony/typedarrays-foreach.js
Index: test/mjsunit/harmony/typedarray-fill.js
diff --git a/test/mjsunit/harmony/typedarray-fill.js
b/test/mjsunit/harmony/typedarray-fill.js
index
40605bbd515ea553bcaf9d6c45124020047def1a..4452bf64cdecf7ae3b4da70a2baaa14c18bb12c3
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]);
}
Index: test/mjsunit/harmony/typedarray-find.js
diff --git a/test/mjsunit/harmony/typedarray-find.js
b/test/mjsunit/harmony/typedarray-find.js
index
5e3512571868c4454a147930bcc820b5b75f010e..3b7ba1e0e9194e935474ec43fc12cb3179201798
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);
+
}
Index: test/mjsunit/harmony/typedarray-findindex.js
diff --git a/test/mjsunit/harmony/typedarray-findindex.js
b/test/mjsunit/harmony/typedarray-findindex.js
index
5a0afb4e0b9082a904f449632609cbd4ad157531..1634448711d315b998998209329178fa0ad27283
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);
+
}
Index: test/mjsunit/harmony/typedarrays-every.js
diff --git a/test/mjsunit/harmony/typedarrays-every.js
b/test/mjsunit/harmony/typedarrays-every.js
index
c81fd966ca623ae268b1d3b257fc07014574bf5f..e6acb566ac61a8adbf96a8b374b509106876cce7
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++) {
Index: test/mjsunit/harmony/typedarrays-foreach.js
diff --git a/test/mjsunit/harmony/typedarrays-foreach.js
b/test/mjsunit/harmony/typedarrays-foreach.js
index
0d34c78efb20f87ddd016c509d8a65dd5aecf592..e1d375da1a08c9e5730436492f89fdc761db791e
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++) {
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.