| OLD | NEW |
| 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 Loading... |
| 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 testArrayIteratorPrototypeGetter() { |
| 350 function countArgs() { return arguments.length; } |
| 351 var a = [1, 2, 3]; |
| 352 var ai = a[Symbol.iterator](); |
| 353 var called = 0; |
| 354 |
| 355 var original_next = ai.__proto__["next"]; |
| 356 |
| 357 Object.defineProperty(ai.__proto__, "next", { |
| 358 get: function() { |
| 359 called++; |
| 360 return original_next; |
| 361 } |
| 362 }); |
| 363 |
| 364 countArgs(...a); |
| 365 |
| 366 // should be called 4 times; 3 for the values, 1 for the final |
| 367 // {value: undefined, done: true} pair |
| 368 assertEquals(4, called); |
| 369 })(); |
| 370 |
| 371 (function testArrayIteratorPrototypeModified() { |
| 372 function countArgs() { return arguments.length; } |
| 373 var a = [1,2,3]; |
| 374 var ai = a[Symbol.iterator](); |
| 375 Object.defineProperty(ai.__proto__, "next", { |
| 376 value: function() { |
| 377 return {value: undefined, done: true}; |
| 378 }, |
| 379 configurable: true |
| 380 }); |
| 381 |
| 382 assertEquals(0, countArgs(...a)); |
| 383 |
| 384 })(); |
| 349 | 385 |
| 350 (function testCustomArrayPrototypeIterator() { | 386 (function testCustomArrayPrototypeIterator() { |
| 351 var origIterator = | 387 var origIterator = |
| 352 Object.getOwnPropertyDescriptor(Array.prototype, Symbol.iterator); | 388 Object.getOwnPropertyDescriptor(Array.prototype, Symbol.iterator); |
| 353 Object.defineProperty(Array.prototype, Symbol.iterator, { | 389 Object.defineProperty(Array.prototype, Symbol.iterator, { |
| 354 value: function*() { | 390 value: function*() { |
| 355 yield 1; | 391 yield 1; |
| 356 yield 2; | 392 yield 2; |
| 357 yield 3; | 393 yield 3; |
| 358 }, | 394 }, |
| 359 configurable: true | 395 configurable: true |
| 360 }); | 396 }); |
| 361 function returnCountStrict() { 'use strict'; return arguments.length; } | 397 function returnCountStrict() { 'use strict'; return arguments.length; } |
| 362 function returnCountSloppy() { return arguments.length; } | 398 function returnCountSloppy() { return arguments.length; } |
| 363 | 399 |
| 364 assertEquals(3, returnCountStrict(...[1])); | 400 assertEquals(3, returnCountStrict(...[1])); |
| 365 assertEquals(4, returnCountStrict(1, ...[2])); | 401 assertEquals(4, returnCountStrict(1, ...[2])); |
| 366 assertEquals(5, returnCountStrict(1, ...[2], 3)); | 402 assertEquals(5, returnCountStrict(1, ...[2], 3)); |
| 367 assertEquals(3, returnCountSloppy(...[1])); | 403 assertEquals(3, returnCountSloppy(...[1])); |
| 368 assertEquals(4, returnCountSloppy(1, ...[2])); | 404 assertEquals(4, returnCountSloppy(1, ...[2])); |
| 369 assertEquals(5, returnCountSloppy(1, ...[2], 3)); | 405 assertEquals(5, returnCountSloppy(1, ...[2], 3)); |
| 370 | 406 |
| 371 Object.defineProperty(Array.prototype, Symbol.iterator, origIterator); | 407 Object.defineProperty(Array.prototype, Symbol.iterator, origIterator); |
| 372 })(); | 408 })(); |
| 409 |
| 410 (function testGetPropertyIteratorCalledExactlyOnce() { |
| 411 function countArgs() { return arguments.length; } |
| 412 var a = [1, 2, 3]; |
| 413 var called = 0; |
| 414 |
| 415 Object.defineProperty(Array.prototype, Symbol.iterator, { |
| 416 value: function*() { |
| 417 yield 1; |
| 418 yield 2; |
| 419 }, |
| 420 configurable: true |
| 421 }); |
| 422 |
| 423 var it = a[Symbol.iterator]; |
| 424 Object.defineProperty(a, Symbol.iterator, { |
| 425 get: function() { |
| 426 called++; |
| 427 return it; |
| 428 } |
| 429 }); |
| 430 |
| 431 countArgs(...a); |
| 432 |
| 433 assertEquals(1, called); |
| 434 })(); |
| OLD | NEW |