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 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 get: function(pr, pk) { throw "myexn" } | 565 get: function(pr, pk) { throw "myexn" } |
566 })) | 566 })) |
567 | 567 |
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 rec |
575 var key | 576 var key |
576 var val | 577 var val |
577 | 578 |
578 function TestSetForDerived(handler) { | 579 function TestSetForDerived(handler) { |
579 TestWithProxies(TestSetForDerived2, handler) | 580 TestWithProxies(TestSetForDerived2, handler) |
580 } | 581 } |
581 | 582 |
582 function TestSetForDerived2(create, handler) { | 583 function TestSetForDerived2(create, handler) { |
583 var p = create(handler) | 584 var p = create(handler) |
584 var o = Object.create(p, {x: {value: 88, writable: true}, | 585 var o = Object.create(p, {x: {value: 88, writable: true}, |
(...skipping 19 matching lines...) Expand all Loading... |
604 assertEquals(44, o.p_writable = 44) | 605 assertEquals(44, o.p_writable = 44) |
605 assertEquals("p_writable", key) | 606 assertEquals("p_writable", key) |
606 assertEquals(44, o.p_writable) | 607 assertEquals(44, o.p_writable) |
607 | 608 |
608 assertEquals(45, o.p_nonwritable = 45) | 609 assertEquals(45, o.p_nonwritable = 45) |
609 assertEquals("p_nonwritable", key) | 610 assertEquals("p_nonwritable", key) |
610 assertEquals(45, o.p_nonwritable) | 611 assertEquals(45, o.p_nonwritable) |
611 | 612 |
612 assertEquals(46, o.p_setter = 46) | 613 assertEquals(46, o.p_setter = 46) |
613 assertEquals("p_setter", key) | 614 assertEquals("p_setter", key) |
| 615 assertSame(o, rec) |
614 assertEquals(46, val) // written to parent | 616 assertEquals(46, val) // written to parent |
615 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_setter")) | 617 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_setter")) |
616 | 618 |
617 val = "" | 619 val = "" |
618 assertEquals(47, o.p_nosetter = 47) | 620 assertEquals(47, o.p_nosetter = 47) |
619 assertEquals("p_nosetter", key) | 621 assertEquals("p_nosetter", key) |
620 assertEquals("", val) // not written at all | 622 assertEquals("", val) // not written at all |
621 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nosetter")); | 623 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nosetter")); |
622 | 624 |
623 key = "" | 625 key = "" |
(...skipping 10 matching lines...) Expand all Loading... |
634 assertThrows(function(){ o.p_setterthrow = 52 }, "myexn") | 636 assertThrows(function(){ o.p_setterthrow = 52 }, "myexn") |
635 assertEquals("p_setterthrow", key) | 637 assertEquals("p_setterthrow", key) |
636 } | 638 } |
637 | 639 |
638 TestSetForDerived({ | 640 TestSetForDerived({ |
639 getPropertyDescriptor: function(k) { | 641 getPropertyDescriptor: function(k) { |
640 key = k; | 642 key = k; |
641 switch (k) { | 643 switch (k) { |
642 case "p_writable": return {writable: true, configurable: true} | 644 case "p_writable": return {writable: true, configurable: true} |
643 case "p_nonwritable": return {writable: false, configurable: true} | 645 case "p_nonwritable": return {writable: false, configurable: true} |
644 case "p_setter":return {set: function(x) { val = x }, configurable: true} | 646 case "p_setter":return { |
645 case "p_nosetter": return {get: function() { return 1 }, configurable: tru
e} | 647 set: function(x) { rec = this; val = x }, |
| 648 configurable: true |
| 649 } |
| 650 case "p_nosetter": return { |
| 651 get: function() { return 1 }, |
| 652 configurable: true |
| 653 } |
646 case "p_nonconf":return {} | 654 case "p_nonconf":return {} |
647 case "p_throw": throw "myexn" | 655 case "p_throw": throw "myexn" |
648 case "p_setterthrow": return {set: function(x) { throw "myexn" }} | 656 case "p_setterthrow": return {set: function(x) { throw "myexn" }} |
649 default: return undefined | 657 default: return undefined |
650 } | 658 } |
651 } | 659 } |
652 }) | 660 }) |
653 | 661 |
654 | 662 |
655 // Evil proxy-induced side-effects shouldn't crash. | 663 // Evil proxy-induced side-effects shouldn't crash. |
(...skipping 1613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2269 function TestConstructorWithProxyPrototype2(create, handler) { | 2277 function TestConstructorWithProxyPrototype2(create, handler) { |
2270 function C() {}; | 2278 function C() {}; |
2271 C.prototype = create(handler); | 2279 C.prototype = create(handler); |
2272 | 2280 |
2273 var o = new C; | 2281 var o = new C; |
2274 assertSame(C.prototype, o.__proto__); | 2282 assertSame(C.prototype, o.__proto__); |
2275 assertSame(C.prototype, Object.getPrototypeOf(o)); | 2283 assertSame(C.prototype, Object.getPrototypeOf(o)); |
2276 } | 2284 } |
2277 | 2285 |
2278 TestConstructorWithProxyPrototype(); | 2286 TestConstructorWithProxyPrototype(); |
OLD | NEW |