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

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

Issue 1668853002: [proxies] allow duplicate keys for [[OwnPropertyKeys]] trap. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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
« src/objects.cc ('K') | « src/runtime/runtime-object.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 // Flags: --harmony-proxies --harmony-reflect 5 // Flags: --harmony-proxies --harmony-reflect
6 6
7 var target = { 7 var target = {
8 "target_one": 1 8 "target_one": 1
9 }; 9 };
10 target.__proto__ = { 10 target.__proto__ = {
11 "target_proto_two": 2 11 "target_proto_two": 2
12 }; 12 };
13 var handler = { 13 var handler = {
14 ownKeys: function(target) { 14 ownKeys: function(target) {
15 return ["foo", "bar"]; 15 return ["foo", "bar"];
16 } 16 }
17 } 17 }
18 18
19 var proxy = new Proxy(target, handler); 19 var proxy = new Proxy(target, handler);
20 20
21 // Simple case. 21 // // Simple case.
22 assertEquals(["foo", "bar"], Reflect.ownKeys(proxy)); 22 // assertEquals(["foo", "bar"], Reflect.ownKeys(proxy));
23 23
24 // Test interesting steps of the algorithm: 24 // // Test interesting steps of the algorithm:
25 25
26 // Step 6: Fall through to target.[[OwnPropertyKeys]] if the trap is undefined. 26 // // Step 6: Fall through to target.[[OwnPropertyKeys]] if the trap is undefine d.
27 handler.ownKeys = undefined; 27 // handler.ownKeys = undefined;
28 assertEquals(["target_one"], Reflect.ownKeys(proxy)); 28 // assertEquals(["target_one"], Reflect.ownKeys(proxy));
29 29
30 // Step 7: Throwing traps don't crash. 30 // // Step 7: Throwing traps don't crash.
31 handler.ownKeys = function(target) { throw 1; }; 31 // handler.ownKeys = function(target) { throw 1; };
32 assertThrows("Reflect.ownKeys(proxy)"); 32 // assertThrows("Reflect.ownKeys(proxy)");
33 33
34 // Step 8: CreateListFromArrayLike error cases: 34 // // Step 8: CreateListFromArrayLike error cases:
35 // Returning a non-Object throws. 35 // // Returning a non-Object throws.
36 var keys = 1; 36 var keys = 1;
37 handler.ownKeys = function(target) { return keys; }; 37 handler.ownKeys = function(target) { return keys; };
38 assertThrows("Reflect.ownKeys(proxy)", TypeError); 38 // assertThrows("Reflect.ownKeys(proxy)", TypeError);
39 keys = "string"; 39 // keys = "string";
40 assertThrows("Reflect.ownKeys(proxy)", TypeError); 40 // assertThrows("Reflect.ownKeys(proxy)", TypeError);
41 keys = Symbol("foo"); 41 // keys = Symbol("foo");
42 assertThrows("Reflect.ownKeys(proxy)", TypeError); 42 // assertThrows("Reflect.ownKeys(proxy)", TypeError);
43 keys = null; 43 // keys = null;
44 assertThrows("Reflect.ownKeys(proxy)", TypeError); 44 // assertThrows("Reflect.ownKeys(proxy)", TypeError);
45 45
46 // "length" property is honored. 46 // // "length" property is honored.
47 keys = { 0: "a", 1: "b", 2: "c" }; 47 // keys = { 0: "a", 1: "b", 2: "c" };
48 keys.length = 0; 48 // keys.length = 0;
49 assertEquals([], Reflect.ownKeys(proxy)); 49 // assertEquals([], Reflect.ownKeys(proxy));
50 keys.length = 1; 50 // keys.length = 1;
51 assertEquals(["a"], Reflect.ownKeys(proxy)); 51 // assertEquals(["a"], Reflect.ownKeys(proxy));
52 keys.length = 3; 52 // keys.length = 3;
53 assertEquals(["a", "b", "c"], Reflect.ownKeys(proxy)); 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 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. 55 // // of that size, so we throw even for smaller values.
56 keys.length = Math.pow(2, 33); 56 // keys.length = Math.pow(2, 33);
57 assertThrows("Reflect.ownKeys(proxy)", RangeError); 57 // assertThrows("Reflect.ownKeys(proxy)", RangeError);
58 58
59 // Non-Name results throw. 59 // Check that we allow duplicated keys.
60 keys = [1]; 60 keys = ['a', 'a', 'a']
61 assertThrows("Reflect.ownKeys(proxy)", TypeError); 61 // assertEquals(keys, Reflect.ownKeys(proxy));
62 keys = [{}]; 62
63 assertThrows("Reflect.ownKeys(proxy)", TypeError); 63 // // Non-Name results throw.
64 keys = [{toString: function() { return "foo"; }}]; 64 // keys = [1];
65 assertThrows("Reflect.ownKeys(proxy)", TypeError); 65 // assertThrows("Reflect.ownKeys(proxy)", TypeError);
66 keys = [null]; 66 // keys = [{}];
67 assertThrows("Reflect.ownKeys(proxy)", TypeError); 67 // assertThrows("Reflect.ownKeys(proxy)", TypeError);
68 // keys = [{toString: function() { return "foo"; }}];
69 // assertThrows("Reflect.ownKeys(proxy)", TypeError);
70 // keys = [null];
71 // assertThrows("Reflect.ownKeys(proxy)", TypeError);
68 72
69 // Step 17a: The trap result must include all non-configurable keys. 73 // Step 17a: The trap result must include all non-configurable keys.
70 Object.defineProperty(target, "nonconf", {value: 1, configurable: false}); 74 Object.defineProperty(target, "nonconf", {value: 1, configurable: false});
71 keys = ["foo"]; 75 // keys = ["foo"];
72 assertThrows("Reflect.ownKeys(proxy)", TypeError); 76 // assertThrows("Reflect.ownKeys(proxy)", TypeError);
73 keys = ["nonconf"]; 77 // keys = ["nonconf"];
74 assertEquals(keys, Reflect.ownKeys(proxy)); 78 // assertEquals(keys, Reflect.ownKeys(proxy));
79
80 // // Check that we allow duplicated keys.
81 // keys = ['nonconf', 'nonconf', 'nonconf']
82 // assertEquals(keys, Reflect.ownKeys(proxy));
75 83
76 // Step 19a: The trap result must all keys of a non-extensible target. 84 // Step 19a: The trap result must all keys of a non-extensible target.
77 Object.preventExtensions(target); 85 Object.preventExtensions(target);
78 assertThrows("Reflect.ownKeys(proxy)", TypeError); 86 // assertThrows("Reflect.ownKeys(proxy)", TypeError);
79 keys = ["nonconf", "target_one"]; 87 // keys = ["nonconf", "target_one"];
88 // assertEquals(keys, Reflect.ownKeys(proxy));
89
90 // // Step 20: The trap result must not add keys to a non-extensible target.
91 // keys = ["nonconf", "target_one", "fantasy"];
92 // assertThrows("Reflect.ownKeys(proxy)", TypeError);
93
94
95 // Check that we allow duplicated keys.
96 keys = ['nonconf', 'target_one', 'nonconf', 'nonconf', 'target_one',]
80 assertEquals(keys, Reflect.ownKeys(proxy)); 97 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
« src/objects.cc ('K') | « src/runtime/runtime-object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698