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(function(handler) { return new Proxy({}, handler) }, x, y, z) | 38 // Separate function for nicer stack traces. |
39 test(function(handler) { | 39 TestWithObjectProxy(test, x, y, z); |
40 return Proxy.createFunction(handler, function() {}) | 40 TestWithFunctionProxy(test, x, y, z); |
41 } | |
42 | |
43 function TestWithObjectProxy(test, x, y, z) { | |
44 test((handler) => { return new Proxy({}, handler) }, x, y, z) | |
45 | |
46 } | |
47 | |
48 function TestWithFunctionProxy(test, x, y, z) { | |
49 test((handler) => { | |
50 return new Proxy(function() {}, handler) | |
41 }, x, y, z) | 51 }, x, y, z) |
42 } | 52 } |
43 | 53 /* |
neis
2015/12/11 12:08:15
What happens when you remove the comment around th
Camillo Bruni
2015/12/11 12:40:55
yawn... I really forgot all the debug comments I h
| |
44 | 54 // --------------------------------------------------------------------------- |
45 | |
46 // Getting property descriptors (Object.getOwnPropertyDescriptor). | 55 // Getting property descriptors (Object.getOwnPropertyDescriptor). |
47 | 56 |
48 var key | 57 var key |
49 | 58 |
50 function TestGetOwnProperty(handler) { | 59 function TestGetOwnProperty(handler) { |
51 TestWithProxies(TestGetOwnProperty2, handler) | 60 TestWithProxies(TestGetOwnProperty2, handler) |
52 } | 61 } |
53 | 62 |
54 function TestGetOwnProperty2(create, handler) { | 63 function TestGetOwnProperty2(create, handler) { |
55 var p = create(handler) | 64 var p = create(handler) |
56 assertEquals(42, Object.getOwnPropertyDescriptor(p, "a").value) | 65 assertEquals(42, Object.getOwnPropertyDescriptor(p, "a").value) |
57 assertEquals("a", key) | 66 assertEquals("a", key) |
58 assertEquals(42, Object.getOwnPropertyDescriptor(p, 99).value) | 67 assertEquals(42, Object.getOwnPropertyDescriptor(p, 99).value) |
59 assertEquals("99", key) | 68 assertEquals("99", key) |
60 } | 69 } |
61 | 70 |
62 TestGetOwnProperty({ | 71 TestGetOwnProperty({ |
63 getOwnPropertyDescriptor: function(k) { | 72 getOwnPropertyDescriptor(target, k) { |
64 key = k | 73 key = k |
65 return {value: 42, configurable: true} | 74 return {value: 42, configurable: true} |
66 } | 75 } |
67 }) | 76 }) |
68 | 77 |
69 TestGetOwnProperty({ | 78 TestGetOwnProperty({ |
70 getOwnPropertyDescriptor: function(k) { | 79 getOwnPropertyDescriptor(target, k) { |
71 return this.getOwnPropertyDescriptor2(k) | 80 return this.getOwnPropertyDescriptor2(k) |
72 }, | 81 }, |
73 getOwnPropertyDescriptor2: function(k) { | 82 getOwnPropertyDescriptor2(k) { |
74 key = k | 83 key = k |
75 return {value: 42, configurable: true} | 84 return {value: 42, configurable: true} |
76 } | 85 } |
77 }) | 86 }) |
78 | 87 |
79 TestGetOwnProperty({ | 88 TestGetOwnProperty({ |
80 getOwnPropertyDescriptor: function(k) { | 89 getOwnPropertyDescriptor(target, k) { |
81 key = k | 90 key = k |
82 return {get value() { return 42 }, get configurable() { return true }} | 91 return {get value() { return 42 }, get configurable() { return true }} |
83 } | 92 } |
84 }) | 93 }) |
85 | 94 |
86 TestGetOwnProperty(new Proxy({}, { | 95 TestGetOwnProperty(new Proxy({}, { |
87 get: function(pr, pk) { | 96 get(target, pk, receiver) { |
88 return function(k) { key = k; return {value: 42, configurable: true} } | 97 return function(t, k) { key = k; return {value: 42, configurable: true} } |
89 } | 98 } |
90 })) | 99 })) |
91 | 100 |
92 | 101 |
102 // --------------------------------------------------------------------------- | |
93 function TestGetOwnPropertyThrow(handler) { | 103 function TestGetOwnPropertyThrow(handler) { |
94 TestWithProxies(TestGetOwnPropertyThrow2, handler) | 104 TestWithProxies(TestGetOwnPropertyThrow2, handler) |
95 } | 105 } |
96 | 106 |
97 function TestGetOwnPropertyThrow2(create, handler) { | 107 function TestGetOwnPropertyThrow2(create, handler) { |
98 var p = create(handler) | 108 var p = create(handler) |
99 assertThrows(function(){ Object.getOwnPropertyDescriptor(p, "a") }, "myexn") | 109 assertThrows(function(){ Object.getOwnPropertyDescriptor(p, "a") }, "myexn") |
100 assertThrows(function(){ Object.getOwnPropertyDescriptor(p, 77) }, "myexn") | 110 assertThrows(function(){ Object.getOwnPropertyDescriptor(p, 77) }, "myexn") |
101 } | 111 } |
102 | 112 |
103 TestGetOwnPropertyThrow({ | 113 TestGetOwnPropertyThrow({ |
104 getOwnPropertyDescriptor: function(k) { throw "myexn" } | 114 getOwnPropertyDescriptor: function(k) { throw "myexn" } |
105 }) | 115 }) |
106 | 116 |
107 TestGetOwnPropertyThrow({ | 117 TestGetOwnPropertyThrow({ |
108 getOwnPropertyDescriptor: function(k) { | 118 getOwnPropertyDescriptor: function(k) { |
109 return this.getPropertyDescriptor2(k) | 119 return this.getPropertyDescriptor2(k) |
110 }, | 120 }, |
111 getOwnPropertyDescriptor2: function(k) { throw "myexn" } | 121 getOwnPropertyDescriptor2: function(k) { throw "myexn" } |
112 }) | 122 }) |
113 | 123 |
114 TestGetOwnPropertyThrow({ | 124 TestGetOwnPropertyThrow({ |
115 getOwnPropertyDescriptor: function(k) { | 125 getOwnPropertyDescriptor: function(k) { |
116 return {get value() { throw "myexn" }} | 126 return {get value() { throw "myexn" }} |
117 } | 127 } |
118 }) | 128 }) |
119 | 129 |
120 TestGetOwnPropertyThrow(Proxy.create({ | 130 TestGetOwnPropertyThrow(new Proxy({}, { |
121 get: function(pr, pk) { | 131 get: function(pr, pk) { |
122 return function(k) { throw "myexn" } | 132 return function(k) { throw "myexn" } |
123 } | 133 } |
124 })) | 134 })) |
125 | 135 |
126 | 136 |
127 | 137 // --------------------------------------------------------------------------- |
128 // Getters (dot, brackets). | 138 // Getters (dot, brackets). |
129 | 139 |
130 var key | 140 var key |
131 | 141 |
132 function TestGet(handler) { | 142 function TestGet(handler) { |
133 TestWithProxies(TestGet2, handler) | 143 TestWithProxies(TestGet2, handler) |
134 } | 144 } |
135 | 145 |
136 function TestGet2(create, handler) { | 146 function TestGet2(create, handler) { |
137 var p = create(handler) | 147 var p = create(handler) |
(...skipping 18 matching lines...) Expand all Loading... | |
156 assertEquals(88, o.x) | 166 assertEquals(88, o.x) |
157 assertEquals(88, o["x"]) | 167 assertEquals(88, o["x"]) |
158 assertEquals(42, (function(n) { return o[n] })("c")) | 168 assertEquals(42, (function(n) { return o[n] })("c")) |
159 assertEquals("c", key) | 169 assertEquals("c", key) |
160 assertEquals(42, (function(n) { return o[n] })(101)) | 170 assertEquals(42, (function(n) { return o[n] })(101)) |
161 assertEquals("101", key) | 171 assertEquals("101", key) |
162 assertEquals(88, (function(n) { return o[n] })("x")) | 172 assertEquals(88, (function(n) { return o[n] })("x")) |
163 } | 173 } |
164 | 174 |
165 TestGet({ | 175 TestGet({ |
166 get: function(r, k) { key = k; return 42 } | 176 get(t, k, r) { key = k; return 42 } |
167 }) | 177 }) |
168 | 178 |
169 TestGet({ | 179 TestGet({ |
170 get: function(r, k) { return this.get2(r, k) }, | 180 get(t, k, r) { return this.get2(r, k) }, |
171 get2: function(r, k) { key = k; return 42 } | 181 get2(r, k) { key = k; return 42 } |
172 }) | 182 }) |
173 | 183 |
174 TestGet({ | 184 TestGet(new Proxy({}, { |
175 getPropertyDescriptor: function(k) { key = k; return {value: 42} } | 185 get(pt, pk, pr) { |
176 }) | 186 return function(t, k, r) { key = k; return 42 } |
177 | |
178 TestGet({ | |
179 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, | |
180 getPropertyDescriptor2: function(k) { key = k; return {value: 42} } | |
181 }) | |
182 | |
183 TestGet({ | |
184 getPropertyDescriptor: function(k) { | |
185 key = k; | |
186 return {get value() { return 42 }} | |
187 } | |
188 }) | |
189 | |
190 TestGet({ | |
191 get: undefined, | |
192 getPropertyDescriptor: function(k) { key = k; return {value: 42} } | |
193 }) | |
194 | |
195 TestGet(Proxy.create({ | |
196 get: function(pr, pk) { | |
197 return function(r, k) { key = k; return 42 } | |
198 } | 187 } |
199 })) | 188 })) |
200 | 189 |
201 | 190 |
191 // --------------------------------------------------------------------------- | |
202 function TestGetCall(handler) { | 192 function TestGetCall(handler) { |
203 TestWithProxies(TestGetCall2, handler) | 193 TestWithProxies(TestGetCall2, handler) |
204 } | 194 } |
205 | 195 |
206 function TestGetCall2(create, handler) { | 196 function TestGetCall2(create, handler) { |
207 var p = create(handler) | 197 var p = create(handler) |
208 assertEquals(55, p.f()) | 198 assertEquals(55, p.f()) |
209 assertEquals(55, p["f"]()) | 199 assertEquals(55, p["f"]()) |
210 assertEquals(55, p.f("unused", "arguments")) | 200 assertEquals(55, p.f("unused", "arguments")) |
211 assertEquals(55, p.f.call(p)) | 201 assertEquals(55, p.f.call(p)) |
(...skipping 24 matching lines...) Expand all Loading... | |
236 assertEquals(55, (function(n) { return o[n].call(o) })("f")) | 226 assertEquals(55, (function(n) { return o[n].call(o) })("f")) |
237 assertEquals(55, (function(n) { return o[n](15, 20) })("withargs")) | 227 assertEquals(55, (function(n) { return o[n](15, 20) })("withargs")) |
238 assertEquals(55, (function(n) { return o[n].call(o, 13, 21) })("withargs")) | 228 assertEquals(55, (function(n) { return o[n].call(o, 13, 21) })("withargs")) |
239 assertEquals(93, (function(n) { return o[n](5) })("g")) | 229 assertEquals(93, (function(n) { return o[n](5) })("g")) |
240 assertEquals(94, (function(n) { return o[n].call(o, 6) })("g")) | 230 assertEquals(94, (function(n) { return o[n].call(o, 6) })("g")) |
241 assertEquals(95, (function(n) { return o[n].call(p, 7) })("g")) | 231 assertEquals(95, (function(n) { return o[n].call(p, 7) })("g")) |
242 assertEquals("6655", "66" + o) // calls o.toString | 232 assertEquals("6655", "66" + o) // calls o.toString |
243 } | 233 } |
244 | 234 |
245 TestGetCall({ | 235 TestGetCall({ |
246 get: function(r, k) { return function() { return 55 } } | 236 get(t, k, r) { return () => { return 55 } } |
247 }) | 237 }) |
248 | 238 |
249 TestGetCall({ | 239 TestGetCall({ |
250 get: function(r, k) { return this.get2(r, k) }, | 240 get(t, k, r) { return this.get2(t, k, r) }, |
251 get2: function(r, k) { return function() { return 55 } } | 241 get2(t, k, r) { return () => { return 55 } } |
252 }) | 242 }) |
253 | 243 |
254 TestGetCall({ | 244 TestGetCall({ |
255 getPropertyDescriptor: function(k) { | 245 get(t, k, r) { |
256 return {value: function() { return 55 }} | |
257 } | |
258 }) | |
259 | |
260 TestGetCall({ | |
261 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, | |
262 getPropertyDescriptor2: function(k) { | |
263 return {value: function() { return 55 }} | |
264 } | |
265 }) | |
266 | |
267 TestGetCall({ | |
268 getPropertyDescriptor: function(k) { | |
269 return {get value() { return function() { return 55 } }} | |
270 } | |
271 }) | |
272 | |
273 TestGetCall({ | |
274 get: undefined, | |
275 getPropertyDescriptor: function(k) { | |
276 return {value: function() { return 55 }} | |
277 } | |
278 }) | |
279 | |
280 TestGetCall({ | |
281 get: function(r, k) { | |
282 if (k == "gg") { | 246 if (k == "gg") { |
283 return function() { return 55 } | 247 return () => { return 55 } |
284 } else if (k == "withargs") { | 248 } else if (k == "withargs") { |
285 return function(n, m) { return n + m * 2 } | 249 return (n, m) => { return n + m * 2 } |
286 } else { | 250 } else { |
287 return function() { return this.gg() } | 251 return () => { return r.gg() } |
288 } | 252 } |
289 } | 253 } |
290 }) | 254 }) |
291 | 255 |
292 TestGetCall(Proxy.create({ | 256 TestGetCall(new Proxy({}, { |
293 get: function(pr, pk) { | 257 get(pt, pk, pr) { |
294 return function(r, k) { return function() { return 55 } } | 258 return (t, k, r) => { return () => { return 55 } } |
295 } | 259 } |
296 })) | 260 })) |
297 | 261 |
298 | 262 |
263 // --------------------------------------------------------------------------- | |
299 function TestGetThrow(handler) { | 264 function TestGetThrow(handler) { |
300 TestWithProxies(TestGetThrow2, handler) | 265 TestWithProxies(TestGetThrow2, handler) |
301 } | 266 } |
302 | 267 |
303 function TestGetThrow2(create, handler) { | 268 function TestGetThrow2(create, handler) { |
304 var p = create(handler) | 269 var p = create(handler) |
305 assertThrows(function(){ p.a }, "myexn") | 270 assertThrows(function(){ p.a }, "myexn") |
306 assertThrows(function(){ p["b"] }, "myexn") | 271 assertThrows(function(){ p["b"] }, "myexn") |
307 assertThrows(function(){ p[3] }, "myexn") | 272 assertThrows(function(){ p[3] }, "myexn") |
308 assertThrows(function(){ (function(n) { p[n] })("c") }, "myexn") | 273 assertThrows(function(){ (function(n) { p[n] })("c") }, "myexn") |
309 assertThrows(function(){ (function(n) { p[n] })(99) }, "myexn") | 274 assertThrows(function(){ (function(n) { p[n] })(99) }, "myexn") |
310 | 275 |
311 var o = Object.create(p, {x: {value: 88}, '4': {value: 89}}) | 276 var o = Object.create(p, {x: {value: 88}, '4': {value: 89}}) |
312 assertThrows(function(){ o.a }, "myexn") | 277 assertThrows(function(){ o.a }, "myexn") |
313 assertThrows(function(){ o["b"] }, "myexn") | 278 assertThrows(function(){ o["b"] }, "myexn") |
314 assertThrows(function(){ o[3] }, "myexn") | 279 assertThrows(function(){ o[3] }, "myexn") |
315 assertThrows(function(){ (function(n) { o[n] })("c") }, "myexn") | 280 assertThrows(function(){ (function(n) { o[n] })("c") }, "myexn") |
316 assertThrows(function(){ (function(n) { o[n] })(99) }, "myexn") | 281 assertThrows(function(){ (function(n) { o[n] })(99) }, "myexn") |
317 } | 282 } |
318 | 283 |
319 TestGetThrow({ | 284 TestGetThrow({ |
320 get: function(r, k) { throw "myexn" } | 285 get(r, k) { throw "myexn" } |
321 }) | 286 }) |
322 | 287 |
323 TestGetThrow({ | 288 TestGetThrow({ |
324 get: function(r, k) { return this.get2(r, k) }, | 289 get(r, k) { return this.get2(r, k) }, |
325 get2: function(r, k) { throw "myexn" } | 290 get2(r, k) { throw "myexn" } |
326 }) | 291 }) |
327 | 292 |
328 TestGetThrow({ | 293 TestGetThrow(new Proxy({}, { |
329 getPropertyDescriptor: function(k) { throw "myexn" } | 294 get(pr, pk) { throw "myexn" } |
330 }) | |
331 | |
332 TestGetThrow({ | |
333 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, | |
334 getPropertyDescriptor2: function(k) { throw "myexn" } | |
335 }) | |
336 | |
337 TestGetThrow({ | |
338 getPropertyDescriptor: function(k) { | |
339 return {get value() { throw "myexn" }} | |
340 } | |
341 }) | |
342 | |
343 TestGetThrow({ | |
344 get: undefined, | |
345 getPropertyDescriptor: function(k) { throw "myexn" } | |
346 }) | |
347 | |
348 TestGetThrow(Proxy.create({ | |
349 get: function(pr, pk) { throw "myexn" } | |
350 })) | 295 })) |
351 | 296 |
352 TestGetThrow(Proxy.create({ | 297 TestGetThrow(new Proxy({}, { |
353 get: function(pr, pk) { | 298 get(pr, pk) { |
354 return function(r, k) { throw "myexn" } | 299 return function(r, k) { throw "myexn" } |
355 } | 300 } |
356 })) | 301 })) |
357 | 302 |
358 | 303 |
359 | 304 // --------------------------------------------------------------------------- |
360 // Setters. | 305 // Setters. |
361 | 306 |
362 var key | 307 var key |
363 var val | 308 var val |
364 | 309 |
365 function TestSet(handler) { | 310 function TestSet(handler) { |
366 TestWithProxies(TestSet2, handler) | 311 TestWithProxies(TestSet2, handler) |
367 } | 312 } |
368 | 313 |
369 function TestSet2(create, handler) { | 314 function TestSet2(create, handler) { |
(...skipping 22 matching lines...) Expand all Loading... | |
392 | 337 |
393 TestSet({ | 338 TestSet({ |
394 set: function(r, k, v) { key = k; val = v; return true } | 339 set: function(r, k, v) { key = k; val = v; return true } |
395 }) | 340 }) |
396 | 341 |
397 TestSet({ | 342 TestSet({ |
398 set: function(r, k, v) { return this.set2(r, k, v) }, | 343 set: function(r, k, v) { return this.set2(r, k, v) }, |
399 set2: function(r, k, v) { key = k; val = v; return true } | 344 set2: function(r, k, v) { key = k; val = v; return true } |
400 }) | 345 }) |
401 | 346 |
402 TestSet({ | 347 TestSet(new Proxy({}, { |
403 getOwnPropertyDescriptor: function(k) { return {writable: true} }, | 348 get(pk, pr) { |
404 defineProperty: function(k, desc) { key = k; val = desc.value } | 349 return (r, k, v) => { key = k; val = v; return true } |
405 }) | |
406 | |
407 TestSet({ | |
408 getOwnPropertyDescriptor: function(k) { | |
409 return this.getOwnPropertyDescriptor2(k) | |
410 }, | |
411 getOwnPropertyDescriptor2: function(k) { return {writable: true} }, | |
412 defineProperty: function(k, desc) { this.defineProperty2(k, desc) }, | |
413 defineProperty2: function(k, desc) { key = k; val = desc.value } | |
414 }) | |
415 | |
416 TestSet({ | |
417 getOwnPropertyDescriptor: function(k) { | |
418 return {get writable() { return true }} | |
419 }, | |
420 defineProperty: function(k, desc) { key = k; val = desc.value } | |
421 }) | |
422 | |
423 TestSet({ | |
424 getOwnPropertyDescriptor: function(k) { | |
425 return {set: function(v) { key = k; val = v }} | |
426 } | |
427 }) | |
428 | |
429 TestSet({ | |
430 getOwnPropertyDescriptor: function(k) { return null }, | |
431 getPropertyDescriptor: function(k) { return {writable: true} }, | |
432 defineProperty: function(k, desc) { key = k; val = desc.value } | |
433 }) | |
434 | |
435 TestSet({ | |
436 getOwnPropertyDescriptor: function(k) { return null }, | |
437 getPropertyDescriptor: function(k) { | |
438 return {get writable() { return true }} | |
439 }, | |
440 defineProperty: function(k, desc) { key = k; val = desc.value } | |
441 }) | |
442 | |
443 TestSet({ | |
444 getOwnPropertyDescriptor: function(k) { return null }, | |
445 getPropertyDescriptor: function(k) { | |
446 return {set: function(v) { key = k; val = v }} | |
447 } | |
448 }) | |
449 | |
450 TestSet({ | |
451 getOwnPropertyDescriptor: function(k) { return null }, | |
452 getPropertyDescriptor: function(k) { return null }, | |
453 defineProperty: function(k, desc) { key = k, val = desc.value } | |
454 }) | |
455 | |
456 TestSet(Proxy.create({ | |
457 get: function(pr, pk) { | |
458 return function(r, k, v) { key = k; val = v; return true } | |
459 } | 350 } |
460 })) | 351 })) |
461 | 352 |
462 | 353 |
354 // --------------------------------------------------------------------------- | |
463 function TestSetThrow(handler) { | 355 function TestSetThrow(handler) { |
464 TestWithProxies(TestSetThrow2, handler) | 356 TestWithProxies(TestSetThrow2, handler) |
465 } | 357 } |
466 | 358 |
467 function TestSetThrow2(create, handler) { | 359 function TestSetThrow2(create, handler) { |
468 var p = create(handler) | 360 var p = create(handler) |
469 assertThrows(function(){ p.a = 42 }, "myexn") | 361 assertThrows(function(){ p.a = 42 }, "myexn") |
470 assertThrows(function(){ p["b"] = 42 }, "myexn") | 362 assertThrows(function(){ p["b"] = 42 }, "myexn") |
471 assertThrows(function(){ p[22] = 42 }, "myexn") | 363 assertThrows(function(){ p[22] = 42 }, "myexn") |
472 assertThrows(function(){ (function(n) { p[n] = 45 })("c") }, "myexn") | 364 assertThrows(function(){ (function(n) { p[n] = 45 })("c") }, "myexn") |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
564 return {set: function(v) { throw "myexn" }} | 456 return {set: function(v) { throw "myexn" }} |
565 } | 457 } |
566 }) | 458 }) |
567 | 459 |
568 TestSetThrow({ | 460 TestSetThrow({ |
569 getOwnPropertyDescriptor: function(k) { return null }, | 461 getOwnPropertyDescriptor: function(k) { return null }, |
570 getPropertyDescriptor: function(k) { return null }, | 462 getPropertyDescriptor: function(k) { return null }, |
571 defineProperty: function(k, desc) { throw "myexn" } | 463 defineProperty: function(k, desc) { throw "myexn" } |
572 }) | 464 }) |
573 | 465 |
574 TestSetThrow(Proxy.create({ | 466 TestSetThrow(new Proxy({}, { |
575 get: function(pr, pk) { throw "myexn" } | 467 get: function(pr, pk) { throw "myexn" } |
576 })) | 468 })) |
577 | 469 |
578 TestSetThrow(Proxy.create({ | 470 TestSetThrow(new Proxy({}, { |
579 get: function(pr, pk) { | 471 get: function(pr, pk) { |
580 return function(r, k, v) { throw "myexn" } | 472 return function(r, k, v) { throw "myexn" } |
581 } | 473 } |
582 })) | 474 })) |
583 | 475 |
584 | 476 // --------------------------------------------------------------------------- |
585 var rec | |
586 var key | |
587 var val | |
588 | |
589 function TestSetForDerived(trap) { | |
590 TestWithProxies(TestSetForDerived2, trap) | |
591 } | |
592 | |
593 function TestSetForDerived2(create, trap) { | |
594 var p = create({getPropertyDescriptor: trap, getOwnPropertyDescriptor: trap}) | |
595 var o = Object.create(p, {x: {value: 88, writable: true}, | |
596 '1': {value: 89, writable: true}}) | |
597 | |
598 key = "" | |
599 assertEquals(48, o.x = 48) | |
600 assertEquals("", key) // trap not invoked | |
601 assertEquals(48, o.x) | |
602 | |
603 assertEquals(47, o[1] = 47) | |
604 assertEquals("", key) // trap not invoked | |
605 assertEquals(47, o[1]) | |
606 | |
607 assertEquals(49, o.y = 49) | |
608 assertEquals("y", key) | |
609 assertEquals(49, o.y) | |
610 | |
611 assertEquals(50, o[2] = 50) | |
612 assertEquals("2", key) | |
613 assertEquals(50, o[2]) | |
614 | |
615 assertEquals(44, o.p_writable = 44) | |
616 assertEquals("p_writable", key) | |
617 assertEquals(44, o.p_writable) | |
618 | |
619 assertEquals(45, o.p_nonwritable = 45) | |
620 assertEquals("p_nonwritable", key) | |
621 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nonwritable")) | |
622 | |
623 assertThrows(function(){ "use strict"; o.p_nonwritable = 45 }, TypeError) | |
624 assertEquals("p_nonwritable", key) | |
625 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nonwritable")) | |
626 | |
627 val = "" | |
628 assertEquals(46, o.p_setter = 46) | |
629 assertEquals("p_setter", key) | |
630 assertSame(o, rec) | |
631 assertEquals(46, val) // written to parent | |
632 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_setter")) | |
633 | |
634 val = "" | |
635 assertEquals(47, o.p_nosetter = 47) | |
636 assertEquals("p_nosetter", key) | |
637 assertEquals("", val) // not written at all | |
638 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nosetter")); | |
639 | |
640 key = "" | |
641 assertThrows(function(){ "use strict"; o.p_nosetter = 50 }, TypeError) | |
642 assertEquals("p_nosetter", key) | |
643 assertEquals("", val) // not written at all | |
644 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nosetter")); | |
645 | |
646 assertThrows(function(){ o.p_nonconf = 53 }, TypeError) | |
647 assertEquals("p_nonconf", key) | |
648 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nonconf")); | |
649 | |
650 assertThrows(function(){ o.p_throw = 51 }, "myexn") | |
651 assertEquals("p_throw", key) | |
652 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_throw")); | |
653 | |
654 assertThrows(function(){ o.p_setterthrow = 52 }, "myexn") | |
655 assertEquals("p_setterthrow", key) | |
656 assertFalse(Object.prototype.hasOwnProperty.call(o, "p_setterthrow")); | |
657 } | |
658 | |
659 | |
660 TestSetForDerived( | |
661 function(k) { | |
662 // TODO(yangguo): issue 2398 - throwing an error causes formatting of | |
663 // the message string, which can be observable through this handler. | |
664 // We ignore keys that occur when formatting the message string. | |
665 if (k == "toString" || k == "valueOf") return; | |
666 | |
667 key = k; | |
668 switch (k) { | |
669 case "p_writable": return {writable: true, configurable: true} | |
670 case "p_nonwritable": return {writable: false, configurable: true} | |
671 case "p_setter": return { | |
672 set: function(x) { rec = this; val = x }, | |
673 configurable: true | |
674 } | |
675 case "p_nosetter": return { | |
676 get: function() { return 1 }, | |
677 configurable: true | |
678 } | |
679 case "p_nonconf": return {} | |
680 case "p_throw": throw "myexn" | |
681 case "p_setterthrow": return {set: function(x) { throw "myexn" }} | |
682 default: return undefined | |
683 } | |
684 } | |
685 ) | |
686 | |
687 | 477 |
688 // Evil proxy-induced side-effects shouldn't crash. | 478 // Evil proxy-induced side-effects shouldn't crash. |
689 // TODO(rossberg): proper behaviour isn't really spec'ed yet, so ignore results. | |
690 | |
691 TestWithProxies(function(create) { | 479 TestWithProxies(function(create) { |
692 var calls = 0 | 480 var calls = 0 |
693 var handler = { | 481 var handler = { |
694 getPropertyDescriptor: function() { | 482 getPropertyDescriptor: function() { |
695 ++calls | 483 ++calls |
696 return (calls % 2 == 1) | 484 return (calls % 2 == 1) |
697 ? {get: function() { return 5 }, configurable: true} | 485 ? {get: function() { return 5 }, configurable: true} |
698 : {set: function() { return false }, configurable: true} | 486 : {set: function() { return false }, configurable: true} |
699 } | 487 } |
700 } | 488 } |
(...skipping 10 matching lines...) Expand all Loading... | |
711 return {set: function() {}} | 499 return {set: function() {}} |
712 } | 500 } |
713 } | 501 } |
714 var p = create(handler) | 502 var p = create(handler) |
715 var o = Object.create(p) | 503 var o = Object.create(p) |
716 // Make object property read-only after CanPut check. | 504 // Make object property read-only after CanPut check. |
717 try { o.x = 4 } catch (e) { assertInstanceof(e, Error) } | 505 try { o.x = 4 } catch (e) { assertInstanceof(e, Error) } |
718 }) | 506 }) |
719 | 507 |
720 | 508 |
721 | 509 // --------------------------------------------------------------------------- |
722 // TODO(rossberg): TestSetReject, returning false | |
723 // TODO(rossberg): TestGetProperty, TestSetProperty | |
724 | |
725 | |
726 | |
727 // Property definition (Object.defineProperty and Object.defineProperties). | 510 // Property definition (Object.defineProperty and Object.defineProperties). |
728 | 511 |
729 var key | 512 var key |
730 var desc | 513 var desc |
731 | 514 |
732 function TestDefine(handler) { | 515 function TestDefine(handler) { |
733 TestWithProxies(TestDefine2, handler) | 516 TestWithProxies(TestDefine2, handler) |
734 } | 517 } |
735 | 518 |
736 function TestDefine2(create, handler) { | 519 function TestDefine2(create, handler) { |
(...skipping 16 matching lines...) Expand all Loading... | |
753 assertEquals(false, desc.enumerable) | 536 assertEquals(false, desc.enumerable) |
754 | 537 |
755 assertEquals(p, Object.defineProperty(p, 101, {value: 47, enumerable: false})) | 538 assertEquals(p, Object.defineProperty(p, 101, {value: 47, enumerable: false})) |
756 assertEquals("101", key) | 539 assertEquals("101", key) |
757 assertEquals(2, Object.getOwnPropertyNames(desc).length) | 540 assertEquals(2, Object.getOwnPropertyNames(desc).length) |
758 assertEquals(47, desc.value) | 541 assertEquals(47, desc.value) |
759 assertEquals(false, desc.enumerable) | 542 assertEquals(false, desc.enumerable) |
760 | 543 |
761 var attributes = {configurable: true, mine: 66, minetoo: 23} | 544 var attributes = {configurable: true, mine: 66, minetoo: 23} |
762 assertEquals(p, Object.defineProperty(p, "d", attributes)) | 545 assertEquals(p, Object.defineProperty(p, "d", attributes)) |
763 assertEquals("d", key) | 546 assertEquals("d", key); |
764 // Modifying the attributes object after the fact should have no effect. | 547 // Modifying the attributes object after the fact should have no effect. |
765 attributes.configurable = false | 548 attributes.configurable = false |
766 attributes.mine = 77 | 549 attributes.mine = 77 |
767 delete attributes.minetoo | 550 delete attributes.minetoo; |
768 assertEquals(3, Object.getOwnPropertyNames(desc).length) | 551 assertEquals(1, Object.getOwnPropertyNames(desc).length) |
769 assertEquals(true, desc.configurable) | 552 assertEquals(true, desc.configurable) |
770 assertEquals(66, desc.mine) | 553 assertEquals(undefined, desc.mine) |
771 assertEquals(23, desc.minetoo) | 554 assertEquals(undefined, desc.minetoo) |
772 | 555 |
773 assertEquals(p, Object.defineProperty(p, "e", {get: function(){ return 5 }})) | 556 assertEquals(p, Object.defineProperty(p, "e", {get: function(){ return 5 }})) |
774 assertEquals("e", key) | 557 assertEquals("e", key) |
775 assertEquals(1, Object.getOwnPropertyNames(desc).length) | 558 assertEquals(1, Object.getOwnPropertyNames(desc).length) |
776 assertEquals(5, desc.get()) | 559 assertEquals(5, desc.get()) |
777 | 560 |
778 assertEquals(p, Object.defineProperty(p, "zzz", {})) | 561 assertEquals(p, Object.defineProperty(p, "zzz", {})) |
779 assertEquals("zzz", key) | 562 assertEquals("zzz", key) |
780 assertEquals(0, Object.getOwnPropertyNames(desc).length) | 563 assertEquals(0, Object.getOwnPropertyNames(desc).length) |
781 | 564 |
782 var d = create({ | |
783 get: function(r, k) { return (k === "value") ? 77 : void 0 }, | |
784 getOwnPropertyNames: function() { return ["value"] }, | |
785 enumerate: function() { return ["value"] } | |
786 }) | |
787 assertEquals(1, Object.getOwnPropertyNames(d).length) | |
788 assertEquals(77, d.value) | |
789 assertEquals(p, Object.defineProperty(p, "p", d)) | |
790 assertEquals("p", key) | |
791 assertEquals(1, Object.getOwnPropertyNames(desc).length) | |
792 assertEquals(77, desc.value) | |
793 | |
794 var props = { | 565 var props = { |
795 '11': {}, | 566 '11': {}, |
796 blub: {get: function() { return true }}, | 567 blub: {get: function() { return true }}, |
797 '': {get value() { return 20 }}, | 568 '': {get value() { return 20 }}, |
798 last: {value: 21, configurable: true, mine: "eyes"} | 569 last: {value: 21, configurable: true, mine: "eyes"} |
799 } | 570 } |
800 Object.defineProperty(props, "hidden", {value: "hidden", enumerable: false}) | 571 Object.defineProperty(props, "hidden", {value: "hidden", enumerable: false}) |
801 assertEquals(p, Object.defineProperties(p, props)) | 572 assertEquals(p, Object.defineProperties(p, props)) |
802 assertEquals("last", key) | 573 assertEquals("last", key) |
803 assertEquals(2, Object.getOwnPropertyNames(desc).length) | 574 assertEquals(2, Object.getOwnPropertyNames(desc).length) |
804 assertEquals(21, desc.value) | 575 assertEquals(21, desc.value) |
805 assertEquals(true, desc.configurable) | 576 assertEquals(true, desc.configurable) |
806 assertEquals(undefined, desc.mine) // Arguably a bug in the spec... | 577 assertEquals(undefined, desc.mine) // Arguably a bug in the spec... |
807 | 578 |
808 var props = {bla: {get value() { throw "myexn" }}} | 579 var props = {bla: {get value() { throw "myexn" }}} |
809 assertThrows(function(){ Object.defineProperties(p, props) }, "myexn") | 580 assertThrows(function(){ Object.defineProperties(p, props) }, "myexn") |
810 } | 581 } |
811 | 582 |
812 TestDefine({ | 583 TestDefine({ |
813 defineProperty: function(k, d) { key = k; desc = d; return true } | 584 defineProperty(t, k, d) { key = k; desc = d; return true } |
814 }) | 585 }) |
815 | 586 |
816 TestDefine({ | 587 TestDefine({ |
817 defineProperty: function(k, d) { return this.defineProperty2(k, d) }, | 588 defineProperty(t, k, d) { return this.defineProperty2(k, d) }, |
818 defineProperty2: function(k, d) { key = k; desc = d; return true } | 589 defineProperty2(k, d) { key = k; desc = d; return true } |
819 }) | 590 }) |
820 | 591 |
821 TestDefine(Proxy.create({ | |
822 get: function(pr, pk) { | |
823 return function(k, d) { key = k; desc = d; return true } | |
824 } | |
825 })) | |
826 | 592 |
827 | 593 // --------------------------------------------------------------------------- |
828 function TestDefineThrow(handler) { | 594 function TestDefineThrow(handler) { |
829 TestWithProxies(TestDefineThrow2, handler) | 595 TestWithProxies(TestDefineThrow2, handler) |
830 } | 596 } |
831 | 597 |
832 function TestDefineThrow2(create, handler) { | 598 function TestDefineThrow2(create, handler) { |
833 var p = create(handler) | 599 var p = create(handler) |
834 assertThrows(function(){ Object.defineProperty(p, "a", {value: 44})}, "myexn") | 600 assertThrows(function(){ Object.defineProperty(p, "a", {value: 44})}, "myexn") |
835 assertThrows(function(){ Object.defineProperty(p, 0, {value: 44})}, "myexn") | 601 assertThrows(function(){ Object.defineProperty(p, 0, {value: 44})}, "myexn") |
836 | 602 |
837 var d1 = create({ | 603 var d1 = create({ |
(...skipping 13 matching lines...) Expand all Loading... | |
851 | 617 |
852 TestDefineThrow({ | 618 TestDefineThrow({ |
853 defineProperty: function(k, d) { throw "myexn" } | 619 defineProperty: function(k, d) { throw "myexn" } |
854 }) | 620 }) |
855 | 621 |
856 TestDefineThrow({ | 622 TestDefineThrow({ |
857 defineProperty: function(k, d) { return this.defineProperty2(k, d) }, | 623 defineProperty: function(k, d) { return this.defineProperty2(k, d) }, |
858 defineProperty2: function(k, d) { throw "myexn" } | 624 defineProperty2: function(k, d) { throw "myexn" } |
859 }) | 625 }) |
860 | 626 |
861 TestDefineThrow(Proxy.create({ | 627 TestDefineThrow(new Proxy({}, { |
862 get: function(pr, pk) { throw "myexn" } | 628 get: function(pr, pk) { throw "myexn" } |
863 })) | 629 })) |
864 | 630 |
865 TestDefineThrow(Proxy.create({ | 631 TestDefineThrow(new Proxy({}, { |
866 get: function(pr, pk) { | 632 get: function(pr, pk) { |
867 return function(k, d) { throw "myexn" } | 633 return function(k, d) { throw "myexn" } |
868 } | 634 } |
869 })) | 635 })) |
870 | 636 |
871 | 637 |
872 | 638 |
639 // --------------------------------------------------------------------------- | |
873 // Property deletion (delete). | 640 // Property deletion (delete). |
874 | 641 |
875 var key | 642 var key |
876 | 643 |
877 function TestDelete(handler) { | 644 function TestDelete(handler) { |
878 TestWithProxies(TestDelete2, handler) | 645 TestWithProxies(TestDelete2, handler) |
879 } | 646 } |
880 | 647 |
881 function TestDelete2(create, handler) { | 648 function TestDelete2(create, handler) { |
882 var p = create(handler) | 649 var p = create(handler) |
(...skipping 19 matching lines...) Expand all Loading... | |
902 assertEquals("2", key) | 669 assertEquals("2", key) |
903 | 670 |
904 assertThrows(function(){ delete p.z3 }, TypeError) | 671 assertThrows(function(){ delete p.z3 }, TypeError) |
905 assertEquals("z3", key) | 672 assertEquals("z3", key) |
906 assertThrows(function(){ delete p["z4"] }, TypeError) | 673 assertThrows(function(){ delete p["z4"] }, TypeError) |
907 assertEquals("z4", key) | 674 assertEquals("z4", key) |
908 })() | 675 })() |
909 } | 676 } |
910 | 677 |
911 TestDelete({ | 678 TestDelete({ |
912 delete: function(k) { key = k; return k < "z" } | 679 deleteProperty(target, k) { key = k; return k < "z" } |
913 }) | 680 }) |
914 | 681 |
915 TestDelete({ | 682 TestDelete({ |
916 delete: function(k) { return this.delete2(k) }, | 683 deleteProperty(target, k) { return this.delete2(k) }, |
917 delete2: function(k) { key = k; return k < "z" } | 684 delete2: function(k) { key = k; return k < "z" } |
918 }) | 685 }) |
919 | 686 |
920 TestDelete(Proxy.create({ | 687 TestDelete(new Proxy({}, { |
921 get: function(pr, pk) { | 688 get(pt, pk, pr) { |
922 return function(k) { key = k; return k < "z" } | 689 return (target, k) => { key = k; return k < "z" } |
923 } | 690 } |
924 })) | 691 })) |
925 | 692 |
926 | 693 |
694 // --------------------------------------------------------------------------- | |
927 function TestDeleteThrow(handler) { | 695 function TestDeleteThrow(handler) { |
928 TestWithProxies(TestDeleteThrow2, handler) | 696 TestWithProxies(TestDeleteThrow2, handler) |
929 } | 697 } |
930 | 698 |
931 function TestDeleteThrow2(create, handler) { | 699 function TestDeleteThrow2(create, handler) { |
932 var p = create(handler) | 700 var p = create(handler) |
933 assertThrows(function(){ delete p.a }, "myexn") | 701 assertThrows(function(){ delete p.a }, "myexn") |
934 assertThrows(function(){ delete p["b"] }, "myexn"); | 702 assertThrows(function(){ delete p["b"] }, "myexn"); |
935 assertThrows(function(){ delete p[3] }, "myexn"); | 703 assertThrows(function(){ delete p[3] }, "myexn"); |
936 | 704 |
937 (function() { | 705 (function() { |
938 "use strict" | 706 "use strict" |
939 assertThrows(function(){ delete p.c }, "myexn") | 707 assertThrows(function(){ delete p.c }, "myexn") |
940 assertThrows(function(){ delete p["d"] }, "myexn") | 708 assertThrows(function(){ delete p["d"] }, "myexn") |
941 assertThrows(function(){ delete p[4] }, "myexn"); | 709 assertThrows(function(){ delete p[4] }, "myexn"); |
942 })() | 710 })() |
943 } | 711 } |
944 | 712 |
945 TestDeleteThrow({ | 713 TestDeleteThrow({ |
946 delete: function(k) { throw "myexn" } | 714 deleteProperty(t, k) { throw "myexn" } |
947 }) | 715 }) |
948 | 716 |
949 TestDeleteThrow({ | 717 TestDeleteThrow({ |
950 delete: function(k) { return this.delete2(k) }, | 718 deleteProperty(t, k) { return this.delete2(k) }, |
951 delete2: function(k) { throw "myexn" } | 719 delete2(k) { throw "myexn" } |
952 }) | 720 }) |
953 | 721 |
954 TestDeleteThrow(Proxy.create({ | 722 TestDeleteThrow(new Proxy({}, { |
955 get: function(pr, pk) { throw "myexn" } | 723 get(pt, pk, pr) { throw "myexn" } |
956 })) | 724 })) |
957 | 725 |
958 TestDeleteThrow(Proxy.create({ | 726 TestDeleteThrow(new Proxy({}, { |
959 get: function(pr, pk) { | 727 get(pt, pk, pr) { |
960 return function(k) { throw "myexn" } | 728 return (k) => { throw "myexn" } |
961 } | 729 } |
962 })) | 730 })) |
963 | 731 |
964 | 732 |
965 | 733 // --------------------------------------------------------------------------- |
966 // Property descriptors (Object.getOwnPropertyDescriptor). | 734 // Property descriptors (Object.getOwnPropertyDescriptor). |
967 | 735 |
968 function TestDescriptor(handler) { | 736 function TestDescriptor(handler) { |
969 TestWithProxies(TestDescriptor2, handler) | 737 TestWithProxies(TestDescriptor2, handler) |
970 } | 738 } |
971 | 739 |
972 function TestDescriptor2(create, handler) { | 740 function TestDescriptor2(create, handler) { |
973 var p = create(handler) | 741 var p = create(handler) |
974 var descs = [ | 742 var descs = [ |
975 {configurable: true}, | 743 {configurable: true}, |
976 {value: 34, enumerable: true, configurable: true}, | 744 {value: 34, enumerable: true, configurable: true}, |
977 {value: 3, writable: false, mine: "eyes", configurable: true}, | 745 {value: 3, writable: false, mine: "eyes", configurable: true}, |
978 {get value() { return 20 }, get configurable() { return true }}, | 746 {get value() { return 20 }, get configurable() { return true }}, |
979 {get: function() { "get" }, set: function() { "set" }, configurable: true} | 747 {get: function() { "get" }, set: function() { "set" }, configurable: true} |
980 ] | 748 ] |
981 for (var i = 0; i < descs.length; ++i) { | 749 for (var i = 0; i < descs.length; ++i) { |
982 assertEquals(p, Object.defineProperty(p, i, descs[i])) | 750 assertEquals(p, Object.defineProperty(p, i, descs[i])) |
983 var desc = Object.getOwnPropertyDescriptor(p, i) | 751 var desc = Object.getOwnPropertyDescriptor(p, i) |
984 for (prop in descs[i]) { | 752 for (prop in descs[i]) { |
985 // TODO(rossberg): Ignore user attributes as long as the spec isn't | 753 // TODO(rossberg): Ignore user attributes as long as the spec isn't |
986 // fixed suitably. | 754 // fixed suitably. |
987 if (prop != "mine") assertEquals(descs[i][prop], desc[prop]) | 755 if (prop != "mine") assertEquals(descs[i][prop], desc[prop]) |
988 } | 756 } |
989 assertEquals(undefined, Object.getOwnPropertyDescriptor(p, "absent")) | 757 assertEquals(undefined, Object.getOwnPropertyDescriptor(p, "absent")) |
990 } | 758 } |
991 } | 759 } |
992 | 760 |
993 TestDescriptor({ | 761 TestDescriptor({ |
994 defineProperty: function(k, d) { this["__" + k] = d; return true }, | 762 defineProperty(t, k, d) { this["__" + k] = d; return true }, |
995 getOwnPropertyDescriptor: function(k) { return this["__" + k] } | 763 getOwnPropertyDescriptor(t, k) { return this["__" + k] } |
996 }) | 764 }) |
997 | 765 |
998 TestDescriptor({ | 766 TestDescriptor({ |
999 defineProperty: function(k, d) { this["__" + k] = d; return true }, | 767 defineProperty(t, k, d) { this["__" + k] = d; return true }, |
1000 getOwnPropertyDescriptor: function(k) { | 768 getOwnPropertyDescriptor(t, k) { |
1001 return this.getOwnPropertyDescriptor2(k) | 769 return this.getOwnPropertyDescriptor2(k) |
1002 }, | 770 }, |
1003 getOwnPropertyDescriptor2: function(k) { return this["__" + k] } | 771 getOwnPropertyDescriptor2: function(k) { return this["__" + k] } |
1004 }) | 772 }) |
1005 | 773 |
1006 | 774 |
775 // --------------------------------------------------------------------------- | |
1007 function TestDescriptorThrow(handler) { | 776 function TestDescriptorThrow(handler) { |
1008 TestWithProxies(TestDescriptorThrow2, handler) | 777 TestWithProxies(TestDescriptorThrow2, handler) |
1009 } | 778 } |
1010 | 779 |
1011 function TestDescriptorThrow2(create, handler) { | 780 function TestDescriptorThrow2(create, handler) { |
1012 var p = create(handler) | 781 var p = create(handler) |
1013 assertThrows(function(){ Object.getOwnPropertyDescriptor(p, "a") }, "myexn") | 782 assertThrows(function(){ Object.getOwnPropertyDescriptor(p, "a") }, "myexn") |
1014 } | 783 } |
1015 | 784 |
1016 TestDescriptorThrow({ | 785 TestDescriptorThrow({ |
1017 getOwnPropertyDescriptor: function(k) { throw "myexn" } | 786 getOwnPropertyDescriptor: function(k) { throw "myexn" } |
1018 }) | 787 }) |
1019 | 788 |
1020 TestDescriptorThrow({ | 789 TestDescriptorThrow({ |
1021 getOwnPropertyDescriptor: function(k) { | 790 getOwnPropertyDescriptor: function(k) { |
1022 return this.getOwnPropertyDescriptor2(k) | 791 return this.getOwnPropertyDescriptor2(k) |
1023 }, | 792 }, |
1024 getOwnPropertyDescriptor2: function(k) { throw "myexn" } | 793 getOwnPropertyDescriptor2: function(k) { throw "myexn" } |
1025 }) | 794 }) |
1026 | 795 |
1027 | 796 |
1028 | 797 |
798 // --------------------------------------------------------------------------- | |
1029 // Comparison. | 799 // Comparison. |
1030 | 800 |
1031 function TestComparison(eq) { | 801 function TestComparison(eq) { |
1032 TestWithProxies(TestComparison2, eq) | 802 TestWithProxies(TestComparison2, eq) |
1033 } | 803 } |
1034 | 804 |
1035 function TestComparison2(create, eq) { | 805 function TestComparison2(create, eq) { |
1036 var p1 = create({}) | 806 var p1 = create({}) |
1037 var p2 = create({}) | 807 var p2 = create({}) |
1038 | 808 |
1039 assertTrue(eq(p1, p1)) | 809 assertTrue(eq(p1, p1)) |
1040 assertTrue(eq(p2, p2)) | 810 assertTrue(eq(p2, p2)) |
1041 assertTrue(!eq(p1, p2)) | 811 assertTrue(!eq(p1, p2)) |
1042 assertTrue(!eq(p1, {})) | 812 assertTrue(!eq(p1, {})) |
1043 assertTrue(!eq({}, p2)) | 813 assertTrue(!eq({}, p2)) |
1044 assertTrue(!eq({}, {})) | 814 assertTrue(!eq({}, {})) |
1045 } | 815 } |
1046 | 816 |
1047 TestComparison(function(o1, o2) { return o1 == o2 }) | 817 TestComparison(function(o1, o2) { return o1 == o2 }) |
1048 TestComparison(function(o1, o2) { return o1 === o2 }) | 818 TestComparison(function(o1, o2) { return o1 === o2 }) |
1049 TestComparison(function(o1, o2) { return !(o1 != o2) }) | 819 TestComparison(function(o1, o2) { return !(o1 != o2) }) |
1050 TestComparison(function(o1, o2) { return !(o1 !== o2) }) | 820 TestComparison(function(o1, o2) { return !(o1 !== o2) }) |
1051 | 821 |
1052 | 822 |
1053 | 823 |
1054 // Type (typeof). | 824 // Type (typeof). |
1055 | 825 |
1056 function TestTypeof() { | 826 function TestTypeof() { |
1057 assertEquals("object", typeof Proxy.create({})) | 827 assertEquals("object", typeof new Proxy({},{})) |
1058 assertTrue(typeof Proxy.create({}) == "object") | 828 assertTrue(typeof new Proxy({}, {}) == "object") |
1059 assertTrue("object" == typeof Proxy.create({})) | 829 assertTrue("object" == typeof new Proxy({},{})) |
1060 | 830 |
1061 assertEquals("function", typeof Proxy.createFunction({}, function() {})) | 831 assertEquals("function", typeof new Proxy(function() {}, {})) |
1062 assertTrue(typeof Proxy.createFunction({}, function() {}) == "function") | 832 assertTrue(typeof new Proxy(function() {}, {}) == "function") |
1063 assertTrue("function" == typeof Proxy.createFunction({}, function() {})) | 833 assertTrue("function" == typeof new Proxy(function() {},{})) |
1064 } | 834 } |
1065 | 835 |
1066 TestTypeof() | 836 TestTypeof() |
1067 | 837 |
1068 | 838 |
1069 | 839 |
840 // --------------------------------------------------------------------------- | |
1070 // Membership test (in). | 841 // Membership test (in). |
1071 | 842 |
1072 var key | 843 var key |
1073 | 844 |
1074 function TestIn(handler) { | 845 function TestIn(handler) { |
1075 TestWithProxies(TestIn2, handler) | 846 TestWithProxies(TestIn2, handler) |
1076 } | 847 } |
1077 | 848 |
1078 function TestIn2(create, handler) { | 849 function TestIn2(create, handler) { |
1079 var p = create(handler) | 850 var p = create(handler) |
(...skipping 27 matching lines...) Expand all Loading... | |
1107 assertEquals("c", key) | 878 assertEquals("c", key) |
1108 | 879 |
1109 if (!("zzz" in p)) { | 880 if (!("zzz" in p)) { |
1110 } else { | 881 } else { |
1111 assertTrue(false) | 882 assertTrue(false) |
1112 } | 883 } |
1113 assertEquals("zzz", key) | 884 assertEquals("zzz", key) |
1114 } | 885 } |
1115 | 886 |
1116 TestIn({ | 887 TestIn({ |
1117 has: function(k) { key = k; return k < "z" } | 888 has(t, k) { key = k; return k < "z" } |
1118 }) | 889 }) |
1119 | 890 |
1120 TestIn({ | 891 TestIn({ |
1121 has: function(k) { return this.has2(k) }, | 892 has(t, k) { return this.has2(k) }, |
1122 has2: function(k) { key = k; return k < "z" } | 893 has2(k) { key = k; return k < "z" } |
1123 }) | 894 }) |
1124 | 895 |
1125 TestIn({ | 896 TestIn(new Proxy({},{ |
1126 getPropertyDescriptor: function(k) { | 897 get(pt, pk, pr) { |
1127 key = k; return k < "z" ? {value: 42} : void 0 | 898 return (t, k) => { key = k; return k < "z" } |
1128 } | |
1129 }) | |
1130 | |
1131 TestIn({ | |
1132 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, | |
1133 getPropertyDescriptor2: function(k) { | |
1134 key = k; return k < "z" ? {value: 42} : void 0 | |
1135 } | |
1136 }) | |
1137 | |
1138 TestIn({ | |
1139 getPropertyDescriptor: function(k) { | |
1140 key = k; return k < "z" ? {get value() { return 42 }} : void 0 | |
1141 } | |
1142 }) | |
1143 | |
1144 TestIn({ | |
1145 has: undefined, | |
1146 getPropertyDescriptor: function(k) { | |
1147 key = k; return k < "z" ? {value: 42} : void 0 | |
1148 } | |
1149 }) | |
1150 | |
1151 TestIn(Proxy.create({ | |
1152 get: function(pr, pk) { | |
1153 return function(k) { key = k; return k < "z" } | |
1154 } | 899 } |
1155 })) | 900 })) |
1156 | 901 |
1157 | 902 |
903 // --------------------------------------------------------------------------- | |
1158 function TestInThrow(handler) { | 904 function TestInThrow(handler) { |
1159 TestWithProxies(TestInThrow2, handler) | 905 TestWithProxies(TestInThrow2, handler) |
1160 } | 906 } |
1161 | 907 |
1162 function TestInThrow2(create, handler) { | 908 function TestInThrow2(create, handler) { |
1163 var p = create(handler) | 909 var p = create(handler) |
1164 assertThrows(function(){ return "a" in o }, "myexn") | 910 assertThrows(function(){ return "a" in o }, "myexn") |
1165 assertThrows(function(){ return 99 in o }, "myexn") | 911 assertThrows(function(){ return 99 in o }, "myexn") |
1166 assertThrows(function(){ return !("a" in o) }, "myexn") | 912 assertThrows(function(){ return !("a" in o) }, "myexn") |
1167 assertThrows(function(){ return ("a" in o) ? 2 : 3 }, "myexn") | 913 assertThrows(function(){ return ("a" in o) ? 2 : 3 }, "myexn") |
(...skipping 18 matching lines...) Expand all Loading... | |
1186 TestInThrow({ | 932 TestInThrow({ |
1187 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, | 933 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, |
1188 getPropertyDescriptor2: function(k) { throw "myexn" } | 934 getPropertyDescriptor2: function(k) { throw "myexn" } |
1189 }) | 935 }) |
1190 | 936 |
1191 TestInThrow({ | 937 TestInThrow({ |
1192 has: undefined, | 938 has: undefined, |
1193 getPropertyDescriptor: function(k) { throw "myexn" } | 939 getPropertyDescriptor: function(k) { throw "myexn" } |
1194 }) | 940 }) |
1195 | 941 |
1196 TestInThrow(Proxy.create({ | 942 TestInThrow(new Proxy({},{ |
1197 get: function(pr, pk) { throw "myexn" } | 943 get: function(pr, pk) { throw "myexn" } |
1198 })) | 944 })) |
1199 | 945 |
1200 TestInThrow(Proxy.create({ | 946 TestInThrow(new Proxy({},{ |
1201 get: function(pr, pk) { | 947 get: function(pr, pk) { |
1202 return function(k) { throw "myexn" } | 948 return function(k) { throw "myexn" } |
1203 } | 949 } |
1204 })) | 950 })) |
1205 | 951 |
1206 | 952 |
1207 function TestInForDerived(handler) { | |
1208 TestWithProxies(TestInForDerived2, handler) | |
1209 } | |
1210 | 953 |
1211 function TestInForDerived2(create, handler) { | 954 // --------------------------------------------------------------------------- |
1212 var p = create(handler) | |
1213 var o = Object.create(p) | |
1214 | |
1215 assertTrue("a" in o) | |
1216 assertEquals("a", key) | |
1217 assertTrue(99 in o) | |
1218 assertEquals("99", key) | |
1219 assertFalse("z" in o) | |
1220 assertEquals("z", key) | |
1221 | |
1222 assertEquals(2, ("a" in o) ? 2 : 0) | |
1223 assertEquals(0, !("a" in o) ? 2 : 0) | |
1224 assertEquals(0, ("zzz" in o) ? 2 : 0) | |
1225 assertEquals(2, !("zzz" in o) ? 2 : 0) | |
1226 | |
1227 if ("b" in o) { | |
1228 } else { | |
1229 assertTrue(false) | |
1230 } | |
1231 assertEquals("b", key) | |
1232 | |
1233 if ("zz" in o) { | |
1234 assertTrue(false) | |
1235 } | |
1236 assertEquals("zz", key) | |
1237 | |
1238 if (!("c" in o)) { | |
1239 assertTrue(false) | |
1240 } | |
1241 assertEquals("c", key) | |
1242 | |
1243 if (!("zzz" in o)) { | |
1244 } else { | |
1245 assertTrue(false) | |
1246 } | |
1247 assertEquals("zzz", key) | |
1248 } | |
1249 | |
1250 TestInForDerived({ | |
1251 getPropertyDescriptor: function(k) { | |
1252 key = k; return k < "z" ? {value: 42, configurable: true} : void 0 | |
1253 } | |
1254 }) | |
1255 | |
1256 TestInForDerived({ | |
1257 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, | |
1258 getPropertyDescriptor2: function(k) { | |
1259 key = k; return k < "z" ? {value: 42, configurable: true} : void 0 | |
1260 } | |
1261 }) | |
1262 | |
1263 TestInForDerived({ | |
1264 getPropertyDescriptor: function(k) { | |
1265 key = k; | |
1266 return k < "z" ? {get value() { return 42 }, configurable: true} : void 0 | |
1267 } | |
1268 }) | |
1269 | |
1270 /* TODO(rossberg): this will work once we implement the newest proposal | |
1271 * regarding default traps for getPropertyDescriptor. | |
1272 TestInForDerived({ | |
1273 getOwnPropertyDescriptor: function(k) { | |
1274 key = k; return k < "z" ? {value: 42, configurable: true} : void 0 | |
1275 } | |
1276 }) | |
1277 | |
1278 TestInForDerived({ | |
1279 getOwnPropertyDescriptor: function(k) { | |
1280 return this.getOwnPropertyDescriptor2(k) | |
1281 }, | |
1282 getOwnPropertyDescriptor2: function(k) { | |
1283 key = k; return k < "z" ? {value: 42, configurable: true} : void 0 | |
1284 } | |
1285 }) | |
1286 | |
1287 TestInForDerived({ | |
1288 getOwnPropertyDescriptor: function(k) { | |
1289 key = k; | |
1290 return k < "z" ? {get value() { return 42 }, configurable: true} : void 0 | |
1291 } | |
1292 }) | |
1293 */ | |
1294 | |
1295 TestInForDerived(Proxy.create({ | |
1296 get: function(pr, pk) { | |
1297 return function(k) { | |
1298 key = k; return k < "z" ? {value: 42, configurable: true} : void 0 | |
1299 } | |
1300 } | |
1301 })) | |
1302 | |
1303 | |
1304 | |
1305 // Property descriptor conversion. | |
1306 | |
1307 var descget | |
1308 | |
1309 function TestDescriptorGetOrder(handler) { | |
1310 var p = Proxy.create(handler) | |
1311 var o = Object.create(p, {b: {value: 0}}) | |
1312 TestDescriptorGetOrder2(function(n) { return p[n] }, "vV") | |
1313 TestDescriptorGetOrder2(function(n) { return n in p }, "") | |
1314 TestDescriptorGetOrder2(function(n) { return o[n] }, "vV") | |
1315 TestDescriptorGetOrder2(function(n) { return n in o }, "") | |
1316 } | |
1317 | |
1318 function TestDescriptorGetOrder2(f, access) { | |
1319 descget = "" | |
1320 assertTrue(f("a")) | |
1321 assertEquals(access, descget) | |
1322 descget = "" | |
1323 assertTrue(f(99)) | |
1324 assertEquals(access, descget) | |
1325 descget = "" | |
1326 assertFalse(!!f("z")) | |
1327 assertEquals("", descget) | |
1328 } | |
1329 | |
1330 TestDescriptorGetOrder({ | |
1331 getPropertyDescriptor: function(k) { | |
1332 if (k >= "z") return void 0 | |
1333 // Return a proxy as property descriptor, so that we can log accesses. | |
1334 return Proxy.create({ | |
1335 get: function(r, attr) { | |
1336 descget += attr[0].toUpperCase() | |
1337 return true | |
1338 }, | |
1339 has: function(attr) { | |
1340 descget += attr[0] | |
1341 switch (attr) { | |
1342 case "writable": | |
1343 case "enumerable": | |
1344 case "configurable": | |
1345 case "value": | |
1346 return true | |
1347 case "get": | |
1348 case "set": | |
1349 return false | |
1350 default: | |
1351 assertUnreachable() | |
1352 } | |
1353 } | |
1354 }) | |
1355 } | |
1356 }) | |
1357 | |
1358 | |
1359 | |
1360 // Own Properties (Object.prototype.hasOwnProperty). | 955 // Own Properties (Object.prototype.hasOwnProperty). |
1361 | 956 |
1362 var key | 957 var key |
1363 | 958 |
1364 function TestHasOwn(handler) { | 959 function TestHasOwn(handler) { |
1365 TestWithProxies(TestHasOwn2, handler) | 960 TestWithProxies(TestHasOwn2, handler) |
1366 } | 961 } |
1367 | 962 |
1368 function TestHasOwn2(create, handler) { | 963 function TestHasOwn2(create, handler) { |
1369 var p = create(handler) | 964 var p = create(handler) |
1370 assertTrue(Object.prototype.hasOwnProperty.call(p, "a")) | 965 assertTrue(Object.prototype.hasOwnProperty.call(p, "a")) |
1371 assertEquals("a", key) | 966 assertEquals("a", key) |
1372 assertTrue(Object.prototype.hasOwnProperty.call(p, 99)) | 967 assertTrue(Object.prototype.hasOwnProperty.call(p, 99)) |
1373 assertEquals("99", key) | 968 assertEquals("99", key) |
1374 assertFalse(Object.prototype.hasOwnProperty.call(p, "z")) | 969 assertFalse(Object.prototype.hasOwnProperty.call(p, "z")) |
1375 assertEquals("z", key) | 970 assertEquals("z", key) |
1376 } | 971 } |
1377 | 972 |
1378 TestHasOwn({ | 973 TestHasOwn({ |
1379 hasOwn: function(k) { key = k; return k < "z" } | 974 has(t, k) { key = k; return k < "z" } |
1380 }) | 975 }) |
1381 | 976 |
1382 TestHasOwn({ | 977 TestHasOwn({ |
1383 hasOwn: function(k) { return this.hasOwn2(k) }, | 978 has(t, k) { return this.hasOwn2(k) }, |
1384 hasOwn2: function(k) { key = k; return k < "z" } | 979 hasOwn2(k) { key = k; return k < "z" } |
1385 }) | 980 }) |
1386 | 981 |
1387 TestHasOwn({ | 982 TestHasOwn(new Proxy({}, { |
1388 getOwnPropertyDescriptor: function(k) { | 983 get(pt, pk, pr) { |
1389 key = k; return k < "z" ? {value: 42} : void 0 | 984 return (t, k) => { key = k; return k < "z" } |
1390 } | |
1391 }) | |
1392 | |
1393 TestHasOwn({ | |
1394 getOwnPropertyDescriptor: function(k) { | |
1395 return this.getOwnPropertyDescriptor2(k) | |
1396 }, | |
1397 getOwnPropertyDescriptor2: function(k) { | |
1398 key = k; return k < "z" ? {value: 42} : void 0 | |
1399 } | |
1400 }) | |
1401 | |
1402 TestHasOwn({ | |
1403 getOwnPropertyDescriptor: function(k) { | |
1404 key = k; return k < "z" ? {get value() { return 42 }} : void 0 | |
1405 } | |
1406 }) | |
1407 | |
1408 TestHasOwn({ | |
1409 hasOwn: undefined, | |
1410 getOwnPropertyDescriptor: function(k) { | |
1411 key = k; return k < "z" ? {value: 42} : void 0 | |
1412 } | |
1413 }) | |
1414 | |
1415 TestHasOwn(Proxy.create({ | |
1416 get: function(pr, pk) { | |
1417 return function(k) { key = k; return k < "z" } | |
1418 } | 985 } |
1419 })) | 986 })) |
1420 | 987 |
1421 | 988 |
989 // --------------------------------------------------------------------------- | |
1422 function TestHasOwnThrow(handler) { | 990 function TestHasOwnThrow(handler) { |
1423 TestWithProxies(TestHasOwnThrow2, handler) | 991 TestWithProxies(TestHasOwnThrow2, handler) |
1424 } | 992 } |
1425 | 993 |
1426 function TestHasOwnThrow2(create, handler) { | 994 function TestHasOwnThrow2(create, handler) { |
1427 var p = create(handler) | 995 var p = create(handler) |
1428 assertThrows(function(){ Object.prototype.hasOwnProperty.call(p, "a")}, | 996 assertThrows(function(){ Object.prototype.hasOwnProperty.call(p, "a")}, |
1429 "myexn") | 997 "myexn") |
1430 assertThrows(function(){ Object.prototype.hasOwnProperty.call(p, 99)}, | 998 assertThrows(function(){ Object.prototype.hasOwnProperty.call(p, 99)}, |
1431 "myexn") | 999 "myexn") |
1432 } | 1000 } |
1433 | 1001 |
1434 TestHasOwnThrow({ | 1002 TestHasOwnThrow({ |
1435 hasOwn: function(k) { throw "myexn" } | 1003 has(t, k) { throw "myexn" } |
1436 }) | 1004 }) |
1437 | 1005 |
1438 TestHasOwnThrow({ | 1006 TestHasOwnThrow({ |
1439 hasOwn: function(k) { return this.hasOwn2(k) }, | 1007 has(t, k) { return this.hasOwn2(k) }, |
1440 hasOwn2: function(k) { throw "myexn" } | 1008 hasOwn2(k) { throw "myexn" } |
1441 }) | 1009 }) |
1442 | 1010 |
1443 TestHasOwnThrow({ | 1011 TestHasOwnThrow(new Proxy({}, { |
1444 getOwnPropertyDescriptor: function(k) { throw "myexn" } | 1012 get(pt, pk, pr) { throw "myexn" } |
1445 }) | |
1446 | |
1447 TestHasOwnThrow({ | |
1448 getOwnPropertyDescriptor: function(k) { | |
1449 return this.getOwnPropertyDescriptor2(k) | |
1450 }, | |
1451 getOwnPropertyDescriptor2: function(k) { throw "myexn" } | |
1452 }) | |
1453 | |
1454 TestHasOwnThrow({ | |
1455 hasOwn: undefined, | |
1456 getOwnPropertyDescriptor: function(k) { throw "myexn" } | |
1457 }) | |
1458 | |
1459 TestHasOwnThrow(Proxy.create({ | |
1460 get: function(pr, pk) { throw "myexn" } | |
1461 })) | 1013 })) |
1462 | 1014 |
1463 TestHasOwnThrow(Proxy.create({ | 1015 TestHasOwnThrow(new Proxy({}, { |
1464 get: function(pr, pk) { | 1016 get(pt, pk, pr) { |
1465 return function(k) { throw "myexn" } | 1017 return (t, k) => { throw "myexn" } |
1466 } | 1018 } |
1467 })) | 1019 })); |
1468 | 1020 |
1469 | 1021 |
1470 | 1022 |
1023 // --------------------------------------------------------------------------- | |
1471 // Instanceof (instanceof) | 1024 // Instanceof (instanceof) |
1472 | 1025 |
1473 function TestProxyInstanceof() { | 1026 (function TestProxyInstanceof() { |
1474 var o1 = {} | 1027 var o1 = {} |
1475 var p1 = Proxy.create({}) | 1028 var p1 = new Proxy({}, {}) |
1476 var p2 = Proxy.create({}, o1) | 1029 var p2 = new Proxy(o1, {}) |
1477 var p3 = Proxy.create({}, p2) | 1030 var p3 = new Proxy(p2, {}) |
1478 var o2 = Object.create(p2) | 1031 var o2 = Object.create(p2) |
1479 | 1032 |
1480 var f0 = function() {} | 1033 var f0 = function() {} |
1481 f0.prototype = o1 | 1034 f0.prototype = o1 |
1482 var f1 = function() {} | 1035 var f1 = function() {} |
1483 f1.prototype = p1 | 1036 f1.prototype = p1 |
1484 var f2 = function() {} | 1037 var f2 = function() {} |
1485 f2.prototype = p2 | 1038 f2.prototype = p2 |
1486 var f3 = function() {} | 1039 var f3 = function() {} |
1487 f3.prototype = o2 | 1040 f3.prototype = o2 |
1488 | 1041 |
1489 assertTrue(o1 instanceof Object) | 1042 assertTrue(o1 instanceof Object) |
1490 assertFalse(o1 instanceof f0) | 1043 assertFalse(o1 instanceof f0) |
1491 assertFalse(o1 instanceof f1) | 1044 assertFalse(o1 instanceof f1) |
1492 assertFalse(o1 instanceof f2) | 1045 assertFalse(o1 instanceof f2) |
1493 assertFalse(o1 instanceof f3) | 1046 assertFalse(o1 instanceof f3) |
1494 assertFalse(p1 instanceof Object) | 1047 assertTrue(p1 instanceof Object) |
1495 assertFalse(p1 instanceof f0) | 1048 assertFalse(p1 instanceof f0) |
1496 assertFalse(p1 instanceof f1) | 1049 assertFalse(p1 instanceof f1) |
1497 assertFalse(p1 instanceof f2) | 1050 assertFalse(p1 instanceof f2) |
1498 assertFalse(p1 instanceof f3) | 1051 assertFalse(p1 instanceof f3) |
1499 assertTrue(p2 instanceof Object) | 1052 assertTrue(p2 instanceof Object) |
1500 assertTrue(p2 instanceof f0) | 1053 assertFalse(p2 instanceof f0) |
1501 assertFalse(p2 instanceof f1) | 1054 assertFalse(p2 instanceof f1) |
1502 assertFalse(p2 instanceof f2) | 1055 assertFalse(p2 instanceof f2) |
1503 assertFalse(p2 instanceof f3) | 1056 assertFalse(p2 instanceof f3) |
1504 assertTrue(p3 instanceof Object) | 1057 assertTrue(p3 instanceof Object) |
1505 assertTrue(p3 instanceof f0) | 1058 assertFalse(p3 instanceof f0) |
1506 assertFalse(p3 instanceof f1) | 1059 assertFalse(p3 instanceof f1) |
1507 assertTrue(p3 instanceof f2) | 1060 assertFalse(p3 instanceof f2) |
1508 assertFalse(p3 instanceof f3) | 1061 assertFalse(p3 instanceof f3) |
1509 assertTrue(o2 instanceof Object) | 1062 assertTrue(o2 instanceof Object) |
1510 assertTrue(o2 instanceof f0) | 1063 assertFalse(o2 instanceof f0) |
1511 assertFalse(o2 instanceof f1) | 1064 assertFalse(o2 instanceof f1) |
1512 assertTrue(o2 instanceof f2) | 1065 assertTrue(o2 instanceof f2) |
1513 assertFalse(o2 instanceof f3) | 1066 assertFalse(o2 instanceof f3) |
1514 | 1067 |
1515 var f = Proxy.createFunction({}, function() {}) | 1068 var f = new Proxy(function() {}, {}) |
1516 assertTrue(f instanceof Function) | 1069 assertTrue(f instanceof Function) |
1517 } | 1070 })(); |
1518 | |
1519 TestProxyInstanceof() | |
1520 | 1071 |
1521 | 1072 |
1522 function TestInstanceofProxy() { | 1073 (function TestInstanceofProxy() { |
1523 var o0 = Object.create(null) | 1074 var o0 = Object.create(null) |
1524 var o1 = {} | 1075 var o1 = {} |
1525 var o2 = Object.create(o0) | 1076 var o2 = Object.create(o0) |
1526 var o3 = Object.create(o1) | 1077 var o3 = Object.create(o1) |
1527 var o4 = Object.create(o2) | 1078 var o4 = Object.create(o2) |
1528 var o5 = Object.create(o3) | 1079 var o5 = Object.create(o3) |
1529 | 1080 |
1530 function handler(o) { return {get: function() { return o } } } | 1081 function handler(o) { return {get: function() { return o } } } |
1531 var f0 = Proxy.createFunction(handler(o0), function() {}) | 1082 var f0 = new Proxy(function() {}, handler(o0)) |
1532 var f1 = Proxy.createFunction(handler(o1), function() {}) | 1083 var f1 = new Proxy(function() {}, handler(o1)) |
1533 var f2 = Proxy.createFunction(handler(o2), function() {}) | 1084 var f2 = new Proxy(function() {}, handler(o2)) |
1534 var f3 = Proxy.createFunction(handler(o3), function() {}) | 1085 var f3 = new Proxy(function() {}, handler(o3)) |
1535 var f4 = Proxy.createFunction(handler(o4), function() {}) | 1086 var f4 = new Proxy(function() {}, handler(o4)) |
1536 var f5 = Proxy.createFunction(handler(o4), function() {}) | 1087 var f5 = new Proxy(function() {}, handler(o4)) |
1537 | 1088 |
1538 assertFalse(null instanceof f0) | 1089 assertFalse(null instanceof f0) |
1539 assertFalse(o0 instanceof f0) | 1090 assertFalse(o0 instanceof f0) |
1540 assertFalse(o0 instanceof f1) | 1091 assertFalse(o0 instanceof f1) |
1541 assertFalse(o0 instanceof f2) | 1092 assertFalse(o0 instanceof f2) |
1542 assertFalse(o0 instanceof f3) | 1093 assertFalse(o0 instanceof f3) |
1543 assertFalse(o0 instanceof f4) | 1094 assertFalse(o0 instanceof f4) |
1544 assertFalse(o0 instanceof f5) | 1095 assertFalse(o0 instanceof f5) |
1545 assertFalse(o1 instanceof f0) | 1096 assertFalse(o1 instanceof f0) |
1546 assertFalse(o1 instanceof f1) | 1097 assertFalse(o1 instanceof f1) |
(...skipping 19 matching lines...) Expand all Loading... | |
1566 assertFalse(o4 instanceof f3) | 1117 assertFalse(o4 instanceof f3) |
1567 assertFalse(o4 instanceof f4) | 1118 assertFalse(o4 instanceof f4) |
1568 assertFalse(o4 instanceof f5) | 1119 assertFalse(o4 instanceof f5) |
1569 assertFalse(o5 instanceof f0) | 1120 assertFalse(o5 instanceof f0) |
1570 assertTrue(o5 instanceof f1) | 1121 assertTrue(o5 instanceof f1) |
1571 assertFalse(o5 instanceof f2) | 1122 assertFalse(o5 instanceof f2) |
1572 assertTrue(o5 instanceof f3) | 1123 assertTrue(o5 instanceof f3) |
1573 assertFalse(o5 instanceof f4) | 1124 assertFalse(o5 instanceof f4) |
1574 assertFalse(o5 instanceof f5) | 1125 assertFalse(o5 instanceof f5) |
1575 | 1126 |
1576 var f = Proxy.createFunction({}, function() {}) | 1127 var f = new Proxy(function() {}, {}) |
1577 var ff = Proxy.createFunction(handler(Function), function() {}) | 1128 var ff = new Proxy(function() {}, handler(Function)) |
1578 assertTrue(f instanceof Function) | 1129 assertTrue(f instanceof Function) |
1579 assertFalse(f instanceof ff) | 1130 assertFalse(f instanceof ff) |
1580 } | 1131 })(); |
1581 | |
1582 TestInstanceofProxy() | |
1583 | 1132 |
1584 | 1133 |
1585 | 1134 // --------------------------------------------------------------------------- |
1586 // Prototype (Object.getPrototypeOf, Object.prototype.isPrototypeOf). | 1135 // Prototype (Object.getPrototypeOf, Object.prototype.isPrototypeOf). |
1587 | 1136 |
1588 function TestPrototype() { | 1137 (function TestPrototype() { |
1589 var o1 = {} | 1138 var o1 = {} |
1590 var p1 = Proxy.create({}) | 1139 var p1 = new Proxy({}, {}) |
1591 var p2 = Proxy.create({}, o1) | 1140 var p2 = new Proxy(o1, {}) |
1592 var p3 = Proxy.create({}, p2) | 1141 var p3 = new Proxy(p2, {}) |
1593 var p4 = Proxy.create({}, null) | |
1594 var o2 = Object.create(p3) | 1142 var o2 = Object.create(p3) |
1595 | 1143 |
1596 assertSame(Object.getPrototypeOf(o1), Object.prototype) | 1144 assertSame(Object.getPrototypeOf(o1), Object.prototype) |
1597 assertSame(Object.getPrototypeOf(p1), null) | 1145 assertSame(Object.getPrototypeOf(p1), Object.prototype) |
1598 assertSame(Object.getPrototypeOf(p2), o1) | 1146 assertSame(Object.getPrototypeOf(p2), Object.prototype) |
1599 assertSame(Object.getPrototypeOf(p3), p2) | 1147 assertSame(Object.getPrototypeOf(p3), Object.prototype) |
1600 assertSame(Object.getPrototypeOf(p4), null) | |
1601 assertSame(Object.getPrototypeOf(o2), p3) | 1148 assertSame(Object.getPrototypeOf(o2), p3) |
1602 | 1149 |
1603 assertTrue(Object.prototype.isPrototypeOf(o1)) | 1150 assertTrue(Object.prototype.isPrototypeOf(o1)) |
1604 assertFalse(Object.prototype.isPrototypeOf(p1)) | 1151 assertTrue(Object.prototype.isPrototypeOf(p1)) |
1605 assertTrue(Object.prototype.isPrototypeOf(p2)) | 1152 assertTrue(Object.prototype.isPrototypeOf(p2)) |
1606 assertTrue(Object.prototype.isPrototypeOf(p3)) | 1153 assertTrue(Object.prototype.isPrototypeOf(p3)) |
1607 assertFalse(Object.prototype.isPrototypeOf(p4)) | |
1608 assertTrue(Object.prototype.isPrototypeOf(o2)) | 1154 assertTrue(Object.prototype.isPrototypeOf(o2)) |
1609 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o1)) | 1155 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o1)) |
1610 assertFalse(Object.prototype.isPrototypeOf.call(Object.prototype, p1)) | 1156 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p1)) |
1611 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p2)) | 1157 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p2)) |
1612 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p3)) | 1158 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p3)) |
1613 assertFalse(Object.prototype.isPrototypeOf.call(Object.prototype, p4)) | |
1614 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o2)) | 1159 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o2)) |
1615 assertFalse(Object.prototype.isPrototypeOf.call(o1, o1)) | 1160 assertFalse(Object.prototype.isPrototypeOf.call(o1, o1)) |
1616 assertFalse(Object.prototype.isPrototypeOf.call(o1, p1)) | 1161 assertFalse(Object.prototype.isPrototypeOf.call(o1, p1)) |
1617 assertTrue(Object.prototype.isPrototypeOf.call(o1, p2)) | 1162 assertFalse(Object.prototype.isPrototypeOf.call(o1, p2)) |
1618 assertTrue(Object.prototype.isPrototypeOf.call(o1, p3)) | 1163 assertFalse(Object.prototype.isPrototypeOf.call(o1, p3)) |
1619 assertFalse(Object.prototype.isPrototypeOf.call(o1, p4)) | 1164 assertFalse(Object.prototype.isPrototypeOf.call(o1, o2)) |
1620 assertTrue(Object.prototype.isPrototypeOf.call(o1, o2)) | |
1621 assertFalse(Object.prototype.isPrototypeOf.call(p1, p1)) | 1165 assertFalse(Object.prototype.isPrototypeOf.call(p1, p1)) |
1622 assertFalse(Object.prototype.isPrototypeOf.call(p1, o1)) | 1166 assertFalse(Object.prototype.isPrototypeOf.call(p1, o1)) |
1623 assertFalse(Object.prototype.isPrototypeOf.call(p1, p2)) | 1167 assertFalse(Object.prototype.isPrototypeOf.call(p1, p2)) |
1624 assertFalse(Object.prototype.isPrototypeOf.call(p1, p3)) | 1168 assertFalse(Object.prototype.isPrototypeOf.call(p1, p3)) |
1625 assertFalse(Object.prototype.isPrototypeOf.call(p1, p4)) | |
1626 assertFalse(Object.prototype.isPrototypeOf.call(p1, o2)) | 1169 assertFalse(Object.prototype.isPrototypeOf.call(p1, o2)) |
1627 assertFalse(Object.prototype.isPrototypeOf.call(p2, p1)) | 1170 assertFalse(Object.prototype.isPrototypeOf.call(p2, p1)) |
1628 assertFalse(Object.prototype.isPrototypeOf.call(p2, p2)) | 1171 assertFalse(Object.prototype.isPrototypeOf.call(p2, p2)) |
1629 assertTrue(Object.prototype.isPrototypeOf.call(p2, p3)) | 1172 assertFalse(Object.prototype.isPrototypeOf.call(p2, p3)) |
1630 assertFalse(Object.prototype.isPrototypeOf.call(p2, p4)) | 1173 assertFalse(Object.prototype.isPrototypeOf.call(p2, o2)) |
1631 assertTrue(Object.prototype.isPrototypeOf.call(p2, o2)) | |
1632 assertFalse(Object.prototype.isPrototypeOf.call(p3, p2)) | 1174 assertFalse(Object.prototype.isPrototypeOf.call(p3, p2)) |
1633 assertTrue(Object.prototype.isPrototypeOf.call(p3, o2)) | 1175 assertTrue(Object.prototype.isPrototypeOf.call(p3, o2)) |
1634 assertFalse(Object.prototype.isPrototypeOf.call(o2, o1)) | 1176 assertFalse(Object.prototype.isPrototypeOf.call(o2, o1)) |
1635 assertFalse(Object.prototype.isPrototypeOf.call(o2, p1)) | 1177 assertFalse(Object.prototype.isPrototypeOf.call(o2, p1)) |
1636 assertFalse(Object.prototype.isPrototypeOf.call(o2, p2)) | 1178 assertFalse(Object.prototype.isPrototypeOf.call(o2, p2)) |
1637 assertFalse(Object.prototype.isPrototypeOf.call(o2, p3)) | 1179 assertFalse(Object.prototype.isPrototypeOf.call(o2, p3)) |
1638 assertFalse(Object.prototype.isPrototypeOf.call(o2, p4)) | |
1639 assertFalse(Object.prototype.isPrototypeOf.call(o2, o2)) | 1180 assertFalse(Object.prototype.isPrototypeOf.call(o2, o2)) |
1640 | 1181 |
1641 var f = Proxy.createFunction({}, function() {}) | 1182 var f = new Proxy(function() {}, {}) |
1642 assertSame(Object.getPrototypeOf(f), Function.prototype) | 1183 assertSame(Object.getPrototypeOf(f), Function.prototype) |
1643 assertTrue(Object.prototype.isPrototypeOf(f)) | 1184 assertTrue(Object.prototype.isPrototypeOf(f)) |
1644 assertTrue(Object.prototype.isPrototypeOf.call(Function.prototype, f)) | 1185 assertTrue(Object.prototype.isPrototypeOf.call(Function.prototype, f)) |
1645 } | 1186 })(); |
1646 | |
1647 TestPrototype() | |
1648 | 1187 |
1649 | 1188 |
1650 | 1189 // --------------------------------------------------------------------------- |
1651 // Property names (Object.getOwnPropertyNames, Object.keys). | |
1652 | |
1653 function TestPropertyNames(names, handler) { | |
1654 TestWithProxies(TestPropertyNames2, handler, names) | |
1655 } | |
1656 | |
1657 function TestPropertyNames2(create, handler, names) { | |
1658 var p = create(handler) | |
1659 assertArrayEquals(names, Object.getOwnPropertyNames(p)) | |
1660 } | |
1661 | |
1662 TestPropertyNames([], { | |
1663 getOwnPropertyNames: function() { return [] } | |
1664 }) | |
1665 | |
1666 TestPropertyNames(["a", "zz", " ", "0", "toString"], { | |
1667 getOwnPropertyNames: function() { return ["a", "zz", " ", 0, "toString"] } | |
1668 }) | |
1669 | |
1670 TestPropertyNames(["throw", "function "], { | |
1671 getOwnPropertyNames: function() { return this.getOwnPropertyNames2() }, | |
1672 getOwnPropertyNames2: function() { return ["throw", "function "] } | |
1673 }) | |
1674 | |
1675 TestPropertyNames(["[object Object]"], { | |
1676 get getOwnPropertyNames() { | |
1677 return function() { return [{}] } | |
1678 } | |
1679 }) | |
1680 | |
1681 | |
1682 function TestPropertyNamesThrow(handler) { | 1190 function TestPropertyNamesThrow(handler) { |
1683 TestWithProxies(TestPropertyNamesThrow2, handler) | 1191 TestWithProxies(TestPropertyNamesThrow2, handler) |
1684 } | 1192 } |
1685 | 1193 |
1686 function TestPropertyNamesThrow2(create, handler) { | 1194 function TestPropertyNamesThrow2(create, handler) { |
1687 var p = create(handler) | 1195 var p = create(handler) |
1688 assertThrows(function(){ Object.getOwnPropertyNames(p) }, "myexn") | 1196 assertThrows(function(){ Object.getOwnPropertyNames(p) }, "myexn") |
1689 } | 1197 } |
1690 | 1198 |
1691 TestPropertyNamesThrow({ | 1199 TestPropertyNamesThrow({ |
1692 getOwnPropertyNames: function() { throw "myexn" } | 1200 ownKeys() { throw "myexn" } |
1693 }) | 1201 }) |
1694 | 1202 |
1695 TestPropertyNamesThrow({ | 1203 TestPropertyNamesThrow({ |
1696 getOwnPropertyNames: function() { return this.getOwnPropertyNames2() }, | 1204 ownKeys() { return this.getOwnPropertyNames2() }, |
1697 getOwnPropertyNames2: function() { throw "myexn" } | 1205 getOwnPropertyNames2() { throw "myexn" } |
1698 }) | 1206 }) |
1699 | 1207 |
1208 */ | |
1209 // --------------------------------------------------------------------------- | |
1700 | 1210 |
1701 function TestKeys(names, handler) { | 1211 function TestKeys(names, handler) { |
1702 TestWithProxies(TestKeys2, handler, names) | 1212 var p = new Proxy({}, handler); |
1703 } | |
1704 | |
1705 function TestKeys2(create, handler, names) { | |
1706 var p = create(handler) | |
1707 assertArrayEquals(names, Object.keys(p)) | 1213 assertArrayEquals(names, Object.keys(p)) |
1708 } | 1214 } |
1709 | 1215 |
1710 TestKeys([], { | 1216 TestKeys([], { |
1711 keys: function() { return [] } | 1217 ownKeys() { return [] } |
1218 }) | |
1219 | |
1220 TestKeys([], { | |
1221 ownKeys() { return ["a", "zz", " ", "0", "toString"] } | |
1712 }) | 1222 }) |
1713 | 1223 |
1714 TestKeys(["a", "zz", " ", "0", "toString"], { | 1224 TestKeys(["a", "zz", " ", "0", "toString"], { |
1715 keys: function() { return ["a", "zz", " ", 0, "toString"] } | 1225 ownKeys() { return ["a", "zz", " ", "0", "toString"] }, |
1226 getOwnPropertyDescriptor(t, p) { | |
1227 return {configurable: true, enumerable: true} | |
1228 } | |
1229 }) | |
1230 | |
1231 TestKeys([], { | |
1232 ownKeys() { return this.keys2() }, | |
1233 keys2() { return ["throw", "function "] } | |
1716 }) | 1234 }) |
1717 | 1235 |
1718 TestKeys(["throw", "function "], { | 1236 TestKeys(["throw", "function "], { |
1719 keys: function() { return this.keys2() }, | 1237 ownKeys() { return this.keys2() }, |
1720 keys2: function() { return ["throw", "function "] } | 1238 keys2() { return ["throw", "function "] }, |
1721 }) | 1239 getOwnPropertyDescriptor(t, p) { |
1722 | 1240 return {configurable: true, enumerable: true} |
1723 TestKeys(["[object Object]"], { | |
1724 get keys() { | |
1725 return function() { return [{}] } | |
1726 } | 1241 } |
1727 }) | 1242 }) |
1728 | 1243 |
1729 TestKeys(["a", "0"], { | 1244 TestKeys(["a", "0"], { |
1730 getOwnPropertyNames: function() { return ["a", 23, "zz", "", 0] }, | 1245 ownKeys() { return ["a", "23", "zz", "", "0"] }, |
1731 getOwnPropertyDescriptor: function(k) { | 1246 getOwnPropertyDescriptor(t, k) { |
1732 return k == "" ? undefined : {enumerable: k.length == 1} | 1247 return k == "" ? |
1248 undefined : | |
1249 { configurable: true, enumerable: k.length == 1} | |
1733 } | 1250 } |
1734 }) | 1251 }) |
1735 | 1252 |
1736 TestKeys(["23", "zz", ""], { | 1253 TestKeys(["23", "zz", ""], { |
1737 getOwnPropertyNames: function() { return this.getOwnPropertyNames2() }, | 1254 ownKeys() { return this.getOwnPropertyNames2() }, |
1738 getOwnPropertyNames2: function() { return ["a", 23, "zz", "", 0] }, | 1255 getOwnPropertyNames2() { return ["a", "23", "zz", "", "0"] }, |
1739 getOwnPropertyDescriptor: function(k) { | 1256 getOwnPropertyDescriptor(t, k) { |
1740 return this.getOwnPropertyDescriptor2(k) | 1257 return this.getOwnPropertyDescriptor2(k) |
1741 }, | 1258 }, |
1742 getOwnPropertyDescriptor2: function(k) { return {enumerable: k.length != 1} } | 1259 getOwnPropertyDescriptor2(k) { |
1743 }) | 1260 return {configurable: true, enumerable: k.length != 1 } |
1744 | |
1745 TestKeys(["a", "b", "c", "5"], { | |
1746 get getOwnPropertyNames() { | |
1747 return function() { return ["0", 4, "a", "b", "c", 5, "ety"] } | |
1748 }, | |
1749 get getOwnPropertyDescriptor() { | |
1750 return function(k) { | |
1751 return k == "ety" ? undefined : {enumerable: k >= "44"} | |
1752 } | |
1753 } | 1261 } |
1754 }) | 1262 }) |
1755 | 1263 |
1756 TestKeys([], { | 1264 TestKeys([], { |
1757 get getOwnPropertyNames() { | 1265 get ownKeys() { |
1758 return function() { return ["a", "b", "c"] } | 1266 return function() { return ["a", "b", "c"] } |
1759 }, | 1267 }, |
1760 getOwnPropertyDescriptor: function(k) { return {} } | 1268 getOwnPropertyDescriptor: function(k) { return {configurable: true} } |
1761 }) | 1269 }) |
1762 | 1270 |
1763 | 1271 |
1272 // --------------------------------------------------------------------------- | |
1764 function TestKeysThrow(handler) { | 1273 function TestKeysThrow(handler) { |
1765 TestWithProxies(TestKeysThrow2, handler) | 1274 TestWithProxies(TestKeysThrow2, handler) |
1766 } | 1275 } |
1767 | 1276 |
1768 function TestKeysThrow2(create, handler) { | 1277 function TestKeysThrow2(create, handler) { |
1769 var p = create(handler) | 1278 var p = create(handler) |
1770 assertThrows(function(){ Object.keys(p) }, "myexn") | 1279 assertThrows(function(){ Object.keys(p) }, "myexn") |
1771 } | 1280 } |
1772 | 1281 |
1773 TestKeysThrow({ | 1282 TestKeysThrow({ |
1774 keys: function() { throw "myexn" } | 1283 ownKeys() { throw "myexn" } |
1775 }) | 1284 }) |
1776 | 1285 |
1777 TestKeysThrow({ | 1286 TestKeysThrow({ |
1778 keys: function() { return this.keys2() }, | 1287 ownKeys() { return this.keys2() }, |
1779 keys2: function() { throw "myexn" } | 1288 keys2() { throw "myexn" } |
1780 }) | 1289 }) |
1781 | 1290 |
1782 TestKeysThrow({ | 1291 TestKeysThrow({ |
1783 getOwnPropertyNames: function() { throw "myexn" }, | 1292 ownKeys() { return ['1'] }, |
1784 getOwnPropertyDescriptor: function(k) { return true } | 1293 getOwnPropertyDescriptor: function() { throw "myexn" }, |
1785 }) | 1294 }) |
1786 | 1295 |
1787 TestKeysThrow({ | 1296 TestKeysThrow({ |
1788 getOwnPropertyNames: function() { return [1, 2] }, | 1297 ownKeys() { return this.getOwnPropertyNames2() }, |
1789 getOwnPropertyDescriptor: function(k) { throw "myexn" } | 1298 getOwnPropertyNames2() { return [1, 2] }, |
1299 getOwnPropertyDescriptor(k) { | |
1300 return this.getOwnPropertyDescriptor2(k) | |
1301 }, | |
1302 getOwnPropertyDescriptor2(k) { throw "myexn" } | |
1790 }) | 1303 }) |
1791 | 1304 |
1792 TestKeysThrow({ | 1305 TestKeysThrow({ |
1793 getOwnPropertyNames: function() { return this.getOwnPropertyNames2() }, | 1306 get ownKeys() { throw "myexn" } |
1794 getOwnPropertyNames2: function() { throw "myexn" }, | |
1795 }) | 1307 }) |
1796 | 1308 |
1797 TestKeysThrow({ | 1309 TestKeysThrow({ |
1798 getOwnPropertyNames: function() { return this.getOwnPropertyNames2() }, | 1310 get ownKeys() { |
1799 getOwnPropertyNames2: function() { return [1, 2] }, | |
1800 getOwnPropertyDescriptor: function(k) { | |
1801 return this.getOwnPropertyDescriptor2(k) | |
1802 }, | |
1803 getOwnPropertyDescriptor2: function(k) { throw "myexn" } | |
1804 }) | |
1805 | |
1806 TestKeysThrow({ | |
1807 get getOwnPropertyNames() { throw "myexn" } | |
1808 }) | |
1809 | |
1810 TestKeysThrow({ | |
1811 get getOwnPropertyNames() { | |
1812 return function() { throw "myexn" } | 1311 return function() { throw "myexn" } |
1813 }, | 1312 }, |
1814 }) | 1313 }) |
1815 | 1314 |
1816 TestKeysThrow({ | 1315 TestKeysThrow({ |
1817 get getOwnPropertyNames() { | 1316 get ownKeys() { |
1818 return function() { return [1, 2] } | 1317 return function() { return [1, 2] } |
1819 }, | 1318 }, |
1820 getOwnPropertyDescriptor: function(k) { throw "myexn" } | 1319 getOwnPropertyDescriptor(k) { throw "myexn" } |
1821 }) | 1320 }) |
1822 | 1321 |
1823 | 1322 |
1824 | 1323 |
1825 // Fixing (Object.freeze, Object.seal, Object.preventExtensions, | 1324 // --------------------------------------------------------------------------- |
1826 // Object.isFrozen, Object.isSealed, Object.isExtensible) | |
1827 | |
1828 function TestFix(names, handler) { | |
1829 var target = {p: 77} | |
1830 var assertFixing = function(o, s, f, e) { | |
1831 assertEquals(s, Object.isSealed(o)) | |
1832 assertEquals(f, Object.isFrozen(o)) | |
1833 assertEquals(e, Object.isExtensible(o)) | |
1834 } | |
1835 | |
1836 var p1 = new Proxy(target, handler) | |
1837 assertFixing(p1, false, false, true) | |
1838 Object.seal(p1) | |
1839 assertFixing(p1, true, names.length === 0, false) | |
1840 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p1).sort()) | |
1841 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), | |
1842 Object.keys(p1).sort()) | |
1843 assertEquals(target, Object.getPrototypeOf(p1)) | |
1844 assertEquals(77, p1.p) | |
1845 for (var n in p1) { | |
1846 var desc = Object.getOwnPropertyDescriptor(p1, n) | |
1847 if (desc !== undefined) assertFalse(desc.configurable) | |
1848 } | |
1849 | |
1850 var p2 = new Proxy(target, handler) | |
1851 assertFixing(p2, false, false, true) | |
1852 Object.freeze(p2) | |
1853 assertFixing(p2, true, true, false) | |
1854 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p2).sort()) | |
1855 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), | |
1856 Object.keys(p2).sort()) | |
1857 assertEquals(target, Object.getPrototypeOf(p2)) | |
1858 assertEquals(77, p2.p) | |
1859 for (var n in p2) { | |
1860 var desc = Object.getOwnPropertyDescriptor(p2, n) | |
1861 if (desc !== undefined) assertFalse(desc.writable) | |
1862 if (desc !== undefined) assertFalse(desc.configurable) | |
1863 } | |
1864 | |
1865 var p3 = new Proxy(target, handler) | |
1866 assertFixing(p3, false, false, true) | |
1867 Object.preventExtensions(p3) | |
1868 assertFixing(p3, names.length === 0, names.length === 0, false) | |
1869 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p3).sort()) | |
1870 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), | |
1871 Object.keys(p3).sort()) | |
1872 assertEquals(target, Object.getPrototypeOf(p3)) | |
1873 assertEquals(77, p3.p) | |
1874 | |
1875 var p = new Proxy(target, handler) | |
1876 var o = Object.create(p) | |
1877 assertFixing(p, false, false, true) | |
1878 assertFixing(o, false, false, true) | |
1879 Object.freeze(o) | |
1880 assertFixing(p, false, false, true) | |
1881 assertFixing(o, true, true, false) | |
1882 } | |
1883 | |
1884 TestFix([], { | |
1885 fix: function() { return {} } | |
1886 }) | |
1887 | |
1888 TestFix(["a", "b", "c", "3", "zz"], { | |
1889 fix: function() { | |
1890 return { | |
1891 a: {value: "a", writable: true, configurable: false, enumerable: true}, | |
1892 b: {value: 33, writable: false, configurable: false, enumerable: true}, | |
1893 c: {value: 0, writable: true, configurable: true, enumerable: true}, | |
1894 '3': {value: true, writable: false, configurable: true, enumerable: true}, | |
1895 zz: {value: 0, enumerable: false} | |
1896 } | |
1897 } | |
1898 }) | |
1899 | |
1900 TestFix(["a"], { | |
1901 fix: function() { return this.fix2() }, | |
1902 fix2: function() { | |
1903 return {a: {value: 4, writable: true, configurable: true, enumerable: true}} | |
1904 } | |
1905 }) | |
1906 | |
1907 TestFix(["b"], { | |
1908 get fix() { | |
1909 return function() { | |
1910 return {b: {configurable: true, writable: true, enumerable: true}} | |
1911 } | |
1912 } | |
1913 }) | |
1914 | |
1915 | |
1916 function TestFixFunction(fix) { | |
1917 var f1 = Proxy.createFunction({ | |
1918 fix: function() { return {} } | |
1919 }, function() {}) | |
1920 fix(f1) | |
1921 assertEquals(0, f1.length) | |
1922 | |
1923 var f2 = Proxy.createFunction({ | |
1924 fix: function() { return {length: {value: 3}} } | |
1925 }, function() {}) | |
1926 fix(f2) | |
1927 assertEquals(3, f2.length) | |
1928 | |
1929 var f3 = Proxy.createFunction({ | |
1930 fix: function() { return {length: {value: "huh"}} } | |
1931 }, function() {}) | |
1932 fix(f3) | |
1933 assertEquals(0, f1.length) | |
1934 } | |
1935 | |
1936 TestFixFunction(Object.seal) | |
1937 TestFixFunction(Object.freeze) | |
1938 TestFixFunction(Object.preventExtensions) | |
1939 | |
1940 | |
1941 function TestFixThrow(handler) { | |
1942 TestWithProxies(TestFixThrow2, handler) | |
1943 } | |
1944 | |
1945 function TestFixThrow2(create, handler) { | |
1946 var p = create(handler, {}) | |
1947 assertThrows(function(){ Object.seal(p) }, "myexn") | |
1948 assertThrows(function(){ Object.freeze(p) }, "myexn") | |
1949 assertThrows(function(){ Object.preventExtensions(p) }, "myexn") | |
1950 } | |
1951 | |
1952 TestFixThrow({ | |
1953 fix: function() { throw "myexn" } | |
1954 }) | |
1955 | |
1956 TestFixThrow({ | |
1957 fix: function() { return this.fix2() }, | |
1958 fix2: function() { throw "myexn" } | |
1959 }) | |
1960 | |
1961 TestFixThrow({ | |
1962 get fix() { throw "myexn" } | |
1963 }) | |
1964 | |
1965 TestFixThrow({ | |
1966 get fix() { | |
1967 return function() { throw "myexn" } | |
1968 } | |
1969 }) | |
1970 | |
1971 | |
1972 // Freeze a proxy in the middle of operations on it. | |
1973 // TODO(rossberg): actual behaviour not specified consistently at the moment, | |
1974 // just make sure that we do not crash. | |
1975 function TestReentrantFix(f) { | |
1976 TestWithProxies(f, Object.freeze) | |
1977 TestWithProxies(f, Object.seal) | |
1978 TestWithProxies(f, Object.preventExtensions) | |
1979 } | |
1980 | |
1981 TestReentrantFix(function(create, freeze) { | |
1982 var handler = { | |
1983 get get() { freeze(p); return undefined }, | |
1984 fix: function() { return {} } | |
1985 } | |
1986 var p = create(handler) | |
1987 // Freeze while getting get trap. | |
1988 try { p.x } catch (e) { assertInstanceof(e, Error) } | |
1989 }) | |
1990 | |
1991 TestReentrantFix(function(create, freeze) { | |
1992 var handler = { | |
1993 get: function() { freeze(p); return 3 }, | |
1994 fix: function() { return {} } | |
1995 } | |
1996 var p = create(handler) | |
1997 // Freeze while executing get trap. | |
1998 try { p.x } catch (e) { assertInstanceof(e, Error) } | |
1999 }) | |
2000 | |
2001 TestReentrantFix(function(create, freeze) { | |
2002 var handler = { | |
2003 getPropertyDescriptor: function() { freeze(p); return undefined }, | |
2004 fix: function() { return {} } | |
2005 } | |
2006 var p = create(handler) | |
2007 // Freeze while executing default get trap. | |
2008 try { p.x } catch (e) { assertInstanceof(e, Error) } | |
2009 }) | |
2010 | |
2011 TestReentrantFix(function(create, freeze) { | |
2012 var handler = { | |
2013 getPropertyDescriptor: function() { freeze(p); return {get: function(){}} }, | |
2014 fix: function() { return {} } | |
2015 } | |
2016 var p = create(handler) | |
2017 var o = Object.create(p) | |
2018 // Freeze while getting a property from prototype. | |
2019 try { o.x } catch (e) { assertInstanceof(e, Error) } | |
2020 }) | |
2021 | |
2022 TestReentrantFix(function(create, freeze) { | |
2023 var handler = { | |
2024 get set() { freeze(p); return undefined }, | |
2025 fix: function() { return {} } | |
2026 } | |
2027 var p = create(handler) | |
2028 // Freeze while getting set trap. | |
2029 try { p.x = 4 } catch (e) { assertInstanceof(e, Error) } | |
2030 }) | |
2031 | |
2032 TestReentrantFix(function(create, freeze) { | |
2033 var handler = { | |
2034 set: function() { freeze(p); return true }, | |
2035 fix: function() { return {} } | |
2036 } | |
2037 var p = create(handler) | |
2038 // Freeze while executing set trap. | |
2039 try { p.x = 4 } catch (e) { assertInstanceof(e, Error) } | |
2040 }) | |
2041 | |
2042 TestReentrantFix(function(create, freeze) { | |
2043 var handler = { | |
2044 getOwnPropertyDescriptor: function() { freeze(p); return undefined }, | |
2045 fix: function() { return {} } | |
2046 } | |
2047 var p = create(handler) | |
2048 // Freeze while executing default set trap. | |
2049 try { p.x } catch (e) { assertInstanceof(e, Error) } | |
2050 }) | |
2051 | |
2052 TestReentrantFix(function(create, freeze) { | |
2053 var handler = { | |
2054 getPropertyDescriptor: function() { freeze(p); return {set: function(){}} }, | |
2055 fix: function() { return {} } | |
2056 } | |
2057 var p = create(handler) | |
2058 var o = Object.create(p) | |
2059 // Freeze while setting a property in prototype, dropping the property! | |
2060 try { o.x = 4 } catch (e) { assertInstanceof(e, Error) } | |
2061 }) | |
2062 | |
2063 TestReentrantFix(function(create, freeze) { | |
2064 var handler = { | |
2065 getPropertyDescriptor: function() { freeze(p); return {set: function(){}} }, | |
2066 fix: function() { return {x: {get: function(){}}} } | |
2067 } | |
2068 var p = create(handler) | |
2069 var o = Object.create(p) | |
2070 // Freeze while setting a property in prototype, making it read-only! | |
2071 try { o.x = 4 } catch (e) { assertInstanceof(e, Error) } | |
2072 }) | |
2073 | |
2074 TestReentrantFix(function(create, freeze) { | |
2075 var handler = { | |
2076 get fix() { freeze(p); return function(){} } | |
2077 } | |
2078 var p = create(handler) | |
2079 // Freeze while getting fix trap. | |
2080 try { Object.freeze(p) } catch (e) { assertInstanceof(e, Error) } | |
2081 p = create(handler) | |
2082 try { Object.seal(p) } catch (e) { assertInstanceof(e, Error) } | |
2083 p = create(handler) | |
2084 try { Object.preventExtensions(p) } catch (e) { assertInstanceof(e, Error) } | |
2085 }) | |
2086 | |
2087 TestReentrantFix(function(create, freeze) { | |
2088 var handler = { | |
2089 fix: function() { freeze(p); return {} } | |
2090 } | |
2091 var p = create(handler) | |
2092 // Freeze while executing fix trap. | |
2093 try { Object.freeze(p) } catch (e) { assertInstanceof(e, Error) } | |
2094 p = create(handler) | |
2095 try { Object.seal(p) } catch (e) { assertInstanceof(e, Error) } | |
2096 p = create(handler) | |
2097 try { Object.preventExtensions(p) } catch (e) { assertInstanceof(e, Error) } | |
2098 }) | |
2099 | |
2100 | |
2101 | |
2102 // String conversion (Object.prototype.toString, | 1325 // String conversion (Object.prototype.toString, |
2103 // Object.prototype.toLocaleString, | 1326 // Object.prototype.toLocaleString, |
2104 // Function.prototype.toString) | 1327 // Function.prototype.toString) |
2105 | 1328 |
1329 //TODO(cbruni): enable once fixed. | |
1330 /* | |
2106 var key | 1331 var key |
2107 | 1332 |
2108 function TestToString(handler) { | 1333 function TestToString(handler) { |
2109 var p = Proxy.create(handler) | 1334 var p = new Proxy({}, handler) |
2110 key = "" | 1335 key = "" |
2111 assertEquals("[object Object]", Object.prototype.toString.call(p)) | 1336 assertEquals("[object Object]", Object.prototype.toString.call(p)) |
2112 assertEquals("", key) | 1337 assertEquals("", key) |
2113 assertEquals("my_proxy", Object.prototype.toLocaleString.call(p)) | 1338 assertEquals("my_proxy", Object.prototype.toLocaleString.call(p)) |
2114 assertEquals("toString", key) | 1339 assertEquals("toString", key) |
2115 | 1340 |
2116 var f = Proxy.createFunction(handler, function() {}) | 1341 var f = new Proxy(handler, function() {}) |
2117 key = "" | 1342 key = "" |
2118 assertEquals("[object Function]", Object.prototype.toString.call(f)) | 1343 assertEquals("[object Function]", Object.prototype.toString.call(f)) |
2119 assertEquals("", key) | 1344 assertEquals("", key) |
2120 assertEquals("my_proxy", Object.prototype.toLocaleString.call(f)) | 1345 assertEquals("my_proxy", Object.prototype.toLocaleString.call(f)) |
2121 assertEquals("toString", key) | 1346 assertEquals("toString", key) |
2122 assertDoesNotThrow(function(){ Function.prototype.toString.call(f) }) | 1347 assertDoesNotThrow(function(){ Function.prototype.toString.call(f) }) |
2123 | 1348 |
2124 var o = Object.create(p) | 1349 var o = Object.create(p) |
2125 key = "" | 1350 key = "" |
2126 assertEquals("[object Object]", Object.prototype.toString.call(o)) | 1351 assertEquals("[object Object]", Object.prototype.toString.call(o)) |
2127 assertEquals("", key) | 1352 assertEquals("", key) |
2128 assertEquals("my_proxy", Object.prototype.toLocaleString.call(o)) | 1353 assertEquals("my_proxy", Object.prototype.toLocaleString.call(o)) |
2129 assertEquals("toString", key) | 1354 assertEquals("toString", key) |
2130 } | 1355 } |
2131 | 1356 |
2132 TestToString({ | 1357 TestToString({ |
2133 get: function(r, k) { key = k; return function() { return "my_proxy" } } | 1358 get: function(r, k) { key = k; return function() { return "my_proxy" } } |
2134 }) | 1359 }) |
2135 | 1360 |
2136 TestToString({ | 1361 TestToString({ |
2137 get: function(r, k) { return this.get2(r, k) }, | 1362 get: function(r, k) { return this.get2(r, k) }, |
2138 get2: function(r, k) { key = k; return function() { return "my_proxy" } } | 1363 get2: function(r, k) { key = k; return function() { return "my_proxy" } } |
2139 }) | 1364 }) |
2140 | 1365 |
2141 TestToString(Proxy.create({ | 1366 TestToString(new Proxy({}, { |
2142 get: function(pr, pk) { | 1367 get: function(pr, pk) { |
2143 return function(r, k) { key = k; return function() { return "my_proxy" } } | 1368 return function(r, k) { key = k; return function() { return "my_proxy" } } |
2144 } | 1369 } |
2145 })) | 1370 })) |
2146 | 1371 |
2147 | 1372 |
2148 function TestToStringThrow(handler) { | 1373 function TestToStringThrow(handler) { |
2149 var p = Proxy.create(handler) | 1374 var p = new Proxy({}, handler) |
2150 assertEquals("[object Object]", Object.prototype.toString.call(p)) | 1375 assertEquals("[object Object]", Object.prototype.toString.call(p)) |
2151 assertThrows(function(){ Object.prototype.toLocaleString.call(p) }, "myexn") | 1376 assertThrows(function(){ Object.prototype.toLocaleString.call(p) }, "myexn") |
2152 | 1377 |
2153 var f = Proxy.createFunction(handler, function() {}) | 1378 var f = new Proxy(function(){}, handler) |
2154 assertEquals("[object Function]", Object.prototype.toString.call(f)) | 1379 assertEquals("[object Function]", Object.prototype.toString.call(f)) |
2155 assertThrows(function(){ Object.prototype.toLocaleString.call(f) }, "myexn") | 1380 assertThrows(function(){ Object.prototype.toLocaleString.call(f) }, "myexn") |
2156 | 1381 |
2157 var o = Object.create(p) | 1382 var o = Object.create(p) |
2158 assertEquals("[object Object]", Object.prototype.toString.call(o)) | 1383 assertEquals("[object Object]", Object.prototype.toString.call(o)) |
2159 assertThrows(function(){ Object.prototype.toLocaleString.call(o) }, "myexn") | 1384 assertThrows(function(){ Object.prototype.toLocaleString.call(o) }, "myexn") |
2160 } | 1385 } |
2161 | 1386 |
2162 TestToStringThrow({ | 1387 TestToStringThrow({ |
2163 get: function(r, k) { throw "myexn" } | 1388 get: function(r, k) { throw "myexn" } |
2164 }) | 1389 }) |
2165 | 1390 |
2166 TestToStringThrow({ | 1391 TestToStringThrow({ |
2167 get: function(r, k) { return function() { throw "myexn" } } | 1392 get: function(r, k) { return function() { throw "myexn" } } |
2168 }) | 1393 }) |
2169 | 1394 |
2170 TestToStringThrow({ | 1395 TestToStringThrow({ |
2171 get: function(r, k) { return this.get2(r, k) }, | 1396 get: function(r, k) { return this.get2(r, k) }, |
2172 get2: function(r, k) { throw "myexn" } | 1397 get2: function(r, k) { throw "myexn" } |
2173 }) | 1398 }) |
2174 | 1399 |
2175 TestToStringThrow(Proxy.create({ | 1400 TestToStringThrow(new Proxy({}, { |
2176 get: function(pr, pk) { throw "myexn" } | 1401 get: function(pr, pk) { throw "myexn" } |
2177 })) | 1402 })) |
2178 | 1403 |
2179 TestToStringThrow(Proxy.create({ | 1404 TestToStringThrow(new Proxy({}, { |
2180 get: function(pr, pk) { | 1405 get: function(pr, pk) { |
2181 return function(r, k) { throw "myexn" } | 1406 return function(r, k) { throw "myexn" } |
2182 } | 1407 } |
2183 })) | 1408 })) |
1409 */ | |
2184 | 1410 |
2185 | 1411 |
2186 | 1412 // --------------------------------------------------------------------------- |
2187 // Value conversion (Object.prototype.toValue) | 1413 // Value conversion (Object.prototype.toValue) |
2188 | 1414 |
2189 function TestValueOf(handler) { | 1415 function TestValueOf(handler) { |
2190 TestWithProxies(TestValueOf2, handler) | 1416 TestWithProxies(TestValueOf2, handler) |
2191 } | 1417 } |
2192 | 1418 |
2193 function TestValueOf2(create, handler) { | 1419 function TestValueOf2(create, handler) { |
2194 var p = create(handler) | 1420 var p = create(handler) |
2195 assertSame(p, Object.prototype.valueOf.call(p)) | 1421 assertSame(p, Object.prototype.valueOf.call(p)) |
2196 } | 1422 } |
2197 | 1423 |
2198 TestValueOf({}) | 1424 TestValueOf({}) |
2199 | 1425 |
2200 | 1426 |
2201 | 1427 |
1428 // --------------------------------------------------------------------------- | |
2202 // Enumerability (Object.prototype.propertyIsEnumerable) | 1429 // Enumerability (Object.prototype.propertyIsEnumerable) |
2203 | 1430 |
2204 var key | 1431 var key |
2205 | 1432 |
2206 function TestIsEnumerable(handler) { | 1433 function TestIsEnumerable(handler) { |
2207 TestWithProxies(TestIsEnumerable2, handler) | 1434 TestWithProxies(TestIsEnumerable2, handler) |
2208 } | 1435 } |
2209 | 1436 |
2210 function TestIsEnumerable2(create, handler) { | 1437 function TestIsEnumerable2(create, handler) { |
2211 var p = create(handler) | 1438 var p = create(handler) |
2212 assertTrue(Object.prototype.propertyIsEnumerable.call(p, "a")) | 1439 assertTrue(Object.prototype.propertyIsEnumerable.call(p, "a")) |
2213 assertEquals("a", key) | 1440 assertEquals("a", key) |
2214 assertTrue(Object.prototype.propertyIsEnumerable.call(p, 2)) | 1441 assertTrue(Object.prototype.propertyIsEnumerable.call(p, 2)) |
2215 assertEquals("2", key) | 1442 assertEquals("2", key) |
2216 assertFalse(Object.prototype.propertyIsEnumerable.call(p, "z")) | 1443 assertFalse(Object.prototype.propertyIsEnumerable.call(p, "z")) |
2217 assertEquals("z", key) | 1444 assertEquals("z", key) |
2218 | 1445 |
2219 var o = Object.create(p) | 1446 var o = Object.create(p) |
2220 key = "" | 1447 key = "" |
2221 assertFalse(Object.prototype.propertyIsEnumerable.call(o, "a")) | 1448 assertFalse(Object.prototype.propertyIsEnumerable.call(o, "a")) |
2222 assertEquals("", key) // trap not invoked | 1449 assertEquals("", key) // trap not invoked |
2223 } | 1450 } |
2224 | 1451 |
2225 TestIsEnumerable({ | 1452 TestIsEnumerable({ |
2226 getOwnPropertyDescriptor: function(k) { | 1453 getOwnPropertyDescriptor(t, k) { |
2227 key = k; return {enumerable: k < "z", configurable: true} | 1454 key = k; |
1455 return {enumerable: k < "z", configurable: true} | |
2228 }, | 1456 }, |
2229 }) | 1457 }) |
2230 | 1458 |
2231 TestIsEnumerable({ | 1459 TestIsEnumerable({ |
2232 getOwnPropertyDescriptor: function(k) { | 1460 getOwnPropertyDescriptor: function(t, k) { |
2233 return this.getOwnPropertyDescriptor2(k) | 1461 return this.getOwnPropertyDescriptor2(k) |
2234 }, | 1462 }, |
2235 getOwnPropertyDescriptor2: function(k) { | 1463 getOwnPropertyDescriptor2: function(k) { |
2236 key = k; return {enumerable: k < "z", configurable: true} | 1464 key = k; |
1465 return {enumerable: k < "z", configurable: true} | |
2237 }, | 1466 }, |
2238 }) | 1467 }) |
2239 | 1468 |
2240 TestIsEnumerable({ | 1469 TestIsEnumerable({ |
2241 getOwnPropertyDescriptor: function(k) { | 1470 getOwnPropertyDescriptor: function(t, k) { |
2242 key = k; return {get enumerable() { return k < "z" }, configurable: true} | 1471 key = k; |
1472 return {get enumerable() { return k < "z" }, configurable: true} | |
2243 }, | 1473 }, |
2244 }) | 1474 }) |
2245 | 1475 |
2246 TestIsEnumerable(Proxy.create({ | 1476 TestIsEnumerable(new Proxy({}, { |
2247 get: function(pr, pk) { | 1477 get: function(pt, pk, pr) { |
2248 return function(k) { | 1478 return function(t, k) { |
2249 key = k; return {enumerable: k < "z", configurable: true} | 1479 key = k; |
1480 return {enumerable: k < "z", configurable: true} | |
2250 } | 1481 } |
2251 } | 1482 } |
2252 })) | 1483 })) |
2253 | 1484 |
2254 | 1485 |
1486 // --------------------------------------------------------------------------- | |
2255 function TestIsEnumerableThrow(handler) { | 1487 function TestIsEnumerableThrow(handler) { |
2256 TestWithProxies(TestIsEnumerableThrow2, handler) | 1488 TestWithProxies(TestIsEnumerableThrow2, handler) |
2257 } | 1489 } |
2258 | 1490 |
2259 function TestIsEnumerableThrow2(create, handler) { | 1491 function TestIsEnumerableThrow2(create, handler) { |
2260 var p = create(handler) | 1492 var p = create(handler) |
2261 assertThrows(function(){ Object.prototype.propertyIsEnumerable.call(p, "a") }, | 1493 assertThrows(function(){ Object.prototype.propertyIsEnumerable.call(p, "a") }, |
2262 "myexn") | 1494 "myexn") |
2263 assertThrows(function(){ Object.prototype.propertyIsEnumerable.call(p, 11) }, | 1495 assertThrows(function(){ Object.prototype.propertyIsEnumerable.call(p, 11) }, |
2264 "myexn") | 1496 "myexn") |
2265 } | 1497 } |
2266 | 1498 |
2267 TestIsEnumerableThrow({ | 1499 TestIsEnumerableThrow({ |
2268 getOwnPropertyDescriptor: function(k) { throw "myexn" } | 1500 getOwnPropertyDescriptor: function(k) { throw "myexn" } |
2269 }) | 1501 }) |
2270 | 1502 |
2271 TestIsEnumerableThrow({ | 1503 TestIsEnumerableThrow({ |
2272 getOwnPropertyDescriptor: function(k) { | 1504 getOwnPropertyDescriptor: function(k) { |
2273 return this.getOwnPropertyDescriptor2(k) | 1505 return this.getOwnPropertyDescriptor2(k) |
2274 }, | 1506 }, |
2275 getOwnPropertyDescriptor2: function(k) { throw "myexn" } | 1507 getOwnPropertyDescriptor2: function(k) { throw "myexn" } |
2276 }) | 1508 }) |
2277 | 1509 |
2278 TestIsEnumerableThrow({ | 1510 TestIsEnumerableThrow({ |
2279 getOwnPropertyDescriptor: function(k) { | 1511 getOwnPropertyDescriptor: function(k) { |
2280 return {get enumerable() { throw "myexn" }, configurable: true} | 1512 return {get enumerable() { throw "myexn" }, configurable: true} |
2281 }, | 1513 }, |
2282 }) | 1514 }) |
2283 | 1515 |
2284 TestIsEnumerableThrow(Proxy.create({ | 1516 TestIsEnumerableThrow(new Proxy({}, { |
2285 get: function(pr, pk) { throw "myexn" } | 1517 get: function(pr, pk) { throw "myexn" } |
2286 })) | 1518 })) |
2287 | 1519 |
2288 TestIsEnumerableThrow(Proxy.create({ | 1520 TestIsEnumerableThrow(new Proxy({}, { |
2289 get: function(pr, pk) { | 1521 get: function(pr, pk) { |
2290 return function(k) { throw "myexn" } | 1522 return function(k) { throw "myexn" } |
2291 } | 1523 } |
2292 })) | 1524 })); |
2293 | 1525 |
2294 | 1526 |
2295 | 1527 |
1528 // --------------------------------------------------------------------------- | |
2296 // Constructor functions with proxy prototypes. | 1529 // Constructor functions with proxy prototypes. |
2297 | 1530 |
2298 function TestConstructorWithProxyPrototype() { | 1531 (function TestConstructorWithProxyPrototype() { |
2299 TestWithProxies(TestConstructorWithProxyPrototype2, {}) | 1532 TestWithProxies(TestConstructorWithProxyPrototype2, {}) |
2300 } | 1533 })(); |
2301 | 1534 |
2302 function TestConstructorWithProxyPrototype2(create, handler) { | 1535 function TestConstructorWithProxyPrototype2(create, handler) { |
2303 function C() {}; | 1536 function C() {}; |
2304 C.prototype = create(handler); | 1537 C.prototype = create(handler); |
2305 | 1538 |
2306 var o = new C; | 1539 var o = new C; |
2307 assertSame(C.prototype, Object.getPrototypeOf(o)); | 1540 assertSame(C.prototype, Object.getPrototypeOf(o)); |
2308 } | 1541 }; |
2309 | 1542 |
2310 TestConstructorWithProxyPrototype(); | |
2311 | 1543 |
2312 function TestOptWithProxyPrototype() { | 1544 (function TestOptWithProxyPrototype() { |
2313 var handler = { | 1545 var handler = { |
2314 getPropertyDescriptor: function(k) { | 1546 get(t, k) { |
2315 return {value: 10, configurable: true, enumerable: true, writable: true}; | 1547 return 10; |
2316 } | 1548 } |
2317 }; | 1549 }; |
2318 | 1550 |
2319 function C() {}; | 1551 function C() {}; |
2320 C.prototype = Proxy.create(handler); | 1552 C.prototype = new Proxy({}, handler); |
2321 var o = new C(); | 1553 var o = new C(); |
2322 | 1554 |
2323 function f() { | 1555 function f() { |
2324 return o.x; | 1556 return o.x; |
2325 } | 1557 } |
2326 assertEquals(10, f()); | 1558 assertEquals(10, f()); |
2327 assertEquals(10, f()); | 1559 assertEquals(10, f()); |
2328 %OptimizeFunctionOnNextCall(f); | 1560 %OptimizeFunctionOnNextCall(f); |
2329 assertEquals(10, f()); | 1561 assertEquals(10, f()); |
2330 } | 1562 })(); |
2331 | |
2332 TestOptWithProxyPrototype(); | |
OLD | NEW |