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 13 matching lines...) Expand all Loading... |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
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 // Helper. | 31 // Helper. |
32 | 32 |
33 function TestWithProxies(test, x, y, z) { | 33 function TestWithProxies(test, x, y, z) { |
34 test(Proxy.create, x, y, z) | 34 test(function(h){ return new Proxy({}, h) }, x, y, z) |
35 test(function(h) {return Proxy.createFunction(h, function() {})}, x, y, z) | 35 test(function(h) { |
| 36 return Proxy.createFunction(h, function() {}) |
| 37 }, x, y, z) |
36 } | 38 } |
37 | 39 |
38 | 40 |
39 // Iterate over a proxy. | 41 // Iterate over a proxy. |
40 | 42 |
41 function TestForIn(properties, handler) { | 43 function TestForIn(properties, handler) { |
42 TestWithProxies(TestForIn2, properties, handler) | 44 TestWithProxies(TestForIn2, properties, handler) |
43 } | 45 } |
44 | 46 |
45 function TestForIn2(create, properties, handler) { | 47 function TestForIn2(create, properties, handler) { |
(...skipping 18 matching lines...) Expand all Loading... |
64 switch (k) { | 66 switch (k) { |
65 case "a": return {enumerable: false, value: "3", configurable: true}; | 67 case "a": return {enumerable: false, value: "3", configurable: true}; |
66 case "b": return {enumerable: true, get get() {}, configurable: true}; | 68 case "b": return {enumerable: true, get get() {}, configurable: true}; |
67 case "c": return {value: 4, configurable: true}; | 69 case "c": return {value: 4, configurable: true}; |
68 case "d": return {get enumerable() { return true }, configurable: true}; | 70 case "d": return {get enumerable() { return true }, configurable: true}; |
69 default: return undefined; | 71 default: return undefined; |
70 } | 72 } |
71 } | 73 } |
72 }) | 74 }) |
73 | 75 |
74 TestForIn(["b", "a", "0", "c"], Proxy.create({ | 76 TestForIn(["b", "a", "0", "c"], new Proxy({}, { |
75 get: function(pr, pk) { | 77 get: function(pr, pk) { |
76 return function() { return ["b", "a", 0, "c"] } | 78 return function() { return ["b", "a", 0, "c"] } |
77 } | 79 } |
78 })) | 80 })) |
79 | 81 |
80 | 82 |
81 | 83 |
82 // Iterate over an object with a proxy prototype. | 84 // Iterate over an object with a proxy prototype. |
83 | 85 |
84 function TestForInDerived(properties, handler) { | 86 function TestForInDerived(properties, handler) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 156 |
155 TestForInThrow({ | 157 TestForInThrow({ |
156 getPropertyNames: function() { throw "myexn" } | 158 getPropertyNames: function() { throw "myexn" } |
157 }) | 159 }) |
158 | 160 |
159 TestForInThrow({ | 161 TestForInThrow({ |
160 getPropertyNames: function() { return ["a"] }, | 162 getPropertyNames: function() { return ["a"] }, |
161 getPropertyDescriptor: function() { throw "myexn" } | 163 getPropertyDescriptor: function() { throw "myexn" } |
162 }) | 164 }) |
163 | 165 |
164 TestForInThrow(Proxy.create({ | 166 TestForInThrow(new Proxy({}, { |
165 get: function(pr, pk) { | 167 get: function(pr, pk) { |
166 return function() { throw "myexn" } | 168 return function() { throw "myexn" } |
167 } | 169 } |
168 })); | 170 })); |
169 | 171 |
170 (function() { | 172 (function() { |
171 var p = Proxy.create({enumerate:function() { return [0]; }}); | 173 var p = new Proxy({}, {enumerate:function() { return [0]; }}); |
172 var o = [0]; | 174 var o = [0]; |
173 o.__proto__ = p; | 175 o.__proto__ = p; |
174 var keys = []; | 176 var keys = []; |
175 for (var k in o) { keys.push(k); }; | 177 for (var k in o) { keys.push(k); }; |
176 assertEquals(["0"], keys); | 178 assertEquals(["0"], keys); |
177 })(); | 179 })(); |
178 | 180 |
179 (function () { | 181 (function () { |
180 var p = Proxy.create({getOwnPropertyNames: | 182 var p = new Proxy({}, {getOwnPropertyNames: |
181 function() { return [1, Symbol(), 2] }}); | 183 function() { return [1, Symbol(), 2] }}); |
182 assertEquals(["1","2"], Object.getOwnPropertyNames(p)); | 184 assertEquals(["1","2"], Object.getOwnPropertyNames(p)); |
183 })(); | 185 })(); |
OLD | NEW |