Revision: 23091
Author: [email protected]
Date: Tue Aug 12 20:09:40 2014 UTC
Log: ES6: Make Map/Set constructors support iterable values
Same for WeakMap/WeakSet
https://bugs.ecmascript.org/show_bug.cgi?id=3111
BUG=v8:3508
LOG=Y
[email protected]
Review URL: https://codereview.chromium.org/466003002
http://code.google.com/p/v8/source/detail?r=23091
Modified:
/branches/bleeding_edge/src/collection.js
/branches/bleeding_edge/src/weak_collection.js
/branches/bleeding_edge/test/mjsunit/es6/collections.js
=======================================
--- /branches/bleeding_edge/src/collection.js Fri Aug 8 13:39:13 2014 UTC
+++ /branches/bleeding_edge/src/collection.js Tue Aug 12 20:09:40 2014 UTC
@@ -23,7 +23,7 @@
var iter, adder;
if (!IS_NULL_OR_UNDEFINED(iterable)) {
- iter = GetIterator(iterable);
+ iter = GetIterator(ToObject(iterable));
adder = this.add;
if (!IS_SPEC_FUNCTION(adder)) {
throw MakeTypeError('property_not_function', ['add', this]);
@@ -147,7 +147,7 @@
var iter, adder;
if (!IS_NULL_OR_UNDEFINED(iterable)) {
- iter = GetIterator(iterable);
+ iter = GetIterator(ToObject(iterable));
adder = this.set;
if (!IS_SPEC_FUNCTION(adder)) {
throw MakeTypeError('property_not_function', ['set', this]);
=======================================
--- /branches/bleeding_edge/src/weak_collection.js Fri Aug 8 13:39:13 2014
UTC
+++ /branches/bleeding_edge/src/weak_collection.js Tue Aug 12 20:09:40 2014
UTC
@@ -23,7 +23,7 @@
var iter, adder;
if (!IS_NULL_OR_UNDEFINED(iterable)) {
- iter = GetIterator(iterable);
+ iter = GetIterator(ToObject(iterable));
adder = this.set;
if (!IS_SPEC_FUNCTION(adder)) {
throw MakeTypeError('property_not_function', ['set', this]);
@@ -139,7 +139,7 @@
var iter, adder;
if (!IS_NULL_OR_UNDEFINED(iterable)) {
- iter = GetIterator(iterable);
+ iter = GetIterator(ToObject(iterable));
adder = this.add;
if (!IS_SPEC_FUNCTION(adder)) {
throw MakeTypeError('property_not_function', ['add', this]);
=======================================
--- /branches/bleeding_edge/test/mjsunit/es6/collections.js Tue Aug 12
19:54:52 2014 UTC
+++ /branches/bleeding_edge/test/mjsunit/es6/collections.js Tue Aug 12
20:09:40 2014 UTC
@@ -1015,6 +1015,9 @@
assertThrows(function() {
new ctor({});
}, TypeError);
+ assertThrows(function() {
+ new ctor(true);
+ }, TypeError);
// @@iterator not callable
assertThrows(function() {
@@ -1148,6 +1151,39 @@
})();
+function TestSetConstructorIterableValue(ctor) {
+ 'use strict';
+ // Strict mode is required to prevent implicit wrapping in the getter.
+ Object.defineProperty(Number.prototype, Symbol.iterator, {
+ get: function() {
+ assertEquals('object', typeof this);
+ return function() {
+ return oneAndTwo.keys();
+ };
+ },
+ configurable: true
+ });
+
+ var set = new ctor(42);
+ assertSize(2, set);
+ assertTrue(set.has(k1));
+ assertTrue(set.has(k2));
+
+ delete Number.prototype[Symbol.iterator];
+}
+TestSetConstructorIterableValue(Set);
+TestSetConstructorIterableValue(WeakSet);
+
+
+(function TestSetConstructorStringValue() {
+ var s = new Set('abc');
+ assertSize(3, s);
+ assertTrue(s.has('a'));
+ assertTrue(s.has('b'));
+ assertTrue(s.has('c'));
+})();
+
+
function TestMapConstructor(ctor) {
var m = new ctor(null);
assertSize(0, m);
@@ -1159,6 +1195,9 @@
assertThrows(function() {
new ctor({});
}, TypeError);
+ assertThrows(function() {
+ new ctor(true);
+ }, TypeError);
// @@iterator not callable
assertThrows(function() {
@@ -1300,3 +1339,27 @@
new WeakMap([[1, 2]])
}, TypeError);
})();
+
+
+function TestMapConstructorIterableValue(ctor) {
+ 'use strict';
+ // Strict mode is required to prevent implicit wrapping in the getter.
+ Object.defineProperty(Number.prototype, Symbol.iterator, {
+ get: function() {
+ assertEquals('object', typeof this);
+ return function() {
+ return oneAndTwo.entries();
+ };
+ },
+ configurable: true
+ });
+
+ var map = new ctor(42);
+ assertSize(2, map);
+ assertEquals(1, map.get(k1));
+ assertEquals(2, map.get(k2));
+
+ delete Number.prototype[Symbol.iterator];
+}
+TestMapConstructorIterableValue(Map);
+TestMapConstructorIterableValue(WeakMap);
--
--
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/d/optout.