Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( | 318 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( | 
| 319 "get", WeakMapGet, | 319 "get", WeakMapGet, | 
| 320 "set", WeakMapSet, | 320 "set", WeakMapSet, | 
| 321 "has", WeakMapHas, | 321 "has", WeakMapHas, | 
| 322 "delete", WeakMapDelete, | 322 "delete", WeakMapDelete, | 
| 323 "clear", WeakMapClear | 323 "clear", WeakMapClear | 
| 324 )); | 324 )); | 
| 325 } | 325 } | 
| 326 | 326 | 
| 327 SetUpWeakMap(); | 327 SetUpWeakMap(); | 
| 328 | |
| 329 | |
| 330 // ------------------------------------------------------------------- | |
| 331 // Harmony WeakSet | |
| 332 | |
| 333 var weaksetDataSymbol = %CreateSymbol(void 0); | |
| 
 
Michael Starzinger
2013/07/17 12:56:41
This requires that Symbols can model private state
 
arv (Not doing code reviews)
2013/07/17 15:26:26
We already depend on private symbols in a few othe
 
Michael Starzinger
2013/07/18 08:33:18
Andreas, what is your opinion about using a Synbol
 
 | |
| 334 | |
| 335 | |
| 336 function WeakSet() { | |
| 
 
Michael Starzinger
2013/07/17 12:56:41
nit: s/WeakSet/WeakSetConstructor/ for consistency
 
arv (Not doing code reviews)
2013/07/17 15:26:26
No, then the name property would be wrong.
Adding
 
Michael Starzinger
2013/07/18 08:33:18
Good point, thanks for adding the tests. But I wou
 
 | |
| 337 if (%_IsConstructCall()) { | |
| 338 this[weaksetDataSymbol] = new $WeakMap(); | |
| 339 } else { | |
| 340 return new $WeakSet(); | |
| 341 } | |
| 342 } | |
| 343 | |
| 344 | |
| 345 var $WeakSet = global.WeakSet = WeakSet; | |
| 
 
Michael Starzinger
2013/07/17 12:56:41
This way of adding "global.WeakSet" unfortunately
 
arv (Not doing code reviews)
2013/07/17 15:26:26
Easy to fix without C++ bootstrapping.
 
Michael Starzinger
2013/07/18 08:33:18
This issue might be easy to fix without C++, but i
 
 | |
| 346 | |
| 347 | |
| 348 function WeakSetAdd(value) { | |
| 349 var weaksetData = this[weaksetDataSymbol]; | |
| 
 
Michael Starzinger
2013/07/17 12:56:41
It would be nice to get rid of this additional ind
 
arv (Not doing code reviews)
2013/07/17 15:26:26
Instead of this indirection we would need to check
 
 | |
| 350 if (!weaksetData) { | |
| 351 throw %MakeTypeError('incompatible_method_receiver', | |
| 352 ['WeakSet.prototype.add', this]); | |
| 353 } | |
| 354 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { | |
| 355 throw %MakeTypeError('invalid_weakset_value', [this, value]); | |
| 356 } | |
| 357 return %WeakMapSet(weaksetData, value, true); | |
| 358 } | |
| 359 | |
| 360 | |
| 361 function WeakSetHas(value) { | |
| 362 var weaksetData = this[weaksetDataSymbol]; | |
| 363 if (!weaksetData) { | |
| 364 throw %MakeTypeError('incompatible_method_receiver', | |
| 365 ['WeakSet.prototype.has', this]); | |
| 366 } | |
| 367 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { | |
| 368 throw %MakeTypeError('invalid_weakset_value', [this, value]); | |
| 369 } | |
| 370 return %WeakMapHas(weaksetData, value); | |
| 371 } | |
| 372 | |
| 373 | |
| 374 function WeakSetDelete(value) { | |
| 375 var weaksetData = this[weaksetDataSymbol]; | |
| 376 if (!weaksetData) { | |
| 377 throw MakeTypeError('incompatible_method_receiver', | |
| 378 ['WeakSet.prototype.delete', this]); | |
| 379 } | |
| 380 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { | |
| 381 throw %MakeTypeError('invalid_weakset_value', [this, value]); | |
| 382 } | |
| 383 return %WeakMapDelete(weaksetData, value); | |
| 384 } | |
| 385 | |
| 386 | |
| 387 function WeakSetClear() { | |
| 388 if (!this[weaksetDataSymbol]) { | |
| 389 throw %MakeTypeError('incompatible_method_receiver', | |
| 390 ['WeakSet.prototype.clear', this]); | |
| 391 } | |
| 392 | |
| 393 this[weaksetDataSymbol] = new $WeakMap(); | |
| 394 } | |
| 395 | |
| 396 | |
| 397 // ------------------------------------------------------------------- | |
| 398 | |
| 399 function SetUpWeakSet() { | |
| 400 %CheckIsBootstrapping(); | |
| 401 | |
| 402 %FunctionSetInstanceClassName($WeakSet, 'WeakSet'); | |
| 403 | |
| 404 %FunctionSetPrototype($WeakSet, new $Object()); | |
| 405 %SetProperty($WeakSet.prototype, "constructor", $WeakSet, DONT_ENUM); | |
| 406 | |
| 407 // Set up the non-enumerable functions on the WeakSet prototype object. | |
| 408 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array( | |
| 409 "add", WeakSetAdd, | |
| 410 "has", WeakSetHas, | |
| 411 "delete", WeakSetDelete, | |
| 412 "clear", WeakSetClear | |
| 413 )); | |
| 414 } | |
| 415 | |
| 416 SetUpWeakSet(); | |
| OLD | NEW |