From b9f006a4047c0c486302adb6850900e6e8a1a0db Mon Sep 17 00:00:00 2001 From: arv Date: Thu, 19 Feb 2015 13:38:04 -0800 Subject: [PATCH] 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} --- src/collection.js | 4 ++-- src/v8natives.js | 16 +++------------- src/weak-collection.js | 4 ++-- test/mjsunit/es6/collections.js | 2 ++ 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/collection.js b/src/collection.js index 94bda70357..9b5716687b 100644 --- a/src/collection.js +++ b/src/collection.js @@ -23,7 +23,7 @@ function SetConstructor(iterable) { var iter, adder; if (!IS_NULL_OR_UNDEFINED(iterable)) { - iter = GetIterator(ToObject(iterable)); + iter = GetIterator(iterable); adder = this.add; if (!IS_SPEC_FUNCTION(adder)) { throw MakeTypeError('property_not_function', ['add', this]); @@ -163,7 +163,7 @@ function MapConstructor(iterable) { var iter, adder; if (!IS_NULL_OR_UNDEFINED(iterable)) { - iter = GetIterator(ToObject(iterable)); + iter = GetIterator(iterable); adder = this.set; if (!IS_SPEC_FUNCTION(adder)) { throw MakeTypeError('property_not_function', ['set', this]); diff --git a/src/v8natives.js b/src/v8natives.js index 23143345f6..3cba466494 100644 --- a/src/v8natives.js +++ b/src/v8natives.js @@ -1879,21 +1879,11 @@ SetUpFunction(); // ---------------------------------------------------------------------------- // Iterator related spec functions. -// ES6 rev 26, 2014-07-18 -// 7.4.1 CheckIterable ( obj ) -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 ) +// ES6 rev 33, 2015-02-12 +// 7.4.1 GetIterator ( obj, method ) function GetIterator(obj, method) { if (IS_UNDEFINED(method)) { - method = ToIterable(obj); + method = ToObject(obj)[symbolIterator]; } if (!IS_SPEC_FUNCTION(method)) { throw MakeTypeError('not_iterable', [obj]); diff --git a/src/weak-collection.js b/src/weak-collection.js index a44c3d7cd7..3cec9cc507 100644 --- a/src/weak-collection.js +++ b/src/weak-collection.js @@ -23,7 +23,7 @@ function WeakMapConstructor(iterable) { var iter, adder; if (!IS_NULL_OR_UNDEFINED(iterable)) { - iter = GetIterator(ToObject(iterable)); + iter = GetIterator(iterable); adder = this.set; if (!IS_SPEC_FUNCTION(adder)) { throw MakeTypeError('property_not_function', ['set', this]); @@ -130,7 +130,7 @@ function WeakSetConstructor(iterable) { var iter, adder; if (!IS_NULL_OR_UNDEFINED(iterable)) { - iter = GetIterator(ToObject(iterable)); + iter = GetIterator(iterable); adder = this.add; if (!IS_SPEC_FUNCTION(adder)) { throw MakeTypeError('property_not_function', ['add', this]); diff --git a/test/mjsunit/es6/collections.js b/test/mjsunit/es6/collections.js index 92cd087839..7f8b4a5feb 100644 --- a/test/mjsunit/es6/collections.js +++ b/test/mjsunit/es6/collections.js @@ -1192,6 +1192,7 @@ function TestSetConstructorIterableValue(ctor) { get: function() { assertEquals('object', typeof this); return function() { + assertEquals('number', typeof this); return oneAndTwo.keys(); }; }, @@ -1382,6 +1383,7 @@ function TestMapConstructorIterableValue(ctor) { get: function() { assertEquals('object', typeof this); return function() { + assertEquals('number', typeof this); return oneAndTwo.entries(); }; },