Revision: 15421
Author:   [email protected]
Date:     Mon Jul  1 06:56:48 2013
Log:      Implement WeakMap.prototype.clear function.

[email protected]
BUG=v8:2753
TEST=mjsunit/harmony/collections

Review URL: https://codereview.chromium.org/18352002
http://code.google.com/p/v8/source/detail?r=15421

Modified:
 /branches/bleeding_edge/src/collection.js
 /branches/bleeding_edge/test/mjsunit/harmony/collections.js

=======================================
--- /branches/bleeding_edge/src/collection.js   Thu Apr 11 06:31:51 2013
+++ /branches/bleeding_edge/src/collection.js   Mon Jul  1 06:56:48 2013
@@ -293,6 +293,16 @@
   }
   return %WeakMapDelete(this, key);
 }
+
+
+function WeakMapClear() {
+  if (!IS_WEAKMAP(this)) {
+    throw MakeTypeError('incompatible_method_receiver',
+                        ['WeakMap.prototype.clear', this]);
+  }
+  // Replace the internal table with a new empty table.
+  %WeakMapInitialize(this);
+}


 // -------------------------------------------------------------------
@@ -309,7 +319,8 @@
     "get", WeakMapGet,
     "set", WeakMapSet,
     "has", WeakMapHas,
-    "delete", WeakMapDelete
+    "delete", WeakMapDelete,
+    "clear", WeakMapClear
   ));
 }

=======================================
--- /branches/bleeding_edge/test/mjsunit/harmony/collections.js Thu Apr 11 06:31:51 2013 +++ /branches/bleeding_edge/test/mjsunit/harmony/collections.js Mon Jul 1 06:56:48 2013
@@ -377,17 +377,39 @@
   assertEquals(i, m.size);
 }

-// Test clear
-var a = new Set();
-s.add(42);
-assertTrue(s.has(42));
-s.clear();
-assertFalse(s.has(42));
-assertEquals(0, s.size);

-var m = new Map();
-m.set(42, true);
-assertTrue(m.has(42));
-m.clear();
-assertFalse(m.has(42));
-assertEquals(0, m.size);
+// Test Set clear
+(function() {
+  var s = new Set();
+  s.add(42);
+  assertTrue(s.has(42));
+  assertEquals(1, s.size);
+  s.clear();
+  assertFalse(s.has(42));
+  assertEquals(0, s.size);
+})();
+
+
+// Test Map clear
+(function() {
+  var m = new Map();
+  m.set(42, true);
+  assertTrue(m.has(42));
+  assertEquals(1, m.size);
+  m.clear();
+  assertFalse(m.has(42));
+  assertEquals(0, m.size);
+})();
+
+
+// Test WeakMap clear
+(function() {
+  var k = new Object();
+  var w = new WeakMap();
+  w.set(k, 23);
+  assertTrue(w.has(k));
+  assertEquals(23, w.get(k));
+  w.clear();
+  assertFalse(w.has(k));
+  assertEquals(undefined, w.get(k));
+})();

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to