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