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

Side by Side Diff: test/mjsunit/harmony/proxies-ownkeys.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 | « test/mjsunit/harmony/proxies-enumerate.js ('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
(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 --harmony-reflect
6
7 var target = {
8 "target_one": 1
9 };
10 target.__proto__ = {
11 "target_proto_two": 2
12 };
13 var handler = {
14 ownKeys: function(target) {
15 return ["foo", "bar"];
16 }
17 }
18
19 var proxy = new Proxy(target, handler);
20
21 // Simple case.
22 assertEquals(["foo", "bar"], Reflect.ownKeys(proxy));
23
24 // Test interesting steps of the algorithm:
25
26 // Step 6: Fall through to target.[[OwnPropertyKeys]] if the trap is undefined.
27 handler.ownKeys = undefined;
28 assertEquals(["target_one"], Reflect.ownKeys(proxy));
29
30 // Step 7: Throwing traps don't crash.
31 handler.ownKeys = function(target) { throw 1; };
32 assertThrows("Reflect.ownKeys(proxy)");
33
34 // Step 8: CreateListFromArrayLike error cases:
35 // Returning a non-Object throws.
36 var keys = 1;
37 handler.ownKeys = function(target) { return keys; };
38 assertThrows("Reflect.ownKeys(proxy)", TypeError);
39 keys = "string";
40 assertThrows("Reflect.ownKeys(proxy)", TypeError);
41 keys = Symbol("foo");
42 assertThrows("Reflect.ownKeys(proxy)", TypeError);
43 keys = null;
44 assertThrows("Reflect.ownKeys(proxy)", TypeError);
45
46 // "length" property is honored.
47 keys = { 0: "a", 1: "b", 2: "c" };
48 keys.length = 0;
49 assertEquals([], Reflect.ownKeys(proxy));
50 keys.length = 1;
51 assertEquals(["a"], Reflect.ownKeys(proxy));
52 keys.length = 3;
53 assertEquals(["a", "b", "c"], Reflect.ownKeys(proxy));
54 // The spec wants to allow lengths up to 2^53, but we can't allocate arrays
55 // of that size, so we throw even for smaller values.
56 keys.length = Math.pow(2, 33);
57 assertThrows("Reflect.ownKeys(proxy)", RangeError);
58
59 // Non-Name results throw.
60 keys = [1];
61 assertThrows("Reflect.ownKeys(proxy)", TypeError);
62 keys = [{}];
63 assertThrows("Reflect.ownKeys(proxy)", TypeError);
64 keys = [{toString: function() { return "foo"; }}];
65 assertThrows("Reflect.ownKeys(proxy)", TypeError);
66 keys = [null];
67 assertThrows("Reflect.ownKeys(proxy)", TypeError);
68
69 // Step 17a: The trap result must include all non-configurable keys.
70 Object.defineProperty(target, "nonconf", {value: 1, configurable: false});
71 keys = ["foo"];
72 assertThrows("Reflect.ownKeys(proxy)", TypeError);
73 keys = ["nonconf"];
74 assertEquals(keys, Reflect.ownKeys(proxy));
75
76 // Step 19a: The trap result must all keys of a non-extensible target.
77 Object.freeze(target);
78 assertThrows("Reflect.ownKeys(proxy)", TypeError);
79 keys = ["nonconf", "target_one"];
80 assertEquals(keys, Reflect.ownKeys(proxy));
81
82 // Step 20: The trap result must not add keys to a non-extensible target.
83 keys = ["nonconf", "target_one", "fantasy"];
84 assertThrows("Reflect.ownKeys(proxy)", TypeError);
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/proxies-enumerate.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698