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 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 get getOwnPropertyDescriptor() { | 522 get getOwnPropertyDescriptor() { |
523 return function(k) { return {enumerable: k >= "44"} } | 523 return function(k) { return {enumerable: k >= "44"} } |
524 } | 524 } |
525 }) | 525 }) |
526 TestKeys([], { | 526 TestKeys([], { |
527 get getOwnPropertyNames() { | 527 get getOwnPropertyNames() { |
528 return function() { return ["a", "b", "c"] } | 528 return function() { return ["a", "b", "c"] } |
529 }, | 529 }, |
530 getOwnPropertyDescriptor: function(k) { return {} } | 530 getOwnPropertyDescriptor: function(k) { return {} } |
531 }) | 531 }) |
| 532 |
| 533 |
| 534 |
| 535 // Fixing (Object.freeze, Object.seal, Object.preventExtensions, |
| 536 // Object.isFrozen, Object.isSealed, Object.isExtensible) |
| 537 |
| 538 function TestFix(names, handler) { |
| 539 var proto = {p: 77} |
| 540 var assertFixing = function(o, s, f, e) { |
| 541 assertEquals(s, Object.isSealed(o)) |
| 542 assertEquals(f, Object.isFrozen(o)) |
| 543 assertEquals(e, Object.isExtensible(o)) |
| 544 } |
| 545 |
| 546 var o1 = Proxy.create(handler, proto) |
| 547 assertFixing(o1, false, false, true) |
| 548 Object.seal(o1) |
| 549 assertFixing(o1, true, names.length === 0, false) |
| 550 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(o1).sort()) |
| 551 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), |
| 552 Object.keys(o1).sort()) |
| 553 assertEquals(proto, Object.getPrototypeOf(o1)) |
| 554 assertEquals(77, o1.p) |
| 555 for (var n in o1) { |
| 556 var desc = Object.getOwnPropertyDescriptor(o1, n) |
| 557 if (desc !== undefined) assertFalse(desc.configurable) |
| 558 } |
| 559 |
| 560 var o2 = Proxy.create(handler, proto) |
| 561 assertFixing(o2, false, false, true) |
| 562 Object.freeze(o2) |
| 563 assertFixing(o2, true, true, false) |
| 564 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(o2).sort()) |
| 565 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), |
| 566 Object.keys(o2).sort()) |
| 567 assertEquals(proto, Object.getPrototypeOf(o2)) |
| 568 assertEquals(77, o2.p) |
| 569 for (var n in o2) { |
| 570 var desc = Object.getOwnPropertyDescriptor(o2, n) |
| 571 if (desc !== undefined) assertFalse(desc.writable) |
| 572 if (desc !== undefined) assertFalse(desc.configurable) |
| 573 } |
| 574 |
| 575 var o3 = Proxy.create(handler, proto) |
| 576 assertFixing(o3, false, false, true) |
| 577 Object.preventExtensions(o3) |
| 578 assertFixing(o3, names.length === 0, names.length === 0, false) |
| 579 assertArrayEquals(names.sort(), Object.getOwnPropertyNames(o3).sort()) |
| 580 assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(), |
| 581 Object.keys(o3).sort()) |
| 582 assertEquals(proto, Object.getPrototypeOf(o3)) |
| 583 assertEquals(77, o3.p) |
| 584 } |
| 585 |
| 586 TestFix([], { |
| 587 fix: function() { return {} } |
| 588 }) |
| 589 TestFix(["a", "b", "c", "d", "zz"], { |
| 590 fix: function() { |
| 591 return { |
| 592 a: {value: "a", writable: true, configurable: false, enumerable: true}, |
| 593 b: {value: 33, writable: false, configurable: false, enumerable: true}, |
| 594 c: {value: 0, writable: true, configurable: true, enumerable: true}, |
| 595 d: {value: true, writable: false, configurable: true, enumerable: true}, |
| 596 zz: {value: 0, enumerable: false} |
| 597 } |
| 598 } |
| 599 }) |
| 600 TestFix(["a"], { |
| 601 fix: function() { return this.fix2() }, |
| 602 fix2: function() { |
| 603 return {a: {value: 4, writable: true, configurable: true, enumerable: true}} |
| 604 } |
| 605 }) |
| 606 TestFix(["b"], { |
| 607 get fix() { |
| 608 return function() { |
| 609 return {b: {configurable: true, writable: true, enumerable: true}} |
| 610 } |
| 611 } |
| 612 }) |
OLD | NEW |