Implement WeakMap.prototype.clear function.

R=rossberg@chromium.org
BUG=v8:2753
TEST=mjsunit/harmony/collections

Review URL: https://codereview.chromium.org/18352002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15421 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 488da005
......@@ -295,6 +295,16 @@ function WeakMapDelete(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);
}
// -------------------------------------------------------------------
function SetUpWeakMap() {
......@@ -309,7 +319,8 @@ function SetUpWeakMap() {
"get", WeakMapGet,
"set", WeakMapSet,
"has", WeakMapHas,
"delete", WeakMapDelete
"delete", WeakMapDelete,
"clear", WeakMapClear
));
}
......
......@@ -377,17 +377,39 @@ for (var i = 9; i >= 0; i--) {
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));
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment