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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 var obj = {} | 333 var obj = {} |
334 obj[publicSymbol] = 1 | 334 obj[publicSymbol] = 1 |
335 obj[privateSymbol] = 2 | 335 obj[privateSymbol] = 2 |
336 obj[publicSymbol2] = 3 | 336 obj[publicSymbol2] = 3 |
337 var syms = Object.getOwnPropertySymbols(obj) | 337 var syms = Object.getOwnPropertySymbols(obj) |
338 assertEquals(syms, [publicSymbol, publicSymbol2]) | 338 assertEquals(syms, [publicSymbol, publicSymbol2]) |
339 } | 339 } |
340 TestGetOwnPropertySymbols() | 340 TestGetOwnPropertySymbols() |
341 | 341 |
342 | 342 |
343 function TestSealAndFreeze(freeze) { | 343 function TestSealAndFreeze(factory, freeze, isFrozen) { |
344 var sym = %CreatePrivateSymbol("private") | 344 var sym = %CreatePrivateSymbol("private") |
345 var obj = {} | 345 var obj = factory(); |
346 obj[sym] = 1 | 346 obj[sym] = 1 |
347 freeze(obj) | 347 freeze(obj) |
| 348 assertTrue(isFrozen(obj)) |
348 obj[sym] = 2 | 349 obj[sym] = 2 |
349 assertEquals(2, obj[sym]) | 350 assertEquals(2, obj[sym]) |
350 assertTrue(delete obj[sym]) | 351 assertTrue(delete obj[sym]) |
351 assertEquals(undefined, obj[sym]) | 352 assertEquals(undefined, obj[sym]) |
352 } | 353 } |
353 TestSealAndFreeze(Object.seal) | 354 |
354 TestSealAndFreeze(Object.freeze) | 355 var fastObj = () => { |
355 TestSealAndFreeze(Object.preventExtensions) | 356 var obj = {} |
| 357 assertTrue(%HasFastProperties(obj)) |
| 358 return obj |
| 359 } |
| 360 var dictObj = () => { |
| 361 var obj = Object.create(null) |
| 362 obj.a = 1 |
| 363 delete obj.a |
| 364 assertFalse(%HasFastProperties(obj)) |
| 365 return obj |
| 366 } |
| 367 |
| 368 TestSealAndFreeze(fastObj, Object.seal, Object.isSealed) |
| 369 TestSealAndFreeze(fastObj, Object.freeze, Object.isFrozen) |
| 370 TestSealAndFreeze(fastObj, Object.preventExtensions, obj => !Object.isExtensible
(obj)) |
| 371 TestSealAndFreeze(dictObj, Object.seal, Object.isSealed) |
| 372 TestSealAndFreeze(dictObj, Object.freeze, Object.isFrozen) |
| 373 TestSealAndFreeze(dictObj, Object.preventExtensions, obj => !Object.isExtensible
(obj)) |
356 | 374 |
357 | 375 |
358 var s = %CreatePrivateSymbol("s"); | 376 var s = %CreatePrivateSymbol("s"); |
359 var s1 = %CreatePrivateSymbol("s1"); | 377 var s1 = %CreatePrivateSymbol("s1"); |
360 | 378 |
361 function TestSimple() { | 379 function TestSimple() { |
362 var p = {} | 380 var p = {} |
363 p[s] = "moo"; | 381 p[s] = "moo"; |
364 | 382 |
365 var o = Object.create(p); | 383 var o = Object.create(p); |
(...skipping 29 matching lines...) Expand all Loading... |
395 | 413 |
396 // Test non-monomorphic. | 414 // Test non-monomorphic. |
397 for (var i = 0; i < 1000; i++) { | 415 for (var i = 0; i < 1000; i++) { |
398 var oNew = Object.create(p); | 416 var oNew = Object.create(p); |
399 oNew["s" + i] = i; | 417 oNew["s" + i] = i; |
400 oNew[s1] = "bow-wow"; | 418 oNew[s1] = "bow-wow"; |
401 checkNonOwn(oNew); | 419 checkNonOwn(oNew); |
402 } | 420 } |
403 } | 421 } |
404 TestICs(); | 422 TestICs(); |
OLD | NEW |