Fix issue with prototype of WeakMap constructor.

The WeakMap constructor didn't have a unique prototype, so it shared one with
Object. All WeakMap functions (including "get" and "set") were installed on
that prototype.

R=rossberg@chromium.org
BUG=v8:1617
TEST=mjsunit/harmony/weakmaps

Review URL: http://codereview.chromium.org/7658008

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8941 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent fc17bd37
......@@ -33,14 +33,13 @@ const $WeakMap = global.WeakMap;
// -------------------------------------------------------------------
// Set the WeakMap function and constructor.
%SetCode($WeakMap, function(x) {
function WeakMapConstructor() {
if (%_IsConstructCall()) {
%WeakMapInitialize(this);
} else {
return new $WeakMap();
}
});
}
function WeakMapGet(key) {
......@@ -82,6 +81,12 @@ function WeakMapDelete(key) {
// -------------------------------------------------------------------
function SetupWeakMap() {
// Setup the WeakMap constructor function.
%SetCode($WeakMap, WeakMapConstructor);
// Setup the WeakMap prototype object.
%FunctionSetPrototype($WeakMap, new $WeakMap());
// Setup the non-enumerable functions on the WeakMap prototype object.
InstallFunctionsOnHiddenPrototype($WeakMap.prototype, DONT_ENUM, $Array(
"get", WeakMapGet,
......
......@@ -139,6 +139,23 @@ assertTrue(WeakMap.prototype.has instanceof Function)
assertTrue(WeakMap.prototype.delete instanceof Function)
// Regression test for issue 1617: The prototype of the WeakMap constructor
// needs to be unique (i.e. different from the one of the Object constructor).
assertFalse(WeakMap.prototype === Object.prototype);
var o = Object.create({});
assertFalse("get" in o);
assertFalse("set" in o);
assertEquals(undefined, o.get);
assertEquals(undefined, o.set);
var o = Object.create({}, { myValue: {
value: 10,
enumerable: false,
configurable: true,
writable: true
}});
assertEquals(10, o.myValue);
// Stress Test
// There is a proposed stress-test available at the es-discuss mailing list
// which cannot be reasonably automated. Check it out by hand if you like:
......
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