From 6fb6a7f49078289bda22d4266637e350e47da87f Mon Sep 17 00:00:00 2001 From: Jason Orendorff Date: Fri, 6 Jun 2014 13:59:46 -0400 Subject: [PATCH] Backout rev 0c9ff69d4263 to re-land with proper credit. Bug 904723, no_r=me. --- js/src/builtin/Array.js | 25 ++++++------------------ js/src/js.msg | 2 +- js/src/tests/ecma_6/Array/from_errors.js | 11 ----------- js/src/tests/ecma_6/Array/from_proxy.js | 10 +--------- 4 files changed, 8 insertions(+), 40 deletions(-) diff --git a/js/src/builtin/Array.js b/js/src/builtin/Array.js index 4dc281d0fd97..96715314079d 100644 --- a/js/src/builtin/Array.js +++ b/js/src/builtin/Array.js @@ -660,7 +660,7 @@ function ArrayKeys() { return CreateArrayIterator(this, ITEM_KIND_KEY); } -/* ES6 rev 25 (2014 May 22) 22.1.2.1 */ +/* ES6 rev 24 (2014 April 27) 22.1.2.1 */ function ArrayFrom(arrayLike, mapfn=undefined, thisArg=undefined) { // Step 1. var C = this; @@ -677,36 +677,23 @@ function ArrayFrom(arrayLike, mapfn=undefined, thisArg=undefined) { var attrs = ATTR_CONFIGURABLE | ATTR_ENUMERABLE | ATTR_WRITABLE; // Steps 6-8. - var usingIterator = items["@@iterator"]; - if (usingIterator !== undefined) { + if (items["@@iterator"] !== undefined) { // Steps 8.a-c. var A = IsConstructor(C) ? new C() : []; - // Steps 8.d-e. - var iterator = callFunction(usingIterator, items); - // Step 8.f. var k = 0; - // Steps 8.g.i-vi. - // These steps cannot be implemented using a for-of loop. - // See . - var next; - while (true) { - // Steps 8.g.ii-vi. - next = iterator.next(); - if (!IsObject(next)) - ThrowError(JSMSG_NEXT_RETURNED_PRIMITIVE); - if (next.done) - break; // Substeps of 8.g.iv are implemented below. - var nextValue = next.value; - + // Steps 8.d-e and 8.g.i-vi. + for (var nextValue of items) { // Steps 8.g.vii-viii. var mappedValue = mapping ? callFunction(mapfn, thisArg, nextValue, k) : nextValue; // Steps 8.g.ix-xi. _DefineDataProperty(A, k++, mappedValue, attrs); } + + // Here we're at step 8.g.iv.1. Fall through; it's implemented below. } else { // Step 9 is an assertion: items is not an Iterator. Testing this is // literally the very last thing we did, so we don't assert here. diff --git a/js/src/js.msg b/js/src/js.msg index f227dabcafcc..79adb5c82ab6 100644 --- a/js/src/js.msg +++ b/js/src/js.msg @@ -357,7 +357,7 @@ MSG_DEF(JSMSG_ALREADY_HAS_PRAGMA, 303, 2, JSEXN_ERR, "{0} is being assigned MSG_DEF(JSMSG_PAR_ARRAY_BAD_ARG, 304, 0, JSEXN_RANGEERR, "invalid parallel method argument") MSG_DEF(JSMSG_REGEXP_RUNTIME_ERROR, 305, 0, JSEXN_INTERNALERR, "an error occurred while executing regular expression") MSG_DEF(JSMSG_DEBUG_OPTIMIZED_OUT, 306, 0, JSEXN_ERR, "variable has been optimized out") -MSG_DEF(JSMSG_NEXT_RETURNED_PRIMITIVE,307, 0, JSEXN_TYPEERR, "iterator.next() returned a non-object value") +MSG_DEF(JSMSG_UNUSED307, 307, 0, JSEXN_NONE, "") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_CONFLICT, 308, 0, JSEXN_ERR, "no conflict resolution function provided") MSG_DEF(JSMSG_PAR_ARRAY_SCATTER_BOUNDS, 309, 0, JSEXN_ERR, "index in scatter vector out of bounds") MSG_DEF(JSMSG_CANT_REPORT_NC_AS_NE, 310, 0, JSEXN_TYPEERR, "proxy can't report a non-configurable own property as non-existent") diff --git a/js/src/tests/ecma_6/Array/from_errors.js b/js/src/tests/ecma_6/Array/from_errors.js index ad494a3507c0..17cb0d769d86 100644 --- a/js/src/tests/ecma_6/Array/from_errors.js +++ b/js/src/tests/ecma_6/Array/from_errors.js @@ -130,16 +130,5 @@ assertThrowsValue(() => Array.from.call(C, arrayish, () => { throw exc; }), exc) assertEq(log, "lC0"); assertEq(obj instanceof C, true); -// It's a TypeError if the iterator's .next() method returns a primitive. -for (var primitive of [undefined, null, 17]) { - assertThrowsInstanceOf( - () => Array.from({ - "@@iterator": () => { - next: () => primitive - } - }), - TypeError); -} - if (typeof reportCompare === 'function') reportCompare(0, 0); diff --git a/js/src/tests/ecma_6/Array/from_proxy.js b/js/src/tests/ecma_6/Array/from_proxy.js index 40505e8a83e9..ad3785c88484 100644 --- a/js/src/tests/ecma_6/Array/from_proxy.js +++ b/js/src/tests/ecma_6/Array/from_proxy.js @@ -36,17 +36,9 @@ assertDeepEq(log, ["define 0", "define 1", "define 2", "set length"]); // calls handler.get on it. log = []; assertDeepEq(Array.from(new LoggingProxy([3, 4, 5])), [3, 4, 5]); -assertDeepEq(log, ["get @@iterator", +assertDeepEq(log, ["get @@iterator", "get @@iterator", "get length", "get 0", "get length", "get 1", "get length", "get 2", "get length"]); -// Array-like iteration only gets the length once. -log = []; -var arr = [5, 6, 7]; -arr["@@iterator"] = undefined; -assertDeepEq(Array.from(new LoggingProxy(arr)), [5, 6, 7]); -assertDeepEq(log, ["get @@iterator", - "get length", "get 0", "get 1", "get 2"]); - if (typeof reportCompare === 'function') reportCompare(0, 0);