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 15 matching lines...) Expand all Loading... |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --harmony-proxies | 28 // Flags: --harmony-proxies |
29 | 29 |
30 | 30 |
31 // TODO(rossberg): for-in not implemented on proxies. | 31 // TODO(rossberg): for-in not implemented on proxies. |
32 | 32 |
33 | 33 |
34 // Helper. | 34 // Helper. |
35 | 35 |
36 function TestWithProxies(test, handler) { | 36 function TestWithProxies(test, x, y, z) { |
37 test(handler, Proxy.create) | 37 test(Proxy.create, x, y, z) |
38 test(handler, function(h) {return Proxy.createFunction(h, function() {})}) | 38 test(function(h) {return Proxy.createFunction(h, function() {})}, x, y, z) |
39 } | 39 } |
40 | 40 |
41 | 41 |
42 | 42 |
43 // Getting property descriptors (Object.getOwnPropertyDescriptor). | 43 // Getting property descriptors (Object.getOwnPropertyDescriptor). |
44 | 44 |
45 var key | 45 var key |
46 | 46 |
47 function TestGetOwnProperty(handler) { | 47 function TestGetOwnProperty(handler) { |
48 TestWithProxies(TestGetOwnProperty2, handler) | 48 TestWithProxies(TestGetOwnProperty2, handler) |
49 } | 49 } |
50 | 50 |
51 function TestGetOwnProperty2(handler, create) { | 51 function TestGetOwnProperty2(create, handler) { |
52 var p = create(handler) | 52 var p = create(handler) |
53 assertEquals(42, Object.getOwnPropertyDescriptor(p, "a").value) | 53 assertEquals(42, Object.getOwnPropertyDescriptor(p, "a").value) |
54 assertEquals("a", key) | 54 assertEquals("a", key) |
55 assertEquals(42, Object.getOwnPropertyDescriptor(p, 99).value) | 55 assertEquals(42, Object.getOwnPropertyDescriptor(p, 99).value) |
56 assertEquals("99", key) | 56 assertEquals("99", key) |
57 } | 57 } |
58 | 58 |
59 TestGetOwnProperty({ | 59 TestGetOwnProperty({ |
60 getOwnPropertyDescriptor: function(k) { | 60 getOwnPropertyDescriptor: function(k) { |
61 key = k | 61 key = k |
(...skipping 22 matching lines...) Expand all Loading... |
84 get: function(pr, pk) { | 84 get: function(pr, pk) { |
85 return function(k) { key = k; return {value: 42, configurable: true} } | 85 return function(k) { key = k; return {value: 42, configurable: true} } |
86 } | 86 } |
87 })) | 87 })) |
88 | 88 |
89 | 89 |
90 function TestGetOwnPropertyThrow(handler) { | 90 function TestGetOwnPropertyThrow(handler) { |
91 TestWithProxies(TestGetOwnPropertyThrow2, handler) | 91 TestWithProxies(TestGetOwnPropertyThrow2, handler) |
92 } | 92 } |
93 | 93 |
94 function TestGetOwnPropertyThrow2(handler, create) { | 94 function TestGetOwnPropertyThrow2(create, handler) { |
95 var p = create(handler) | 95 var p = create(handler) |
96 assertThrows(function(){ Object.getOwnPropertyDescriptor(p, "a") }, "myexn") | 96 assertThrows(function(){ Object.getOwnPropertyDescriptor(p, "a") }, "myexn") |
97 assertThrows(function(){ Object.getOwnPropertyDescriptor(p, 77) }, "myexn") | 97 assertThrows(function(){ Object.getOwnPropertyDescriptor(p, 77) }, "myexn") |
98 } | 98 } |
99 | 99 |
100 TestGetOwnPropertyThrow({ | 100 TestGetOwnPropertyThrow({ |
101 getOwnPropertyDescriptor: function(k) { throw "myexn" } | 101 getOwnPropertyDescriptor: function(k) { throw "myexn" } |
102 }) | 102 }) |
103 | 103 |
104 TestGetOwnPropertyThrow({ | 104 TestGetOwnPropertyThrow({ |
(...skipping 18 matching lines...) Expand all Loading... |
123 | 123 |
124 | 124 |
125 // Getters (dot, brackets). | 125 // Getters (dot, brackets). |
126 | 126 |
127 var key | 127 var key |
128 | 128 |
129 function TestGet(handler) { | 129 function TestGet(handler) { |
130 TestWithProxies(TestGet2, handler) | 130 TestWithProxies(TestGet2, handler) |
131 } | 131 } |
132 | 132 |
133 function TestGet2(handler, create) { | 133 function TestGet2(create, handler) { |
134 var p = create(handler) | 134 var p = create(handler) |
135 assertEquals(42, p.a) | 135 assertEquals(42, p.a) |
136 assertEquals("a", key) | 136 assertEquals("a", key) |
137 assertEquals(42, p["b"]) | 137 assertEquals(42, p["b"]) |
138 assertEquals("b", key) | 138 assertEquals("b", key) |
139 assertEquals(42, p[99]) | 139 assertEquals(42, p[99]) |
140 assertEquals("99", key) | 140 assertEquals("99", key) |
141 | 141 |
142 var o = Object.create(p, {x: {value: 88}}) | 142 var o = Object.create(p, {x: {value: 88}}) |
143 assertEquals(42, o.a) | 143 assertEquals(42, o.a) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 get: function(pr, pk) { | 184 get: function(pr, pk) { |
185 return function(r, k) { key = k; return 42 } | 185 return function(r, k) { key = k; return 42 } |
186 } | 186 } |
187 })) | 187 })) |
188 | 188 |
189 | 189 |
190 function TestGetCall(handler) { | 190 function TestGetCall(handler) { |
191 TestWithProxies(TestGetCall2, handler) | 191 TestWithProxies(TestGetCall2, handler) |
192 } | 192 } |
193 | 193 |
194 function TestGetCall2(handler, create) { | 194 function TestGetCall2(create, handler) { |
195 var p = create(handler) | 195 var p = create(handler) |
196 assertEquals(55, p.f()) | 196 assertEquals(55, p.f()) |
197 assertEquals(55, p["f"]()) | 197 assertEquals(55, p["f"]()) |
198 assertEquals(55, p.f("unused", "arguments")) | 198 assertEquals(55, p.f("unused", "arguments")) |
199 assertEquals(55, p.f.call(p)) | 199 assertEquals(55, p.f.call(p)) |
200 assertEquals(55, p["f"].call(p)) | 200 assertEquals(55, p["f"].call(p)) |
201 assertEquals(55, p[101].call(p)) | 201 assertEquals(55, p[101].call(p)) |
202 assertEquals(55, p.withargs(45, 5)) | 202 assertEquals(55, p.withargs(45, 5)) |
203 assertEquals(55, p.withargs.call(p, 11, 22)) | 203 assertEquals(55, p.withargs.call(p, 11, 22)) |
204 assertEquals("6655", "66" + p) // calls p.toString | 204 assertEquals("6655", "66" + p) // calls p.toString |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 get: function(pr, pk) { | 270 get: function(pr, pk) { |
271 return function(r, k) { return function() { return 55 } } | 271 return function(r, k) { return function() { return 55 } } |
272 } | 272 } |
273 })) | 273 })) |
274 | 274 |
275 | 275 |
276 function TestGetThrow(handler) { | 276 function TestGetThrow(handler) { |
277 TestWithProxies(TestGetThrow2, handler) | 277 TestWithProxies(TestGetThrow2, handler) |
278 } | 278 } |
279 | 279 |
280 function TestGetThrow2(handler, create) { | 280 function TestGetThrow2(create, handler) { |
281 var p = create(handler) | 281 var p = create(handler) |
282 assertThrows(function(){ p.a }, "myexn") | 282 assertThrows(function(){ p.a }, "myexn") |
283 assertThrows(function(){ p["b"] }, "myexn") | 283 assertThrows(function(){ p["b"] }, "myexn") |
284 assertThrows(function(){ p[3] }, "myexn") | 284 assertThrows(function(){ p[3] }, "myexn") |
285 | 285 |
286 var o = Object.create(p, {x: {value: 88}, '4': {value: 89}}) | 286 var o = Object.create(p, {x: {value: 88}, '4': {value: 89}}) |
287 assertThrows(function(){ o.a }, "myexn") | 287 assertThrows(function(){ o.a }, "myexn") |
288 assertThrows(function(){ o["b"] }, "myexn") | 288 assertThrows(function(){ o["b"] }, "myexn") |
289 assertThrows(function(){ o[3] }, "myexn") | 289 assertThrows(function(){ o[3] }, "myexn") |
290 assertEquals(88, o.x) | 290 assertEquals(88, o.x) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 } | 331 } |
332 })) | 332 })) |
333 | 333 |
334 | 334 |
335 | 335 |
336 // Setters. | 336 // Setters. |
337 | 337 |
338 var key | 338 var key |
339 var val | 339 var val |
340 | 340 |
341 function TestSet(handler, create) { | 341 function TestSet(handler) { |
342 TestWithProxies(TestSet2, handler) | 342 TestWithProxies(TestSet2, handler) |
343 } | 343 } |
344 | 344 |
345 function TestSet2(handler, create) { | 345 function TestSet2(create, handler) { |
346 var p = create(handler) | 346 var p = create(handler) |
347 assertEquals(42, p.a = 42) | 347 assertEquals(42, p.a = 42) |
348 assertEquals("a", key) | 348 assertEquals("a", key) |
349 assertEquals(42, val) | 349 assertEquals(42, val) |
350 assertEquals(43, p["b"] = 43) | 350 assertEquals(43, p["b"] = 43) |
351 assertEquals("b", key) | 351 assertEquals("b", key) |
352 assertEquals(43, val) | 352 assertEquals(43, val) |
353 assertEquals(44, p[77] = 44) | 353 assertEquals(44, p[77] = 44) |
354 assertEquals("77", key) | 354 assertEquals("77", key) |
355 assertEquals(44, val) | 355 assertEquals(44, val) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 defineProperty: function(k, desc) { key = k, val = desc.value } | 418 defineProperty: function(k, desc) { key = k, val = desc.value } |
419 }) | 419 }) |
420 | 420 |
421 TestSet(Proxy.create({ | 421 TestSet(Proxy.create({ |
422 get: function(pr, pk) { | 422 get: function(pr, pk) { |
423 return function(r, k, v) { key = k; val = v; return true } | 423 return function(r, k, v) { key = k; val = v; return true } |
424 } | 424 } |
425 })) | 425 })) |
426 | 426 |
427 | 427 |
428 function TestSetThrow(handler, create) { | 428 function TestSetThrow(handler) { |
429 TestWithProxies(TestSetThrow2, handler) | 429 TestWithProxies(TestSetThrow2, handler) |
430 } | 430 } |
431 | 431 |
432 function TestSetThrow2(handler, create) { | 432 function TestSetThrow2(create, handler) { |
433 var p = create(handler) | 433 var p = create(handler) |
434 assertThrows(function(){ p.a = 42 }, "myexn") | 434 assertThrows(function(){ p.a = 42 }, "myexn") |
435 assertThrows(function(){ p["b"] = 42 }, "myexn") | 435 assertThrows(function(){ p["b"] = 42 }, "myexn") |
436 assertThrows(function(){ p[22] = 42 }, "myexn") | 436 assertThrows(function(){ p[22] = 42 }, "myexn") |
437 } | 437 } |
438 | 438 |
439 TestSetThrow({ | 439 TestSetThrow({ |
440 set: function(r, k, v) { throw "myexn" } | 440 set: function(r, k, v) { throw "myexn" } |
441 }) | 441 }) |
442 | 442 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 TestSetThrow(Proxy.create({ | 541 TestSetThrow(Proxy.create({ |
542 get: function(pr, pk) { | 542 get: function(pr, pk) { |
543 return function(r, k, v) { throw "myexn" } | 543 return function(r, k, v) { throw "myexn" } |
544 } | 544 } |
545 })) | 545 })) |
546 | 546 |
547 | 547 |
548 var key | 548 var key |
549 var val | 549 var val |
550 | 550 |
551 function TestSetForDerived(handler, create) { | 551 function TestSetForDerived(handler) { |
552 TestWithProxies(TestSetForDerived2, handler) | 552 TestWithProxies(TestSetForDerived2, handler) |
553 } | 553 } |
554 | 554 |
555 function TestSetForDerived2(handler, create) { | 555 function TestSetForDerived2(create, handler) { |
556 var p = create(handler) | 556 var p = create(handler) |
557 var o = Object.create(p, {x: {value: 88, writable: true}, | 557 var o = Object.create(p, {x: {value: 88, writable: true}, |
558 '1': {value: 89, writable: true}}) | 558 '1': {value: 89, writable: true}}) |
559 | 559 |
560 key = "" | 560 key = "" |
561 assertEquals(48, o.x = 48) | 561 assertEquals(48, o.x = 48) |
562 assertEquals("", key) // trap not invoked | 562 assertEquals("", key) // trap not invoked |
563 assertEquals(48, o.x) | 563 assertEquals(48, o.x) |
564 | 564 |
565 assertEquals(47, o[1] = 47) | 565 assertEquals(47, o[1] = 47) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 case "p_nosetter": return {get: function() { return 1 }, configurable: tru
e} | 618 case "p_nosetter": return {get: function() { return 1 }, configurable: tru
e} |
619 case "p_nonconf":return {} | 619 case "p_nonconf":return {} |
620 case "p_throw": throw "myexn" | 620 case "p_throw": throw "myexn" |
621 case "p_setterthrow": return {set: function(x) { throw "myexn" }} | 621 case "p_setterthrow": return {set: function(x) { throw "myexn" }} |
622 default: return undefined | 622 default: return undefined |
623 } | 623 } |
624 } | 624 } |
625 }) | 625 }) |
626 | 626 |
627 | 627 |
| 628 // Evil proxy-induced side-effects shouldn't crash. |
| 629 // TODO(rossberg): proper behaviour isn't really spec'ed yet, so ignore results. |
| 630 |
| 631 TestWithProxies(function(create) { |
| 632 var calls = 0 |
| 633 var handler = { |
| 634 getPropertyDescriptor: function() { |
| 635 ++calls |
| 636 return (calls % 2 == 1) |
| 637 ? {get: function() { return 5 }, configurable: true} |
| 638 : {set: function() { return false }, configurable: true} |
| 639 } |
| 640 } |
| 641 var p = create(handler) |
| 642 var o = Object.create(p) |
| 643 // Make proxy prototype property read-only after CanPut check. |
| 644 try { o.x = 4 } catch (e) { assertInstanceof(e, Error) } |
| 645 }) |
| 646 |
| 647 TestWithProxies(function(create) { |
| 648 var handler = { |
| 649 getPropertyDescriptor: function() { |
| 650 Object.defineProperty(o, "x", {get: function() { return 5 }}); |
| 651 return {set: function() {}} |
| 652 } |
| 653 } |
| 654 var p = create(handler) |
| 655 var o = Object.create(p) |
| 656 // Make object property read-only after CanPut check. |
| 657 try { o.x = 4 } catch (e) { assertInstanceof(e, Error) } |
| 658 }) |
| 659 |
| 660 |
| 661 |
628 // TODO(rossberg): TestSetReject, returning false | 662 // TODO(rossberg): TestSetReject, returning false |
629 // TODO(rossberg): TestGetProperty, TestSetProperty | 663 // TODO(rossberg): TestGetProperty, TestSetProperty |
630 | 664 |
631 | 665 |
632 | 666 |
633 // Property definition (Object.defineProperty and Object.defineProperties). | 667 // Property definition (Object.defineProperty and Object.defineProperties). |
634 | 668 |
635 var key | 669 var key |
636 var desc | 670 var desc |
637 | 671 |
638 function TestDefine(handler) { | 672 function TestDefine(handler) { |
639 TestWithProxies(TestDefine2, handler) | 673 TestWithProxies(TestDefine2, handler) |
640 } | 674 } |
641 | 675 |
642 function TestDefine2(handler, create) { | 676 function TestDefine2(create, handler) { |
643 var p = create(handler) | 677 var p = create(handler) |
644 assertEquals(p, Object.defineProperty(p, "a", {value: 44})) | 678 assertEquals(p, Object.defineProperty(p, "a", {value: 44})) |
645 assertEquals("a", key) | 679 assertEquals("a", key) |
646 assertEquals(1, Object.getOwnPropertyNames(desc).length) | 680 assertEquals(1, Object.getOwnPropertyNames(desc).length) |
647 assertEquals(44, desc.value) | 681 assertEquals(44, desc.value) |
648 | 682 |
649 assertEquals(p, Object.defineProperty(p, "b", {value: 45, writable: false})) | 683 assertEquals(p, Object.defineProperty(p, "b", {value: 45, writable: false})) |
650 assertEquals("b", key) | 684 assertEquals("b", key) |
651 assertEquals(2, Object.getOwnPropertyNames(desc).length) | 685 assertEquals(2, Object.getOwnPropertyNames(desc).length) |
652 assertEquals(45, desc.value) | 686 assertEquals(45, desc.value) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 get: function(pr, pk) { | 762 get: function(pr, pk) { |
729 return function(k, d) { key = k; desc = d; return true } | 763 return function(k, d) { key = k; desc = d; return true } |
730 } | 764 } |
731 })) | 765 })) |
732 | 766 |
733 | 767 |
734 function TestDefineThrow(handler) { | 768 function TestDefineThrow(handler) { |
735 TestWithProxies(TestDefineThrow2, handler) | 769 TestWithProxies(TestDefineThrow2, handler) |
736 } | 770 } |
737 | 771 |
738 function TestDefineThrow2(handler, create) { | 772 function TestDefineThrow2(create, handler) { |
739 var p = create(handler) | 773 var p = create(handler) |
740 assertThrows(function(){ Object.defineProperty(p, "a", {value: 44})}, "myexn") | 774 assertThrows(function(){ Object.defineProperty(p, "a", {value: 44})}, "myexn") |
741 assertThrows(function(){ Object.defineProperty(p, 0, {value: 44})}, "myexn") | 775 assertThrows(function(){ Object.defineProperty(p, 0, {value: 44})}, "myexn") |
742 | 776 |
743 // TODO(rossberg): These tests require for-in on proxies. | 777 // TODO(rossberg): These tests require for-in on proxies. |
744 // var d1 = create({ | 778 // var d1 = create({ |
745 // get: function(r, k) { throw "myexn" }, | 779 // get: function(r, k) { throw "myexn" }, |
746 // getOwnPropertyNames: function() { return ["value"] } | 780 // getOwnPropertyNames: function() { return ["value"] } |
747 // }) | 781 // }) |
748 // assertThrows(function(){ Object.defineProperty(p, "p", d1) }, "myexn") | 782 // assertThrows(function(){ Object.defineProperty(p, "p", d1) }, "myexn") |
(...skipping 29 matching lines...) Expand all Loading... |
778 | 812 |
779 | 813 |
780 // Property deletion (delete). | 814 // Property deletion (delete). |
781 | 815 |
782 var key | 816 var key |
783 | 817 |
784 function TestDelete(handler) { | 818 function TestDelete(handler) { |
785 TestWithProxies(TestDelete2, handler) | 819 TestWithProxies(TestDelete2, handler) |
786 } | 820 } |
787 | 821 |
788 function TestDelete2(handler, create) { | 822 function TestDelete2(create, handler) { |
789 var p = create(handler) | 823 var p = create(handler) |
790 assertEquals(true, delete p.a) | 824 assertEquals(true, delete p.a) |
791 assertEquals("a", key) | 825 assertEquals("a", key) |
792 assertEquals(true, delete p["b"]) | 826 assertEquals(true, delete p["b"]) |
793 assertEquals("b", key) | 827 assertEquals("b", key) |
794 assertEquals(true, delete p[1]) | 828 assertEquals(true, delete p[1]) |
795 assertEquals("1", key) | 829 assertEquals("1", key) |
796 | 830 |
797 assertEquals(false, delete p.z1) | 831 assertEquals(false, delete p.z1) |
798 assertEquals("z1", key) | 832 assertEquals("z1", key) |
(...skipping 29 matching lines...) Expand all Loading... |
828 get: function(pr, pk) { | 862 get: function(pr, pk) { |
829 return function(k) { key = k; return k < "z" } | 863 return function(k) { key = k; return k < "z" } |
830 } | 864 } |
831 })) | 865 })) |
832 | 866 |
833 | 867 |
834 function TestDeleteThrow(handler) { | 868 function TestDeleteThrow(handler) { |
835 TestWithProxies(TestDeleteThrow2, handler) | 869 TestWithProxies(TestDeleteThrow2, handler) |
836 } | 870 } |
837 | 871 |
838 function TestDeleteThrow2(handler, create) { | 872 function TestDeleteThrow2(create, handler) { |
839 var p = create(handler) | 873 var p = create(handler) |
840 assertThrows(function(){ delete p.a }, "myexn") | 874 assertThrows(function(){ delete p.a }, "myexn") |
841 assertThrows(function(){ delete p["b"] }, "myexn"); | 875 assertThrows(function(){ delete p["b"] }, "myexn"); |
842 assertThrows(function(){ delete p[3] }, "myexn"); | 876 assertThrows(function(){ delete p[3] }, "myexn"); |
843 | 877 |
844 (function() { | 878 (function() { |
845 "use strict" | 879 "use strict" |
846 assertThrows(function(){ delete p.c }, "myexn") | 880 assertThrows(function(){ delete p.c }, "myexn") |
847 assertThrows(function(){ delete p["d"] }, "myexn") | 881 assertThrows(function(){ delete p["d"] }, "myexn") |
848 assertThrows(function(){ delete p[4] }, "myexn"); | 882 assertThrows(function(){ delete p[4] }, "myexn"); |
(...skipping 20 matching lines...) Expand all Loading... |
869 })) | 903 })) |
870 | 904 |
871 | 905 |
872 | 906 |
873 // Property descriptors (Object.getOwnPropertyDescriptor). | 907 // Property descriptors (Object.getOwnPropertyDescriptor). |
874 | 908 |
875 function TestDescriptor(handler) { | 909 function TestDescriptor(handler) { |
876 TestWithProxies(TestDescriptor2, handler) | 910 TestWithProxies(TestDescriptor2, handler) |
877 } | 911 } |
878 | 912 |
879 function TestDescriptor2(handler, create) { | 913 function TestDescriptor2(create, handler) { |
880 var p = create(handler) | 914 var p = create(handler) |
881 var descs = [ | 915 var descs = [ |
882 {configurable: true}, | 916 {configurable: true}, |
883 {value: 34, enumerable: true, configurable: true}, | 917 {value: 34, enumerable: true, configurable: true}, |
884 {value: 3, writable: false, mine: "eyes", configurable: true}, | 918 {value: 3, writable: false, mine: "eyes", configurable: true}, |
885 {get value() { return 20 }, get configurable() { return true }}, | 919 {get value() { return 20 }, get configurable() { return true }}, |
886 {get: function() { "get" }, set: function() { "set" }, configurable: true} | 920 {get: function() { "get" }, set: function() { "set" }, configurable: true} |
887 ] | 921 ] |
888 for (var i = 0; i < descs.length; ++i) { | 922 for (var i = 0; i < descs.length; ++i) { |
889 assertEquals(p, Object.defineProperty(p, i, descs[i])) | 923 assertEquals(p, Object.defineProperty(p, i, descs[i])) |
(...skipping 18 matching lines...) Expand all Loading... |
908 return this.getOwnPropertyDescriptor2(k) | 942 return this.getOwnPropertyDescriptor2(k) |
909 }, | 943 }, |
910 getOwnPropertyDescriptor2: function(k) { return this["__" + k] } | 944 getOwnPropertyDescriptor2: function(k) { return this["__" + k] } |
911 }) | 945 }) |
912 | 946 |
913 | 947 |
914 function TestDescriptorThrow(handler) { | 948 function TestDescriptorThrow(handler) { |
915 TestWithProxies(TestDescriptorThrow2, handler) | 949 TestWithProxies(TestDescriptorThrow2, handler) |
916 } | 950 } |
917 | 951 |
918 function TestDescriptorThrow2(handler, create) { | 952 function TestDescriptorThrow2(create, handler) { |
919 var p = create(handler) | 953 var p = create(handler) |
920 assertThrows(function(){ Object.getOwnPropertyDescriptor(p, "a") }, "myexn") | 954 assertThrows(function(){ Object.getOwnPropertyDescriptor(p, "a") }, "myexn") |
921 } | 955 } |
922 | 956 |
923 TestDescriptorThrow({ | 957 TestDescriptorThrow({ |
924 getOwnPropertyDescriptor: function(k) { throw "myexn" } | 958 getOwnPropertyDescriptor: function(k) { throw "myexn" } |
925 }) | 959 }) |
926 | 960 |
927 TestDescriptorThrow({ | 961 TestDescriptorThrow({ |
928 getOwnPropertyDescriptor: function(k) { | 962 getOwnPropertyDescriptor: function(k) { |
929 return this.getOwnPropertyDescriptor2(k) | 963 return this.getOwnPropertyDescriptor2(k) |
930 }, | 964 }, |
931 getOwnPropertyDescriptor2: function(k) { throw "myexn" } | 965 getOwnPropertyDescriptor2: function(k) { throw "myexn" } |
932 }) | 966 }) |
933 | 967 |
934 | 968 |
935 | 969 |
936 // Comparison. | 970 // Comparison. |
937 | 971 |
938 function TestComparison(eq) { | 972 function TestComparison(eq) { |
939 TestWithProxies(TestComparison2, eq) | 973 TestWithProxies(TestComparison2, eq) |
940 } | 974 } |
941 | 975 |
942 function TestComparison2(eq, create) { | 976 function TestComparison2(create, eq) { |
943 var p1 = create({}) | 977 var p1 = create({}) |
944 var p2 = create({}) | 978 var p2 = create({}) |
945 | 979 |
946 assertTrue(eq(p1, p1)) | 980 assertTrue(eq(p1, p1)) |
947 assertTrue(eq(p2, p2)) | 981 assertTrue(eq(p2, p2)) |
948 assertTrue(!eq(p1, p2)) | 982 assertTrue(!eq(p1, p2)) |
949 assertTrue(!eq(p1, {})) | 983 assertTrue(!eq(p1, {})) |
950 assertTrue(!eq({}, p2)) | 984 assertTrue(!eq({}, p2)) |
951 assertTrue(!eq({}, {})) | 985 assertTrue(!eq({}, {})) |
952 } | 986 } |
(...skipping 22 matching lines...) Expand all Loading... |
975 | 1009 |
976 | 1010 |
977 // Membership test (in). | 1011 // Membership test (in). |
978 | 1012 |
979 var key | 1013 var key |
980 | 1014 |
981 function TestIn(handler) { | 1015 function TestIn(handler) { |
982 TestWithProxies(TestIn2, handler) | 1016 TestWithProxies(TestIn2, handler) |
983 } | 1017 } |
984 | 1018 |
985 function TestIn2(handler, create) { | 1019 function TestIn2(create, handler) { |
986 var p = create(handler) | 1020 var p = create(handler) |
987 assertTrue("a" in p) | 1021 assertTrue("a" in p) |
988 assertEquals("a", key) | 1022 assertEquals("a", key) |
989 assertTrue(99 in p) | 1023 assertTrue(99 in p) |
990 assertEquals("99", key) | 1024 assertEquals("99", key) |
991 assertFalse("z" in p) | 1025 assertFalse("z" in p) |
992 assertEquals("z", key) | 1026 assertEquals("z", key) |
993 | 1027 |
994 assertEquals(2, ("a" in p) ? 2 : 0) | 1028 assertEquals(2, ("a" in p) ? 2 : 0) |
995 assertEquals(0, !("a" in p) ? 2 : 0) | 1029 assertEquals(0, !("a" in p) ? 2 : 0) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 get: function(pr, pk) { | 1093 get: function(pr, pk) { |
1060 return function(k) { key = k; return k < "z" } | 1094 return function(k) { key = k; return k < "z" } |
1061 } | 1095 } |
1062 })) | 1096 })) |
1063 | 1097 |
1064 | 1098 |
1065 function TestInThrow(handler) { | 1099 function TestInThrow(handler) { |
1066 TestWithProxies(TestInThrow2, handler) | 1100 TestWithProxies(TestInThrow2, handler) |
1067 } | 1101 } |
1068 | 1102 |
1069 function TestInThrow2(handler, create) { | 1103 function TestInThrow2(create, handler) { |
1070 var p = create(handler) | 1104 var p = create(handler) |
1071 assertThrows(function(){ return "a" in o }, "myexn") | 1105 assertThrows(function(){ return "a" in o }, "myexn") |
1072 assertThrows(function(){ return 99 in o }, "myexn") | 1106 assertThrows(function(){ return 99 in o }, "myexn") |
1073 assertThrows(function(){ return !("a" in o) }, "myexn") | 1107 assertThrows(function(){ return !("a" in o) }, "myexn") |
1074 assertThrows(function(){ return ("a" in o) ? 2 : 3 }, "myexn") | 1108 assertThrows(function(){ return ("a" in o) ? 2 : 3 }, "myexn") |
1075 assertThrows(function(){ if ("b" in o) {} }, "myexn") | 1109 assertThrows(function(){ if ("b" in o) {} }, "myexn") |
1076 assertThrows(function(){ if (!("b" in o)) {} }, "myexn") | 1110 assertThrows(function(){ if (!("b" in o)) {} }, "myexn") |
1077 assertThrows(function(){ if ("zzz" in o) {} }, "myexn") | 1111 assertThrows(function(){ if ("zzz" in o) {} }, "myexn") |
1078 } | 1112 } |
1079 | 1113 |
(...skipping 28 matching lines...) Expand all Loading... |
1108 get: function(pr, pk) { | 1142 get: function(pr, pk) { |
1109 return function(k) { throw "myexn" } | 1143 return function(k) { throw "myexn" } |
1110 } | 1144 } |
1111 })) | 1145 })) |
1112 | 1146 |
1113 | 1147 |
1114 function TestInForDerived(handler) { | 1148 function TestInForDerived(handler) { |
1115 TestWithProxies(TestInForDerived2, handler) | 1149 TestWithProxies(TestInForDerived2, handler) |
1116 } | 1150 } |
1117 | 1151 |
1118 function TestInForDerived2(handler, create) { | 1152 function TestInForDerived2(create, handler) { |
1119 var p = create(handler) | 1153 var p = create(handler) |
1120 var o = Object.create(p) | 1154 var o = Object.create(p) |
1121 | 1155 |
1122 assertTrue("a" in o) | 1156 assertTrue("a" in o) |
1123 assertEquals("a", key) | 1157 assertEquals("a", key) |
1124 assertTrue(99 in o) | 1158 assertTrue(99 in o) |
1125 assertEquals("99", key) | 1159 assertEquals("99", key) |
1126 assertFalse("z" in o) | 1160 assertFalse("z" in o) |
1127 assertEquals("z", key) | 1161 assertEquals("z", key) |
1128 | 1162 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1265 | 1299 |
1266 | 1300 |
1267 // Own Properties (Object.prototype.hasOwnProperty). | 1301 // Own Properties (Object.prototype.hasOwnProperty). |
1268 | 1302 |
1269 var key | 1303 var key |
1270 | 1304 |
1271 function TestHasOwn(handler) { | 1305 function TestHasOwn(handler) { |
1272 TestWithProxies(TestHasOwn2, handler) | 1306 TestWithProxies(TestHasOwn2, handler) |
1273 } | 1307 } |
1274 | 1308 |
1275 function TestHasOwn2(handler, create) { | 1309 function TestHasOwn2(create, handler) { |
1276 var p = create(handler) | 1310 var p = create(handler) |
1277 assertTrue(Object.prototype.hasOwnProperty.call(p, "a")) | 1311 assertTrue(Object.prototype.hasOwnProperty.call(p, "a")) |
1278 assertEquals("a", key) | 1312 assertEquals("a", key) |
1279 assertTrue(Object.prototype.hasOwnProperty.call(p, 99)) | 1313 assertTrue(Object.prototype.hasOwnProperty.call(p, 99)) |
1280 assertEquals("99", key) | 1314 assertEquals("99", key) |
1281 assertFalse(Object.prototype.hasOwnProperty.call(p, "z")) | 1315 assertFalse(Object.prototype.hasOwnProperty.call(p, "z")) |
1282 assertEquals("z", key) | 1316 assertEquals("z", key) |
1283 } | 1317 } |
1284 | 1318 |
1285 TestHasOwn({ | 1319 TestHasOwn({ |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 get: function(pr, pk) { | 1357 get: function(pr, pk) { |
1324 return function(k) { key = k; return k < "z" } | 1358 return function(k) { key = k; return k < "z" } |
1325 } | 1359 } |
1326 })) | 1360 })) |
1327 | 1361 |
1328 | 1362 |
1329 function TestHasOwnThrow(handler) { | 1363 function TestHasOwnThrow(handler) { |
1330 TestWithProxies(TestHasOwnThrow2, handler) | 1364 TestWithProxies(TestHasOwnThrow2, handler) |
1331 } | 1365 } |
1332 | 1366 |
1333 function TestHasOwnThrow2(handler, create) { | 1367 function TestHasOwnThrow2(create, handler) { |
1334 var p = create(handler) | 1368 var p = create(handler) |
1335 assertThrows(function(){ Object.prototype.hasOwnProperty.call(p, "a")}, | 1369 assertThrows(function(){ Object.prototype.hasOwnProperty.call(p, "a")}, |
1336 "myexn") | 1370 "myexn") |
1337 assertThrows(function(){ Object.prototype.hasOwnProperty.call(p, 99)}, | 1371 assertThrows(function(){ Object.prototype.hasOwnProperty.call(p, 99)}, |
1338 "myexn") | 1372 "myexn") |
1339 } | 1373 } |
1340 | 1374 |
1341 TestHasOwnThrow({ | 1375 TestHasOwnThrow({ |
1342 hasOwn: function(k) { throw "myexn" } | 1376 hasOwn: function(k) { throw "myexn" } |
1343 }) | 1377 }) |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1488 assertTrue(Object.prototype.isPrototypeOf.call(Function.prototype, f)) | 1522 assertTrue(Object.prototype.isPrototypeOf.call(Function.prototype, f)) |
1489 } | 1523 } |
1490 | 1524 |
1491 TestPrototype() | 1525 TestPrototype() |
1492 | 1526 |
1493 | 1527 |
1494 | 1528 |
1495 // Property names (Object.getOwnPropertyNames, Object.keys). | 1529 // Property names (Object.getOwnPropertyNames, Object.keys). |
1496 | 1530 |
1497 function TestPropertyNames(names, handler) { | 1531 function TestPropertyNames(names, handler) { |
1498 TestWithProxies(TestPropertyNames2, [names, handler]) | 1532 TestWithProxies(TestPropertyNames2, handler, names) |
1499 } | 1533 } |
1500 | 1534 |
1501 function TestPropertyNames2(names_handler, create) { | 1535 function TestPropertyNames2(create, handler, names) { |
1502 var p = create(names_handler[1]) | 1536 var p = create(handler) |
1503 assertArrayEquals(names_handler[0], Object.getOwnPropertyNames(p)) | 1537 assertArrayEquals(names, Object.getOwnPropertyNames(p)) |
1504 } | 1538 } |
1505 | 1539 |
1506 TestPropertyNames([], { | 1540 TestPropertyNames([], { |
1507 getOwnPropertyNames: function() { return [] } | 1541 getOwnPropertyNames: function() { return [] } |
1508 }) | 1542 }) |
1509 | 1543 |
1510 TestPropertyNames(["a", "zz", " ", "0"], { | 1544 TestPropertyNames(["a", "zz", " ", "0"], { |
1511 getOwnPropertyNames: function() { return ["a", "zz", " ", 0] } | 1545 getOwnPropertyNames: function() { return ["a", "zz", " ", 0] } |
1512 }) | 1546 }) |
1513 | 1547 |
1514 TestPropertyNames(["throw", "function "], { | 1548 TestPropertyNames(["throw", "function "], { |
1515 getOwnPropertyNames: function() { return this.getOwnPropertyNames2() }, | 1549 getOwnPropertyNames: function() { return this.getOwnPropertyNames2() }, |
1516 getOwnPropertyNames2: function() { return ["throw", "function "] } | 1550 getOwnPropertyNames2: function() { return ["throw", "function "] } |
1517 }) | 1551 }) |
1518 | 1552 |
1519 TestPropertyNames(["[object Object]"], { | 1553 TestPropertyNames(["[object Object]"], { |
1520 get getOwnPropertyNames() { | 1554 get getOwnPropertyNames() { |
1521 return function() { return [{}] } | 1555 return function() { return [{}] } |
1522 } | 1556 } |
1523 }) | 1557 }) |
1524 | 1558 |
1525 | 1559 |
1526 function TestPropertyNamesThrow(handler) { | 1560 function TestPropertyNamesThrow(handler) { |
1527 TestWithProxies(TestPropertyNamesThrow2, handler) | 1561 TestWithProxies(TestPropertyNamesThrow2, handler) |
1528 } | 1562 } |
1529 | 1563 |
1530 function TestPropertyNamesThrow2(handler, create) { | 1564 function TestPropertyNamesThrow2(create, handler) { |
1531 var p = create(handler) | 1565 var p = create(handler) |
1532 assertThrows(function(){ Object.getOwnPropertyNames(p) }, "myexn") | 1566 assertThrows(function(){ Object.getOwnPropertyNames(p) }, "myexn") |
1533 } | 1567 } |
1534 | 1568 |
1535 TestPropertyNamesThrow({ | 1569 TestPropertyNamesThrow({ |
1536 getOwnPropertyNames: function() { throw "myexn" } | 1570 getOwnPropertyNames: function() { throw "myexn" } |
1537 }) | 1571 }) |
1538 | 1572 |
1539 TestPropertyNamesThrow({ | 1573 TestPropertyNamesThrow({ |
1540 getOwnPropertyNames: function() { return this.getOwnPropertyNames2() }, | 1574 getOwnPropertyNames: function() { return this.getOwnPropertyNames2() }, |
1541 getOwnPropertyNames2: function() { throw "myexn" } | 1575 getOwnPropertyNames2: function() { throw "myexn" } |
1542 }) | 1576 }) |
1543 | 1577 |
1544 | 1578 |
1545 function TestKeys(names, handler) { | 1579 function TestKeys(names, handler) { |
1546 TestWithProxies(TestKeys2, [names, handler]) | 1580 TestWithProxies(TestKeys2, handler, names) |
1547 } | 1581 } |
1548 | 1582 |
1549 function TestKeys2(names_handler, create) { | 1583 function TestKeys2(create, handler, names) { |
1550 var p = create(names_handler[1]) | 1584 var p = create(handler) |
1551 assertArrayEquals(names_handler[0], Object.keys(p)) | 1585 assertArrayEquals(names, Object.keys(p)) |
1552 } | 1586 } |
1553 | 1587 |
1554 TestKeys([], { | 1588 TestKeys([], { |
1555 keys: function() { return [] } | 1589 keys: function() { return [] } |
1556 }) | 1590 }) |
1557 | 1591 |
1558 TestKeys(["a", "zz", " ", "0"], { | 1592 TestKeys(["a", "zz", " ", "0"], { |
1559 keys: function() { return ["a", "zz", " ", 0] } | 1593 keys: function() { return ["a", "zz", " ", 0] } |
1560 }) | 1594 }) |
1561 | 1595 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1598 return function() { return ["a", "b", "c"] } | 1632 return function() { return ["a", "b", "c"] } |
1599 }, | 1633 }, |
1600 getOwnPropertyDescriptor: function(k) { return {} } | 1634 getOwnPropertyDescriptor: function(k) { return {} } |
1601 }) | 1635 }) |
1602 | 1636 |
1603 | 1637 |
1604 function TestKeysThrow(handler) { | 1638 function TestKeysThrow(handler) { |
1605 TestWithProxies(TestKeysThrow2, handler) | 1639 TestWithProxies(TestKeysThrow2, handler) |
1606 } | 1640 } |
1607 | 1641 |
1608 function TestKeysThrow2(handler, create) { | 1642 function TestKeysThrow2(create, handler) { |
1609 var p = create(handler) | 1643 var p = create(handler) |
1610 assertThrows(function(){ Object.keys(p) }, "myexn") | 1644 assertThrows(function(){ Object.keys(p) }, "myexn") |
1611 } | 1645 } |
1612 | 1646 |
1613 TestKeysThrow({ | 1647 TestKeysThrow({ |
1614 keys: function() { throw "myexn" } | 1648 keys: function() { throw "myexn" } |
1615 }) | 1649 }) |
1616 | 1650 |
1617 TestKeysThrow({ | 1651 TestKeysThrow({ |
1618 keys: function() { return this.keys2() }, | 1652 keys: function() { return this.keys2() }, |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1775 | 1809 |
1776 TestFixFunction(Object.seal) | 1810 TestFixFunction(Object.seal) |
1777 TestFixFunction(Object.freeze) | 1811 TestFixFunction(Object.freeze) |
1778 TestFixFunction(Object.preventExtensions) | 1812 TestFixFunction(Object.preventExtensions) |
1779 | 1813 |
1780 | 1814 |
1781 function TestFixThrow(handler) { | 1815 function TestFixThrow(handler) { |
1782 TestWithProxies(TestFixThrow2, handler) | 1816 TestWithProxies(TestFixThrow2, handler) |
1783 } | 1817 } |
1784 | 1818 |
1785 function TestFixThrow2(handler) { | 1819 function TestFixThrow2(create, handler) { |
1786 var p = Proxy.create(handler, {}) | 1820 var p = create(handler, {}) |
1787 assertThrows(function(){ Object.seal(p) }, "myexn") | 1821 assertThrows(function(){ Object.seal(p) }, "myexn") |
1788 assertThrows(function(){ Object.freeze(p) }, "myexn") | 1822 assertThrows(function(){ Object.freeze(p) }, "myexn") |
1789 assertThrows(function(){ Object.preventExtensions(p) }, "myexn") | 1823 assertThrows(function(){ Object.preventExtensions(p) }, "myexn") |
1790 } | 1824 } |
1791 | 1825 |
1792 TestFixThrow({ | 1826 TestFixThrow({ |
1793 fix: function() { throw "myexn" } | 1827 fix: function() { throw "myexn" } |
1794 }) | 1828 }) |
1795 | 1829 |
1796 TestFixThrow({ | 1830 TestFixThrow({ |
1797 fix: function() { return this.fix2() }, | 1831 fix: function() { return this.fix2() }, |
1798 fix2: function() { throw "myexn" } | 1832 fix2: function() { throw "myexn" } |
1799 }) | 1833 }) |
1800 | 1834 |
1801 TestFixThrow({ | 1835 TestFixThrow({ |
1802 get fix() { throw "myexn" } | 1836 get fix() { throw "myexn" } |
1803 }) | 1837 }) |
1804 | 1838 |
1805 TestFixThrow({ | 1839 TestFixThrow({ |
1806 get fix() { | 1840 get fix() { |
1807 return function() { throw "myexn" } | 1841 return function() { throw "myexn" } |
1808 } | 1842 } |
1809 }) | 1843 }) |
1810 | 1844 |
1811 | 1845 |
| 1846 // Freeze a proxy in the middle of operations on it. |
| 1847 // TODO(rossberg): actual behaviour not specified consistently at the moment, |
| 1848 // just make sure that we do not crash. |
| 1849 function TestReentrantFix(f) { |
| 1850 TestWithProxies(f, Object.freeze) |
| 1851 TestWithProxies(f, Object.seal) |
| 1852 TestWithProxies(f, Object.preventExtensions) |
| 1853 } |
| 1854 |
| 1855 TestReentrantFix(function(create, freeze) { |
| 1856 var handler = { |
| 1857 get get() { freeze(p); return undefined }, |
| 1858 fix: function() { return {} } |
| 1859 } |
| 1860 var p = create(handler) |
| 1861 // Freeze while getting get trap. |
| 1862 try { p.x } catch (e) { assertInstanceof(e, Error) } |
| 1863 }) |
| 1864 |
| 1865 TestReentrantFix(function(create, freeze) { |
| 1866 var handler = { |
| 1867 get: function() { freeze(p); return 3 }, |
| 1868 fix: function() { return {} } |
| 1869 } |
| 1870 var p = create(handler) |
| 1871 // Freeze while executing get trap. |
| 1872 try { p.x } catch (e) { assertInstanceof(e, Error) } |
| 1873 }) |
| 1874 |
| 1875 TestReentrantFix(function(create, freeze) { |
| 1876 var handler = { |
| 1877 getPropertyDescriptor: function() { freeze(p); return undefined }, |
| 1878 fix: function() { return {} } |
| 1879 } |
| 1880 var p = create(handler) |
| 1881 // Freeze while executing default get trap. |
| 1882 try { p.x } catch (e) { assertInstanceof(e, Error) } |
| 1883 }) |
| 1884 |
| 1885 TestReentrantFix(function(create, freeze) { |
| 1886 var handler = { |
| 1887 getPropertyDescriptor: function() { freeze(p); return {get: function(){}} }, |
| 1888 fix: function() { return {} } |
| 1889 } |
| 1890 var p = create(handler) |
| 1891 var o = Object.create(p) |
| 1892 // Freeze while getting a property from prototype. |
| 1893 try { o.x } catch (e) { assertInstanceof(e, Error) } |
| 1894 }) |
| 1895 |
| 1896 TestReentrantFix(function(create, freeze) { |
| 1897 var handler = { |
| 1898 get set() { freeze(p); return undefined }, |
| 1899 fix: function() { return {} } |
| 1900 } |
| 1901 var p = create(handler) |
| 1902 // Freeze while getting set trap. |
| 1903 try { p.x = 4 } catch (e) { assertInstanceof(e, Error) } |
| 1904 }) |
| 1905 |
| 1906 TestReentrantFix(function(create, freeze) { |
| 1907 var handler = { |
| 1908 set: function() { freeze(p); return true }, |
| 1909 fix: function() { return {} } |
| 1910 } |
| 1911 var p = create(handler) |
| 1912 // Freeze while executing set trap. |
| 1913 try { p.x = 4 } catch (e) { assertInstanceof(e, Error) } |
| 1914 }) |
| 1915 |
| 1916 TestReentrantFix(function(create, freeze) { |
| 1917 var handler = { |
| 1918 getOwnPropertyDescriptor: function() { freeze(p); return undefined }, |
| 1919 fix: function() { return {} } |
| 1920 } |
| 1921 var p = create(handler) |
| 1922 // Freeze while executing default set trap. |
| 1923 try { p.x } catch (e) { assertInstanceof(e, Error) } |
| 1924 }) |
| 1925 |
| 1926 TestReentrantFix(function(create, freeze) { |
| 1927 var handler = { |
| 1928 getPropertyDescriptor: function() { freeze(p); return {set: function(){}} }, |
| 1929 fix: function() { return {} } |
| 1930 } |
| 1931 var p = create(handler) |
| 1932 var o = Object.create(p) |
| 1933 // Freeze while setting a property in prototype, dropping the property! |
| 1934 try { o.x = 4 } catch (e) { assertInstanceof(e, Error) } |
| 1935 }) |
| 1936 |
| 1937 TestReentrantFix(function(create, freeze) { |
| 1938 var handler = { |
| 1939 getPropertyDescriptor: function() { freeze(p); return {set: function(){}} }, |
| 1940 fix: function() { return {x: {get: function(){}}} } |
| 1941 } |
| 1942 var p = create(handler) |
| 1943 var o = Object.create(p) |
| 1944 // Freeze while setting a property in prototype, making it read-only! |
| 1945 try { o.x = 4 } catch (e) { assertInstanceof(e, Error) } |
| 1946 }) |
| 1947 |
| 1948 |
| 1949 //TestReentrantFix(function(create, freeze) { |
| 1950 var h = { getPropertyDescriptor: function() { Object.freeze(p); return {set: fun
ction() {}} }, fix: function() { return {x: {get: function() { return 5 }}} }};
var p = Proxy.create(h); var o = Object.create(p); try { o.x = 4 } catch (e) {e2
=e} |
| 1951 //}) |
| 1952 |
| 1953 |
| 1954 TestReentrantFix(function(create, freeze) { |
| 1955 var handler = { |
| 1956 get fix() { freeze(p); return function(){} } |
| 1957 } |
| 1958 var p = create(handler) |
| 1959 // Freeze while getting fix trap. |
| 1960 try { Object.freeze(p) } catch (e) { assertInstanceof(e, Error) } |
| 1961 p = create(handler) |
| 1962 try { Object.seal(p) } catch (e) { assertInstanceof(e, Error) } |
| 1963 p = create(handler) |
| 1964 try { Object.preventExtensions(p) } catch (e) { assertInstanceof(e, Error) } |
| 1965 }) |
| 1966 |
| 1967 TestReentrantFix(function(create, freeze) { |
| 1968 var handler = { |
| 1969 fix: function() { freeze(p); return {} } |
| 1970 } |
| 1971 var p = create(handler) |
| 1972 // Freeze while executing fix trap. |
| 1973 try { Object.freeze(p) } catch (e) { assertInstanceof(e, Error) } |
| 1974 p = create(handler) |
| 1975 try { Object.seal(p) } catch (e) { assertInstanceof(e, Error) } |
| 1976 p = create(handler) |
| 1977 try { Object.preventExtensions(p) } catch (e) { assertInstanceof(e, Error) } |
| 1978 }) |
| 1979 |
| 1980 |
1812 | 1981 |
1813 // String conversion (Object.prototype.toString, | 1982 // String conversion (Object.prototype.toString, |
1814 // Object.prototype.toLocaleString, | 1983 // Object.prototype.toLocaleString, |
1815 // Function.prototype.toString) | 1984 // Function.prototype.toString) |
1816 | 1985 |
1817 var key | 1986 var key |
1818 | 1987 |
1819 function TestToString(handler) { | 1988 function TestToString(handler) { |
1820 var p = Proxy.create(handler) | 1989 var p = Proxy.create(handler) |
1821 key = "" | 1990 key = "" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1894 })) | 2063 })) |
1895 | 2064 |
1896 | 2065 |
1897 | 2066 |
1898 // Value conversion (Object.prototype.toValue) | 2067 // Value conversion (Object.prototype.toValue) |
1899 | 2068 |
1900 function TestValueOf(handler) { | 2069 function TestValueOf(handler) { |
1901 TestWithProxies(TestValueOf2, handler) | 2070 TestWithProxies(TestValueOf2, handler) |
1902 } | 2071 } |
1903 | 2072 |
1904 function TestValueOf2(handler, create) { | 2073 function TestValueOf2(create, handler) { |
1905 var p = create(handler) | 2074 var p = create(handler) |
1906 assertSame(p, Object.prototype.valueOf.call(p)) | 2075 assertSame(p, Object.prototype.valueOf.call(p)) |
1907 } | 2076 } |
1908 | 2077 |
1909 TestValueOf({}) | 2078 TestValueOf({}) |
1910 | 2079 |
1911 | 2080 |
1912 | 2081 |
1913 // Enumerability (Object.prototype.propertyIsEnumerable) | 2082 // Enumerability (Object.prototype.propertyIsEnumerable) |
1914 | 2083 |
1915 var key | 2084 var key |
1916 | 2085 |
1917 function TestIsEnumerable(handler) { | 2086 function TestIsEnumerable(handler) { |
1918 TestWithProxies(TestIsEnumerable2, handler) | 2087 TestWithProxies(TestIsEnumerable2, handler) |
1919 } | 2088 } |
1920 | 2089 |
1921 function TestIsEnumerable2(handler, create) { | 2090 function TestIsEnumerable2(create, handler) { |
1922 var p = create(handler) | 2091 var p = create(handler) |
1923 assertTrue(Object.prototype.propertyIsEnumerable.call(p, "a")) | 2092 assertTrue(Object.prototype.propertyIsEnumerable.call(p, "a")) |
1924 assertEquals("a", key) | 2093 assertEquals("a", key) |
1925 assertTrue(Object.prototype.propertyIsEnumerable.call(p, 2)) | 2094 assertTrue(Object.prototype.propertyIsEnumerable.call(p, 2)) |
1926 assertEquals("2", key) | 2095 assertEquals("2", key) |
1927 assertFalse(Object.prototype.propertyIsEnumerable.call(p, "z")) | 2096 assertFalse(Object.prototype.propertyIsEnumerable.call(p, "z")) |
1928 assertEquals("z", key) | 2097 assertEquals("z", key) |
1929 | 2098 |
1930 var o = Object.create(p) | 2099 var o = Object.create(p) |
1931 key = "" | 2100 key = "" |
(...skipping 28 matching lines...) Expand all Loading... |
1960 key = k; return {enumerable: k < "z", configurable: true} | 2129 key = k; return {enumerable: k < "z", configurable: true} |
1961 } | 2130 } |
1962 } | 2131 } |
1963 })) | 2132 })) |
1964 | 2133 |
1965 | 2134 |
1966 function TestIsEnumerableThrow(handler) { | 2135 function TestIsEnumerableThrow(handler) { |
1967 TestWithProxies(TestIsEnumerableThrow2, handler) | 2136 TestWithProxies(TestIsEnumerableThrow2, handler) |
1968 } | 2137 } |
1969 | 2138 |
1970 function TestIsEnumerableThrow2(handler, create) { | 2139 function TestIsEnumerableThrow2(create, handler) { |
1971 var p = create(handler) | 2140 var p = create(handler) |
1972 assertThrows(function(){ Object.prototype.propertyIsEnumerable.call(p, "a") }, | 2141 assertThrows(function(){ Object.prototype.propertyIsEnumerable.call(p, "a") }, |
1973 "myexn") | 2142 "myexn") |
1974 assertThrows(function(){ Object.prototype.propertyIsEnumerable.call(p, 11) }, | 2143 assertThrows(function(){ Object.prototype.propertyIsEnumerable.call(p, 11) }, |
1975 "myexn") | 2144 "myexn") |
1976 } | 2145 } |
1977 | 2146 |
1978 TestIsEnumerableThrow({ | 2147 TestIsEnumerableThrow({ |
1979 getOwnPropertyDescriptor: function(k) { throw "myexn" } | 2148 getOwnPropertyDescriptor: function(k) { throw "myexn" } |
1980 }) | 2149 }) |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2346 | 2515 |
2347 TestAccessorCall( | 2516 TestAccessorCall( |
2348 Proxy.createFunction({}, function() { receiver = this; return 42 }), | 2517 Proxy.createFunction({}, function() { receiver = this; return 42 }), |
2349 Proxy.createFunction({}, function(x) { receiver = this; value = x }) | 2518 Proxy.createFunction({}, function(x) { receiver = this; value = x }) |
2350 ) | 2519 ) |
2351 | 2520 |
2352 TestAccessorCall( | 2521 TestAccessorCall( |
2353 CreateFrozen({}, function() { receiver = this; return 42 }), | 2522 CreateFrozen({}, function() { receiver = this; return 42 }), |
2354 CreateFrozen({}, function(x) { receiver = this; value = x }) | 2523 CreateFrozen({}, function(x) { receiver = this; value = x }) |
2355 ) | 2524 ) |
OLD | NEW |