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 7var target = { 8 target: 1 9}; 10target.__proto__ = { 11 target_proto: 2 12}; 13 14var 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 25var proxy = new Proxy(target, handler); 26 27// Object.keys() ignores symbols and non-enumerable keys. 28assertEquals(["foo", "bar"], Object.keys(proxy)); 29 30// Edge case: no properties left after filtering. 31handler.getOwnPropertyDescriptor = undefined; 32assertEquals([], Object.keys(proxy)); 33 34// Throwing shouldn't crash. 35handler.getOwnPropertyDescriptor = function() { throw new Number(1); }; 36assertThrows("Object.keys(proxy)", Number); 37 38// Fall through to target if there is no trap. 39handler.ownKeys = undefined; 40assertEquals(["target"], Object.keys(proxy)); 41assertEquals(["target"], Object.keys(target)); 42