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