Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1227)

Unified Diff: test/mjsunit/es6/spread-call.js

Issue 2465253011: Fastpath some spread-call desugaring. (Closed)
Patch Set: rename constant Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/mjsunit/es6/spread-call.js
diff --git a/test/mjsunit/es6/spread-call.js b/test/mjsunit/es6/spread-call.js
index 05e17741d6862886be52ea2abe502bb798716fe8..22d4406d479e91f862367699ff841ec03cadc86d 100644
--- a/test/mjsunit/es6/spread-call.js
+++ b/test/mjsunit/es6/spread-call.js
@@ -346,6 +346,88 @@
assertEquals("ABXYC1C2DEBXYC1C2", log);
})();
+(function testArrayPrototypeHoleGetterModifiesIteratorPrototypeNext() {
+ function sum() {
+ var sum = arguments[0];
+ for (var i = 1; i < arguments.length; ++i) {
+ sum += arguments[i];
+ }
+ return sum;
+ }
+ var a = [1, 2];
+ a[3] = 4;
+ var called = 0;
+
+ Object.defineProperty(Array.prototype, 2, {
+ get: function() {
+ var ai = a[Symbol.iterator]();
+ var original_next = ai.__proto__["next"];
+ Object.defineProperty(ai.__proto__, "next", {
+ get: function() {
+ called++;
+ return original_next;
+ }
+ });
+ return 3;
+ }
+ });
+
+ assertEquals(10, sum(...a));
+ assertEquals(2, called);
+})();
+
+(function testArrayHasOtherPrototype() {
+ function countArgs() { return arguments.length; }
+ var a = [1, 2, 3];
+ var b = {};
+ Object.defineProperty(b, Symbol.iterator, {
+ value: function*() {
+ yield 4;
+ },
+ configurable: true
+ });
+
+ Object.setPrototypeOf(a, b);
+
+ assertEquals(1, countArgs(...a));
+})();
+
+(function testArrayIteratorPrototypeGetter() {
+ function countArgs() { return arguments.length; }
+ var a = [1, 2, 3];
+ var ai = a[Symbol.iterator]();
+ var called = 0;
+
+ var original_next = ai.__proto__["next"];
+
+ Object.defineProperty(ai.__proto__, "next", {
+ get: function() {
+ called++;
+ return original_next;
+ }
+ });
+
+ countArgs(...a);
+
+ // should be called 4 times; 3 for the values, 1 for the final
+ // {value: undefined, done: true} pair
+ assertEquals(4, called);
+})();
+
+(function testArrayIteratorPrototypeModified() {
+ function countArgs() { return arguments.length; }
+ var a = [1,2,3];
+ var ai = a[Symbol.iterator]();
+ Object.defineProperty(ai.__proto__, "next", {
+ value: function() {
+ return {value: undefined, done: true};
+ },
+ configurable: true
+ });
+
+ assertEquals(0, countArgs(...a));
+
+})();
(function testCustomArrayPrototypeIterator() {
var origIterator =
@@ -370,3 +452,29 @@
Object.defineProperty(Array.prototype, Symbol.iterator, origIterator);
})();
+
+(function testGetPropertyIteratorCalledExactlyOnce() {
+ function countArgs() { return arguments.length; }
+ var a = [1, 2, 3];
+ var called = 0;
+
+ Object.defineProperty(Array.prototype, Symbol.iterator, {
+ value: function*() {
+ yield 1;
+ yield 2;
+ },
+ configurable: true
+ });
+
+ var it = a[Symbol.iterator];
+ Object.defineProperty(a, Symbol.iterator, {
+ get: function() {
+ called++;
+ return it;
+ }
+ });
+
+ countArgs(...a);
+
+ assertEquals(1, called);
+})();

Powered by Google App Engine
This is Rietveld 408576698