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 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 TestSetThrow(Proxy.create({ | 568 TestSetThrow(Proxy.create({ |
569 get: function(pr, pk) { | 569 get: function(pr, pk) { |
570 return function(r, k, v) { throw "myexn" } | 570 return function(r, k, v) { throw "myexn" } |
571 } | 571 } |
572 })) | 572 })) |
573 | 573 |
574 | 574 |
575 var key | 575 var key |
576 var val | 576 var val |
577 | 577 |
578 function TestSetForDerived(handler) { | 578 function TestSetForDerived(trap) { |
579 TestWithProxies(TestSetForDerived2, handler) | 579 TestWithProxies(TestSetForDerived2, trap) |
580 } | 580 } |
581 | 581 |
582 function TestSetForDerived2(create, handler) { | 582 function TestSetForDerived2(create, trap) { |
583 var p = create(handler) | 583 var p = create({getPropertyDescriptor: trap, getOwnPropertyDescriptor: trap}) |
584 var o = Object.create(p, {x: {value: 88, writable: true}, | 584 var o = Object.create(p, {x: {value: 88, writable: true}, |
585 '1': {value: 89, writable: true}}) | 585 '1': {value: 89, writable: true}}) |
586 | 586 |
587 key = "" | 587 key = "" |
588 assertEquals(48, o.x = 48) | 588 assertEquals(48, o.x = 48) |
589 assertEquals("", key) // trap not invoked | 589 assertEquals("", key) // trap not invoked |
590 assertEquals(48, o.x) | 590 assertEquals(48, o.x) |
591 | 591 |
592 assertEquals(47, o[1] = 47) | 592 assertEquals(47, o[1] = 47) |
593 assertEquals("", key) // trap not invoked | 593 assertEquals("", key) // trap not invoked |
594 assertEquals(47, o[1]) | 594 assertEquals(47, o[1]) |
595 | 595 |
596 assertEquals(49, o.y = 49) | 596 assertEquals(49, o.y = 49) |
597 assertEquals("y", key) | 597 assertEquals("y", key) |
598 assertEquals(49, o.y) | 598 assertEquals(49, o.y) |
599 | 599 |
600 assertEquals(50, o[2] = 50) | 600 assertEquals(50, o[2] = 50) |
601 assertEquals("2", key) | 601 assertEquals("2", key) |
602 assertEquals(50, o[2]) | 602 assertEquals(50, o[2]) |
603 | 603 |
604 assertEquals(44, o.p_writable = 44) | 604 assertEquals(44, o.p_writable = 44) |
605 assertEquals("p_writable", key) | 605 assertEquals("p_writable", key) |
606 assertEquals(44, o.p_writable) | 606 assertEquals(44, o.p_writable) |
607 | 607 |
608 assertEquals(45, o.p_nonwritable = 45) | 608 assertEquals(45, o.p_nonwritable = 45) |
609 assertEquals("p_nonwritable", key) | 609 assertEquals("p_nonwritable", key) |
610 assertEquals(45, o.p_nonwritable) | 610 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nonwritable")) |
611 | 611 |
| 612 assertThrows(function(){ "use strict"; o.p_nonwritable = 45 }, TypeError) |
| 613 assertEquals("p_nonwritable", key) |
| 614 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nonwritable")) |
| 615 |
| 616 val = "" |
612 assertEquals(46, o.p_setter = 46) | 617 assertEquals(46, o.p_setter = 46) |
613 assertEquals("p_setter", key) | 618 assertEquals("p_setter", key) |
614 assertEquals(46, val) // written to parent | 619 assertEquals(46, val) // written to parent |
615 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_setter")) | 620 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_setter")) |
616 | 621 |
617 val = "" | 622 val = "" |
618 assertEquals(47, o.p_nosetter = 47) | 623 assertEquals(47, o.p_nosetter = 47) |
619 assertEquals("p_nosetter", key) | 624 assertEquals("p_nosetter", key) |
620 assertEquals("", val) // not written at all | 625 assertEquals("", val) // not written at all |
621 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nosetter")); | 626 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nosetter")); |
622 | 627 |
623 key = "" | 628 key = "" |
624 assertThrows(function(){ "use strict"; o.p_nosetter = 50 }, TypeError) | 629 assertThrows(function(){ "use strict"; o.p_nosetter = 50 }, TypeError) |
625 assertEquals("p_nosetter", key) | 630 assertEquals("p_nosetter", key) |
626 assertEquals("", val) // not written at all | 631 assertEquals("", val) // not written at all |
| 632 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nosetter")); |
627 | 633 |
628 assertThrows(function(){ o.p_nonconf = 53 }, TypeError) | 634 assertThrows(function(){ o.p_nonconf = 53 }, TypeError) |
629 assertEquals("p_nonconf", key) | 635 assertEquals("p_nonconf", key) |
| 636 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nonconf")); |
630 | 637 |
631 assertThrows(function(){ o.p_throw = 51 }, "myexn") | 638 assertThrows(function(){ o.p_throw = 51 }, "myexn") |
632 assertEquals("p_throw", key) | 639 assertEquals("p_throw", key) |
| 640 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_throw")); |
633 | 641 |
634 assertThrows(function(){ o.p_setterthrow = 52 }, "myexn") | 642 assertThrows(function(){ o.p_setterthrow = 52 }, "myexn") |
635 assertEquals("p_setterthrow", key) | 643 assertEquals("p_setterthrow", key) |
| 644 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_setterthrow")); |
636 } | 645 } |
637 | 646 |
638 TestSetForDerived({ | 647 |
639 getPropertyDescriptor: function(k) { | 648 TestSetForDerived( |
| 649 function(k) { |
640 key = k; | 650 key = k; |
641 switch (k) { | 651 switch (k) { |
642 case "p_writable": return {writable: true, configurable: true} | 652 case "p_writable": return {writable: true, configurable: true} |
643 case "p_nonwritable": return {writable: false, configurable: true} | 653 case "p_nonwritable": return {writable: false, configurable: true} |
644 case "p_setter":return {set: function(x) { val = x }, configurable: true} | 654 case "p_setter": return {set: function(x) {val = x}, configurable: true} |
645 case "p_nosetter": return {get: function() { return 1 }, configurable: tru
e} | 655 case "p_nosetter": return {get: function() {return 1}, configurable: true} |
646 case "p_nonconf":return {} | 656 case "p_nonconf": return {} |
647 case "p_throw": throw "myexn" | 657 case "p_throw": throw "myexn" |
648 case "p_setterthrow": return {set: function(x) { throw "myexn" }} | 658 case "p_setterthrow": return {set: function(x) { throw "myexn" }} |
649 default: return undefined | 659 default: return undefined |
650 } | 660 } |
651 } | 661 } |
652 }) | 662 ) |
653 | 663 |
654 | 664 |
655 // Evil proxy-induced side-effects shouldn't crash. | 665 // Evil proxy-induced side-effects shouldn't crash. |
656 // TODO(rossberg): proper behaviour isn't really spec'ed yet, so ignore results. | 666 // TODO(rossberg): proper behaviour isn't really spec'ed yet, so ignore results. |
657 | 667 |
658 TestWithProxies(function(create) { | 668 TestWithProxies(function(create) { |
659 var calls = 0 | 669 var calls = 0 |
660 var handler = { | 670 var handler = { |
661 getPropertyDescriptor: function() { | 671 getPropertyDescriptor: function() { |
662 ++calls | 672 ++calls |
(...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2269 function TestConstructorWithProxyPrototype2(create, handler) { | 2279 function TestConstructorWithProxyPrototype2(create, handler) { |
2270 function C() {}; | 2280 function C() {}; |
2271 C.prototype = create(handler); | 2281 C.prototype = create(handler); |
2272 | 2282 |
2273 var o = new C; | 2283 var o = new C; |
2274 assertSame(C.prototype, o.__proto__); | 2284 assertSame(C.prototype, o.__proto__); |
2275 assertSame(C.prototype, Object.getPrototypeOf(o)); | 2285 assertSame(C.prototype, Object.getPrototypeOf(o)); |
2276 } | 2286 } |
2277 | 2287 |
2278 TestConstructorWithProxyPrototype(); | 2288 TestConstructorWithProxyPrototype(); |
OLD | NEW |