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 10 matching lines...) Expand all Loading... |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --harmony-proxies | 28 // Flags: --harmony-proxies |
29 | 29 |
30 | 30 |
31 // TODO(rossberg): for-in not implemented on proxies. | |
32 | |
33 | |
34 // Helper. | 31 // Helper. |
35 | 32 |
36 function TestWithProxies(test, x, y, z) { | 33 function TestWithProxies(test, x, y, z) { |
37 test(Proxy.create, x, y, z) | 34 test(Proxy.create, x, y, z) |
38 test(function(h) {return Proxy.createFunction(h, function() {})}, x, y, z) | 35 test(function(h) {return Proxy.createFunction(h, function() {})}, x, y, z) |
39 } | 36 } |
40 | 37 |
41 | 38 |
42 | 39 |
43 // Getting property descriptors (Object.getOwnPropertyDescriptor). | 40 // Getting property descriptors (Object.getOwnPropertyDescriptor). |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 | 709 |
713 assertEquals(p, Object.defineProperty(p, "e", {get: function(){ return 5 }})) | 710 assertEquals(p, Object.defineProperty(p, "e", {get: function(){ return 5 }})) |
714 assertEquals("e", key) | 711 assertEquals("e", key) |
715 assertEquals(1, Object.getOwnPropertyNames(desc).length) | 712 assertEquals(1, Object.getOwnPropertyNames(desc).length) |
716 assertEquals(5, desc.get()) | 713 assertEquals(5, desc.get()) |
717 | 714 |
718 assertEquals(p, Object.defineProperty(p, "zzz", {})) | 715 assertEquals(p, Object.defineProperty(p, "zzz", {})) |
719 assertEquals("zzz", key) | 716 assertEquals("zzz", key) |
720 assertEquals(0, Object.getOwnPropertyNames(desc).length) | 717 assertEquals(0, Object.getOwnPropertyNames(desc).length) |
721 | 718 |
722 // TODO(rossberg): This test requires for-in on proxies. | 719 var d = create({ |
723 // var d = create({ | 720 get: function(r, k) { return (k === "value") ? 77 : void 0 }, |
724 // get: function(r, k) { return (k === "value") ? 77 : void 0 }, | 721 getOwnPropertyNames: function() { return ["value"] }, |
725 // getOwnPropertyNames: function() { return ["value"] } | 722 enumerate: function() { return ["value"] } |
726 // }) | 723 }) |
727 // assertEquals(1, Object.getOwnPropertyNames(d).length) | 724 assertEquals(1, Object.getOwnPropertyNames(d).length) |
728 // assertEquals(77, d.value) | 725 assertEquals(77, d.value) |
729 // assertEquals(p, Object.defineProperty(p, "p", d)) | 726 assertEquals(p, Object.defineProperty(p, "p", d)) |
730 // assertEquals("p", key) | 727 assertEquals("p", key) |
731 // assertEquals(1, Object.getOwnPropertyNames(desc).length) | 728 assertEquals(1, Object.getOwnPropertyNames(desc).length) |
732 // assertEquals(77, desc.value) | 729 assertEquals(77, desc.value) |
733 | 730 |
734 var props = { | 731 var props = { |
735 '11': {}, | 732 '11': {}, |
736 blub: {get: function() { return true }}, | 733 blub: {get: function() { return true }}, |
737 '': {get value() { return 20 }}, | 734 '': {get value() { return 20 }}, |
738 last: {value: 21, configurable: true, mine: "eyes"} | 735 last: {value: 21, configurable: true, mine: "eyes"} |
739 } | 736 } |
740 Object.defineProperty(props, "hidden", {value: "hidden", enumerable: false}) | 737 Object.defineProperty(props, "hidden", {value: "hidden", enumerable: false}) |
741 assertEquals(p, Object.defineProperties(p, props)) | 738 assertEquals(p, Object.defineProperties(p, props)) |
742 assertEquals("last", key) | 739 assertEquals("last", key) |
(...skipping 24 matching lines...) Expand all Loading... |
767 | 764 |
768 function TestDefineThrow(handler) { | 765 function TestDefineThrow(handler) { |
769 TestWithProxies(TestDefineThrow2, handler) | 766 TestWithProxies(TestDefineThrow2, handler) |
770 } | 767 } |
771 | 768 |
772 function TestDefineThrow2(create, handler) { | 769 function TestDefineThrow2(create, handler) { |
773 var p = create(handler) | 770 var p = create(handler) |
774 assertThrows(function(){ Object.defineProperty(p, "a", {value: 44})}, "myexn") | 771 assertThrows(function(){ Object.defineProperty(p, "a", {value: 44})}, "myexn") |
775 assertThrows(function(){ Object.defineProperty(p, 0, {value: 44})}, "myexn") | 772 assertThrows(function(){ Object.defineProperty(p, 0, {value: 44})}, "myexn") |
776 | 773 |
777 // TODO(rossberg): These tests require for-in on proxies. | 774 var d1 = create({ |
778 // var d1 = create({ | 775 get: function(r, k) { throw "myexn" }, |
779 // get: function(r, k) { throw "myexn" }, | 776 getOwnPropertyNames: function() { return ["value"] } |
780 // getOwnPropertyNames: function() { return ["value"] } | 777 }) |
781 // }) | 778 assertThrows(function(){ Object.defineProperty(p, "p", d1) }, "myexn") |
782 // assertThrows(function(){ Object.defineProperty(p, "p", d1) }, "myexn") | 779 var d2 = create({ |
783 // var d2 = create({ | 780 get: function(r, k) { return 77 }, |
784 // get: function(r, k) { return 77 }, | 781 getOwnPropertyNames: function() { throw "myexn" } |
785 // getOwnPropertyNames: function() { throw "myexn" } | 782 }) |
786 // }) | 783 assertThrows(function(){ Object.defineProperty(p, "p", d2) }, "myexn") |
787 // assertThrows(function(){ Object.defineProperty(p, "p", d2) }, "myexn") | |
788 | 784 |
789 var props = {bla: {get value() { throw "otherexn" }}} | 785 var props = {bla: {get value() { throw "otherexn" }}} |
790 assertThrows(function(){ Object.defineProperties(p, props) }, "otherexn") | 786 assertThrows(function(){ Object.defineProperties(p, props) }, "otherexn") |
791 } | 787 } |
792 | 788 |
793 TestDefineThrow({ | 789 TestDefineThrow({ |
794 defineProperty: function(k, d) { throw "myexn" } | 790 defineProperty: function(k, d) { throw "myexn" } |
795 }) | 791 }) |
796 | 792 |
797 TestDefineThrow({ | 793 TestDefineThrow({ |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1599 }) | 1595 }) |
1600 | 1596 |
1601 TestKeys(["[object Object]"], { | 1597 TestKeys(["[object Object]"], { |
1602 get keys() { | 1598 get keys() { |
1603 return function() { return [{}] } | 1599 return function() { return [{}] } |
1604 } | 1600 } |
1605 }) | 1601 }) |
1606 | 1602 |
1607 TestKeys(["a", "0"], { | 1603 TestKeys(["a", "0"], { |
1608 getOwnPropertyNames: function() { return ["a", 23, "zz", "", 0] }, | 1604 getOwnPropertyNames: function() { return ["a", 23, "zz", "", 0] }, |
1609 getOwnPropertyDescriptor: function(k) { return {enumerable: k.length == 1} } | 1605 getOwnPropertyDescriptor: function(k) { |
| 1606 return k == "" ? undefined : {enumerable: k.length == 1} |
| 1607 } |
1610 }) | 1608 }) |
1611 | 1609 |
1612 TestKeys(["23", "zz", ""], { | 1610 TestKeys(["23", "zz", ""], { |
1613 getOwnPropertyNames: function() { return this.getOwnPropertyNames2() }, | 1611 getOwnPropertyNames: function() { return this.getOwnPropertyNames2() }, |
1614 getOwnPropertyNames2: function() { return ["a", 23, "zz", "", 0] }, | 1612 getOwnPropertyNames2: function() { return ["a", 23, "zz", "", 0] }, |
1615 getOwnPropertyDescriptor: function(k) { | 1613 getOwnPropertyDescriptor: function(k) { |
1616 return this.getOwnPropertyDescriptor2(k) | 1614 return this.getOwnPropertyDescriptor2(k) |
1617 }, | 1615 }, |
1618 getOwnPropertyDescriptor2: function(k) { return {enumerable: k.length != 1} } | 1616 getOwnPropertyDescriptor2: function(k) { return {enumerable: k.length != 1} } |
1619 }) | 1617 }) |
1620 | 1618 |
1621 TestKeys(["a", "b", "c", "5"], { | 1619 TestKeys(["a", "b", "c", "5"], { |
1622 get getOwnPropertyNames() { | 1620 get getOwnPropertyNames() { |
1623 return function() { return ["0", 4, "a", "b", "c", 5] } | 1621 return function() { return ["0", 4, "a", "b", "c", 5, "ety"] } |
1624 }, | 1622 }, |
1625 get getOwnPropertyDescriptor() { | 1623 get getOwnPropertyDescriptor() { |
1626 return function(k) { return {enumerable: k >= "44"} } | 1624 return function(k) { |
| 1625 return k == "ety" ? undefined : {enumerable: k >= "44"} |
| 1626 } |
1627 } | 1627 } |
1628 }) | 1628 }) |
1629 | 1629 |
1630 TestKeys([], { | 1630 TestKeys([], { |
1631 get getOwnPropertyNames() { | 1631 get getOwnPropertyNames() { |
1632 return function() { return ["a", "b", "c"] } | 1632 return function() { return ["a", "b", "c"] } |
1633 }, | 1633 }, |
1634 getOwnPropertyDescriptor: function(k) { return {} } | 1634 getOwnPropertyDescriptor: function(k) { return {} } |
1635 }) | 1635 }) |
1636 | 1636 |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2157 | 2157 |
2158 TestIsEnumerableThrow(Proxy.create({ | 2158 TestIsEnumerableThrow(Proxy.create({ |
2159 get: function(pr, pk) { throw "myexn" } | 2159 get: function(pr, pk) { throw "myexn" } |
2160 })) | 2160 })) |
2161 | 2161 |
2162 TestIsEnumerableThrow(Proxy.create({ | 2162 TestIsEnumerableThrow(Proxy.create({ |
2163 get: function(pr, pk) { | 2163 get: function(pr, pk) { |
2164 return function(k) { throw "myexn" } | 2164 return function(k) { throw "myexn" } |
2165 } | 2165 } |
2166 })) | 2166 })) |
OLD | NEW |