Align GetIterator with ES6 spec

BUG=None
LOG=N
R=adamk

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

Cr-Commit-Position: refs/heads/master@{#26759}
This commit is contained in:
arv 2015-02-19 13:38:04 -08:00 committed by Commit bot
parent a538d945e3
commit b9f006a404
4 changed files with 9 additions and 17 deletions

View File

@ -23,7 +23,7 @@ function SetConstructor(iterable) {
var iter, adder; var iter, adder;
if (!IS_NULL_OR_UNDEFINED(iterable)) { if (!IS_NULL_OR_UNDEFINED(iterable)) {
iter = GetIterator(ToObject(iterable)); iter = GetIterator(iterable);
adder = this.add; adder = this.add;
if (!IS_SPEC_FUNCTION(adder)) { if (!IS_SPEC_FUNCTION(adder)) {
throw MakeTypeError('property_not_function', ['add', this]); throw MakeTypeError('property_not_function', ['add', this]);
@ -163,7 +163,7 @@ function MapConstructor(iterable) {
var iter, adder; var iter, adder;
if (!IS_NULL_OR_UNDEFINED(iterable)) { if (!IS_NULL_OR_UNDEFINED(iterable)) {
iter = GetIterator(ToObject(iterable)); iter = GetIterator(iterable);
adder = this.set; adder = this.set;
if (!IS_SPEC_FUNCTION(adder)) { if (!IS_SPEC_FUNCTION(adder)) {
throw MakeTypeError('property_not_function', ['set', this]); throw MakeTypeError('property_not_function', ['set', this]);

View File

@ -1879,21 +1879,11 @@ SetUpFunction();
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Iterator related spec functions. // Iterator related spec functions.
// ES6 rev 26, 2014-07-18 // ES6 rev 33, 2015-02-12
// 7.4.1 CheckIterable ( obj ) // 7.4.1 GetIterator ( obj, method )
function ToIterable(obj) {
if (!IS_SPEC_OBJECT(obj)) {
return UNDEFINED;
}
return obj[symbolIterator];
}
// ES6 rev 26, 2014-07-18
// 7.4.2 GetIterator ( obj, method )
function GetIterator(obj, method) { function GetIterator(obj, method) {
if (IS_UNDEFINED(method)) { if (IS_UNDEFINED(method)) {
method = ToIterable(obj); method = ToObject(obj)[symbolIterator];
} }
if (!IS_SPEC_FUNCTION(method)) { if (!IS_SPEC_FUNCTION(method)) {
throw MakeTypeError('not_iterable', [obj]); throw MakeTypeError('not_iterable', [obj]);

View File

@ -23,7 +23,7 @@ function WeakMapConstructor(iterable) {
var iter, adder; var iter, adder;
if (!IS_NULL_OR_UNDEFINED(iterable)) { if (!IS_NULL_OR_UNDEFINED(iterable)) {
iter = GetIterator(ToObject(iterable)); iter = GetIterator(iterable);
adder = this.set; adder = this.set;
if (!IS_SPEC_FUNCTION(adder)) { if (!IS_SPEC_FUNCTION(adder)) {
throw MakeTypeError('property_not_function', ['set', this]); throw MakeTypeError('property_not_function', ['set', this]);
@ -130,7 +130,7 @@ function WeakSetConstructor(iterable) {
var iter, adder; var iter, adder;
if (!IS_NULL_OR_UNDEFINED(iterable)) { if (!IS_NULL_OR_UNDEFINED(iterable)) {
iter = GetIterator(ToObject(iterable)); iter = GetIterator(iterable);
adder = this.add; adder = this.add;
if (!IS_SPEC_FUNCTION(adder)) { if (!IS_SPEC_FUNCTION(adder)) {
throw MakeTypeError('property_not_function', ['add', this]); throw MakeTypeError('property_not_function', ['add', this]);

View File

@ -1192,6 +1192,7 @@ function TestSetConstructorIterableValue(ctor) {
get: function() { get: function() {
assertEquals('object', typeof this); assertEquals('object', typeof this);
return function() { return function() {
assertEquals('number', typeof this);
return oneAndTwo.keys(); return oneAndTwo.keys();
}; };
}, },
@ -1382,6 +1383,7 @@ function TestMapConstructorIterableValue(ctor) {
get: function() { get: function() {
assertEquals('object', typeof this); assertEquals('object', typeof this);
return function() { return function() {
assertEquals('number', typeof this);
return oneAndTwo.entries(); return oneAndTwo.entries();
}; };
}, },