Revision: 16006
Author: [email protected]
Date: Thu Aug 1 02:18:28 2013
Log: 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
[email protected], [email protected]
Review URL: https://codereview.chromium.org/21400002
Patch from Erik Arvidsson <[email protected]>.
http://code.google.com/p/v8/source/detail?r=16006
Modified:
/branches/bleeding_edge/src/collection.js
/branches/bleeding_edge/test/mjsunit/harmony/collections.js
/branches/bleeding_edge/test/mjsunit/harmony/proxies-example-membrane.js
/branches/bleeding_edge/test/mjsunit/harmony/proxies-hash.js
=======================================
--- /branches/bleeding_edge/src/collection.js Mon Jul 22 01:32:24 2013
+++ /branches/bleeding_edge/src/collection.js Thu Aug 1 02:18:28 2013
@@ -47,7 +47,7 @@
if (%_IsConstructCall()) {
%SetInitialize(this);
} else {
- return new $Set();
+ throw MakeTypeError('constructor_not_function', ['Set']);
}
}
@@ -141,7 +141,7 @@
if (%_IsConstructCall()) {
%MapInitialize(this);
} else {
- return new $Map();
+ throw MakeTypeError('constructor_not_function', ['Map']);
}
}
@@ -243,7 +243,7 @@
if (%_IsConstructCall()) {
%WeakCollectionInitialize(this);
} else {
- return new $WeakMap();
+ throw MakeTypeError('constructor_not_function', ['WeakMap']);
}
}
@@ -335,7 +335,7 @@
if (%_IsConstructCall()) {
%WeakCollectionInitialize(this);
} else {
- return new $WeakSet();
+ throw MakeTypeError('constructor_not_function', ['WeakSet']);
}
}
=======================================
--- /branches/bleeding_edge/test/mjsunit/harmony/collections.js Mon Jul 22
11:18:55 2013
+++ /branches/bleeding_edge/test/mjsunit/harmony/collections.js Thu Aug 1
02:18:28 2013
@@ -207,10 +207,10 @@
// 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 @@
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);
=======================================
---
/branches/bleeding_edge/test/mjsunit/harmony/proxies-example-membrane.js
Thu Nov 10 08:24:43 2011
+++
/branches/bleeding_edge/test/mjsunit/harmony/proxies-example-membrane.js
Thu Aug 1 02:18:28 2013
@@ -285,8 +285,8 @@
//
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)
=======================================
--- /branches/bleeding_edge/test/mjsunit/harmony/proxies-hash.js Tue Oct 25
07:14:56 2011
+++ /branches/bleeding_edge/test/mjsunit/harmony/proxies-hash.js Thu Aug 1
02:18:28 2013
@@ -51,7 +51,7 @@
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 @@
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));
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.