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 14 matching lines...) Expand all Loading... | |
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(function(h) { return new Proxy({}, h) }, x, y, z) | 34 test(function(h) { return new Proxy({}, h) }, x, y, z) |
35 test(function(h) { | 35 // TODO(cbruni): enable once we have [[Call]] working. |
Jakob Kummerow
2015/12/10 15:35:03
Don't we have [[Call]] working?
| |
36 return Proxy.createFunction(h, function() {}) | 36 // test(function(h) { |
37 }, x, y, z) | 37 // return Proxy.createFunction(h, function() {}) |
38 // }, x, y, z) | |
neis
2015/12/10 15:13:50
This can be done now :)
| |
38 } | 39 } |
39 | 40 |
40 | 41 |
41 | 42 |
42 // Getting. | 43 // Getting. |
43 | 44 |
44 function TestWithGet(handler) { | 45 function TestWithGet(handler) { |
45 TestWithProxies(TestWithGet2, handler) | 46 TestWithProxies(TestWithGet2, handler) |
46 } | 47 } |
47 | 48 |
(...skipping 17 matching lines...) Expand all Loading... | |
65 assertEquals("global", c) | 66 assertEquals("global", c) |
66 assertEquals("own", d) | 67 assertEquals("own", d) |
67 } | 68 } |
68 } | 69 } |
69 | 70 |
70 TestWithGet({ | 71 TestWithGet({ |
71 get: function(r, k) { | 72 get: function(r, k) { |
72 key = k; | 73 key = k; |
73 return k === "a" ? "onproxy" : undefined | 74 return k === "a" ? "onproxy" : undefined |
74 }, | 75 }, |
75 getPropertyDescriptor: function(k) { | 76 getOwnPropertyDescriptor: function(t, k) { |
76 key = k; | 77 key = k; |
77 return k === "a" ? {value: "onproxy", configurable: true} : undefined | 78 return k === "a" ? {value: "onproxy", configurable: true} : undefined |
78 } | 79 } |
79 }) | 80 }) |
80 | 81 |
81 TestWithGet({ | 82 TestWithGet({ |
82 get: function(r, k) { return this.get2(r, k) }, | 83 get: function(r, k) { return this.get2(r, k) }, |
83 get2: function(r, k) { key = k; return k === "a" ? "onproxy" : undefined }, | 84 get2: function(r, k) { key = k; return k === "a" ? "onproxy" : undefined }, |
84 getPropertyDescriptor: function(k) { | 85 getOwnPropertyDescriptor: function(t, k) { |
85 key = k; | 86 key = k; |
86 return k === "a" ? {value: "onproxy", configurable: true} : undefined | 87 return k === "a" ? {value: "onproxy", configurable: true} : undefined |
87 } | 88 } |
88 }) | 89 }) |
89 | 90 |
90 TestWithGet({ | 91 TestWithGet({ |
91 getPropertyDescriptor: function(k) { | 92 get: function(r, k) { |
93 key = k; | |
94 return k === "a" ? "onproxy" : undefined | |
95 }, | |
96 getOwnPropertyDescriptor: function(t, k) { | |
97 return this.getOwnPropertyDescriptor2(k) | |
98 }, | |
99 getOwnPropertyDescriptor2: function(k) { | |
92 key = k; | 100 key = k; |
93 return k === "a" ? {value: "onproxy", configurable: true} : undefined | 101 return k === "a" ? {value: "onproxy", configurable: true} : undefined |
94 } | 102 } |
95 }) | 103 }) |
96 | 104 |
97 TestWithGet({ | 105 TestWithGet({ |
98 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, | 106 get: function(r, k) { |
99 getPropertyDescriptor2: function(k) { | |
100 key = k; | 107 key = k; |
101 return k === "a" ? {value: "onproxy", configurable: true} : undefined | 108 return k === "a" ? "onproxy" : undefined |
102 } | 109 }, |
103 }) | 110 getOwnPropertyDescriptor: function(t, k) { |
104 | |
105 TestWithGet({ | |
106 getPropertyDescriptor: function(k) { | |
107 key = k; | 111 key = k; |
108 return k === "a" ? | 112 return k === "a" ? |
109 {get value() { return "onproxy" }, configurable: true} : undefined | 113 {get value() { return "onproxy" }, configurable: true} : undefined |
110 } | 114 } |
111 }) | 115 }) |
112 | 116 |
113 TestWithGet({ | |
114 get: undefined, | |
115 getPropertyDescriptor: function(k) { | |
116 key = k; | |
117 return k === "a" ? {value: "onproxy", configurable: true} : undefined | |
118 } | |
119 }) | |
120 | |
121 | 117 |
122 | 118 |
123 // Invoking. | 119 // Invoking. |
124 | 120 |
125 function TestWithGetCall(handler) { | 121 function TestWithGetCall(handler) { |
126 TestWithProxies(TestWithGetCall2, handler) | 122 TestWithProxies(TestWithGetCall2, handler) |
127 } | 123 } |
128 | 124 |
129 var receiver = null | 125 var receiver = null |
130 var c = function() { return "global" } | 126 var c = function() { return "global" } |
(...skipping 18 matching lines...) Expand all Loading... | |
149 assertEquals("local", b()) | 145 assertEquals("local", b()) |
150 assertEquals("global", c()) | 146 assertEquals("global", c()) |
151 assertEquals("own", d()) | 147 assertEquals("own", d()) |
152 } | 148 } |
153 } | 149 } |
154 | 150 |
155 function onproxy() { receiver = this; return "onproxy" } | 151 function onproxy() { receiver = this; return "onproxy" } |
156 | 152 |
157 TestWithGetCall({ | 153 TestWithGetCall({ |
158 get: function(r, k) { key = k; return k === "a" ? onproxy : undefined }, | 154 get: function(r, k) { key = k; return k === "a" ? onproxy : undefined }, |
159 getPropertyDescriptor: function(k) { | 155 getOwnPropertyDescriptor: function(t, k) { |
160 key = k; | 156 key = k; |
161 return k === "a" ? {value: onproxy, configurable: true} : undefined | 157 return k === "a" ? {value: onproxy, configurable: true} : undefined |
162 } | 158 } |
163 }) | 159 }) |
164 | 160 |
165 TestWithGetCall({ | 161 TestWithGetCall({ |
166 get: function(r, k) { return this.get2(r, k) }, | 162 get: function(r, k) { return this.get2(r, k) }, |
167 get2: function(r, k) { key = k; return k === "a" ? onproxy : undefined }, | 163 get2: function(r, k) { key = k; return k === "a" ? onproxy : undefined }, |
168 getPropertyDescriptor: function(k) { | 164 getOwnPropertyDescriptor: function(t, k) { |
169 key = k; | 165 key = k; |
170 return k === "a" ? {value: onproxy, configurable: true} : undefined | 166 return k === "a" ? {value: onproxy, configurable: true} : undefined |
171 } | 167 } |
172 }) | 168 }) |
173 | 169 |
174 TestWithGetCall({ | 170 TestWithGetCall({ |
175 getPropertyDescriptor: function(k) { | 171 get: function(r, k) { key = k; return k === "a" ? onproxy : undefined }, |
172 getOwnPropertyDescriptor: function(t, k) { | |
173 return this.getOwnPropertyDescriptor2(k) | |
174 }, | |
175 getOwnPropertyDescriptor2: function(k) { | |
176 key = k; | 176 key = k; |
177 return k === "a" ? {value: onproxy, configurable: true} : undefined | 177 return k === "a" ? {value: onproxy, configurable: true} : undefined |
178 } | 178 } |
179 }) | 179 }) |
180 | 180 |
181 TestWithGetCall({ | 181 TestWithGetCall({ |
182 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, | 182 get: function(r, k) { key = k; return k === "a" ? onproxy : undefined }, |
183 getPropertyDescriptor2: function(k) { | 183 getOwnPropertyDescriptor: function(t, k) { |
184 key = k; | |
185 return k === "a" ? {value: onproxy, configurable: true} : undefined | |
186 } | |
187 }) | |
188 | |
189 TestWithGetCall({ | |
190 getPropertyDescriptor: function(k) { | |
191 key = k; | 184 key = k; |
192 return k === "a" ? | 185 return k === "a" ? |
193 {get value() { return onproxy }, configurable: true} : undefined | 186 {get value() { return onproxy }, configurable: true} : undefined |
194 } | 187 } |
195 }) | 188 }) |
196 | 189 |
197 TestWithGetCall({ | |
198 get: undefined, | |
199 getPropertyDescriptor: function(k) { | |
200 key = k; | |
201 return k === "a" ? {value: onproxy, configurable: true} : undefined | |
202 } | |
203 }) | |
204 | |
205 | 190 |
206 function TestWithGetCallThrow(handler) { | 191 function TestWithGetCallThrow(handler) { |
207 TestWithProxies(TestWithGetCallThrow2, handler) | 192 TestWithProxies(TestWithGetCallThrow2, handler) |
208 } | 193 } |
209 | 194 |
210 function TestWithGetCallThrow2(create, handler) { | 195 function TestWithGetCallThrow2(create, handler) { |
211 var b = function() { return "local" } | 196 var b = function() { return "local" } |
212 | 197 |
213 var p = create(handler) | 198 var p = create(handler) |
214 with (p) { | 199 with (p) { |
215 assertThrows(function(){ a() }, "myexn") | 200 assertThrows(function(){ a() }, "myexn") |
216 assertEquals("local", b()) | 201 assertEquals("local", b()) |
217 assertEquals("global", c()) | 202 assertEquals("global", c()) |
218 } | 203 } |
219 | 204 |
220 var o = Object.create(p, {d: {value: function() { return "own" }}}) | 205 var o = Object.create(p, {d: {value: function() { return "own" }}}) |
221 with (o) { | 206 with (o) { |
222 assertThrows(function(){ a() }, "myexn") | 207 assertThrows(function(){ a() }, "myexn") |
223 assertEquals("local", b()) | 208 assertEquals("local", b()) |
224 assertEquals("global", c()) | 209 assertEquals("global", c()) |
225 assertEquals("own", d()) | 210 assertEquals("own", d()) |
226 } | 211 } |
227 } | 212 } |
228 | 213 |
229 function onproxythrow() { throw "myexn" } | 214 function onproxythrow() { throw "myexn" } |
230 | 215 |
231 TestWithGetCallThrow({ | 216 TestWithGetCallThrow({ |
232 get: function(r, k) { key = k; return k === "a" ? onproxythrow : undefined }, | 217 get: function(r, k) { key = k; return k === "a" ? onproxythrow : undefined }, |
233 getPropertyDescriptor: function(k) { | |
234 key = k; | |
235 return k === "a" ? {value: onproxythrow, configurable: true} : undefined | |
236 } | |
237 }) | 218 }) |
238 | 219 |
239 TestWithGetCallThrow({ | 220 TestWithGetCallThrow({ |
240 get: function(r, k) { return this.get2(r, k) }, | 221 get: function(r, k) { return this.get2(r, k) }, |
241 get2: function(r, k) { key = k; return k === "a" ? onproxythrow : undefined }, | 222 get2: function(r, k) { key = k; return k === "a" ? onproxythrow : undefined }, |
242 getPropertyDescriptor: function(k) { | |
243 key = k; | |
244 return k === "a" ? {value: onproxythrow, configurable: true} : undefined | |
245 } | |
246 }) | |
247 | |
248 TestWithGetCallThrow({ | |
249 getPropertyDescriptor: function(k) { | |
250 key = k; | |
251 return k === "a" ? {value: onproxythrow, configurable: true} : undefined | |
252 } | |
253 }) | |
254 | |
255 TestWithGetCallThrow({ | |
256 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, | |
257 getPropertyDescriptor2: function(k) { | |
258 key = k; | |
259 return k === "a" ? {value: onproxythrow, configurable: true} : undefined | |
260 } | |
261 }) | |
262 | |
263 TestWithGetCallThrow({ | |
264 getPropertyDescriptor: function(k) { | |
265 key = k; | |
266 return k === "a" ? | |
267 {get value() { return onproxythrow }, configurable: true} : undefined | |
268 } | |
269 }) | |
270 | |
271 TestWithGetCallThrow({ | |
272 get: undefined, | |
273 getPropertyDescriptor: function(k) { | |
274 key = k; | |
275 return k === "a" ? {value: onproxythrow, configurable: true} : undefined | |
276 } | |
277 }) | 223 }) |
278 | 224 |
279 | 225 |
280 | 226 |
281 // Setting. | 227 // Setting. |
282 | 228 |
283 var key | 229 var key |
284 var val | 230 var val |
285 | 231 |
286 function TestWithSet(handler, hasSetter) { | 232 function TestWithSet(handler, hasSetter) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 b = "local" | 266 b = "local" |
321 c = "global" | 267 c = "global" |
322 d = "own" | 268 d = "own" |
323 assertEquals("a", key) | 269 assertEquals("a", key) |
324 assertEquals("set", val) | 270 assertEquals("set", val) |
325 } | 271 } |
326 } | 272 } |
327 | 273 |
328 TestWithSet({ | 274 TestWithSet({ |
329 set: function(r, k, v) { key = k; val = v; return true }, | 275 set: function(r, k, v) { key = k; val = v; return true }, |
330 getPropertyDescriptor: function(k) { | 276 getOwnPropertyDescriptor: function(t, k) { |
331 return k === "a" ? {writable: true, configurable: true} : undefined | 277 return k === "a" ? {writable: true, configurable: true} : undefined |
332 } | 278 } |
333 }) | 279 }) |
334 | 280 |
335 TestWithSet({ | 281 TestWithSet({ |
336 set: function(r, k, v) { return this.set2(r, k, v) }, | 282 set: function(r, k, v) { return this.set2(r, k, v) }, |
337 set2: function(r, k, v) { key = k; val = v; return true }, | 283 set2: function(r, k, v) { key = k; val = v; return true }, |
338 getPropertyDescriptor: function(k) { | 284 getOwnPropertyDescriptor: function(t, k) { |
339 return k === "a" ? {writable: true, configurable: true} : undefined | 285 return k === "a" ? {writable: true, configurable: true} : undefined |
340 } | 286 } |
341 }) | 287 }) |
342 | 288 |
343 TestWithSet({ | 289 TestWithSet({ |
344 getPropertyDescriptor: function(k) { | 290 getOwnPropertyDescriptor: function(t, k) { |
345 return this.getOwnPropertyDescriptor(k) | |
346 }, | |
347 getOwnPropertyDescriptor: function(k) { | |
348 return k === "a" ? {writable: true, configurable: true} : undefined | 291 return k === "a" ? {writable: true, configurable: true} : undefined |
349 }, | 292 }, |
350 defineProperty: function(k, desc) { key = k; val = desc.value } | 293 defineProperty: function(t, k, desc) { key = k; val = desc.value } |
351 }) | 294 }) |
352 | 295 |
353 TestWithSet({ | 296 TestWithSet({ |
354 getOwnPropertyDescriptor: function(k) { | 297 getOwnPropertyDescriptor: function(t, k) { |
355 return this.getPropertyDescriptor2(k) | 298 return this.getOwnPropertyDescriptor2(k) |
356 }, | 299 }, |
357 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, | 300 getOwnPropertyDescriptor2: function(k) { |
358 getPropertyDescriptor2: function(k) { | |
359 return k === "a" ? {writable: true, configurable: true} : undefined | 301 return k === "a" ? {writable: true, configurable: true} : undefined |
360 }, | 302 }, |
361 defineProperty: function(k, desc) { this.defineProperty2(k, desc) }, | 303 defineProperty: function(t, k, desc) { this.defineProperty2(k, desc) }, |
362 defineProperty2: function(k, desc) { key = k; val = desc.value } | 304 defineProperty2: function(k, desc) { key = k; val = desc.value } |
363 }) | 305 }) |
364 | 306 |
365 TestWithSet({ | 307 TestWithSet({ |
366 getOwnPropertyDescriptor: function(k) { | 308 getOwnPropertyDescriptor: function(t, k) { |
367 return this.getPropertyDescriptor(k) | |
368 }, | |
369 getPropertyDescriptor: function(k) { | |
370 return k === "a" ? | 309 return k === "a" ? |
371 {get writable() { return true }, configurable: true} : undefined | 310 {get writable() { return true }, configurable: true} : undefined |
372 }, | 311 }, |
373 defineProperty: function(k, desc) { key = k; val = desc.value } | 312 defineProperty: function(t, k, desc) { key = k; val = desc.value } |
374 }) | 313 }) |
375 | 314 |
376 TestWithSet({ | 315 TestWithSet({ |
377 getOwnPropertyDescriptor: function(k) { | 316 getOwnPropertyDescriptor: function(t, k) { |
378 return this.getPropertyDescriptor(k) | 317 return this.getOwnPropertyDescriptor2(k) }, |
379 }, | 318 getOwnPropertyDescriptor2: function(k) { |
380 getPropertyDescriptor: function(k) { | |
381 return k === "a" ? | 319 return k === "a" ? |
382 {set: function(v) { key = k; val = v }, configurable: true} : undefined | 320 {set: function(v) { key = k; val = v }, configurable: true} : undefined |
383 } | 321 }, |
322 set: function(t, k, v) { key = k; val = v; return true } | |
384 }, true) | 323 }, true) |
385 | 324 |
386 TestWithSet({ | 325 TestWithSet({ |
387 getOwnPropertyDescriptor: function(k) { | 326 getOwnPropertyDescriptor: function(t, k) { |
388 return this.getPropertyDescriptor(k) | |
389 }, | |
390 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, | |
391 getPropertyDescriptor2: function(k) { | |
392 return k === "a" ? | |
393 {set: function(v) { key = k; val = v }, configurable: true} : undefined | |
394 } | |
395 }, true) | |
396 | |
397 TestWithSet({ | |
398 getOwnPropertyDescriptor: function(k) { return null }, | |
399 getPropertyDescriptor: function(k) { | |
400 return k === "a" ? {writable: true, configurable: true} : undefined | 327 return k === "a" ? {writable: true, configurable: true} : undefined |
401 }, | 328 }, |
402 defineProperty: function(k, desc) { key = k; val = desc.value } | 329 defineProperty: function(t, k, desc) { key = k; val = desc.value } |
403 }) | 330 }) |
404 | 331 |
405 | 332 |
406 function TestWithSetThrow(handler, hasSetter) { | 333 function TestWithSetThrow(handler, hasSetter) { |
407 TestWithProxies(TestWithSetThrow2, handler, hasSetter) | 334 TestWithProxies(TestWithSetThrow2, handler, hasSetter) |
408 } | 335 } |
409 | 336 |
410 function TestWithSetThrow2(create, handler, hasSetter) { | 337 function TestWithSetThrow2(create, handler, hasSetter) { |
411 var p = create(handler) | 338 var p = create(handler) |
412 assertThrows(function(){ | 339 assertThrows(function(){ |
413 with (p) { | 340 with (p) { |
414 a = 1 | 341 a = 1 |
415 } | 342 } |
416 }, "myexn") | 343 }, "myexn") |
417 | 344 |
418 if (!hasSetter) return | 345 if (!hasSetter) return |
419 | 346 |
420 var o = Object.create(p, {}) | 347 var o = Object.create(p, {}) |
421 assertThrows(function(){ | 348 assertThrows(function(){ |
422 with (o) { | 349 with (o) { |
423 a = 1 | 350 a = 1 |
424 } | 351 } |
425 }, "myexn") | 352 }, "myexn") |
426 } | 353 } |
427 | 354 |
428 TestWithSetThrow({ | 355 TestWithSetThrow({ |
429 set: function(r, k, v) { throw "myexn" }, | 356 set: function() { throw "myexn" }, |
430 getPropertyDescriptor: function(k) { | 357 getOwnPropertyDescriptor: function(t, k) { |
431 return k === "a" ? {writable: true, configurable: true} : undefined | 358 return k === "a" ? {writable: true, configurable: true} : undefined |
432 } | 359 } |
433 }) | 360 }) |
434 | 361 |
435 TestWithSetThrow({ | 362 TestWithSetThrow({ |
436 getPropertyDescriptor: function(k) { throw "myexn" }, | 363 getOwnPropertyDescriptor: function() { throw "myexn" }, |
437 }) | 364 }) |
438 | 365 |
439 TestWithSetThrow({ | 366 TestWithSetThrow({ |
440 getPropertyDescriptor: function(k) { | 367 has: function() { throw "myexn" }, |
441 return k === "a" ? {writable: true, configurable: true} : undefined | |
442 }, | |
443 defineProperty: function(k, desc) { throw "myexn" } | |
444 }) | 368 }) |
445 | 369 |
446 TestWithSetThrow({ | 370 TestWithSetThrow({ |
447 getPropertyDescriptor: function(k) { | 371 getOwnPropertyDescriptor: function(t, k) { |
372 return k === "a" ? {writable: true, configurable: true} : undefined | |
373 }, | |
374 defineProperty: function() { throw "myexn" } | |
375 }) | |
376 | |
377 TestWithSetThrow({ | |
378 getOwnPropertyDescriptor: function(t, k) { | |
448 return k === "a" ? | 379 return k === "a" ? |
449 {set: function() { throw "myexn" }, configurable: true} : undefined | 380 {set: function() { throw "myexn" }, configurable: true} : undefined |
450 } | 381 }, |
382 defineProperty: function() { throw "myexn" } | |
451 }, true) | 383 }, true) |
OLD | NEW |