Revision: 8825
Author: [email protected]
Date: Thu Aug 4 04:13:15 2011
Log: Additional functions to Harmony weak maps API.
[email protected]
BUG=v8:1565
TEST=mjsunit/harmony/weakmaps
Review URL: http://codereview.chromium.org/7572013
http://code.google.com/p/v8/source/detail?r=8825
Modified:
/branches/bleeding_edge/src/weakmap.js
/branches/bleeding_edge/test/mjsunit/harmony/weakmaps.js
=======================================
--- /branches/bleeding_edge/src/weakmap.js Wed Aug 3 04:55:13 2011
+++ /branches/bleeding_edge/src/weakmap.js Thu Aug 4 04:13:15 2011
@@ -57,6 +57,27 @@
}
return %WeakMapSet(this, key, value);
}
+
+
+function WeakMapHas(key) {
+ if (!IS_SPEC_OBJECT(key)) {
+ throw %MakeTypeError('invalid_weakmap_key', [this, key]);
+ }
+ return !IS_UNDEFINED(%WeakMapGet(this, key));
+}
+
+
+function WeakMapDelete(key) {
+ if (!IS_SPEC_OBJECT(key)) {
+ throw %MakeTypeError('invalid_weakmap_key', [this, key]);
+ }
+ if (!IS_UNDEFINED(%WeakMapGet(this, key))) {
+ %WeakMapSet(this, key, void 0);
+ return true;
+ } else {
+ return false;
+ }
+}
// -------------------------------------------------------------------
@@ -64,7 +85,9 @@
// Setup the non-enumerable functions on the WeakMap prototype object.
InstallFunctionsOnHiddenPrototype($WeakMap.prototype, DONT_ENUM, $Array(
"get", WeakMapGet,
- "set", WeakMapSet
+ "set", WeakMapSet,
+ "has", WeakMapHas,
+ "delete", WeakMapDelete
));
}
=======================================
--- /branches/bleeding_edge/test/mjsunit/harmony/weakmaps.js Wed Aug 3
05:48:30 2011
+++ /branches/bleeding_edge/test/mjsunit/harmony/weakmaps.js Thu Aug 4
04:13:15 2011
@@ -32,6 +32,8 @@
var m = new WeakMap;
assertDoesNotThrow(function () { m.get(new Object) });
assertDoesNotThrow(function () { m.set(new Object) });
+assertDoesNotThrow(function () { m.has(new Object) });
+assertDoesNotThrow(function () { m.delete(new Object) });
// Test invalid getter and setter calls
@@ -55,6 +57,27 @@
TestMapping(m, new Object, new Object);
+// Test expected querying behavior
+var m = new WeakMap;
+var key = new Object;
+TestMapping(m, key, 'to-be-present');
+assertTrue(m.has(key));
+assertFalse(m.has(new Object));
+TestMapping(m, key, undefined);
+assertFalse(m.has(key));
+assertFalse(m.has(new Object));
+
+
+// Test expected deletion behavior
+var m = new WeakMap;
+var key = new Object;
+TestMapping(m, key, 'to-be-deleted');
+assertTrue(m.delete(key));
+assertFalse(m.delete(key));
+assertFalse(m.delete(new Object));
+assertSame(m.get(key), undefined);
+
+
// Test GC of map with entry
var m = new WeakMap;
var key = new Object;
@@ -112,6 +135,8 @@
assertTrue(m instanceof WeakMap);
assertTrue(WeakMap.prototype.set instanceof Function)
assertTrue(WeakMap.prototype.get instanceof Function)
+assertTrue(WeakMap.prototype.has instanceof Function)
+assertTrue(WeakMap.prototype.delete instanceof Function)
// Stress Test
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev