Chromium Code Reviews| Index: src/collection.js |
| diff --git a/src/collection.js b/src/collection.js |
| index c5604ab30f359b1287a664ed22d3656d8843b075..351d797cc96a136b73ffed36f5de35b3cbc32613 100644 |
| --- a/src/collection.js |
| +++ b/src/collection.js |
| @@ -325,3 +325,92 @@ function SetUpWeakMap() { |
| } |
| SetUpWeakMap(); |
| + |
| + |
| +// ------------------------------------------------------------------- |
| +// Harmony WeakSet |
| + |
| +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
|
| + |
| + |
| +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
|
| + if (%_IsConstructCall()) { |
| + this[weaksetDataSymbol] = new $WeakMap(); |
| + } else { |
| + return new $WeakSet(); |
| + } |
| +} |
| + |
| + |
| +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
|
| + |
| + |
| +function WeakSetAdd(value) { |
| + 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
|
| + if (!weaksetData) { |
| + throw %MakeTypeError('incompatible_method_receiver', |
| + ['WeakSet.prototype.add', this]); |
| + } |
| + if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { |
| + throw %MakeTypeError('invalid_weakset_value', [this, value]); |
| + } |
| + return %WeakMapSet(weaksetData, value, true); |
| +} |
| + |
| + |
| +function WeakSetHas(value) { |
| + var weaksetData = this[weaksetDataSymbol]; |
| + if (!weaksetData) { |
| + throw %MakeTypeError('incompatible_method_receiver', |
| + ['WeakSet.prototype.has', this]); |
| + } |
| + if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { |
| + throw %MakeTypeError('invalid_weakset_value', [this, value]); |
| + } |
| + return %WeakMapHas(weaksetData, value); |
| +} |
| + |
| + |
| +function WeakSetDelete(value) { |
| + var weaksetData = this[weaksetDataSymbol]; |
| + if (!weaksetData) { |
| + throw MakeTypeError('incompatible_method_receiver', |
| + ['WeakSet.prototype.delete', this]); |
| + } |
| + if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { |
| + throw %MakeTypeError('invalid_weakset_value', [this, value]); |
| + } |
| + return %WeakMapDelete(weaksetData, value); |
| +} |
| + |
| + |
| +function WeakSetClear() { |
| + if (!this[weaksetDataSymbol]) { |
| + throw %MakeTypeError('incompatible_method_receiver', |
| + ['WeakSet.prototype.clear', this]); |
| + } |
| + |
| + this[weaksetDataSymbol] = new $WeakMap(); |
| +} |
| + |
| + |
| +// ------------------------------------------------------------------- |
| + |
| +function SetUpWeakSet() { |
| + %CheckIsBootstrapping(); |
| + |
| + %FunctionSetInstanceClassName($WeakSet, 'WeakSet'); |
| + |
| + %FunctionSetPrototype($WeakSet, new $Object()); |
| + %SetProperty($WeakSet.prototype, "constructor", $WeakSet, DONT_ENUM); |
| + |
| + // Set up the non-enumerable functions on the WeakSet prototype object. |
| + InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array( |
| + "add", WeakSetAdd, |
| + "has", WeakSetHas, |
| + "delete", WeakSetDelete, |
| + "clear", WeakSetClear |
| + )); |
| +} |
| + |
| +SetUpWeakSet(); |