OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 assertEquals(object[1], "one"); | 431 assertEquals(object[1], "one"); |
432 assertThrows(function() { delete_element(object, "7"); }, TypeError); | 432 assertThrows(function() { delete_element(object, "7"); }, TypeError); |
433 assertThrows(function() { delete_element(object, 7); }, TypeError); | 433 assertThrows(function() { delete_element(object, 7); }, TypeError); |
434 assertEquals(object[7], "seven"); | 434 assertEquals(object[7], "seven"); |
435 assertThrows(function() { delete_element(object, "3.14"); }, TypeError); | 435 assertThrows(function() { delete_element(object, "3.14"); }, TypeError); |
436 assertThrows(function() { delete_element(object, 3.14); }, TypeError); | 436 assertThrows(function() { delete_element(object, 3.14); }, TypeError); |
437 assertEquals(object[3.14], "pi"); | 437 assertEquals(object[3.14], "pi"); |
438 })(); | 438 })(); |
439 | 439 |
440 // Not transforming this in Function.call and Function.apply. | 440 // Not transforming this in Function.call and Function.apply. |
441 (function testThisTransform() { | 441 (function testThisTransformCallApply() { |
442 function non_strict() { | 442 function non_strict() { |
443 return this; | 443 return this; |
444 } | 444 } |
445 function strict() { | 445 function strict() { |
446 "use strict"; | 446 "use strict"; |
447 return this; | 447 return this; |
448 } | 448 } |
449 | 449 |
450 var global_object = (function() { return this; })(); | 450 var global_object = (function() { return this; })(); |
451 var object = {}; | 451 var object = {}; |
(...skipping 19 matching lines...) Expand all Loading... |
471 assertEquals(typeof strict.call("Hello"), "string"); | 471 assertEquals(typeof strict.call("Hello"), "string"); |
472 assertTrue(strict.call(object) === object); | 472 assertTrue(strict.call(object) === object); |
473 | 473 |
474 // Strict apply. | 474 // Strict apply. |
475 assertTrue(strict.apply(null) === null); | 475 assertTrue(strict.apply(null) === null); |
476 assertTrue(strict.apply(undefined) === undefined); | 476 assertTrue(strict.apply(undefined) === undefined); |
477 assertEquals(typeof strict.apply(7), "number"); | 477 assertEquals(typeof strict.apply(7), "number"); |
478 assertEquals(typeof strict.apply("Hello"), "string"); | 478 assertEquals(typeof strict.apply("Hello"), "string"); |
479 assertTrue(strict.apply(object) === object); | 479 assertTrue(strict.apply(object) === object); |
480 })(); | 480 })(); |
| 481 |
| 482 (function testThisTransform() { |
| 483 try { |
| 484 function strict() { |
| 485 "use strict"; |
| 486 return typeof(this); |
| 487 } |
| 488 function nonstrict() { |
| 489 return typeof(this); |
| 490 } |
| 491 |
| 492 // Concat to avoid symbol. |
| 493 var strict_name = "str" + "ict"; |
| 494 var nonstrict_name = "non" + "str" + "ict"; |
| 495 var strict_number = 1943; |
| 496 var nonstrict_number = 1974; |
| 497 |
| 498 function install(t) { |
| 499 t.prototype.strict = strict; |
| 500 t.prototype.nonstrict = nonstrict; |
| 501 t.prototype[strict_number] = strict; |
| 502 t.prototype[nonstrict_number] = nonstrict; |
| 503 } |
| 504 |
| 505 function cleanup(t) { |
| 506 delete t.prototype.strict; |
| 507 delete t.prototype.nonstrict; |
| 508 delete t.prototype[strict_number]; |
| 509 delete t.prototype[nonstrict_number]; |
| 510 } |
| 511 |
| 512 // Set up fakes |
| 513 install(String); |
| 514 install(Number); |
| 515 install(Boolean) |
| 516 |
| 517 function callStrict(o) { |
| 518 return o.strict(); |
| 519 } |
| 520 function callNonStrict(o) { |
| 521 return o.nonstrict(); |
| 522 } |
| 523 function callKeyedStrict(o) { |
| 524 return o[strict_name](); |
| 525 } |
| 526 function callKeyedNonStrict(o) { |
| 527 return o[nonstrict_name](); |
| 528 } |
| 529 function callIndexedStrict(o) { |
| 530 return o[strict_number](); |
| 531 } |
| 532 function callIndexedNonStrict(o) { |
| 533 return o[nonstrict_number](); |
| 534 } |
| 535 |
| 536 for (var i = 0; i < 10; i ++) { |
| 537 assertEquals(("hello").strict(), "string"); |
| 538 assertEquals(("hello").nonstrict(), "object"); |
| 539 assertEquals(("hello")[strict_name](), "string"); |
| 540 assertEquals(("hello")[nonstrict_name](), "object"); |
| 541 assertEquals(("hello")[strict_number](), "string"); |
| 542 assertEquals(("hello")[nonstrict_number](), "object"); |
| 543 |
| 544 assertEquals((10 + i).strict(), "number"); |
| 545 assertEquals((10 + i).nonstrict(), "object"); |
| 546 assertEquals((10 + i)[strict_name](), "number"); |
| 547 assertEquals((10 + i)[nonstrict_name](), "object"); |
| 548 assertEquals((10 + i)[strict_number](), "number"); |
| 549 assertEquals((10 + i)[nonstrict_number](), "object"); |
| 550 |
| 551 assertEquals((true).strict(), "boolean"); |
| 552 assertEquals((true).nonstrict(), "object"); |
| 553 assertEquals((true)[strict_name](), "boolean"); |
| 554 assertEquals((true)[nonstrict_name](), "object"); |
| 555 assertEquals((true)[strict_number](), "boolean"); |
| 556 assertEquals((true)[nonstrict_number](), "object"); |
| 557 |
| 558 assertEquals((false).strict(), "boolean"); |
| 559 assertEquals((false).nonstrict(), "object"); |
| 560 assertEquals((false)[strict_name](), "boolean"); |
| 561 assertEquals((false)[nonstrict_name](), "object"); |
| 562 assertEquals((false)[strict_number](), "boolean"); |
| 563 assertEquals((false)[nonstrict_number](), "object"); |
| 564 |
| 565 assertEquals(callStrict("howdy"), "string"); |
| 566 assertEquals(callNonStrict("howdy"), "object"); |
| 567 assertEquals(callKeyedStrict("howdy"), "string"); |
| 568 assertEquals(callKeyedNonStrict("howdy"), "object"); |
| 569 assertEquals(callIndexedStrict("howdy"), "string"); |
| 570 assertEquals(callIndexedNonStrict("howdy"), "object"); |
| 571 |
| 572 assertEquals(callStrict(17 + i), "number"); |
| 573 assertEquals(callNonStrict(17 + i), "object"); |
| 574 assertEquals(callKeyedStrict(17 + i), "number"); |
| 575 assertEquals(callKeyedNonStrict(17 + i), "object"); |
| 576 assertEquals(callIndexedStrict(17 + i), "number"); |
| 577 assertEquals(callIndexedNonStrict(17 + i), "object"); |
| 578 |
| 579 assertEquals(callStrict(true), "boolean"); |
| 580 assertEquals(callNonStrict(true), "object"); |
| 581 assertEquals(callKeyedStrict(true), "boolean"); |
| 582 assertEquals(callKeyedNonStrict(true), "object"); |
| 583 assertEquals(callIndexedStrict(true), "boolean"); |
| 584 assertEquals(callIndexedNonStrict(true), "object"); |
| 585 |
| 586 assertEquals(callStrict(false), "boolean"); |
| 587 assertEquals(callNonStrict(false), "object"); |
| 588 assertEquals(callKeyedStrict(false), "boolean"); |
| 589 assertEquals(callKeyedNonStrict(false), "object"); |
| 590 assertEquals(callIndexedStrict(false), "boolean"); |
| 591 assertEquals(callIndexedNonStrict(false), "object"); |
| 592 } |
| 593 } finally { |
| 594 // Cleanup |
| 595 cleanup(String); |
| 596 cleanup(Number); |
| 597 cleanup(Boolean); |
| 598 } |
| 599 })(); |
OLD | NEW |