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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function testSpreadCallsStrict() { 5 (function testSpreadCallsStrict() {
6 "use strict" 6 "use strict"
7 function countArgs() { return arguments.length; } 7 function countArgs() { return arguments.length; }
8 8
9 // Test this argument 9 // Test this argument
10 function returnThis() { return this; } 10 function returnThis() { return this; }
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 result = fn(a(), ...b(), ...c(), d(), e()); 339 result = fn(a(), ...b(), ...c(), d(), e());
340 assertEquals([undefined, 0, 1, undefined, undefined], result); 340 assertEquals([undefined, 0, 1, undefined, undefined], result);
341 assertEquals("ABXYC1C2DE", log); 341 assertEquals("ABXYC1C2DE", log);
342 342
343 log = ""; 343 log = "";
344 result = fn(a(), ...b(), ...c(), d(), e(), ...b(), ...c()); 344 result = fn(a(), ...b(), ...c(), d(), e(), ...b(), ...c());
345 assertEquals([undefined, 0, 1, undefined, undefined, 0, 1], result); 345 assertEquals([undefined, 0, 1, undefined, undefined, 0, 1], result);
346 assertEquals("ABXYC1C2DEBXYC1C2", log); 346 assertEquals("ABXYC1C2DEBXYC1C2", log);
347 })(); 347 })();
348 348
349 (function testArrayPrototypeHoleGetterModifiesIteratorPrototypeNext() {
350 function sum() {
351 var sum = arguments[0];
352 for (var i = 1; i < arguments.length; ++i) {
353 sum += arguments[i];
354 }
355 return sum;
356 }
357 var a = [1, 2];
358 a[3] = 4;
359 var called = 0;
360
361 Object.defineProperty(Array.prototype, 2, {
362 get: function() {
363 var ai = a[Symbol.iterator]();
364 var original_next = ai.__proto__["next"];
365 Object.defineProperty(ai.__proto__, "next", {
366 get: function() {
367 called++;
368 return original_next;
369 }
370 });
371 return 3;
372 }
373 });
374
375 assertEquals(10, sum(...a));
376 assertEquals(2, called);
377 })();
378
379 (function testArrayHasOtherPrototype() {
380 function countArgs() { return arguments.length; }
381 var a = [1, 2, 3];
382 var b = {};
383 Object.defineProperty(b, Symbol.iterator, {
384 value: function*() {
385 yield 4;
386 },
387 configurable: true
388 });
389
390 Object.setPrototypeOf(a, b);
391
392 assertEquals(1, countArgs(...a));
393 })();
394
395 (function testArrayIteratorPrototypeGetter() {
396 function countArgs() { return arguments.length; }
397 var a = [1, 2, 3];
398 var ai = a[Symbol.iterator]();
399 var called = 0;
400
401 var original_next = ai.__proto__["next"];
402
403 Object.defineProperty(ai.__proto__, "next", {
404 get: function() {
405 called++;
406 return original_next;
407 }
408 });
409
410 countArgs(...a);
411
412 // should be called 4 times; 3 for the values, 1 for the final
413 // {value: undefined, done: true} pair
414 assertEquals(4, called);
415 })();
416
417 (function testArrayIteratorPrototypeModified() {
418 function countArgs() { return arguments.length; }
419 var a = [1,2,3];
420 var ai = a[Symbol.iterator]();
421 Object.defineProperty(ai.__proto__, "next", {
422 value: function() {
423 return {value: undefined, done: true};
424 },
425 configurable: true
426 });
427
428 assertEquals(0, countArgs(...a));
429
430 })();
349 431
350 (function testCustomArrayPrototypeIterator() { 432 (function testCustomArrayPrototypeIterator() {
351 var origIterator = 433 var origIterator =
352 Object.getOwnPropertyDescriptor(Array.prototype, Symbol.iterator); 434 Object.getOwnPropertyDescriptor(Array.prototype, Symbol.iterator);
353 Object.defineProperty(Array.prototype, Symbol.iterator, { 435 Object.defineProperty(Array.prototype, Symbol.iterator, {
354 value: function*() { 436 value: function*() {
355 yield 1; 437 yield 1;
356 yield 2; 438 yield 2;
357 yield 3; 439 yield 3;
358 }, 440 },
359 configurable: true 441 configurable: true
360 }); 442 });
361 function returnCountStrict() { 'use strict'; return arguments.length; } 443 function returnCountStrict() { 'use strict'; return arguments.length; }
362 function returnCountSloppy() { return arguments.length; } 444 function returnCountSloppy() { return arguments.length; }
363 445
364 assertEquals(3, returnCountStrict(...[1])); 446 assertEquals(3, returnCountStrict(...[1]));
365 assertEquals(4, returnCountStrict(1, ...[2])); 447 assertEquals(4, returnCountStrict(1, ...[2]));
366 assertEquals(5, returnCountStrict(1, ...[2], 3)); 448 assertEquals(5, returnCountStrict(1, ...[2], 3));
367 assertEquals(3, returnCountSloppy(...[1])); 449 assertEquals(3, returnCountSloppy(...[1]));
368 assertEquals(4, returnCountSloppy(1, ...[2])); 450 assertEquals(4, returnCountSloppy(1, ...[2]));
369 assertEquals(5, returnCountSloppy(1, ...[2], 3)); 451 assertEquals(5, returnCountSloppy(1, ...[2], 3));
370 452
371 Object.defineProperty(Array.prototype, Symbol.iterator, origIterator); 453 Object.defineProperty(Array.prototype, Symbol.iterator, origIterator);
372 })(); 454 })();
455
456 (function testGetPropertyIteratorCalledExactlyOnce() {
457 function countArgs() { return arguments.length; }
458 var a = [1, 2, 3];
459 var called = 0;
460
461 Object.defineProperty(Array.prototype, Symbol.iterator, {
462 value: function*() {
463 yield 1;
464 yield 2;
465 },
466 configurable: true
467 });
468
469 var it = a[Symbol.iterator];
470 Object.defineProperty(a, Symbol.iterator, {
471 get: function() {
472 called++;
473 return it;
474 }
475 });
476
477 countArgs(...a);
478
479 assertEquals(1, called);
480 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698