Chromium Code Reviews| 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 17 matching lines...) Expand all Loading... | |
| 28 // We change the stack size for the ARM64 simulator because at one point this | 28 // We change the stack size for the ARM64 simulator because at one point this |
| 29 // test enters an infinite recursion which goes through the runtime and we | 29 // test enters an infinite recursion which goes through the runtime and we |
| 30 // overflow the system stack before the simulator stack. | 30 // overflow the system stack before the simulator stack. |
| 31 | 31 |
| 32 // Flags: --harmony-proxies --sim-stack-size=500 --allow-natives-syntax | 32 // Flags: --harmony-proxies --sim-stack-size=500 --allow-natives-syntax |
| 33 | 33 |
| 34 | 34 |
| 35 // Helper. | 35 // Helper. |
| 36 | 36 |
| 37 function TestWithProxies(test, x, y, z) { | 37 function TestWithProxies(test, x, y, z) { |
| 38 test(Proxy.create, x, y, z) | 38 test(function(handler) { return new Proxy({}, handler) }, x, y, z) |
| 39 test(function(h) {return Proxy.createFunction(h, function() {})}, x, y, z) | 39 test(function(handler) { |
| 40 return Proxy.createFunction(handler, function() {}) | |
| 41 }, x, y, z) | |
| 40 } | 42 } |
| 41 | 43 |
| 42 | 44 |
| 43 | 45 |
| 44 // Getting property descriptors (Object.getOwnPropertyDescriptor). | 46 // Getting property descriptors (Object.getOwnPropertyDescriptor). |
| 45 | 47 |
| 46 var key | 48 var key |
| 47 | 49 |
| 48 function TestGetOwnProperty(handler) { | 50 function TestGetOwnProperty(handler) { |
| 49 TestWithProxies(TestGetOwnProperty2, handler) | 51 TestWithProxies(TestGetOwnProperty2, handler) |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 74 } | 76 } |
| 75 }) | 77 }) |
| 76 | 78 |
| 77 TestGetOwnProperty({ | 79 TestGetOwnProperty({ |
| 78 getOwnPropertyDescriptor: function(k) { | 80 getOwnPropertyDescriptor: function(k) { |
| 79 key = k | 81 key = k |
| 80 return {get value() { return 42 }, get configurable() { return true }} | 82 return {get value() { return 42 }, get configurable() { return true }} |
| 81 } | 83 } |
| 82 }) | 84 }) |
| 83 | 85 |
| 84 TestGetOwnProperty(Proxy.create({ | 86 TestGetOwnProperty(new Proxy({}, { |
| 85 get: function(pr, pk) { | 87 get: function(pr, pk) { |
| 86 return function(k) { key = k; return {value: 42, configurable: true} } | 88 return function(k) { key = k; return {value: 42, configurable: true} } |
| 87 } | 89 } |
| 88 })) | 90 })) |
| 89 | 91 |
| 90 | 92 |
| 91 function TestGetOwnPropertyThrow(handler) { | 93 function TestGetOwnPropertyThrow(handler) { |
| 92 TestWithProxies(TestGetOwnPropertyThrow2, handler) | 94 TestWithProxies(TestGetOwnPropertyThrow2, handler) |
| 93 } | 95 } |
| 94 | 96 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 108 }, | 110 }, |
| 109 getOwnPropertyDescriptor2: function(k) { throw "myexn" } | 111 getOwnPropertyDescriptor2: function(k) { throw "myexn" } |
| 110 }) | 112 }) |
| 111 | 113 |
| 112 TestGetOwnPropertyThrow({ | 114 TestGetOwnPropertyThrow({ |
| 113 getOwnPropertyDescriptor: function(k) { | 115 getOwnPropertyDescriptor: function(k) { |
| 114 return {get value() { throw "myexn" }} | 116 return {get value() { throw "myexn" }} |
| 115 } | 117 } |
| 116 }) | 118 }) |
| 117 | 119 |
| 118 TestGetOwnPropertyThrow(Proxy.create({ | 120 TestGetOwnPropertyThrow(new Proxy({}, { |
| 119 get: function(pr, pk) { | 121 get: function(pr, pk) { |
| 120 return function(k) { throw "myexn" } | 122 return function(k) { throw "myexn" } |
| 121 } | 123 } |
| 122 })) | 124 })) |
| 123 | 125 |
| 124 | 126 |
| 125 | 127 |
| 126 // Getters (dot, brackets). | 128 // Getters (dot, brackets). |
| 127 | 129 |
| 128 var key | 130 var key |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 key = k; | 185 key = k; |
| 184 return {get value() { return 42 }} | 186 return {get value() { return 42 }} |
| 185 } | 187 } |
| 186 }) | 188 }) |
| 187 | 189 |
| 188 TestGet({ | 190 TestGet({ |
| 189 get: undefined, | 191 get: undefined, |
| 190 getPropertyDescriptor: function(k) { key = k; return {value: 42} } | 192 getPropertyDescriptor: function(k) { key = k; return {value: 42} } |
| 191 }) | 193 }) |
| 192 | 194 |
| 193 TestGet(Proxy.create({ | 195 TestGet(new Proxy({}, { |
| 194 get: function(pr, pk) { | 196 get: function(pr, pk) { |
| 195 return function(r, k) { key = k; return 42 } | 197 return function(r, k) { key = k; return 42 } |
| 196 } | 198 } |
| 197 })) | 199 })) |
| 198 | 200 |
| 199 | 201 |
| 200 function TestGetCall(handler) { | 202 function TestGetCall(handler) { |
| 201 TestWithProxies(TestGetCall2, handler) | 203 TestWithProxies(TestGetCall2, handler) |
| 202 } | 204 } |
| 203 | 205 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 if (k == "gg") { | 282 if (k == "gg") { |
| 281 return function() { return 55 } | 283 return function() { return 55 } |
| 282 } else if (k == "withargs") { | 284 } else if (k == "withargs") { |
| 283 return function(n, m) { return n + m * 2 } | 285 return function(n, m) { return n + m * 2 } |
| 284 } else { | 286 } else { |
| 285 return function() { return this.gg() } | 287 return function() { return this.gg() } |
| 286 } | 288 } |
| 287 } | 289 } |
| 288 }) | 290 }) |
| 289 | 291 |
| 290 TestGetCall(Proxy.create({ | 292 TestGetCall(new Proxy({}, { |
| 291 get: function(pr, pk) { | 293 get: function(pr, pk) { |
| 292 return function(r, k) { return function() { return 55 } } | 294 return function(r, k) { return function() { return 55 } } |
| 293 } | 295 } |
| 294 })) | 296 })) |
| 295 | 297 |
| 296 | 298 |
| 297 function TestGetThrow(handler) { | 299 function TestGetThrow(handler) { |
| 298 TestWithProxies(TestGetThrow2, handler) | 300 TestWithProxies(TestGetThrow2, handler) |
| 299 } | 301 } |
| 300 | 302 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 getPropertyDescriptor: function(k) { | 338 getPropertyDescriptor: function(k) { |
| 337 return {get value() { throw "myexn" }} | 339 return {get value() { throw "myexn" }} |
| 338 } | 340 } |
| 339 }) | 341 }) |
| 340 | 342 |
| 341 TestGetThrow({ | 343 TestGetThrow({ |
| 342 get: undefined, | 344 get: undefined, |
| 343 getPropertyDescriptor: function(k) { throw "myexn" } | 345 getPropertyDescriptor: function(k) { throw "myexn" } |
| 344 }) | 346 }) |
| 345 | 347 |
| 346 TestGetThrow(Proxy.create({ | 348 TestGetThrow(new Proxy({}, { |
| 347 get: function(pr, pk) { throw "myexn" } | 349 get: function(pr, pk) { throw "myexn" } |
| 348 })) | 350 })) |
| 349 | 351 |
| 350 TestGetThrow(Proxy.create({ | 352 TestGetThrow(new Proxy({}, { |
| 351 get: function(pr, pk) { | 353 get: function(pr, pk) { |
| 352 return function(r, k) { throw "myexn" } | 354 return function(r, k) { throw "myexn" } |
| 353 } | 355 } |
| 354 })) | 356 })) |
| 355 | 357 |
| 356 | 358 |
| 357 | 359 |
| 358 // Setters. | 360 // Setters. |
| 359 | 361 |
| 360 var key | 362 var key |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 return {set: function(v) { key = k; val = v }} | 446 return {set: function(v) { key = k; val = v }} |
| 445 } | 447 } |
| 446 }) | 448 }) |
| 447 | 449 |
| 448 TestSet({ | 450 TestSet({ |
| 449 getOwnPropertyDescriptor: function(k) { return null }, | 451 getOwnPropertyDescriptor: function(k) { return null }, |
| 450 getPropertyDescriptor: function(k) { return null }, | 452 getPropertyDescriptor: function(k) { return null }, |
| 451 defineProperty: function(k, desc) { key = k, val = desc.value } | 453 defineProperty: function(k, desc) { key = k, val = desc.value } |
| 452 }) | 454 }) |
| 453 | 455 |
| 454 TestSet(Proxy.create({ | 456 TestSet(new Proxy({}, { |
| 455 get: function(pr, pk) { | 457 get: function(pr, pk) { |
| 456 return function(r, k, v) { key = k; val = v; return true } | 458 return function(r, k, v) { key = k; val = v; return true } |
| 457 } | 459 } |
| 458 })) | 460 })) |
| 459 | 461 |
| 460 | 462 |
| 461 function TestSetThrow(handler) { | 463 function TestSetThrow(handler) { |
| 462 TestWithProxies(TestSetThrow2, handler) | 464 TestWithProxies(TestSetThrow2, handler) |
| 463 } | 465 } |
| 464 | 466 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 562 return {set: function(v) { throw "myexn" }} | 564 return {set: function(v) { throw "myexn" }} |
| 563 } | 565 } |
| 564 }) | 566 }) |
| 565 | 567 |
| 566 TestSetThrow({ | 568 TestSetThrow({ |
| 567 getOwnPropertyDescriptor: function(k) { return null }, | 569 getOwnPropertyDescriptor: function(k) { return null }, |
| 568 getPropertyDescriptor: function(k) { return null }, | 570 getPropertyDescriptor: function(k) { return null }, |
| 569 defineProperty: function(k, desc) { throw "myexn" } | 571 defineProperty: function(k, desc) { throw "myexn" } |
| 570 }) | 572 }) |
| 571 | 573 |
| 572 TestSetThrow(Proxy.create({ | 574 TestSetThrow(new Proxy({}, { |
| 573 get: function(pr, pk) { throw "myexn" } | 575 get: function(pr, pk) { throw "myexn" } |
| 574 })) | 576 })) |
| 575 | 577 |
| 576 TestSetThrow(Proxy.create({ | 578 TestSetThrow(new Proxy({}, { |
| 577 get: function(pr, pk) { | 579 get: function(pr, pk) { |
| 578 return function(r, k, v) { throw "myexn" } | 580 return function(r, k, v) { throw "myexn" } |
| 579 } | 581 } |
| 580 })) | 582 })) |
| 581 | 583 |
| 582 | 584 |
| 583 var rec | 585 var rec |
| 584 var key | 586 var key |
| 585 var val | 587 var val |
| 586 | 588 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 809 | 811 |
| 810 TestDefine({ | 812 TestDefine({ |
| 811 defineProperty: function(k, d) { key = k; desc = d; return true } | 813 defineProperty: function(k, d) { key = k; desc = d; return true } |
| 812 }) | 814 }) |
| 813 | 815 |
| 814 TestDefine({ | 816 TestDefine({ |
| 815 defineProperty: function(k, d) { return this.defineProperty2(k, d) }, | 817 defineProperty: function(k, d) { return this.defineProperty2(k, d) }, |
| 816 defineProperty2: function(k, d) { key = k; desc = d; return true } | 818 defineProperty2: function(k, d) { key = k; desc = d; return true } |
| 817 }) | 819 }) |
| 818 | 820 |
| 819 TestDefine(Proxy.create({ | 821 TestDefine(new Proxy({}, { |
| 820 get: function(pr, pk) { | 822 get: function(pr, pk) { |
| 821 return function(k, d) { key = k; desc = d; return true } | 823 return function(k, d) { key = k; desc = d; return true } |
| 822 } | 824 } |
| 823 })) | 825 })) |
| 824 | 826 |
| 825 | 827 |
| 826 function TestDefineThrow(handler) { | 828 function TestDefineThrow(handler) { |
| 827 TestWithProxies(TestDefineThrow2, handler) | 829 TestWithProxies(TestDefineThrow2, handler) |
| 828 } | 830 } |
| 829 | 831 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 849 | 851 |
| 850 TestDefineThrow({ | 852 TestDefineThrow({ |
| 851 defineProperty: function(k, d) { throw "myexn" } | 853 defineProperty: function(k, d) { throw "myexn" } |
| 852 }) | 854 }) |
| 853 | 855 |
| 854 TestDefineThrow({ | 856 TestDefineThrow({ |
| 855 defineProperty: function(k, d) { return this.defineProperty2(k, d) }, | 857 defineProperty: function(k, d) { return this.defineProperty2(k, d) }, |
| 856 defineProperty2: function(k, d) { throw "myexn" } | 858 defineProperty2: function(k, d) { throw "myexn" } |
| 857 }) | 859 }) |
| 858 | 860 |
| 859 TestDefineThrow(Proxy.create({ | 861 TestDefineThrow(new Proxy({}, { |
| 860 get: function(pr, pk) { throw "myexn" } | 862 get: function(pr, pk) { throw "myexn" } |
| 861 })) | 863 })) |
| 862 | 864 |
| 863 TestDefineThrow(Proxy.create({ | 865 TestDefineThrow(new Proxy({}, { |
| 864 get: function(pr, pk) { | 866 get: function(pr, pk) { |
| 865 return function(k, d) { throw "myexn" } | 867 return function(k, d) { throw "myexn" } |
| 866 } | 868 } |
| 867 })) | 869 })) |
| 868 | 870 |
| 869 | 871 |
| 870 | 872 |
| 871 // Property deletion (delete). | 873 // Property deletion (delete). |
| 872 | 874 |
| 873 var key | 875 var key |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 908 | 910 |
| 909 TestDelete({ | 911 TestDelete({ |
| 910 delete: function(k) { key = k; return k < "z" } | 912 delete: function(k) { key = k; return k < "z" } |
| 911 }) | 913 }) |
| 912 | 914 |
| 913 TestDelete({ | 915 TestDelete({ |
| 914 delete: function(k) { return this.delete2(k) }, | 916 delete: function(k) { return this.delete2(k) }, |
| 915 delete2: function(k) { key = k; return k < "z" } | 917 delete2: function(k) { key = k; return k < "z" } |
| 916 }) | 918 }) |
| 917 | 919 |
| 918 TestDelete(Proxy.create({ | 920 TestDelete(new Proxy({}, { |
| 919 get: function(pr, pk) { | 921 get: function(pr, pk) { |
| 920 return function(k) { key = k; return k < "z" } | 922 return function(k) { key = k; return k < "z" } |
| 921 } | 923 } |
| 922 })) | 924 })) |
| 923 | 925 |
| 924 | 926 |
| 925 function TestDeleteThrow(handler) { | 927 function TestDeleteThrow(handler) { |
| 926 TestWithProxies(TestDeleteThrow2, handler) | 928 TestWithProxies(TestDeleteThrow2, handler) |
| 927 } | 929 } |
| 928 | 930 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 942 | 944 |
| 943 TestDeleteThrow({ | 945 TestDeleteThrow({ |
| 944 delete: function(k) { throw "myexn" } | 946 delete: function(k) { throw "myexn" } |
| 945 }) | 947 }) |
| 946 | 948 |
| 947 TestDeleteThrow({ | 949 TestDeleteThrow({ |
| 948 delete: function(k) { return this.delete2(k) }, | 950 delete: function(k) { return this.delete2(k) }, |
| 949 delete2: function(k) { throw "myexn" } | 951 delete2: function(k) { throw "myexn" } |
| 950 }) | 952 }) |
| 951 | 953 |
| 952 TestDeleteThrow(Proxy.create({ | 954 TestDeleteThrow(new Proxy({}, { |
| 953 get: function(pr, pk) { throw "myexn" } | 955 get: function(pr, pk) { throw "myexn" } |
| 954 })) | 956 })) |
| 955 | 957 |
| 956 TestDeleteThrow(Proxy.create({ | 958 TestDeleteThrow(new Proxy({}, { |
| 957 get: function(pr, pk) { | 959 get: function(pr, pk) { |
| 958 return function(k) { throw "myexn" } | 960 return function(k) { throw "myexn" } |
| 959 } | 961 } |
| 960 })) | 962 })) |
| 961 | 963 |
| 962 | 964 |
| 963 | 965 |
| 964 // Property descriptors (Object.getOwnPropertyDescriptor). | 966 // Property descriptors (Object.getOwnPropertyDescriptor). |
| 965 | 967 |
| 966 function TestDescriptor(handler) { | 968 function TestDescriptor(handler) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1045 TestComparison(function(o1, o2) { return o1 == o2 }) | 1047 TestComparison(function(o1, o2) { return o1 == o2 }) |
| 1046 TestComparison(function(o1, o2) { return o1 === o2 }) | 1048 TestComparison(function(o1, o2) { return o1 === o2 }) |
| 1047 TestComparison(function(o1, o2) { return !(o1 != o2) }) | 1049 TestComparison(function(o1, o2) { return !(o1 != o2) }) |
| 1048 TestComparison(function(o1, o2) { return !(o1 !== o2) }) | 1050 TestComparison(function(o1, o2) { return !(o1 !== o2) }) |
| 1049 | 1051 |
| 1050 | 1052 |
| 1051 | 1053 |
| 1052 // Type (typeof). | 1054 // Type (typeof). |
| 1053 | 1055 |
| 1054 function TestTypeof() { | 1056 function TestTypeof() { |
| 1055 assertEquals("object", typeof Proxy.create({})) | 1057 assertEquals("object", typeof new Proxy({}, {})) |
| 1056 assertTrue(typeof Proxy.create({}) == "object") | 1058 assertTrue(typeof new Proxy({}, {}) == "object") |
| 1057 assertTrue("object" == typeof Proxy.create({})) | 1059 assertTrue("object" == typeof new Proxy({}, {})) |
| 1058 | 1060 |
| 1059 assertEquals("function", typeof Proxy.createFunction({}, function() {})) | 1061 assertEquals("function", typeof Proxy.createFunction({}, function() {})) |
| 1060 assertTrue(typeof Proxy.createFunction({}, function() {}) == "function") | 1062 assertTrue(typeof Proxy.createFunction({}, function() {}) == "function") |
| 1061 assertTrue("function" == typeof Proxy.createFunction({}, function() {})) | 1063 assertTrue("function" == typeof Proxy.createFunction({}, function() {})) |
| 1062 } | 1064 } |
| 1063 | 1065 |
| 1064 TestTypeof() | 1066 TestTypeof() |
| 1065 | 1067 |
| 1066 | 1068 |
| 1067 | 1069 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1139 } | 1141 } |
| 1140 }) | 1142 }) |
| 1141 | 1143 |
| 1142 TestIn({ | 1144 TestIn({ |
| 1143 has: undefined, | 1145 has: undefined, |
| 1144 getPropertyDescriptor: function(k) { | 1146 getPropertyDescriptor: function(k) { |
| 1145 key = k; return k < "z" ? {value: 42} : void 0 | 1147 key = k; return k < "z" ? {value: 42} : void 0 |
| 1146 } | 1148 } |
| 1147 }) | 1149 }) |
| 1148 | 1150 |
| 1149 TestIn(Proxy.create({ | 1151 TestIn(new Proxy({}, { |
| 1150 get: function(pr, pk) { | 1152 get: function(pr, pk) { |
| 1151 return function(k) { key = k; return k < "z" } | 1153 return function(k) { key = k; return k < "z" } |
| 1152 } | 1154 } |
| 1153 })) | 1155 })) |
| 1154 | 1156 |
| 1155 | 1157 |
| 1156 function TestInThrow(handler) { | 1158 function TestInThrow(handler) { |
| 1157 TestWithProxies(TestInThrow2, handler) | 1159 TestWithProxies(TestInThrow2, handler) |
| 1158 } | 1160 } |
| 1159 | 1161 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1184 TestInThrow({ | 1186 TestInThrow({ |
| 1185 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, | 1187 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, |
| 1186 getPropertyDescriptor2: function(k) { throw "myexn" } | 1188 getPropertyDescriptor2: function(k) { throw "myexn" } |
| 1187 }) | 1189 }) |
| 1188 | 1190 |
| 1189 TestInThrow({ | 1191 TestInThrow({ |
| 1190 has: undefined, | 1192 has: undefined, |
| 1191 getPropertyDescriptor: function(k) { throw "myexn" } | 1193 getPropertyDescriptor: function(k) { throw "myexn" } |
| 1192 }) | 1194 }) |
| 1193 | 1195 |
| 1194 TestInThrow(Proxy.create({ | 1196 TestInThrow(new Proxy({}, { |
| 1195 get: function(pr, pk) { throw "myexn" } | 1197 get: function(pr, pk) { throw "myexn" } |
| 1196 })) | 1198 })) |
| 1197 | 1199 |
| 1198 TestInThrow(Proxy.create({ | 1200 TestInThrow(new Proxy({}, { |
| 1199 get: function(pr, pk) { | 1201 get: function(pr, pk) { |
| 1200 return function(k) { throw "myexn" } | 1202 return function(k) { throw "myexn" } |
| 1201 } | 1203 } |
| 1202 })) | 1204 })) |
| 1203 | 1205 |
| 1204 | 1206 |
| 1205 function TestInForDerived(handler) { | 1207 function TestInForDerived(handler) { |
| 1206 TestWithProxies(TestInForDerived2, handler) | 1208 TestWithProxies(TestInForDerived2, handler) |
| 1207 } | 1209 } |
| 1208 | 1210 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1283 }) | 1285 }) |
| 1284 | 1286 |
| 1285 TestInForDerived({ | 1287 TestInForDerived({ |
| 1286 getOwnPropertyDescriptor: function(k) { | 1288 getOwnPropertyDescriptor: function(k) { |
| 1287 key = k; | 1289 key = k; |
| 1288 return k < "z" ? {get value() { return 42 }, configurable: true} : void 0 | 1290 return k < "z" ? {get value() { return 42 }, configurable: true} : void 0 |
| 1289 } | 1291 } |
| 1290 }) | 1292 }) |
| 1291 */ | 1293 */ |
| 1292 | 1294 |
| 1293 TestInForDerived(Proxy.create({ | 1295 TestInForDerived(new Proxy({}, { |
| 1294 get: function(pr, pk) { | 1296 get: function(pr, pk) { |
| 1295 return function(k) { | 1297 return function(k) { |
| 1296 key = k; return k < "z" ? {value: 42, configurable: true} : void 0 | 1298 key = k; return k < "z" ? {value: 42, configurable: true} : void 0 |
| 1297 } | 1299 } |
| 1298 } | 1300 } |
| 1299 })) | 1301 })) |
| 1300 | 1302 |
| 1301 | 1303 |
| 1302 | 1304 |
| 1303 // Property descriptor conversion. | 1305 // Property descriptor conversion. |
| 1304 | 1306 |
| 1305 var descget | 1307 var descget |
| 1306 | 1308 |
| 1307 function TestDescriptorGetOrder(handler) { | 1309 function TestDescriptorGetOrder(handler) { |
| 1308 var p = Proxy.create(handler) | 1310 var p = new Proxy({}, handler) |
| 1309 var o = Object.create(p, {b: {value: 0}}) | 1311 var o = Object.create(p, {b: {value: 0}}) |
| 1310 TestDescriptorGetOrder2(function(n) { return p[n] }, "vV") | 1312 TestDescriptorGetOrder2(function(n) { return p[n] }, "vV") |
| 1311 TestDescriptorGetOrder2(function(n) { return n in p }, "") | 1313 TestDescriptorGetOrder2(function(n) { return n in p }, "") |
| 1312 TestDescriptorGetOrder2(function(n) { return o[n] }, "vV") | 1314 TestDescriptorGetOrder2(function(n) { return o[n] }, "vV") |
| 1313 TestDescriptorGetOrder2(function(n) { return n in o }, "") | 1315 TestDescriptorGetOrder2(function(n) { return n in o }, "") |
| 1314 } | 1316 } |
| 1315 | 1317 |
| 1316 function TestDescriptorGetOrder2(f, access) { | 1318 function TestDescriptorGetOrder2(f, access) { |
| 1317 descget = "" | 1319 descget = "" |
| 1318 assertTrue(f("a")) | 1320 assertTrue(f("a")) |
| 1319 assertEquals(access, descget) | 1321 assertEquals(access, descget) |
| 1320 descget = "" | 1322 descget = "" |
| 1321 assertTrue(f(99)) | 1323 assertTrue(f(99)) |
| 1322 assertEquals(access, descget) | 1324 assertEquals(access, descget) |
| 1323 descget = "" | 1325 descget = "" |
| 1324 assertFalse(!!f("z")) | 1326 assertFalse(!!f("z")) |
| 1325 assertEquals("", descget) | 1327 assertEquals("", descget) |
| 1326 } | 1328 } |
| 1327 | 1329 |
| 1328 TestDescriptorGetOrder({ | 1330 TestDescriptorGetOrder({ |
| 1329 getPropertyDescriptor: function(k) { | 1331 getPropertyDescriptor: function(k) { |
| 1330 if (k >= "z") return void 0 | 1332 if (k >= "z") return void 0 |
| 1331 // Return a proxy as property descriptor, so that we can log accesses. | 1333 // Return a proxy as property descriptor, so that we can log accesses. |
| 1332 return Proxy.create({ | 1334 return new Proxy({}, { |
| 1333 get: function(r, attr) { | 1335 get: function(r, attr) { |
| 1334 descget += attr[0].toUpperCase() | 1336 descget += attr[0].toUpperCase() |
| 1335 return true | 1337 return true |
| 1336 }, | 1338 }, |
| 1337 has: function(attr) { | 1339 has: function(attr) { |
| 1338 descget += attr[0] | 1340 descget += attr[0] |
| 1339 switch (attr) { | 1341 switch (attr) { |
| 1340 case "writable": | 1342 case "writable": |
| 1341 case "enumerable": | 1343 case "enumerable": |
| 1342 case "configurable": | 1344 case "configurable": |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1403 } | 1405 } |
| 1404 }) | 1406 }) |
| 1405 | 1407 |
| 1406 TestHasOwn({ | 1408 TestHasOwn({ |
| 1407 hasOwn: undefined, | 1409 hasOwn: undefined, |
| 1408 getOwnPropertyDescriptor: function(k) { | 1410 getOwnPropertyDescriptor: function(k) { |
| 1409 key = k; return k < "z" ? {value: 42} : void 0 | 1411 key = k; return k < "z" ? {value: 42} : void 0 |
| 1410 } | 1412 } |
| 1411 }) | 1413 }) |
| 1412 | 1414 |
| 1413 TestHasOwn(Proxy.create({ | 1415 TestHasOwn(new Proxy({}, { |
| 1414 get: function(pr, pk) { | 1416 get: function(pr, pk) { |
| 1415 return function(k) { key = k; return k < "z" } | 1417 return function(k) { key = k; return k < "z" } |
| 1416 } | 1418 } |
| 1417 })) | 1419 })) |
| 1418 | 1420 |
| 1419 | 1421 |
| 1420 function TestHasOwnThrow(handler) { | 1422 function TestHasOwnThrow(handler) { |
| 1421 TestWithProxies(TestHasOwnThrow2, handler) | 1423 TestWithProxies(TestHasOwnThrow2, handler) |
| 1422 } | 1424 } |
| 1423 | 1425 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1447 return this.getOwnPropertyDescriptor2(k) | 1449 return this.getOwnPropertyDescriptor2(k) |
| 1448 }, | 1450 }, |
| 1449 getOwnPropertyDescriptor2: function(k) { throw "myexn" } | 1451 getOwnPropertyDescriptor2: function(k) { throw "myexn" } |
| 1450 }) | 1452 }) |
| 1451 | 1453 |
| 1452 TestHasOwnThrow({ | 1454 TestHasOwnThrow({ |
| 1453 hasOwn: undefined, | 1455 hasOwn: undefined, |
| 1454 getOwnPropertyDescriptor: function(k) { throw "myexn" } | 1456 getOwnPropertyDescriptor: function(k) { throw "myexn" } |
| 1455 }) | 1457 }) |
| 1456 | 1458 |
| 1457 TestHasOwnThrow(Proxy.create({ | 1459 TestHasOwnThrow(new Proxy({}, { |
| 1458 get: function(pr, pk) { throw "myexn" } | 1460 get: function(pr, pk) { throw "myexn" } |
| 1459 })) | 1461 })) |
| 1460 | 1462 |
| 1461 TestHasOwnThrow(Proxy.create({ | 1463 TestHasOwnThrow(new Proxy({}, { |
| 1462 get: function(pr, pk) { | 1464 get: function(pr, pk) { |
| 1463 return function(k) { throw "myexn" } | 1465 return function(k) { throw "myexn" } |
| 1464 } | 1466 } |
| 1465 })) | 1467 })) |
| 1466 | 1468 |
| 1467 | 1469 |
| 1468 | 1470 |
| 1469 // Instanceof (instanceof) | 1471 // Instanceof (instanceof) |
| 1470 | 1472 |
| 1471 function TestProxyInstanceof() { | 1473 function TestProxyInstanceof() { |
| 1472 var o1 = {} | 1474 var o1 = {} |
| 1473 var p1 = Proxy.create({}) | 1475 var p1 = new Proxy({}, {}) |
| 1474 var p2 = Proxy.create({}, o1) | 1476 var p2 = new Proxy(o1, {}) |
| 1475 var p3 = Proxy.create({}, p2) | 1477 var p3 = new Proxy(p2, {}) |
| 1476 var o2 = Object.create(p2) | 1478 var o2 = Object.create(p2) |
| 1477 | 1479 |
| 1478 var f0 = function() {} | 1480 var f0 = function() {} |
| 1479 f0.prototype = o1 | 1481 f0.prototype = o1 |
| 1480 var f1 = function() {} | 1482 var f1 = function() {} |
| 1481 f1.prototype = p1 | 1483 f1.prototype = p1 |
| 1482 var f2 = function() {} | 1484 var f2 = function() {} |
| 1483 f2.prototype = p2 | 1485 f2.prototype = p2 |
| 1484 var f3 = function() {} | 1486 var f3 = function() {} |
| 1485 f3.prototype = o2 | 1487 f3.prototype = o2 |
| 1486 | 1488 |
| 1487 assertTrue(o1 instanceof Object) | 1489 assertTrue(o1 instanceof Object) |
| 1488 assertFalse(o1 instanceof f0) | 1490 assertFalse(o1 instanceof f0) |
| 1489 assertFalse(o1 instanceof f1) | 1491 assertFalse(o1 instanceof f1) |
| 1490 assertFalse(o1 instanceof f2) | 1492 assertFalse(o1 instanceof f2) |
| 1491 assertFalse(o1 instanceof f3) | 1493 assertFalse(o1 instanceof f3); |
| 1492 assertFalse(p1 instanceof Object) | 1494 assertTrue(p1 instanceof Object) |
| 1493 assertFalse(p1 instanceof f0) | 1495 assertFalse(p1 instanceof f0) |
| 1494 assertFalse(p1 instanceof f1) | 1496 assertFalse(p1 instanceof f1) |
| 1495 assertFalse(p1 instanceof f2) | 1497 assertFalse(p1 instanceof f2) |
| 1496 assertFalse(p1 instanceof f3) | 1498 assertFalse(p1 instanceof f3) |
| 1497 assertTrue(p2 instanceof Object) | 1499 assertTrue(p2 instanceof Object) |
| 1498 assertTrue(p2 instanceof f0) | 1500 assertTrue(p2 instanceof f0) |
| 1499 assertFalse(p2 instanceof f1) | 1501 assertFalse(p2 instanceof f1) |
| 1500 assertFalse(p2 instanceof f2) | 1502 assertFalse(p2 instanceof f2) |
| 1501 assertFalse(p2 instanceof f3) | 1503 assertFalse(p2 instanceof f3) |
| 1502 assertTrue(p3 instanceof Object) | 1504 assertTrue(p3 instanceof Object) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1577 assertFalse(f instanceof ff) | 1579 assertFalse(f instanceof ff) |
| 1578 } | 1580 } |
| 1579 | 1581 |
| 1580 TestInstanceofProxy() | 1582 TestInstanceofProxy() |
| 1581 | 1583 |
| 1582 | 1584 |
| 1583 | 1585 |
| 1584 // Prototype (Object.getPrototypeOf, Object.prototype.isPrototypeOf). | 1586 // Prototype (Object.getPrototypeOf, Object.prototype.isPrototypeOf). |
| 1585 | 1587 |
| 1586 function TestPrototype() { | 1588 function TestPrototype() { |
| 1587 var o1 = {} | 1589 var o1 = {o1:true} |
| 1588 var p1 = Proxy.create({}) | 1590 var p1 = new Proxy({p1:true}, {handler_p1:true}) |
| 1589 var p2 = Proxy.create({}, o1) | 1591 var p2 = new Proxy(o1, {handler_p2:true}) |
| 1590 var p3 = Proxy.create({}, p2) | 1592 var p3 = new Proxy(p2, {handler_p3:true}) |
| 1591 var p4 = Proxy.create({}, null) | 1593 var p4 = new Proxy({p4:true}, {handler_p4:true}) |
| 1592 var o2 = Object.create(p3) | 1594 var o2 = Object.create(p3) |
| 1593 | 1595 |
| 1594 assertSame(Object.getPrototypeOf(o1), Object.prototype) | 1596 assertSame(Object.getPrototypeOf(o1), Object.prototype) |
| 1595 assertSame(Object.getPrototypeOf(p1), null) | 1597 assertSame(Object.getPrototypeOf(p1), Object.prototype) |
| 1596 assertSame(Object.getPrototypeOf(p2), o1) | 1598 assertSame(Object.getPrototypeOf(p2), Object.prototype) |
| 1597 assertSame(Object.getPrototypeOf(p3), p2) | 1599 assertSame(Object.getPrototypeOf(p3), Object.prototype) |
| 1598 assertSame(Object.getPrototypeOf(p4), null) | 1600 assertSame(Object.getPrototypeOf(p4), Object.prototype) |
| 1599 assertSame(Object.getPrototypeOf(o2), p3) | 1601 assertSame(Object.getPrototypeOf(o2), p3) |
| 1600 | 1602 |
| 1601 assertTrue(Object.prototype.isPrototypeOf(o1)) | 1603 assertTrue(Object.prototype.isPrototypeOf(o1)) |
| 1602 assertFalse(Object.prototype.isPrototypeOf(p1)) | 1604 assertTrue(Object.prototype.isPrototypeOf(p1)) |
| 1603 assertTrue(Object.prototype.isPrototypeOf(p2)) | 1605 assertTrue(Object.prototype.isPrototypeOf(p2)) |
| 1604 assertTrue(Object.prototype.isPrototypeOf(p3)) | 1606 assertTrue(Object.prototype.isPrototypeOf(p3)) |
| 1605 assertFalse(Object.prototype.isPrototypeOf(p4)) | 1607 assertTrue(Object.prototype.isPrototypeOf(p4)) |
| 1606 assertTrue(Object.prototype.isPrototypeOf(o2)) | 1608 assertTrue(Object.prototype.isPrototypeOf(o2)) |
| 1607 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o1)) | 1609 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o1)) |
| 1608 assertFalse(Object.prototype.isPrototypeOf.call(Object.prototype, p1)) | 1610 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p1)) |
| 1609 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p2)) | 1611 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p2)) |
| 1610 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p3)) | 1612 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p3)) |
| 1611 assertFalse(Object.prototype.isPrototypeOf.call(Object.prototype, p4)) | 1613 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p4)) |
| 1612 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o2)) | 1614 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o2)) |
| 1613 assertFalse(Object.prototype.isPrototypeOf.call(o1, o1)) | 1615 assertFalse(Object.prototype.isPrototypeOf.call(o1, o1)) |
| 1614 assertFalse(Object.prototype.isPrototypeOf.call(o1, p1)) | 1616 assertFalse(Object.prototype.isPrototypeOf.call(o1, p1)) |
| 1615 assertTrue(Object.prototype.isPrototypeOf.call(o1, p2)) | 1617 assertTrue(Object.prototype.isPrototypeOf.call(o1, p2)) |
| 1616 assertTrue(Object.prototype.isPrototypeOf.call(o1, p3)) | 1618 assertTrue(Object.prototype.isPrototypeOf.call(o1, p3)) |
| 1617 assertFalse(Object.prototype.isPrototypeOf.call(o1, p4)) | 1619 assertFalse(Object.prototype.isPrototypeOf.call(o1, p4)) |
| 1618 assertTrue(Object.prototype.isPrototypeOf.call(o1, o2)) | 1620 assertTrue(Object.prototype.isPrototypeOf.call(o1, o2)) |
| 1619 assertFalse(Object.prototype.isPrototypeOf.call(p1, p1)) | 1621 assertFalse(Object.prototype.isPrototypeOf.call(p1, p1)) |
| 1620 assertFalse(Object.prototype.isPrototypeOf.call(p1, o1)) | 1622 assertFalse(Object.prototype.isPrototypeOf.call(p1, o1)) |
| 1621 assertFalse(Object.prototype.isPrototypeOf.call(p1, p2)) | 1623 assertFalse(Object.prototype.isPrototypeOf.call(p1, p2)) |
| 1622 assertFalse(Object.prototype.isPrototypeOf.call(p1, p3)) | 1624 assertFalse(Object.prototype.isPrototypeOf.call(p1, p3)) |
| 1623 assertFalse(Object.prototype.isPrototypeOf.call(p1, p4)) | 1625 assertFalse(Object.prototype.isPrototypeOf.call(p1, p4)) |
| 1624 assertFalse(Object.prototype.isPrototypeOf.call(p1, o2)) | 1626 assertFalse(Object.prototype.isPrototypeOf.call(p1, o2)) |
| 1625 assertFalse(Object.prototype.isPrototypeOf.call(p2, p1)) | 1627 assertFalse(Object.prototype.isPrototypeOf.call(p2, p1)) |
| 1626 assertFalse(Object.prototype.isPrototypeOf.call(p2, p2)) | 1628 assertFalse(Object.prototype.isPrototypeOf.call(p2, p2)) |
| 1627 assertTrue(Object.prototype.isPrototypeOf.call(p2, p3)) | 1629 assertTrue(Object.prototype.isPrototypeOf.call(p2, p3)) |
| 1628 assertFalse(Object.prototype.isPrototypeOf.call(p2, p4)) | 1630 assertFalse(Object.prototype.isPrototypeOf.call(p2, p4)) |
| 1629 assertTrue(Object.prototype.isPrototypeOf.call(p2, o2)) | 1631 assertTrue(Object.prototype.isPrototypeOf.call(p2, o2)) |
| 1630 assertFalse(Object.prototype.isPrototypeOf.call(p3, p2)) | 1632 assertFalse(Object.prototype.isPrototypeOf.call(p3, p2)) |
| 1631 assertTrue(Object.prototype.isPrototypeOf.call(p3, o2)) | 1633 assertTrue(Object.prototype.isPrototypeOf.call(p3, o2)) |
| 1632 assertFalse(Object.prototype.isPrototypeOf.call(o2, o1)) | 1634 assertFalse(Object.prototype.isPrototypeOf.call(o2, o1)) |
| 1633 assertFalse(Object.prototype.isPrototypeOf.call(o2, p1)) | 1635 assertFalse(Object.prototype.isPrototypeOf.call(o2, p1)) |
| 1634 assertFalse(Object.prototype.isPrototypeOf.call(o2, p2)) | 1636 assertFalse(Object.prototype.isPrototypeOf.call(o2, p2)) |
| 1635 assertFalse(Object.prototype.isPrototypeOf.call(o2, p3)) | 1637 assertFalse(Object.prototype.isPrototypeOf.call(o2, p3)) |
| 1636 assertFalse(Object.prototype.isPrototypeOf.call(o2, p4)) | 1638 assertFalse(Object.prototype.isPrototypeOf.call(o2, p4)) |
| 1637 assertFalse(Object.prototype.isPrototypeOf.call(o2, o2)) | 1639 assertFalse(Object.prototype.isPrototypeOf.call(o2, o2)) |
| 1638 | 1640 |
| 1639 var f = Proxy.createFunction({}, function() {}) | 1641 // var f = Proxy.createFunction({}, function() {}) |
|
Jakob Kummerow
2015/11/12 12:04:24
how about adding a TODO so this shows up when grep
| |
| 1640 assertSame(Object.getPrototypeOf(f), Function.prototype) | 1642 // assertSame(Object.getPrototypeOf(f), Function.prototype) |
| 1641 assertTrue(Object.prototype.isPrototypeOf(f)) | 1643 // assertTrue(Object.prototype.isPrototypeOf(f)) |
| 1642 assertTrue(Object.prototype.isPrototypeOf.call(Function.prototype, f)) | 1644 // assertTrue(Object.prototype.isPrototypeOf.call(Function.prototype, f)) |
| 1643 } | 1645 } |
| 1644 | 1646 |
| 1645 TestPrototype() | 1647 TestPrototype() |
| 1646 | 1648 |
| 1647 | 1649 |
| 1648 | 1650 |
| 1649 // Property names (Object.getOwnPropertyNames, Object.keys). | 1651 // Property names (Object.getOwnPropertyNames, Object.keys). |
| 1650 | 1652 |
| 1651 function TestPropertyNames(names, handler) { | 1653 function TestPropertyNames(names, handler) { |
| 1652 TestWithProxies(TestPropertyNames2, handler, names) | 1654 TestWithProxies(TestPropertyNames2, handler, names) |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1817 }, | 1819 }, |
| 1818 getOwnPropertyDescriptor: function(k) { throw "myexn" } | 1820 getOwnPropertyDescriptor: function(k) { throw "myexn" } |
| 1819 }) | 1821 }) |
| 1820 | 1822 |
| 1821 | 1823 |
| 1822 | 1824 |
| 1823 // Fixing (Object.freeze, Object.seal, Object.preventExtensions, | 1825 // Fixing (Object.freeze, Object.seal, Object.preventExtensions, |
| 1824 // Object.isFrozen, Object.isSealed, Object.isExtensible) | 1826 // Object.isFrozen, Object.isSealed, Object.isExtensible) |
| 1825 | 1827 |
| 1826 function TestFix(names, handler) { | 1828 function TestFix(names, handler) { |
| 1827 var proto = {p: 77} | 1829 var target = {p: 77} |
| 1828 var assertFixing = function(o, s, f, e) { | 1830 var assertFixing = function(o, s, f, e) { |
| 1829 assertEquals(s, Object.isSealed(o)) | 1831 assertEquals(s, Object.isSealed(o)) |
| 1830 assertEquals(f, Object.isFrozen(o)) | 1832 assertEquals(f, Object.isFrozen(o)) |
| 1831 assertEquals(e, Object.isExtensible(o)) | 1833 assertEquals(e, Object.isExtensible(o)) |
| 1832 } | 1834 } |
| 1833 | 1835 |
| 1834 var p1 = Proxy.create(handler, proto) | 1836 var p1 = new Proxy(target, handler) |
| 1835 assertFixing(p1, false, false, true) | 1837 assertFixing(p1, false, false, true) |
| 1836 Object.seal(p1) | 1838 Object.seal(p1) |
| 1837 assertFixing(p1, true, names.length === 0, false) | 1839 assertFixing(p1, true, names.length === 0, false) |
| 1838 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p1).sort()) | 1840 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p1).sort()) |
| 1839 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), | 1841 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), |
| 1840 Object.keys(p1).sort()) | 1842 Object.keys(p1).sort()) |
| 1841 assertEquals(proto, Object.getPrototypeOf(p1)) | 1843 assertEquals(target, Object.getPrototypeOf(p1)) |
| 1842 assertEquals(77, p1.p) | 1844 assertEquals(77, p1.p) |
| 1843 for (var n in p1) { | 1845 for (var n in p1) { |
| 1844 var desc = Object.getOwnPropertyDescriptor(p1, n) | 1846 var desc = Object.getOwnPropertyDescriptor(p1, n) |
| 1845 if (desc !== undefined) assertFalse(desc.configurable) | 1847 if (desc !== undefined) assertFalse(desc.configurable) |
| 1846 } | 1848 } |
| 1847 | 1849 |
| 1848 var p2 = Proxy.create(handler, proto) | 1850 var p2 = new Proxy(target, handler) |
| 1849 assertFixing(p2, false, false, true) | 1851 assertFixing(p2, false, false, true) |
| 1850 Object.freeze(p2) | 1852 Object.freeze(p2) |
| 1851 assertFixing(p2, true, true, false) | 1853 assertFixing(p2, true, true, false) |
| 1852 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p2).sort()) | 1854 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p2).sort()) |
| 1853 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), | 1855 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), |
| 1854 Object.keys(p2).sort()) | 1856 Object.keys(p2).sort()) |
| 1855 assertEquals(proto, Object.getPrototypeOf(p2)) | 1857 assertEquals(target, Object.getPrototypeOf(p2)) |
| 1856 assertEquals(77, p2.p) | 1858 assertEquals(77, p2.p) |
| 1857 for (var n in p2) { | 1859 for (var n in p2) { |
| 1858 var desc = Object.getOwnPropertyDescriptor(p2, n) | 1860 var desc = Object.getOwnPropertyDescriptor(p2, n) |
| 1859 if (desc !== undefined) assertFalse(desc.writable) | 1861 if (desc !== undefined) assertFalse(desc.writable) |
| 1860 if (desc !== undefined) assertFalse(desc.configurable) | 1862 if (desc !== undefined) assertFalse(desc.configurable) |
| 1861 } | 1863 } |
| 1862 | 1864 |
| 1863 var p3 = Proxy.create(handler, proto) | 1865 var p3 = new Proxy(target, handler) |
| 1864 assertFixing(p3, false, false, true) | 1866 assertFixing(p3, false, false, true) |
| 1865 Object.preventExtensions(p3) | 1867 Object.preventExtensions(p3) |
| 1866 assertFixing(p3, names.length === 0, names.length === 0, false) | 1868 assertFixing(p3, names.length === 0, names.length === 0, false) |
| 1867 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p3).sort()) | 1869 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p3).sort()) |
| 1868 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), | 1870 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), |
| 1869 Object.keys(p3).sort()) | 1871 Object.keys(p3).sort()) |
| 1870 assertEquals(proto, Object.getPrototypeOf(p3)) | 1872 assertEquals(target, Object.getPrototypeOf(p3)) |
| 1871 assertEquals(77, p3.p) | 1873 assertEquals(77, p3.p) |
| 1872 | 1874 |
| 1873 var p = Proxy.create(handler, proto) | 1875 var p = new Proxy(target, handler) |
| 1874 var o = Object.create(p) | 1876 var o = Object.create(p) |
| 1875 assertFixing(p, false, false, true) | 1877 assertFixing(p, false, false, true) |
| 1876 assertFixing(o, false, false, true) | 1878 assertFixing(o, false, false, true) |
| 1877 Object.freeze(o) | 1879 Object.freeze(o) |
| 1878 assertFixing(p, false, false, true) | 1880 assertFixing(p, false, false, true) |
| 1879 assertFixing(o, true, true, false) | 1881 assertFixing(o, true, true, false) |
| 1880 } | 1882 } |
| 1881 | 1883 |
| 1882 TestFix([], { | 1884 TestFix([], { |
| 1883 fix: function() { return {} } | 1885 fix: function() { return {} } |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2097 | 2099 |
| 2098 | 2100 |
| 2099 | 2101 |
| 2100 // String conversion (Object.prototype.toString, | 2102 // String conversion (Object.prototype.toString, |
| 2101 // Object.prototype.toLocaleString, | 2103 // Object.prototype.toLocaleString, |
| 2102 // Function.prototype.toString) | 2104 // Function.prototype.toString) |
| 2103 | 2105 |
| 2104 var key | 2106 var key |
| 2105 | 2107 |
| 2106 function TestToString(handler) { | 2108 function TestToString(handler) { |
| 2107 var p = Proxy.create(handler) | 2109 var p = new Proxy({}, handler) |
| 2108 key = "" | 2110 key = "" |
| 2109 assertEquals("[object Object]", Object.prototype.toString.call(p)) | 2111 assertEquals("[object Object]", Object.prototype.toString.call(p)) |
| 2110 assertEquals("", key) | 2112 assertEquals("", key) |
| 2111 assertEquals("my_proxy", Object.prototype.toLocaleString.call(p)) | 2113 assertEquals("my_proxy", Object.prototype.toLocaleString.call(p)) |
| 2112 assertEquals("toString", key) | 2114 assertEquals("toString", key) |
| 2113 | 2115 |
| 2114 var f = Proxy.createFunction(handler, function() {}) | 2116 var f = Proxy.createFunction(handler, function() {}) |
| 2115 key = "" | 2117 key = "" |
| 2116 assertEquals("[object Function]", Object.prototype.toString.call(f)) | 2118 assertEquals("[object Function]", Object.prototype.toString.call(f)) |
| 2117 assertEquals("", key) | 2119 assertEquals("", key) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 2129 | 2131 |
| 2130 TestToString({ | 2132 TestToString({ |
| 2131 get: function(r, k) { key = k; return function() { return "my_proxy" } } | 2133 get: function(r, k) { key = k; return function() { return "my_proxy" } } |
| 2132 }) | 2134 }) |
| 2133 | 2135 |
| 2134 TestToString({ | 2136 TestToString({ |
| 2135 get: function(r, k) { return this.get2(r, k) }, | 2137 get: function(r, k) { return this.get2(r, k) }, |
| 2136 get2: function(r, k) { key = k; return function() { return "my_proxy" } } | 2138 get2: function(r, k) { key = k; return function() { return "my_proxy" } } |
| 2137 }) | 2139 }) |
| 2138 | 2140 |
| 2139 TestToString(Proxy.create({ | 2141 TestToString(new Proxy({}, { |
| 2140 get: function(pr, pk) { | 2142 get: function(pr, pk) { |
| 2141 return function(r, k) { key = k; return function() { return "my_proxy" } } | 2143 return function(r, k) { key = k; return function() { return "my_proxy" } } |
| 2142 } | 2144 } |
| 2143 })) | 2145 })) |
| 2144 | 2146 |
| 2145 | 2147 |
| 2146 function TestToStringThrow(handler) { | 2148 function TestToStringThrow(handler) { |
| 2147 var p = Proxy.create(handler) | 2149 var p = new Proxy({}, handler) |
| 2148 assertEquals("[object Object]", Object.prototype.toString.call(p)) | 2150 assertEquals("[object Object]", Object.prototype.toString.call(p)) |
| 2149 assertThrows(function(){ Object.prototype.toLocaleString.call(p) }, "myexn") | 2151 assertThrows(function(){ Object.prototype.toLocaleString.call(p) }, "myexn") |
| 2150 | 2152 |
| 2151 var f = Proxy.createFunction(handler, function() {}) | 2153 var f = Proxy.createFunction(handler, function() {}) |
| 2152 assertEquals("[object Function]", Object.prototype.toString.call(f)) | 2154 assertEquals("[object Function]", Object.prototype.toString.call(f)) |
| 2153 assertThrows(function(){ Object.prototype.toLocaleString.call(f) }, "myexn") | 2155 assertThrows(function(){ Object.prototype.toLocaleString.call(f) }, "myexn") |
| 2154 | 2156 |
| 2155 var o = Object.create(p) | 2157 var o = Object.create(p) |
| 2156 assertEquals("[object Object]", Object.prototype.toString.call(o)) | 2158 assertEquals("[object Object]", Object.prototype.toString.call(o)) |
| 2157 assertThrows(function(){ Object.prototype.toLocaleString.call(o) }, "myexn") | 2159 assertThrows(function(){ Object.prototype.toLocaleString.call(o) }, "myexn") |
| 2158 } | 2160 } |
| 2159 | 2161 |
| 2160 TestToStringThrow({ | 2162 TestToStringThrow({ |
| 2161 get: function(r, k) { throw "myexn" } | 2163 get: function(r, k) { throw "myexn" } |
| 2162 }) | 2164 }) |
| 2163 | 2165 |
| 2164 TestToStringThrow({ | 2166 TestToStringThrow({ |
| 2165 get: function(r, k) { return function() { throw "myexn" } } | 2167 get: function(r, k) { return function() { throw "myexn" } } |
| 2166 }) | 2168 }) |
| 2167 | 2169 |
| 2168 TestToStringThrow({ | 2170 TestToStringThrow({ |
| 2169 get: function(r, k) { return this.get2(r, k) }, | 2171 get: function(r, k) { return this.get2(r, k) }, |
| 2170 get2: function(r, k) { throw "myexn" } | 2172 get2: function(r, k) { throw "myexn" } |
| 2171 }) | 2173 }) |
| 2172 | 2174 |
| 2173 TestToStringThrow(Proxy.create({ | 2175 TestToStringThrow(new Proxy({}, { |
| 2174 get: function(pr, pk) { throw "myexn" } | 2176 get: function(pr, pk) { throw "myexn" } |
| 2175 })) | 2177 })) |
| 2176 | 2178 |
| 2177 TestToStringThrow(Proxy.create({ | 2179 TestToStringThrow(new Proxy({}, { |
| 2178 get: function(pr, pk) { | 2180 get: function(pr, pk) { |
| 2179 return function(r, k) { throw "myexn" } | 2181 return function(r, k) { throw "myexn" } |
| 2180 } | 2182 } |
| 2181 })) | 2183 })) |
| 2182 | 2184 |
| 2183 | 2185 |
| 2184 | 2186 |
| 2185 // Value conversion (Object.prototype.toValue) | 2187 // Value conversion (Object.prototype.toValue) |
| 2186 | 2188 |
| 2187 function TestValueOf(handler) { | 2189 function TestValueOf(handler) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2234 key = k; return {enumerable: k < "z", configurable: true} | 2236 key = k; return {enumerable: k < "z", configurable: true} |
| 2235 }, | 2237 }, |
| 2236 }) | 2238 }) |
| 2237 | 2239 |
| 2238 TestIsEnumerable({ | 2240 TestIsEnumerable({ |
| 2239 getOwnPropertyDescriptor: function(k) { | 2241 getOwnPropertyDescriptor: function(k) { |
| 2240 key = k; return {get enumerable() { return k < "z" }, configurable: true} | 2242 key = k; return {get enumerable() { return k < "z" }, configurable: true} |
| 2241 }, | 2243 }, |
| 2242 }) | 2244 }) |
| 2243 | 2245 |
| 2244 TestIsEnumerable(Proxy.create({ | 2246 TestIsEnumerable(new Proxy({}, { |
| 2245 get: function(pr, pk) { | 2247 get: function(pr, pk) { |
| 2246 return function(k) { | 2248 return function(k) { |
| 2247 key = k; return {enumerable: k < "z", configurable: true} | 2249 key = k; return {enumerable: k < "z", configurable: true} |
| 2248 } | 2250 } |
| 2249 } | 2251 } |
| 2250 })) | 2252 })) |
| 2251 | 2253 |
| 2252 | 2254 |
| 2253 function TestIsEnumerableThrow(handler) { | 2255 function TestIsEnumerableThrow(handler) { |
| 2254 TestWithProxies(TestIsEnumerableThrow2, handler) | 2256 TestWithProxies(TestIsEnumerableThrow2, handler) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2272 }, | 2274 }, |
| 2273 getOwnPropertyDescriptor2: function(k) { throw "myexn" } | 2275 getOwnPropertyDescriptor2: function(k) { throw "myexn" } |
| 2274 }) | 2276 }) |
| 2275 | 2277 |
| 2276 TestIsEnumerableThrow({ | 2278 TestIsEnumerableThrow({ |
| 2277 getOwnPropertyDescriptor: function(k) { | 2279 getOwnPropertyDescriptor: function(k) { |
| 2278 return {get enumerable() { throw "myexn" }, configurable: true} | 2280 return {get enumerable() { throw "myexn" }, configurable: true} |
| 2279 }, | 2281 }, |
| 2280 }) | 2282 }) |
| 2281 | 2283 |
| 2282 TestIsEnumerableThrow(Proxy.create({ | 2284 TestIsEnumerableThrow(new Proxy({}, { |
| 2283 get: function(pr, pk) { throw "myexn" } | 2285 get: function(pr, pk) { throw "myexn" } |
| 2284 })) | 2286 })) |
| 2285 | 2287 |
| 2286 TestIsEnumerableThrow(Proxy.create({ | 2288 TestIsEnumerableThrow(new Proxy({}, { |
| 2287 get: function(pr, pk) { | 2289 get: function(pr, pk) { |
| 2288 return function(k) { throw "myexn" } | 2290 return function(k) { throw "myexn" } |
| 2289 } | 2291 } |
| 2290 })) | 2292 })) |
| 2291 | 2293 |
| 2292 | 2294 |
| 2293 | 2295 |
| 2294 // Constructor functions with proxy prototypes. | 2296 // Constructor functions with proxy prototypes. |
| 2295 | 2297 |
| 2296 function TestConstructorWithProxyPrototype() { | 2298 function TestConstructorWithProxyPrototype() { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 2308 TestConstructorWithProxyPrototype(); | 2310 TestConstructorWithProxyPrototype(); |
| 2309 | 2311 |
| 2310 function TestOptWithProxyPrototype() { | 2312 function TestOptWithProxyPrototype() { |
| 2311 var handler = { | 2313 var handler = { |
| 2312 getPropertyDescriptor: function(k) { | 2314 getPropertyDescriptor: function(k) { |
| 2313 return {value: 10, configurable: true, enumerable: true, writable: true}; | 2315 return {value: 10, configurable: true, enumerable: true, writable: true}; |
| 2314 } | 2316 } |
| 2315 }; | 2317 }; |
| 2316 | 2318 |
| 2317 function C() {}; | 2319 function C() {}; |
| 2318 C.prototype = Proxy.create(handler); | 2320 C.prototype = new Proxy({}, handler); |
| 2319 var o = new C(); | 2321 var o = new C(); |
| 2320 | 2322 |
| 2321 function f() { | 2323 function f() { |
| 2322 return o.x; | 2324 return o.x; |
| 2323 } | 2325 } |
| 2324 assertEquals(10, f()); | 2326 assertEquals(10, f()); |
| 2325 assertEquals(10, f()); | 2327 assertEquals(10, f()); |
| 2326 %OptimizeFunctionOnNextCall(f); | 2328 %OptimizeFunctionOnNextCall(f); |
| 2327 assertEquals(10, f()); | 2329 assertEquals(10, f()); |
| 2328 } | 2330 } |
| 2329 | 2331 |
| 2330 TestOptWithProxyPrototype(); | 2332 TestOptWithProxyPrototype(); |
| OLD | NEW |