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

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

Issue 1491863002: [proxies] Adapt and reenable harmony/proxies-for.js test. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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 | « no previous file | test/mjsunit/mjsunit.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 22 matching lines...) Expand all
33 function TestWithProxies(test, x, y, z) { 33 function TestWithProxies(test, x, y, z) {
34 test(function(h){ return new Proxy({}, h) }, x, y, z) 34 test(function(h){ return new Proxy({}, h) }, x, y, z)
35 test(function(h) { 35 test(function(h) {
36 return Proxy.createFunction(h, function() {}) 36 return Proxy.createFunction(h, function() {})
37 }, x, y, z) 37 }, x, y, z)
38 } 38 }
39 39
40 40
41 // Iterate over a proxy. 41 // Iterate over a proxy.
42 42
43 Array.prototype.values = function() { return this[Symbol.iterator]() }
44
43 function TestForIn(properties, handler) { 45 function TestForIn(properties, handler) {
44 TestWithProxies(TestForIn2, properties, handler) 46 TestWithProxies(TestForIn2, properties, handler)
45 } 47 }
46 48
47 function TestForIn2(create, properties, handler) { 49 function TestForIn2(create, properties, handler) {
48 var p = create(handler) 50 var p = create(handler)
49 var found = [] 51 var found = []
50 for (var x in p) found.push(x) 52 for (var x in p) found.push(x)
51 assertArrayEquals(properties, found) 53 assertArrayEquals(properties, found)
52 } 54 }
53 55
54 TestForIn(["0", "a"], { 56 TestForIn(["0", "a"], {
55 enumerate: function() { return [0, "a"] } 57 enumerate: function() { return ["0", "a"].values() }
56 }) 58 })
57 59
58 TestForIn(["null", "a"], { 60 TestForIn(["null", "a"], {
59 enumerate: function() { return this.enumerate2() }, 61 enumerate: function() { return this.enumerate2() },
60 enumerate2: function() { return [null, "a"] } 62 enumerate2: function() { return ["null", "a"].values() }
61 })
62
63 TestForIn(["b", "d"], {
64 getPropertyNames: function() { return ["a", "b", "c", "d", "e"] },
65 getPropertyDescriptor: function(k) {
66 switch (k) {
67 case "a": return {enumerable: false, value: "3", configurable: true};
68 case "b": return {enumerable: true, get get() {}, configurable: true};
69 case "c": return {value: 4, configurable: true};
70 case "d": return {get enumerable() { return true }, configurable: true};
71 default: return undefined;
72 }
73 }
74 }) 63 })
75 64
76 TestForIn(["b", "a", "0", "c"], new Proxy({}, { 65 TestForIn(["b", "a", "0", "c"], new Proxy({}, {
77 get: function(pr, pk) { 66 get: function(pr, pk) {
78 return function() { return ["b", "a", 0, "c"] } 67 return function() { return ["b", "a", "0", "c"].values() }
79 } 68 }
80 })) 69 }))
81 70
82 71
83 72
84 // Iterate over an object with a proxy prototype. 73 // Iterate over an object with a proxy prototype.
85 74
86 function TestForInDerived(properties, handler) { 75 function TestForInDerived(properties, handler) {
87 TestWithProxies(TestForInDerived2, properties, handler) 76 TestWithProxies(TestForInDerived2, properties, handler)
88 } 77 }
89 78
90 function TestForInDerived2(create, properties, handler) { 79 function TestForInDerived2(create, properties, handler) {
91 var p = create(handler) 80 var p = create(handler)
92 var o = Object.create(p) 81 var o = Object.create(p)
93 o.z = 0 82 o.z = 0
94 var found = [] 83 var found = []
95 for (var x in o) found.push(x) 84 for (var x in o) found.push(x)
96 assertArrayEquals(["z"].concat(properties), found) 85 assertArrayEquals(["z"].concat(properties), found)
97 86
98 var oo = Object.create(o) 87 var oo = Object.create(o)
99 oo.y = 0 88 oo.y = 0
100 var found = [] 89 var found = []
101 for (var x in oo) found.push(x) 90 for (var x in oo) found.push(x)
102 assertArrayEquals(["y", "z"].concat(properties), found) 91 assertArrayEquals(["y", "z"].concat(properties), found)
103 } 92 }
104 93
105 TestForInDerived(["0", "a"], { 94 TestForInDerived(["0", "a"], {
106 enumerate: function() { return [0, "a"] }, 95 enumerate: function() { return ["0", "a"].values() },
107 getPropertyDescriptor: function(k) { 96 has: function(t, k) {
108 return k == "0" || k == "a" ? {configurable: true} : undefined 97 return k == "0" || k == "a"
rossberg 2015/12/03 14:40:46 Nit: fit on one line
109 } 98 }
110 }) 99 })
111 100
112 TestForInDerived(["null", "a"], { 101 TestForInDerived(["null", "a"], {
113 enumerate: function() { return this.enumerate2() }, 102 enumerate: function() { return this.enumerate2() },
114 enumerate2: function() { return [null, "a"] }, 103 enumerate2: function() { return ["null", "a"].values() },
115 getPropertyDescriptor: function(k) { 104 has: function(t, k) {
116 return k == "null" || k == "a" ? {configurable: true} : undefined 105 return k == "null" || k == "a"
rossberg 2015/12/03 14:40:46 Dito
117 } 106 }
118 }) 107 })
119 108
120 TestForInDerived(["b", "d"], {
121 getPropertyNames: function() { return ["a", "b", "c", "d", "e"] },
122 getPropertyDescriptor: function(k) {
123 switch (k) {
124 case "a": return {enumerable: false, value: "3", configurable: true};
125 case "b": return {enumerable: true, get get() {}, configurable: true};
126 case "c": return {value: 4, configurable: true};
127 case "d": return {get enumerable() { return true }, configurable: true};
128 default: return undefined;
129 }
130 }
131 })
132
133 109
134 110
135 // Throw exception in enumerate trap. 111 // Throw exception in enumerate trap.
136 112
137 function TestForInThrow(handler) { 113 function TestForInThrow(handler) {
138 TestWithProxies(TestForInThrow2, handler) 114 TestWithProxies(TestForInThrow2, handler)
139 } 115 }
140 116
141 function TestForInThrow2(create, handler) { 117 function TestForInThrow2(create, handler) {
142 var p = create(handler) 118 var p = create(handler)
143 var o = Object.create(p) 119 var o = Object.create(p)
144 assertThrows(function(){ for (var x in p) {} }, "myexn") 120 assertThrows(function(){ for (var x in p) {} }, "myexn")
145 assertThrows(function(){ for (var x in o) {} }, "myexn") 121 assertThrows(function(){ for (var x in o) {} }, "myexn")
146 } 122 }
147 123
148 TestForInThrow({ 124 TestForInThrow({
149 enumerate: function() { throw "myexn" } 125 enumerate: function() { throw "myexn" }
150 }) 126 })
151 127
152 TestForInThrow({ 128 TestForInThrow({
153 enumerate: function() { return this.enumerate2() }, 129 enumerate: function() { return this.enumerate2() },
154 enumerate2: function() { throw "myexn" } 130 enumerate2: function() { throw "myexn" }
155 }) 131 })
156 132
157 TestForInThrow({
158 getPropertyNames: function() { throw "myexn" }
159 })
160
161 TestForInThrow({
162 getPropertyNames: function() { return ["a"] },
163 getPropertyDescriptor: function() { throw "myexn" }
164 })
165
166 TestForInThrow(new Proxy({}, { 133 TestForInThrow(new Proxy({}, {
167 get: function(pr, pk) { 134 get: function(pr, pk) {
168 return function() { throw "myexn" } 135 return function() { throw "myexn" }
169 } 136 }
170 })); 137 }));
171 138
172 (function() { 139 (function() {
173 var p = new Proxy({}, {enumerate:function() { return [0]; }}); 140 var p = new Proxy({}, {enumerate:function() { return ["0"].values(); }});
174 var o = [0]; 141 var o = [0];
175 o.__proto__ = p; 142 o.__proto__ = p;
176 var keys = []; 143 var keys = [];
177 for (var k in o) { keys.push(k); }; 144 for (var k in o) { keys.push(k); };
178 assertEquals(["0"], keys); 145 assertEquals(["0"], keys);
179 })(); 146 })();
180 147
181 (function () { 148 (function () {
182 var p = new Proxy({}, {getOwnPropertyNames: 149 var p = new Proxy({}, {getOwnPropertyNames:
183 function() { return [1, Symbol(), 2] }}); 150 function() { return [1, Symbol(), 2] }});
184 assertEquals(["1","2"], Object.getOwnPropertyNames(p)); 151 assertEquals(["1","2"], Object.getOwnPropertyNames(p));
185 })(); 152 })();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/mjsunit.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698