| 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 14 matching lines...) Expand all Loading... |
| 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 // Helper. | 31 // Helper. |
| 32 | 32 |
| 33 function TestWithProxies(test, x, y, z) { | 33 function TestWithProxies(test, x, y, z) { |
| 34 test(function(h){ return new Proxy({}, h) }, x, y, z) | 34 test(function(h){ return new Proxy({}, h) }, x, y, z) |
| 35 // TODO(cbruni): enable once we have [[Call]] working. | 35 test(function(h) { |
| 36 // test(function(h) { | 36 return new Proxy(function() {}, h) |
| 37 // return Proxy.createFunction(h, function() {}) | 37 }, x, y, z) |
| 38 // }, x, y, z) | |
| 39 } | 38 } |
| 40 | 39 |
| 41 | 40 |
| 42 // Iterate over a proxy. | 41 // Iterate over a proxy. |
| 43 | 42 |
| 44 Array.prototype.values = function() { return this[Symbol.iterator]() } | 43 Array.prototype.values = function() { return this[Symbol.iterator]() } |
| 45 | 44 |
| 46 function TestForIn(properties, handler) { | 45 function TestForIn(properties, handler) { |
| 47 TestWithProxies(TestForIn2, properties, handler) | 46 TestWithProxies(TestForIn2, properties, handler) |
| 48 } | 47 } |
| 49 | 48 |
| 50 function TestForIn2(create, properties, handler) { | 49 function TestForIn2(create, properties, handler) { |
| 51 var p = create(handler) | 50 var p = create(handler) |
| 52 var found = [] | 51 var found = [] |
| 53 for (var x in p) found.push(x) | 52 for (var x in p) found.push(x) |
| 54 assertArrayEquals(properties, found) | 53 assertArrayEquals(properties, found) |
| 55 } | 54 } |
| 56 | 55 |
| 57 TestForIn(["0", "a"], { | 56 TestForIn(["0", "a"], { |
| 58 enumerate: function() { return ["0", "a"].values() } | 57 enumerate() { return ["0", "a"].values() }, |
| 58 has(target, property) { return true } |
| 59 }) | 59 }) |
| 60 | 60 |
| 61 TestForIn(["null", "a"], { | 61 TestForIn(["null", "a"], { |
| 62 enumerate: function() { return this.enumerate2() }, | 62 enumerate() { return this.enumerate2() }, |
| 63 enumerate2: function() { return ["null", "a"].values() } | 63 enumerate2() { return ["null", "a"].values() }, |
| 64 has(target, property) { return true } |
| 64 }) | 65 }) |
| 65 | 66 |
| 66 TestForIn(["b", "a", "0", "c"], new Proxy({}, { | 67 TestForIn(["b", "a", "0", "c"], new Proxy({}, { |
| 67 get: function(pr, pk) { | 68 get: function(pr, pk) { |
| 68 return function() { return ["b", "a", "0", "c"].values() } | 69 return function() { return ["b", "a", "0", "c"].values() } |
| 69 } | 70 } |
| 70 })) | 71 })) |
| 71 | 72 |
| 72 | 73 |
| 73 | 74 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 o.__proto__ = p; | 140 o.__proto__ = p; |
| 140 var keys = []; | 141 var keys = []; |
| 141 for (var k in o) { keys.push(k); }; | 142 for (var k in o) { keys.push(k); }; |
| 142 assertEquals(["0"], keys); | 143 assertEquals(["0"], keys); |
| 143 })(); | 144 })(); |
| 144 | 145 |
| 145 (function () { | 146 (function () { |
| 146 var p = new Proxy({}, {ownKeys: function() { return ["1", Symbol(), "2"] }}); | 147 var p = new Proxy({}, {ownKeys: function() { return ["1", Symbol(), "2"] }}); |
| 147 assertEquals(["1","2"], Object.getOwnPropertyNames(p)); | 148 assertEquals(["1","2"], Object.getOwnPropertyNames(p)); |
| 148 })(); | 149 })(); |
| OLD | NEW |