OLD | NEW |
1 // Flags: --harmony-proxies | 1 // Flags: --harmony-proxies |
2 | 2 |
3 // Copyright 2008 the V8 project authors. All rights reserved. | 3 // Copyright 2008 the V8 project authors. All rights reserved. |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 10 matching lines...) Expand all Loading... |
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 | 30 |
| 31 // TODO(rossberg): test exception cases. |
| 32 |
31 | 33 |
32 // Getters. | 34 // Getters. |
33 | 35 |
34 function TestGet(handler) { | 36 function TestGet(handler) { |
35 var o = Proxy.create(handler) | 37 var o = Proxy.create(handler) |
36 assertEquals(42, o.a) | 38 assertEquals(42, o.a) |
37 assertEquals(42, o["b"]) | 39 assertEquals(42, o["b"]) |
38 } | 40 } |
39 | 41 |
40 TestGet({ | 42 TestGet({ |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 // Type. | 397 // Type. |
396 | 398 |
397 assertEquals("object", typeof Proxy.create({})) | 399 assertEquals("object", typeof Proxy.create({})) |
398 assertTrue(typeof Proxy.create({}) == "object") | 400 assertTrue(typeof Proxy.create({}) == "object") |
399 assertTrue("object" == typeof Proxy.create({})) | 401 assertTrue("object" == typeof Proxy.create({})) |
400 | 402 |
401 // No function proxies yet. | 403 // No function proxies yet. |
402 | 404 |
403 | 405 |
404 | 406 |
| 407 // Element (in). |
| 408 |
| 409 var key |
| 410 function TestIn(handler) { |
| 411 var o = Proxy.create(handler) |
| 412 assertTrue("a" in o) |
| 413 assertEquals("a", key) |
| 414 assertTrue(99 in o) |
| 415 assertEquals("99", key) |
| 416 assertFalse("z" in o) |
| 417 assertEquals("z", key) |
| 418 |
| 419 if ("b" in o) { |
| 420 } else { |
| 421 assertTrue(false) |
| 422 } |
| 423 assertEquals("b", key) |
| 424 |
| 425 if ("zz" in o) { |
| 426 assertTrue(false) |
| 427 } |
| 428 assertEquals("zz", key) |
| 429 |
| 430 if (!("c" in o)) { |
| 431 assertTrue(false) |
| 432 } |
| 433 assertEquals("c", key) |
| 434 |
| 435 if (!("zzz" in o)) { |
| 436 } else { |
| 437 assertTrue(false) |
| 438 } |
| 439 assertEquals("zzz", key) |
| 440 } |
| 441 |
| 442 TestIn({ |
| 443 has: function(k) { key = k; return k < "z" } |
| 444 }) |
| 445 TestIn({ |
| 446 has: function(k) { return this.has2(k) }, |
| 447 has2: function(k) { key = k; return k < "z" } |
| 448 }) |
| 449 TestIn({ |
| 450 getPropertyDescriptor: function(k) { |
| 451 key = k; return k < "z" ? {value: 42} : void 0 |
| 452 } |
| 453 }) |
| 454 TestIn({ |
| 455 getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, |
| 456 getPropertyDescriptor2: function(k) { |
| 457 key = k; return k < "z" ? {value: 42} : void 0 |
| 458 } |
| 459 }) |
| 460 TestIn({ |
| 461 getPropertyDescriptor: function(k) { |
| 462 key = k; return k < "z" ? {get value() { return 42 }} : void 0 |
| 463 } |
| 464 }) |
| 465 TestIn({ |
| 466 get: undefined, |
| 467 getPropertyDescriptor: function(k) { |
| 468 key = k; return k < "z" ? {value: 42} : void 0 |
| 469 } |
| 470 }) |
| 471 |
| 472 TestIn(Proxy.create({ |
| 473 get: function(pr, pk) { |
| 474 return function(k) { key = k; return k < "z" } |
| 475 } |
| 476 })) |
| 477 |
| 478 |
| 479 |
405 // Instanceof (instanceof). | 480 // Instanceof (instanceof). |
406 | 481 |
407 function TestInstanceof() { | 482 function TestInstanceof() { |
408 var o = {} | 483 var o = {} |
409 var p1 = Proxy.create({}) | 484 var p1 = Proxy.create({}) |
410 var p2 = Proxy.create({}, o) | 485 var p2 = Proxy.create({}, o) |
411 var p3 = Proxy.create({}, p2) | 486 var p3 = Proxy.create({}, p2) |
412 | 487 |
413 var f = function() {} | 488 var f = function() {} |
414 f.prototype = o | 489 f.prototype = o |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 return {a: {value: 4, writable: true, configurable: true, enumerable: true}} | 678 return {a: {value: 4, writable: true, configurable: true, enumerable: true}} |
604 } | 679 } |
605 }) | 680 }) |
606 TestFix(["b"], { | 681 TestFix(["b"], { |
607 get fix() { | 682 get fix() { |
608 return function() { | 683 return function() { |
609 return {b: {configurable: true, writable: true, enumerable: true}} | 684 return {b: {configurable: true, writable: true, enumerable: true}} |
610 } | 685 } |
611 } | 686 } |
612 }) | 687 }) |
OLD | NEW |