OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 function TestKeyNames(obj) { | 291 function TestKeyNames(obj) { |
292 assertEquals(0, Object.keys(obj).length) | 292 assertEquals(0, Object.keys(obj).length) |
293 | 293 |
294 var names = Object.getOwnPropertyNames(obj) | 294 var names = Object.getOwnPropertyNames(obj) |
295 for (var i in names) { | 295 for (var i in names) { |
296 assertEquals("string", typeof names[i]) | 296 assertEquals("string", typeof names[i]) |
297 } | 297 } |
298 } | 298 } |
299 | 299 |
300 | 300 |
301 function TestKeySymbols(obj) { | |
rossberg
2013/12/10 10:39:53
Let's call this TestGetOwnPropertySymbols
arv (Not doing code reviews)
2013/12/11 00:16:26
Done.
| |
302 var syms = Object.getOwnPropertySymbols(obj) | |
303 assertEquals(syms.length, symbols.length) | |
304 for (var i in syms) { | |
305 assertEquals("symbol", typeof syms[i]) | |
rossberg
2013/12/10 10:39:53
Also assert that insertion order is maintained (wh
arv (Not doing code reviews)
2013/12/11 00:16:26
You sent me off on goose chase there. I finally fi
rossberg
2013/12/12 15:37:59
Ah, sorry about that. I should have known.
| |
306 } | |
307 } | |
308 | |
309 | |
301 function TestKeyDescriptor(obj) { | 310 function TestKeyDescriptor(obj) { |
302 for (var i in symbols) { | 311 for (var i in symbols) { |
303 var desc = Object.getOwnPropertyDescriptor(obj, symbols[i]); | 312 var desc = Object.getOwnPropertyDescriptor(obj, symbols[i]); |
304 assertEquals(i|0, desc.value) | 313 assertEquals(i|0, desc.value) |
305 assertTrue(desc.configurable) | 314 assertTrue(desc.configurable) |
306 assertEquals(i % 2 == 0, desc.writable) | 315 assertEquals(i % 2 == 0, desc.writable) |
307 assertEquals(i % 2 == 0, desc.enumerable) | 316 assertEquals(i % 2 == 0, desc.enumerable) |
308 assertEquals(i % 2 == 0, | 317 assertEquals(i % 2 == 0, |
309 Object.prototype.propertyIsEnumerable.call(obj, symbols[i])) | 318 Object.prototype.propertyIsEnumerable.call(obj, symbols[i])) |
310 } | 319 } |
(...skipping 13 matching lines...) Expand all Loading... | |
324 var objs = [{}, [], Object.create(null), Object(1), new Map, function(){}] | 333 var objs = [{}, [], Object.create(null), Object(1), new Map, function(){}] |
325 | 334 |
326 for (var i in objs) { | 335 for (var i in objs) { |
327 var obj = objs[i] | 336 var obj = objs[i] |
328 TestKeySet(obj) | 337 TestKeySet(obj) |
329 TestKeyDefine(obj) | 338 TestKeyDefine(obj) |
330 TestKeyGet(obj) | 339 TestKeyGet(obj) |
331 TestKeyHas(obj) | 340 TestKeyHas(obj) |
332 TestKeyEnum(obj) | 341 TestKeyEnum(obj) |
333 TestKeyNames(obj) | 342 TestKeyNames(obj) |
343 TestKeySymbols(obj) | |
334 TestKeyDescriptor(obj) | 344 TestKeyDescriptor(obj) |
335 TestKeyDelete(obj) | 345 TestKeyDelete(obj) |
336 } | 346 } |
337 | 347 |
338 | 348 |
339 function TestCachedKeyAfterScavenge() { | 349 function TestCachedKeyAfterScavenge() { |
340 gc(); | 350 gc(); |
341 // Keyed property lookup are cached. Hereby we assume that the keys are | 351 // Keyed property lookup are cached. Hereby we assume that the keys are |
342 // tenured, so that we only have to clear the cache between mark compacts, | 352 // tenured, so that we only have to clear the cache between mark compacts, |
343 // but not between scavenges. This must also apply for symbol keys. | 353 // but not between scavenges. This must also apply for symbol keys. |
344 var key = Symbol("key"); | 354 var key = Symbol("key"); |
345 var a = {}; | 355 var a = {}; |
346 a[key] = "abc"; | 356 a[key] = "abc"; |
347 | 357 |
348 for (var i = 0; i < 100000; i++) { | 358 for (var i = 0; i < 100000; i++) { |
349 a[key] += "a"; // Allocations cause a scavenge. | 359 a[key] += "a"; // Allocations cause a scavenge. |
350 } | 360 } |
351 } | 361 } |
352 TestCachedKeyAfterScavenge(); | 362 TestCachedKeyAfterScavenge(); |
363 | |
364 | |
365 function TestGetOwnPropertySymbolsWithPrivateSymbols() { | |
rossberg
2013/12/10 10:39:53
Nit: Move this next to the other test.
arv (Not doing code reviews)
2013/12/11 00:16:26
I kept it here because this test does not take an
| |
366 var privateSymbol = %CreatePrivateSymbol("private") | |
367 var obj = {} | |
rossberg
2013/12/10 10:39:53
Hm, the private symbol is never added to obj. ;)
arv (Not doing code reviews)
2013/12/11 00:16:26
Doh!
| |
368 var syms = Object.getOwnPropertySymbols(obj) | |
369 assertEquals(syms.length, 0) | |
370 } | |
371 TestGetOwnPropertySymbolsWithPrivateSymbols() | |
OLD | NEW |