OLD | NEW |
---|---|
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-reflect | 5 // Flags: --harmony-reflect |
6 | 6 |
7 // TODO(neis): Test with proxies. | 7 // TODO(neis): Test with proxies. |
8 | 8 |
9 | 9 |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 Date, | 45 Date, |
46 RegExp, | 46 RegExp, |
47 global | 47 global |
48 ]; | 48 ]; |
49 | 49 |
50 function prepare(tgt) { | 50 function prepare(tgt) { |
51 tgt["bla"] = true; | 51 tgt["bla"] = true; |
52 tgt[4] = 42; | 52 tgt[4] = 42; |
53 tgt[sym] = "foo"; | 53 tgt[sym] = "foo"; |
54 tgt["noconf"] = 43; | 54 tgt["noconf"] = 43; |
55 | |
55 Object.defineProperty(tgt, "noconf", {configurable: false}); | 56 Object.defineProperty(tgt, "noconf", {configurable: false}); |
57 Object.defineProperty(tgt, "nowrite", {writable: false, value: 44}); | |
56 Object.defineProperty(tgt, "getter", | 58 Object.defineProperty(tgt, "getter", |
57 { get: function () {return this.bla}, configurable: true }); | 59 { get: function () {return this.bla}, configurable: true }); |
58 Object.defineProperty(tgt, "setter", | 60 Object.defineProperty(tgt, "setter", |
59 { set: function () {}, configurable: true }); | 61 { set: function (x) {this.gaga = x}, configurable: true }); |
62 Object.defineProperty(tgt, "setter2", | |
63 { set: function (x) {}, configurable: true}); | |
60 } | 64 } |
61 | 65 |
62 | 66 |
63 | 67 |
64 //////////////////////////////////////////////////////////////////////////////// | 68 //////////////////////////////////////////////////////////////////////////////// |
65 // Reflect.get | 69 // Reflect.get |
66 | 70 |
67 | 71 |
68 (function testReflectGetArity() { | 72 (function testReflectGetArity() { |
69 assertEquals(3, Reflect.get.length); | 73 assertEquals(3, Reflect.get.length); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 assertEquals(true, Reflect.get(tgt, "foo")); | 127 assertEquals(true, Reflect.get(tgt, "foo")); |
124 assertEquals(true, Reflect.get(tgt, "foo", tgt)); | 128 assertEquals(true, Reflect.get(tgt, "foo", tgt)); |
125 assertEquals(false, Reflect.get(tgt, "foo", receiver)); | 129 assertEquals(false, Reflect.get(tgt, "foo", receiver)); |
126 tgt.__proto__ = proto; | 130 tgt.__proto__ = proto; |
127 } | 131 } |
128 })(); | 132 })(); |
129 | 133 |
130 | 134 |
131 | 135 |
132 //////////////////////////////////////////////////////////////////////////////// | 136 //////////////////////////////////////////////////////////////////////////////// |
137 // Reflect.set | |
138 | |
139 | |
140 (function testReflectSetArity() { | |
141 assertEquals(3, Reflect.set.length); | |
142 })(); | |
143 | |
144 | |
145 (function testReflectSetOnNonObject() { | |
146 assertThrows(function() { Reflect.set(); }, TypeError); | |
147 assertThrows(function() { Reflect.set(42, "bla"); }, TypeError); | |
148 assertThrows(function() { Reflect.set(null, "bla"); }, TypeError); | |
149 })(); | |
150 | |
151 | |
152 (function testReflectSetKeyConversion() { | |
153 var tgt = {}; | |
154 var a = { [Symbol.toPrimitive]: function() { return "bla" } }; | |
155 var b = { [Symbol.toPrimitive]: function() { throw "gaga" } }; | |
156 assertTrue(Reflect.set(tgt, a, 42)); | |
157 assertEquals(42, tgt.bla); | |
158 assertThrows(function() { Reflect.set(tgt, b, 42); }, "gaga"); | |
159 })(); | |
160 | |
161 | |
162 (function testReflectSetOnObject() { | |
163 var receiver = {bla: false}; | |
164 var value = 34234; | |
165 for (let tgt of objects) { | |
166 prepare(tgt); | |
167 assertTrue(Reflect.set(tgt, "bla", value)); | |
168 assertEquals(value, tgt.bla); | |
169 | |
170 prepare(tgt); | |
171 assertTrue(Reflect.set(tgt, "bla", value, tgt)); | |
172 assertEquals(value, tgt.bla); | |
173 | |
174 prepare(tgt); | |
175 assertTrue(Reflect.set(tgt, "bla", value, receiver)); | |
176 assertEquals(true, tgt.bla); | |
177 assertEquals(value, receiver.bla); | |
178 receiver.bla = false; | |
179 | |
180 prepare(tgt); | |
181 assertTrue(Reflect.set(tgt, 4, value)); | |
182 assertEquals(value, tgt[4]); | |
183 | |
184 prepare(tgt); | |
185 assertTrue(Reflect.set(tgt, 4, value, tgt)); | |
186 assertEquals(value, tgt[4]); | |
187 | |
188 prepare(tgt); | |
189 assertTrue(Reflect.set(tgt, 4, value, receiver)); | |
190 assertEquals(42, tgt[4]); | |
191 assertEquals(value, receiver[4]); | |
192 delete receiver[4]; | |
193 | |
194 prepare(tgt); | |
195 assertTrue(Reflect.set(tgt, sym, value)); | |
196 assertEquals(value, tgt[sym]); | |
197 | |
198 prepare(tgt); | |
199 assertTrue(Reflect.set(tgt, sym, value, tgt)); | |
200 assertEquals(value, tgt[sym]); | |
201 | |
202 prepare(tgt); | |
203 assertTrue(Reflect.set(tgt, sym, value, receiver)); | |
204 assertEquals("foo", tgt[sym]); | |
205 assertEquals(value, receiver[sym]); | |
206 delete receiver[sym]; | |
207 | |
208 prepare(tgt); | |
209 assertTrue(Reflect.set(tgt, "noconf", value)); | |
210 assertEquals(value, tgt.noconf); | |
211 | |
212 prepare(tgt); | |
213 assertTrue(Reflect.set(tgt, "noconf", value, tgt)); | |
214 assertEquals(value, tgt.noconf); | |
215 | |
216 prepare(tgt); | |
217 assertTrue(Reflect.set(tgt, "noconf", value, receiver)); | |
218 assertEquals(43, tgt.noconf); | |
219 assertEquals(value, receiver.noconf); | |
220 delete receiver.noconf; | |
221 | |
222 assertTrue(Reflect.set(tgt, "setter", value)); | |
223 assertEquals(value, tgt.gaga) | |
224 delete tgt.gaga; | |
225 | |
226 assertTrue(Reflect.set(tgt, "setter", value, tgt)); | |
227 assertEquals(value, tgt.gaga) | |
228 delete tgt.gaga; | |
229 | |
230 assertTrue(Reflect.set(tgt, "setter", value, receiver)); | |
231 assertFalse("gaga" in tgt); | |
232 assertEquals(value, receiver.gaga); | |
233 delete receiver.gaga; | |
234 | |
235 assertFalse(Reflect.set(tgt, "nowrite", value)); | |
236 assertEquals(44, tgt.nowrite); | |
237 | |
238 assertFalse(Reflect.set(tgt, "nowrite", value, tgt)); | |
239 assertEquals(44, tgt.nowrite); | |
240 | |
241 assertFalse(Reflect.set(tgt, "nowrite", value, receiver)); | |
242 assertEquals(44, tgt.nowrite); | |
243 assertFalse("nowrite" in receiver); | |
244 | |
245 assertFalse(Reflect.set({}, "nowrite", value, tgt)); | |
246 | |
247 // Data vs Accessor | |
248 // TODO(neis): This must return false but currently doesn't. | |
249 // assertFalse(Reflect.set(tgt, "bla", value, {set bla(x) {}})); | |
250 | |
251 // Accessor vs Data | |
252 assertTrue(Reflect.set({set bla(x) {}}), "bla", value, tgt); | |
253 | |
254 // Data vs Non-Object | |
255 // TODO(neis): These must return false but currently don't. | |
256 // assertFalse(Reflect.set({}, "bla", null)); | |
rossberg
2015/10/29 16:38:24
Something is missing here...
| |
257 // assertFalse(Reflect.set({bla: 42}, "bla", null)); | |
258 | |
259 // Accessor vs Non-Object | |
260 assertTrue(Reflect.set(tgt, "setter2", value, null)); | |
261 } | |
262 })(); | |
263 | |
264 | |
265 | |
266 //////////////////////////////////////////////////////////////////////////////// | |
133 // Reflect.has | 267 // Reflect.has |
134 | 268 |
135 | 269 |
136 (function testReflectHasArity() { | 270 (function testReflectHasArity() { |
137 assertEquals(2, Reflect.has.length); | 271 assertEquals(2, Reflect.has.length); |
138 })(); | 272 })(); |
139 | 273 |
140 | 274 |
141 (function testReflectHasOnNonObject() { | 275 (function testReflectHasOnNonObject() { |
142 assertThrows(function() { Reflect.has(); }, TypeError); | 276 assertThrows(function() { Reflect.has(); }, TypeError); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 assertThrows(function() { Reflect.preventExtensions(); }, TypeError); | 472 assertThrows(function() { Reflect.preventExtensions(); }, TypeError); |
339 assertThrows(function() { Reflect.preventExtensions(42); }, TypeError); | 473 assertThrows(function() { Reflect.preventExtensions(42); }, TypeError); |
340 assertThrows(function() { Reflect.preventExtensions(null); }, TypeError); | 474 assertThrows(function() { Reflect.preventExtensions(null); }, TypeError); |
341 })(); | 475 })(); |
342 | 476 |
343 | 477 |
344 // See reflect-prevent-extensions.js for further tests. | 478 // See reflect-prevent-extensions.js for further tests. |
345 | 479 |
346 // TODO(neis): Need proxies to test the situation where | 480 // TODO(neis): Need proxies to test the situation where |
347 // [[preventExtensions]] returns false. | 481 // [[preventExtensions]] returns false. |
OLD | NEW |