OLD | NEW |
| (Empty) |
1 // Copyright 2015 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Flags: --harmony-proxies | |
6 | |
7 var target = { | |
8 target: 1 | |
9 }; | |
10 target.__proto__ = { | |
11 target_proto: 2 | |
12 }; | |
13 | |
14 var handler = { | |
15 ownKeys: function(target) { | |
16 return ["foo", "bar", Symbol("baz"), "non-enum", "not-found"]; | |
17 }, | |
18 getOwnPropertyDescriptor: function(target, name) { | |
19 if (name == "non-enum") return {configurable: true}; | |
20 if (name == "not-found") return undefined; | |
21 return {enumerable: true, configurable: true}; | |
22 } | |
23 } | |
24 | |
25 var proxy = new Proxy(target, handler); | |
26 | |
27 // Object.keys() ignores symbols and non-enumerable keys. | |
28 assertEquals(["foo", "bar"], Object.keys(proxy)); | |
29 | |
30 // Edge case: no properties left after filtering. | |
31 handler.getOwnPropertyDescriptor = undefined; | |
32 assertEquals([], Object.keys(proxy)); | |
33 | |
34 // Throwing shouldn't crash. | |
35 handler.getOwnPropertyDescriptor = function() { throw new Number(1); }; | |
36 assertThrows("Object.keys(proxy)", Number); | |
37 | |
38 // Fall through to target if there is no trap. | |
39 handler.ownKeys = undefined; | |
40 assertEquals(["target"], Object.keys(proxy)); | |
41 assertEquals(["target"], Object.keys(target)); | |
OLD | NEW |