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

Side by Side Diff: test/mjsunit/strict-mode.js

Issue 6523052: CallIC and KeyedCallIC not wrapping this. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Last touches. Created 9 years, 10 months 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 | Annotate | Revision Log
« src/ic.cc ('K') | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 = 17;
496 var nonstrict_number = 19;
497 var strict_name_get = "str" + "ict" + "get";
498 var nonstrict_name_get = "non" + "str" + "ict" + "get"
499 var strict_number_get = 23;
500 var nonstrict_number_get = 29;
501
502 function install(t) {
503 t.prototype.strict = strict;
504 t.prototype.nonstrict = nonstrict;
505 t.prototype[strict_number] = strict;
506 t.prototype[nonstrict_number] = nonstrict;
507 Object.defineProperty(t.prototype, strict_name_get,
508 { get: function() { return strict; },
509 configurable: true });
510 Object.defineProperty(t.prototype, nonstrict_name_get,
511 { get: function() { return nonstrict; },
512 configurable: true });
513 Object.defineProperty(t.prototype, strict_number_get,
514 { get: function() { return strict; },
515 configurable: true });
516 Object.defineProperty(t.prototype, nonstrict_number_get,
517 { get: function() { return nonstrict; },
518 configurable: true });
519 }
520
521 function cleanup(t) {
522 delete t.prototype.strict;
523 delete t.prototype.nonstrict;
524 delete t.prototype[strict_number];
525 delete t.prototype[nonstrict_number];
526 delete t.prototype[strict_name_get];
527 delete t.prototype[nonstrict_name_get];
528 delete t.prototype[strict_number_get];
529 delete t.prototype[nonstrict_number_get];
530 }
531
532 // Set up fakes
533 install(String);
534 install(Number);
535 install(Boolean)
536
537 function callStrict(o) {
538 return o.strict();
539 }
540 function callNonStrict(o) {
541 return o.nonstrict();
542 }
543 function callKeyedStrict(o) {
544 return o[strict_name]();
545 }
546 function callKeyedNonStrict(o) {
547 return o[nonstrict_name]();
548 }
549 function callIndexedStrict(o) {
550 return o[strict_number]();
551 }
552 function callIndexedNonStrict(o) {
553 return o[nonstrict_number]();
554 }
555 function callStrictGet(o) {
556 return o.strictget();
557 }
558 function callNonStrictGet(o) {
559 return o.nonstrictget();
560 }
561 function callKeyedStrictGet(o) {
562 return o[strict_name_get]();
563 }
564 function callKeyedNonStrictGet(o) {
565 return o[nonstrict_name_get]();
566 }
567 function callIndexedStrictGet(o) {
568 return o[strict_number_get]();
569 }
570 function callIndexedNonStrictGet(o) {
571 return o[nonstrict_number_get]();
572 }
573
574 for (var i = 0; i < 10; i ++) {
575 assertEquals(("hello").strict(), "string");
576 assertEquals(("hello").nonstrict(), "object");
577 assertEquals(("hello")[strict_name](), "string");
578 assertEquals(("hello")[nonstrict_name](), "object");
579 assertEquals(("hello")[strict_number](), "string");
580 assertEquals(("hello")[nonstrict_number](), "object");
581
582 assertEquals((10 + i).strict(), "number");
583 assertEquals((10 + i).nonstrict(), "object");
584 assertEquals((10 + i)[strict_name](), "number");
585 assertEquals((10 + i)[nonstrict_name](), "object");
586 assertEquals((10 + i)[strict_number](), "number");
587 assertEquals((10 + i)[nonstrict_number](), "object");
588
589 assertEquals((true).strict(), "boolean");
590 assertEquals((true).nonstrict(), "object");
591 assertEquals((true)[strict_name](), "boolean");
592 assertEquals((true)[nonstrict_name](), "object");
593 assertEquals((true)[strict_number](), "boolean");
594 assertEquals((true)[nonstrict_number](), "object");
595
596 assertEquals((false).strict(), "boolean");
597 assertEquals((false).nonstrict(), "object");
598 assertEquals((false)[strict_name](), "boolean");
599 assertEquals((false)[nonstrict_name](), "object");
600 assertEquals((false)[strict_number](), "boolean");
601 assertEquals((false)[nonstrict_number](), "object");
602
603 assertEquals(callStrict("howdy"), "string");
604 assertEquals(callNonStrict("howdy"), "object");
605 assertEquals(callKeyedStrict("howdy"), "string");
606 assertEquals(callKeyedNonStrict("howdy"), "object");
607 assertEquals(callIndexedStrict("howdy"), "string");
608 assertEquals(callIndexedNonStrict("howdy"), "object");
609
610 assertEquals(callStrict(17 + i), "number");
611 assertEquals(callNonStrict(17 + i), "object");
612 assertEquals(callKeyedStrict(17 + i), "number");
613 assertEquals(callKeyedNonStrict(17 + i), "object");
614 assertEquals(callIndexedStrict(17 + i), "number");
615 assertEquals(callIndexedNonStrict(17 + i), "object");
616
617 assertEquals(callStrict(true), "boolean");
618 assertEquals(callNonStrict(true), "object");
619 assertEquals(callKeyedStrict(true), "boolean");
620 assertEquals(callKeyedNonStrict(true), "object");
621 assertEquals(callIndexedStrict(true), "boolean");
622 assertEquals(callIndexedNonStrict(true), "object");
623
624 assertEquals(callStrict(false), "boolean");
625 assertEquals(callNonStrict(false), "object");
626 assertEquals(callKeyedStrict(false), "boolean");
627 assertEquals(callKeyedNonStrict(false), "object");
628 assertEquals(callIndexedStrict(false), "boolean");
629 assertEquals(callIndexedNonStrict(false), "object");
630
631 // All of the above, with getters
632 assertEquals(("hello").strictget(), "string");
633 assertEquals(("hello").nonstrictget(), "object");
634 assertEquals(("hello")[strict_name_get](), "string");
635 assertEquals(("hello")[nonstrict_name_get](), "object");
636 assertEquals(("hello")[strict_number_get](), "string");
637 assertEquals(("hello")[nonstrict_number_get](), "object");
638
639 assertEquals((10 + i).strictget(), "number");
640 assertEquals((10 + i).nonstrictget(), "object");
641 assertEquals((10 + i)[strict_name_get](), "number");
642 assertEquals((10 + i)[nonstrict_name_get](), "object");
643 assertEquals((10 + i)[strict_number_get](), "number");
644 assertEquals((10 + i)[nonstrict_number_get](), "object");
645
646 assertEquals((true).strictget(), "boolean");
647 assertEquals((true).nonstrictget(), "object");
648 assertEquals((true)[strict_name_get](), "boolean");
649 assertEquals((true)[nonstrict_name_get](), "object");
650 assertEquals((true)[strict_number_get](), "boolean");
651 assertEquals((true)[nonstrict_number_get](), "object");
652
653 assertEquals((false).strictget(), "boolean");
654 assertEquals((false).nonstrictget(), "object");
655 assertEquals((false)[strict_name_get](), "boolean");
656 assertEquals((false)[nonstrict_name_get](), "object");
657 assertEquals((false)[strict_number_get](), "boolean");
658 assertEquals((false)[nonstrict_number_get](), "object");
659
660 assertEquals(callStrictGet("howdy"), "string");
661 assertEquals(callNonStrictGet("howdy"), "object");
662 assertEquals(callKeyedStrictGet("howdy"), "string");
663 assertEquals(callKeyedNonStrictGet("howdy"), "object");
664 assertEquals(callIndexedStrictGet("howdy"), "string");
665 assertEquals(callIndexedNonStrictGet("howdy"), "object");
666
667 assertEquals(callStrictGet(17 + i), "number");
668 assertEquals(callNonStrictGet(17 + i), "object");
669 assertEquals(callKeyedStrictGet(17 + i), "number");
670 assertEquals(callKeyedNonStrictGet(17 + i), "object");
671 assertEquals(callIndexedStrictGet(17 + i), "number");
672 assertEquals(callIndexedNonStrictGet(17 + i), "object");
673
674 assertEquals(callStrictGet(true), "boolean");
675 assertEquals(callNonStrictGet(true), "object");
676 assertEquals(callKeyedStrictGet(true), "boolean");
677 assertEquals(callKeyedNonStrictGet(true), "object");
678 assertEquals(callIndexedStrictGet(true), "boolean");
679 assertEquals(callIndexedNonStrictGet(true), "object");
680
681 assertEquals(callStrictGet(false), "boolean");
682 assertEquals(callNonStrictGet(false), "object");
683 assertEquals(callKeyedStrictGet(false), "boolean");
684 assertEquals(callKeyedNonStrictGet(false), "object");
685 assertEquals(callIndexedStrictGet(false), "boolean");
686 assertEquals(callIndexedNonStrictGet(false), "object");
687
688 }
689 } finally {
690 // Cleanup
691 cleanup(String);
692 cleanup(Number);
693 cleanup(Boolean);
694 }
695 })();
OLDNEW
« src/ic.cc ('K') | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698