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

Side by Side Diff: test/mjsunit/harmony/proxies-enumerate.js

Issue 1474083003: [proxies] Implement [[Enumerate]] and [[OwnPropertyKeys]] (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: gcmole fix Created 5 years 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/objects.cc ('k') | test/mjsunit/harmony/proxies-ownkeys.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_one": 1
9 };
10 target.__proto__ = {
11 "target_two": 2
12 };
13 var handler = {
14 enumerate: function(target) {
15 function* keys() {
16 yield "foo";
17 yield "bar";
18 }
19 return keys();
20 }
21 }
22
23 var proxy = new Proxy(target, handler);
24
25 function TestForIn(receiver, expected) {
26 var result = [];
27 for (var k in receiver) {
28 result.push(k);
29 }
30 assertEquals(expected, result);
31 }
32
33 TestForIn(proxy, ["foo", "bar"]);
34
35 // Properly call traps on proxies on the prototype chain.
36 var receiver = {
37 "receiver_one": 1
38 };
39 receiver.__proto__ = proxy;
40 // TODO(jkummerow): Needs proper 'has' trap; implement that and enable this!
41 // TestForIn(receiver, ["receiver_one", "foo", "bar"]);
42
43 // Fall through to default behavior when trap is undefined.
44 handler.enumerate = undefined;
45 TestForIn(proxy, ["target_one", "target_two"]);
46 delete handler.enumerate;
47 TestForIn(proxy, ["target_one", "target_two"]);
48
49 // Non-string keys must be filtered.
50 function TestNonStringKey(key) {
51 handler.enumerate = function(target) {
52 function* keys() { yield key; }
53 return keys();
54 }
55 assertThrows("for (var k in proxy) {}", TypeError);
56 }
57
58 TestNonStringKey(1);
59 TestNonStringKey(3.14);
60 TestNonStringKey(Symbol("foo"));
61 TestNonStringKey({bad: "value"});
62 TestNonStringKey(null);
63 TestNonStringKey(undefined);
64 TestNonStringKey(true);
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | test/mjsunit/harmony/proxies-ownkeys.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698