Additional functions to Harmony weak maps API.
R=rossberg@chromium.org BUG=v8:1565 TEST=mjsunit/harmony/weakmaps Review URL: http://codereview.chromium.org/7572013 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8825 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
861c895a34
commit
9b826964f2
@ -58,13 +58,36 @@ function WeakMapSet(key, value) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function SetupWeakMap() {
|
||||
// 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
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -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, 'the-value');
|
||||
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 @@ var m = new WeakMap;
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user