v8/test/mjsunit/es6/proxies-keys.js
adamk 249bf75e0c Remove runtime flags for Proxy and Reflect
Both of them shipped in Chrome 49 without incident.

Also move relevant tests from harmony/ to es6/.

Review URL: https://codereview.chromium.org/1815773002

Cr-Commit-Position: refs/heads/master@{#34964}
2016-03-21 19:40:02 +00:00

40 lines
1.1 KiB
JavaScript

// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var target = {
target: 1
};
target.__proto__ = {
target_proto: 2
};
var handler = {
ownKeys: function(target) {
return ["foo", "bar", Symbol("baz"), "non-enum", "not-found"];
},
getOwnPropertyDescriptor: function(target, name) {
if (name == "non-enum") return {configurable: true};
if (name == "not-found") return undefined;
return {enumerable: true, configurable: true};
}
}
var proxy = new Proxy(target, handler);
// Object.keys() ignores symbols and non-enumerable keys.
assertEquals(["foo", "bar"], Object.keys(proxy));
// Edge case: no properties left after filtering.
handler.getOwnPropertyDescriptor = undefined;
assertEquals([], Object.keys(proxy));
// Throwing shouldn't crash.
handler.getOwnPropertyDescriptor = function() { throw new Number(1); };
assertThrows("Object.keys(proxy)", Number);
// Fall through to target if there is no trap.
handler.ownKeys = undefined;
assertEquals(["target"], Object.keys(proxy));
assertEquals(["target"], Object.keys(target));