summaryrefslogtreecommitdiffstats
path: root/js/src/builtin/Array.js
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-03-24 12:15:02 +0100
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-03-24 12:15:02 +0100
commit4b487efb58bfba4c3f67d898e86b9f6daaab59b2 (patch)
treeedfe3d4039917175b4c0966de99b2979e3e067e1 /js/src/builtin/Array.js
parent2d2a60cdae0fb5ac13eb544e54495f54ac886c6c (diff)
downloadUXP-4b487efb58bfba4c3f67d898e86b9f6daaab59b2.tar
UXP-4b487efb58bfba4c3f67d898e86b9f6daaab59b2.tar.gz
UXP-4b487efb58bfba4c3f67d898e86b9f6daaab59b2.tar.lz
UXP-4b487efb58bfba4c3f67d898e86b9f6daaab59b2.tar.xz
UXP-4b487efb58bfba4c3f67d898e86b9f6daaab59b2.zip
Bug 1147371: Convert self-hosted code that need to call IteratorClose to use for-of
Issue #74
Diffstat (limited to 'js/src/builtin/Array.js')
-rw-r--r--js/src/builtin/Array.js46
1 files changed, 12 insertions, 34 deletions
diff --git a/js/src/builtin/Array.js b/js/src/builtin/Array.js
index 5ab0b71be..45f90a7b8 100644
--- a/js/src/builtin/Array.js
+++ b/js/src/builtin/Array.js
@@ -803,54 +803,32 @@ function ArrayFrom(items, mapfn=undefined, thisArg=undefined) {
// Steps 5.a-c.
var A = IsConstructor(C) ? new C() : [];
- // Step 5.c.
- var iterator = GetIterator(items, usingIterator);
-
// Step 5.d.
var k = 0;
- // Step 5.e.
- // These steps cannot be implemented using a for-of loop.
- // See <https://bugs.ecmascript.org/show_bug.cgi?id=2883>.
- while (true) {
+ // Step 5.c, 5.e.
+ var iteratorWrapper = { [std_iterator]() { return GetIterator(items, usingIterator); } };
+ for (var nextValue of allowContentIter(iteratorWrapper)) {
// Step 5.e.i.
// Disabled for performance reason. We won't hit this case on
// normal array, since _DefineDataProperty will throw before it.
// We could hit this when |A| is a proxy and it ignores
// |_DefineDataProperty|, but it happens only after too long loop.
/*
- if (k >= 0x1fffffffffffff) {
- IteratorCloseThrow(iterator);
+ if (k >= 0x1fffffffffffff)
ThrowTypeError(JSMSG_TOO_LONG_ARRAY);
- }
*/
- // Step 5.e.iii.
- var next = callContentFunction(iterator.next, iterator);
- if (!IsObject(next))
- ThrowTypeError(JSMSG_NEXT_RETURNED_PRIMITIVE);
-
- // Step 5.e.iv.
- if (next.done) {
- A.length = k;
- return A;
- }
-
- // Steps 5.e.v.
- var nextValue = next.value;
-
// Steps 5.e.vi-vii.
- try {
- var mappedValue = mapping ? callContentFunction(mapfn, thisArg, nextValue, k) : nextValue;
-
- // Steps 5.e.ii (reordered), 5.e.viii.
- _DefineDataProperty(A, k++, mappedValue);
- } catch (e) {
- // Steps 5.e.vi.2, 5.e.ix.
- IteratorCloseThrow(iterator);
- throw e;
- }
+ var mappedValue = mapping ? callContentFunction(mapfn, thisArg, nextValue, k) : nextValue;
+
+ // Steps 5.e.ii (reordered), 5.e.viii.
+ _DefineDataProperty(A, k++, mappedValue);
}
+
+ // Step 5.e.iv.
+ A.length = k;
+ return A;
}
// Step 7.