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 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 var p = create(handler) | 964 var p = create(handler) |
965 assertTrue(Object.prototype.hasOwnProperty.call(p, "a")) | 965 assertTrue(Object.prototype.hasOwnProperty.call(p, "a")) |
966 assertEquals("a", key) | 966 assertEquals("a", key) |
967 assertTrue(Object.prototype.hasOwnProperty.call(p, 99)) | 967 assertTrue(Object.prototype.hasOwnProperty.call(p, 99)) |
968 assertEquals("99", key) | 968 assertEquals("99", key) |
969 assertFalse(Object.prototype.hasOwnProperty.call(p, "z")) | 969 assertFalse(Object.prototype.hasOwnProperty.call(p, "z")) |
970 assertEquals("z", key) | 970 assertEquals("z", key) |
971 } | 971 } |
972 | 972 |
973 TestHasOwn({ | 973 TestHasOwn({ |
974 has(t, k) { key = k; return k < "z" } | 974 getOwnPropertyDescriptor(t, k) { |
| 975 key = k; if (k < "z") return {configurable: true} |
| 976 }, |
| 977 has() { assertUnreachable() } |
975 }) | 978 }) |
976 | 979 |
977 TestHasOwn({ | 980 TestHasOwn({ |
978 has(t, k) { return this.hasOwn2(k) }, | 981 getOwnPropertyDescriptor(t, k) { return this.getOwnPropertyDescriptor2(k) }, |
979 hasOwn2(k) { key = k; return k < "z" } | 982 getOwnPropertyDescriptor2(k) { |
| 983 key = k; if (k < "z") return {configurable: true} |
| 984 } |
980 }) | 985 }) |
981 | 986 |
982 TestHasOwn(new Proxy({}, { | |
983 get(pt, pk, pr) { | |
984 return (t, k) => { key = k; return k < "z" } | |
985 } | |
986 })) | |
987 | 987 |
988 | 988 |
989 // --------------------------------------------------------------------------- | 989 // --------------------------------------------------------------------------- |
990 function TestHasOwnThrow(handler) { | 990 function TestHasOwnThrow(handler) { |
991 TestWithProxies(TestHasOwnThrow2, handler) | 991 TestWithProxies(TestHasOwnThrow2, handler) |
992 } | 992 } |
993 | 993 |
994 function TestHasOwnThrow2(create, handler) { | 994 function TestHasOwnThrow2(create, handler) { |
995 var p = create(handler) | 995 var p = create(handler) |
996 assertThrows(function(){ Object.prototype.hasOwnProperty.call(p, "a")}, | 996 assertThrows(function(){ Object.prototype.hasOwnProperty.call(p, "a")}, |
997 "myexn") | 997 "myexn") |
998 assertThrows(function(){ Object.prototype.hasOwnProperty.call(p, 99)}, | 998 assertThrows(function(){ Object.prototype.hasOwnProperty.call(p, 99)}, |
999 "myexn") | 999 "myexn") |
1000 } | 1000 } |
1001 | 1001 |
1002 TestHasOwnThrow({ | 1002 TestHasOwnThrow({ |
1003 has(t, k) { throw "myexn" } | 1003 getOwnPropertyDescriptor(t, k) { throw "myexn" } |
1004 }) | 1004 }) |
1005 | 1005 |
1006 TestHasOwnThrow({ | 1006 TestHasOwnThrow({ |
1007 has(t, k) { return this.hasOwn2(k) }, | 1007 getOwnPropertyDescriptor(t, k) { return this.getOwnPropertyDescriptor2(k) }, |
1008 hasOwn2(k) { throw "myexn" } | 1008 getOwnPropertyDescriptor2(k) { throw "myexn" } |
1009 }) | 1009 }); |
1010 | |
1011 TestHasOwnThrow(new Proxy({}, { | |
1012 get(pt, pk, pr) { throw "myexn" } | |
1013 })) | |
1014 | |
1015 TestHasOwnThrow(new Proxy({}, { | |
1016 get(pt, pk, pr) { | |
1017 return (t, k) => { throw "myexn" } | |
1018 } | |
1019 })); | |
1020 | |
1021 | 1010 |
1022 | 1011 |
1023 // --------------------------------------------------------------------------- | 1012 // --------------------------------------------------------------------------- |
1024 // Instanceof (instanceof) | 1013 // Instanceof (instanceof) |
1025 | 1014 |
1026 (function TestProxyInstanceof() { | 1015 (function TestProxyInstanceof() { |
1027 var o1 = {} | 1016 var o1 = {} |
1028 var p1 = new Proxy({}, {}) | 1017 var p1 = new Proxy({}, {}) |
1029 var p2 = new Proxy(o1, {}) | 1018 var p2 = new Proxy(o1, {}) |
1030 var p3 = new Proxy(p2, {}) | 1019 var p3 = new Proxy(p2, {}) |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1552 var o = new C(); | 1541 var o = new C(); |
1553 | 1542 |
1554 function f() { | 1543 function f() { |
1555 return o.x; | 1544 return o.x; |
1556 } | 1545 } |
1557 assertEquals(10, f()); | 1546 assertEquals(10, f()); |
1558 assertEquals(10, f()); | 1547 assertEquals(10, f()); |
1559 %OptimizeFunctionOnNextCall(f); | 1548 %OptimizeFunctionOnNextCall(f); |
1560 assertEquals(10, f()); | 1549 assertEquals(10, f()); |
1561 })(); | 1550 })(); |
OLD | NEW |