Commit f62ffeef authored by dslomov@chromium.org's avatar dslomov@chromium.org

Calling Map etc without new should throw TypeError

Even though we do not yet allow Map, Set, WeakMap and WeakSet to be
subclassed we need to ensure that we do not allow them to be [[Call]]ed
to allow them to be subclassed in the future.

BUG=v8:2819
R=dslomov@chromium.org, mstarzinger@chromium.org

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

Patch from Erik Arvidsson <arv@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16006 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 4ebeda21
......@@ -47,7 +47,7 @@ function SetConstructor() {
if (%_IsConstructCall()) {
%SetInitialize(this);
} else {
return new $Set();
throw MakeTypeError('constructor_not_function', ['Set']);
}
}
......@@ -141,7 +141,7 @@ function MapConstructor() {
if (%_IsConstructCall()) {
%MapInitialize(this);
} else {
return new $Map();
throw MakeTypeError('constructor_not_function', ['Map']);
}
}
......@@ -243,7 +243,7 @@ function WeakMapConstructor() {
if (%_IsConstructCall()) {
%WeakCollectionInitialize(this);
} else {
return new $WeakMap();
throw MakeTypeError('constructor_not_function', ['WeakMap']);
}
}
......@@ -335,7 +335,7 @@ function WeakSetConstructor() {
if (%_IsConstructCall()) {
%WeakCollectionInitialize(this);
} else {
return new $WeakSet();
throw MakeTypeError('constructor_not_function', ['WeakSet']);
}
}
......
......@@ -207,10 +207,10 @@ TestArbitrary(new WeakMap);
// Test direct constructor call
assertTrue(Set() instanceof Set);
assertTrue(Map() instanceof Map);
assertTrue(WeakMap() instanceof WeakMap);
assertTrue(WeakSet() instanceof WeakSet);
assertThrows(function() { Set(); }, TypeError);
assertThrows(function() { Map(); }, TypeError);
assertThrows(function() { WeakMap(); }, TypeError);
assertThrows(function() { WeakSet(); }, TypeError);
// Test whether NaN values as keys are treated correctly.
......@@ -308,7 +308,6 @@ TestPrototype(WeakSet);
function TestConstructor(C) {
assertFalse(C === Object.prototype.constructor);
assertSame(C, C.prototype.constructor);
assertSame(C, C().__proto__.constructor);
assertSame(C, (new C).__proto__.constructor);
}
TestConstructor(Set);
......
......@@ -285,8 +285,8 @@ assertEquals(4, wh4.q);
// http://wiki.ecmascript.org/doku.php?id=harmony:proxies#an_identity-preserving_membrane
function createMembrane(wetTarget) {
var wet2dry = WeakMap();
var dry2wet = WeakMap();
var wet2dry = new WeakMap();
var dry2wet = new WeakMap();
function asDry(obj) {
registerObject(obj)
......
......@@ -51,7 +51,7 @@ function TestSet2(construct, fix, create) {
var p3 = create(handler)
fix(p3)
var s = construct();
var s = new construct();
s.add(p1);
s.add(p2);
assertTrue(s.has(p1));
......@@ -88,7 +88,7 @@ function TestMap2(construct, fix, create) {
var p3 = create(handler)
fix(p3)
var m = construct();
var m = new construct();
m.set(p1, 123);
m.set(p2, 321);
assertTrue(m.has(p1));
......
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