Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Unified Diff: src/collection.js

Issue 19429002: ES6: Implement WeakSet (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix enumerable and expand tests Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/messages.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/collection.js
diff --git a/src/collection.js b/src/collection.js
index c5604ab30f359b1287a664ed22d3656d8843b075..2ea7af1135a4d4eea633e185ec703111747d5a91 100644
--- a/src/collection.js
+++ b/src/collection.js
@@ -325,3 +325,94 @@ function SetUpWeakMap() {
}
SetUpWeakMap();
+
+
+// -------------------------------------------------------------------
+// Harmony WeakSet
+
+var weaksetDataSymbol = %CreateSymbol(void 0);
+
+
+function WeakSet() {
+ if (%_IsConstructCall()) {
+ this[weaksetDataSymbol] = new $WeakMap();
+ } else {
+ return new $WeakSet();
+ }
+}
+
+
+var $WeakSet = WeakSet;
+
+
+function WeakSetAdd(value) {
+ var weaksetData = this[weaksetDataSymbol];
+ 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();
+
+ %SetProperty(global, 'WeakSet', $WeakSet, DONT_ENUM);
+
+ %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();
« no previous file with comments | « no previous file | src/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698