Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(524)

Side by Side Diff: test/mjsunit/es6/proxies-keys.js

Issue 2176113009: [keys] Trigger [[getOwnPropertyDescriptor]] trap for Object.keys (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: eval scoping is hard Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/runtime/runtime-forin.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var target = { 5 (function testObjectKeys() {
6 target: 1 6 var target = {
7 }; 7 target: 1
8 target.__proto__ = { 8 };
9 target_proto: 2 9 target.__proto__ = {
10 }; 10 target_proto: 2
11 };
11 12
12 var handler = { 13 var handler = {
13 ownKeys: function(target) { 14 ownKeys: function(target) {
14 return ["foo", "bar", Symbol("baz"), "non-enum", "not-found"]; 15 return ["foo", "bar", Symbol("baz"), "non-enum", "not-found"];
15 }, 16 },
16 getOwnPropertyDescriptor: function(target, name) { 17 getOwnPropertyDescriptor: function(target, name) {
17 if (name == "non-enum") return {configurable: true}; 18 if (name == "non-enum") return {configurable: true};
18 if (name == "not-found") return undefined; 19 if (name == "not-found") return undefined;
19 return {enumerable: true, configurable: true}; 20 return {enumerable: true, configurable: true};
21 }
20 } 22 }
21 }
22 23
23 var proxy = new Proxy(target, handler); 24 var proxy = new Proxy(target, handler);
24 25
25 // Object.keys() ignores symbols and non-enumerable keys. 26 // Object.keys() ignores symbols and non-enumerable keys.
26 assertEquals(["foo", "bar"], Object.keys(proxy)); 27 assertEquals(["foo", "bar"], Object.keys(proxy));
27 28
28 // Edge case: no properties left after filtering. 29 // Edge case: no properties left after filtering.
29 handler.getOwnPropertyDescriptor = undefined; 30 handler.getOwnPropertyDescriptor = undefined;
30 assertEquals([], Object.keys(proxy)); 31 assertEquals([], Object.keys(proxy));
31 32
32 // Throwing shouldn't crash. 33 // Throwing shouldn't crash.
33 handler.getOwnPropertyDescriptor = function() { throw new Number(1); }; 34 handler.getOwnPropertyDescriptor = function() { throw new Number(1); };
34 assertThrows("Object.keys(proxy)", Number); 35 assertThrows(() => Object.keys(proxy), Number);
35 36
36 // Fall through to target if there is no trap. 37 // Fall through to getOwnPropertyDescriptor if there is no trap.
37 handler.ownKeys = undefined; 38 handler.ownKeys = undefined;
38 assertEquals(["target"], Object.keys(proxy)); 39 assertThrows(() => Object.keys(proxy), Number);
39 assertEquals(["target"], Object.keys(target));
40 40
41 var proxy2 = new Proxy(proxy, {}); 41 // Fall through to target if there is no trap.
42 assertEquals(["target"], Object.keys(proxy2)); 42 handler.getOwnPropertyDescriptor = undefined;
43 assertEquals(["target"], Object.keys(proxy));
44 assertEquals(["target"], Object.keys(target));
43 45
46 var proxy2 = new Proxy(proxy, {});
47 assertEquals(["target"], Object.keys(proxy2));
48 })();
44 49
45 (function testForSymbols() { 50 (function testForSymbols() {
46 var symbol = Symbol(); 51 var symbol = Symbol();
47 var p = new Proxy({}, {ownKeys() { return ["1", symbol, "2"] }}); 52 var p = new Proxy({}, {ownKeys() { return ["1", symbol, "2"] }});
48 assertEquals(["1","2"], Object.getOwnPropertyNames(p)); 53 assertEquals(["1","2"], Object.getOwnPropertyNames(p));
49 assertEquals([symbol], Object.getOwnPropertySymbols(p)); 54 assertEquals([symbol], Object.getOwnPropertySymbols(p));
50 })(); 55 })();
51 56
52 (function testNoProxyTraps() { 57 (function testNoProxyTraps() {
53 var test_sym = Symbol("sym1"); 58 var test_sym = Symbol("sym1");
(...skipping 15 matching lines...) Expand all
69 Object.defineProperty( 74 Object.defineProperty(
70 target.__proto__, "non-enum2", 75 target.__proto__, "non-enum2",
71 { enumerable: false, value: "nope", configurable: true, writable: true }); 76 { enumerable: false, value: "nope", configurable: true, writable: true });
72 var proxy = new Proxy(target, {}); 77 var proxy = new Proxy(target, {});
73 78
74 assertEquals(["0", "one", "two"], Object.keys(proxy)); 79 assertEquals(["0", "one", "two"], Object.keys(proxy));
75 assertEquals(["0", "one", "two", "non-enum"], 80 assertEquals(["0", "one", "two", "non-enum"],
76 Object.getOwnPropertyNames(proxy)); 81 Object.getOwnPropertyNames(proxy));
77 assertEquals([test_sym], Object.getOwnPropertySymbols(proxy)); 82 assertEquals([test_sym], Object.getOwnPropertySymbols(proxy));
78 })(); 83 })();
OLDNEW
« no previous file with comments | « src/runtime/runtime-forin.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698