summaryrefslogtreecommitdiffstats
path: root/js/src/builtin
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-03-27 13:21:40 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-03-27 13:21:40 +0200
commite19749682050ff716fc9ff3bbc05ee3911570670 (patch)
tree4213a4e8efdaadea0409642702ec6c499f7b9ccc /js/src/builtin
parent72721d1d032db2099593076bf96f274623af3c26 (diff)
parent70c8cf8db71880c1ab1f8fee4787a19316960dac (diff)
downloadUXP-e19749682050ff716fc9ff3bbc05ee3911570670.tar
UXP-e19749682050ff716fc9ff3bbc05ee3911570670.tar.gz
UXP-e19749682050ff716fc9ff3bbc05ee3911570670.tar.lz
UXP-e19749682050ff716fc9ff3bbc05ee3911570670.tar.xz
UXP-e19749682050ff716fc9ff3bbc05ee3911570670.zip
Merge remote-tracking branch 'janek/js_IteratorClose_1'
Diffstat (limited to 'js/src/builtin')
-rw-r--r--js/src/builtin/Array.js46
-rw-r--r--js/src/builtin/Classes.js2
-rw-r--r--js/src/builtin/Map.js38
-rw-r--r--js/src/builtin/Set.js36
-rw-r--r--js/src/builtin/TypedArray.js4
-rw-r--r--js/src/builtin/Utilities.js23
-rw-r--r--js/src/builtin/WeakMap.js38
-rw-r--r--js/src/builtin/WeakSet.js36
8 files changed, 29 insertions, 194 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.
diff --git a/js/src/builtin/Classes.js b/js/src/builtin/Classes.js
index d0f20b5fd..24841d605 100644
--- a/js/src/builtin/Classes.js
+++ b/js/src/builtin/Classes.js
@@ -5,7 +5,7 @@
var DefaultDerivedClassConstructor =
class extends null {
constructor(...args) {
- super(...allowContentSpread(args));
+ super(...allowContentIter(args));
}
};
MakeDefaultConstructor(DefaultDerivedClassConstructor);
diff --git a/js/src/builtin/Map.js b/js/src/builtin/Map.js
index 27a12bfff..580629a13 100644
--- a/js/src/builtin/Map.js
+++ b/js/src/builtin/Map.js
@@ -14,44 +14,14 @@ function MapConstructorInit(iterable) {
if (!IsCallable(adder))
ThrowTypeError(JSMSG_NOT_FUNCTION, typeof adder);
- // Step 6.c.
- var iterFn = iterable[std_iterator];
- if (!IsCallable(iterFn))
- ThrowTypeError(JSMSG_NOT_ITERABLE, DecompileArg(0, iterable));
-
- var iter = callContentFunction(iterFn, iterable);
- if (!IsObject(iter))
- ThrowTypeError(JSMSG_NOT_NONNULL_OBJECT, typeof iter);
-
- // Step 7 (not applicable).
-
- // Step 8.
- while (true) {
- // Step 8.a.
- var next = callContentFunction(iter.next, iter);
- if (!IsObject(next))
- ThrowTypeError(JSMSG_NOT_NONNULL_OBJECT, typeof next);
-
- // Step 8.b.
- if (next.done)
- return;
-
- // Step 8.c.
- var nextItem = next.value;
-
+ // Steps 6.c-8.
+ for (var nextItem of allowContentIter(iterable)) {
// Step 8.d.
- if (!IsObject(nextItem)) {
- IteratorCloseThrow(iter);
+ if (!IsObject(nextItem))
ThrowTypeError(JSMSG_INVALID_MAP_ITERABLE, "Map");
- }
// Steps 8.e-j.
- try {
- callContentFunction(adder, map, nextItem[0], nextItem[1]);
- } catch (e) {
- IteratorCloseThrow(iter);
- throw e;
- }
+ callContentFunction(adder, map, nextItem[0], nextItem[1]);
}
}
diff --git a/js/src/builtin/Set.js b/js/src/builtin/Set.js
index c61a49ef8..9af6cf8d1 100644
--- a/js/src/builtin/Set.js
+++ b/js/src/builtin/Set.js
@@ -14,39 +14,9 @@ function SetConstructorInit(iterable) {
if (!IsCallable(adder))
ThrowTypeError(JSMSG_NOT_FUNCTION, typeof adder);
- // Step 6.c.
- var iterFn = iterable[std_iterator];
- if (!IsCallable(iterFn))
- ThrowTypeError(JSMSG_NOT_ITERABLE, DecompileArg(0, iterable));
-
- var iter = callContentFunction(iterFn, iterable);
- if (!IsObject(iter))
- ThrowTypeError(JSMSG_NOT_NONNULL_OBJECT, typeof iter);
-
- // Step 7 (not applicable).
-
- // Step 8.
- while (true) {
- // Step 8.a.
- var next = callContentFunction(iter.next, iter);
- if (!IsObject(next))
- ThrowTypeError(JSMSG_NOT_NONNULL_OBJECT, typeof next);
-
- // Step 8.b.
- if (next.done)
- return;
-
- // Step 8.c.
- var nextValue = next.value;
-
- // Steps 8.d-e.
- try {
- callContentFunction(adder, set, nextValue);
- } catch (e) {
- IteratorCloseThrow(iter);
- throw e;
- }
- }
+ // Steps 6.c-8.
+ for (var nextValue of allowContentIter(iterable))
+ callContentFunction(adder, set, nextValue);
}
/* ES6 20121122 draft 15.16.4.6. */
diff --git a/js/src/builtin/TypedArray.js b/js/src/builtin/TypedArray.js
index 4a3f38365..a2205dc92 100644
--- a/js/src/builtin/TypedArray.js
+++ b/js/src/builtin/TypedArray.js
@@ -1428,7 +1428,7 @@ function TypedArrayStaticFrom(source, mapfn = undefined, thisArg = undefined) {
// 22.2.2.1.1 IterableToList, step 4.a.
var next = callContentFunction(iterator.next, iterator);
if (!IsObject(next))
- ThrowTypeError(JSMSG_NEXT_RETURNED_PRIMITIVE);
+ ThrowTypeError(JSMSG_ITER_METHOD_RETURNED_PRIMITIVE, "next");
// 22.2.2.1.1 IterableToList, step 4.b.
if (next.done)
@@ -1555,7 +1555,7 @@ function IterableToList(items, method) {
// Step 4.a.
var next = callContentFunction(iterator.next, iterator);
if (!IsObject(next))
- ThrowTypeError(JSMSG_NEXT_RETURNED_PRIMITIVE);
+ ThrowTypeError(JSMSG_ITER_METHOD_RETURNED_PRIMITIVE, "next");
// Step 4.b.
if (next.done)
diff --git a/js/src/builtin/Utilities.js b/js/src/builtin/Utilities.js
index 2dece3801..bfb1fe7f4 100644
--- a/js/src/builtin/Utilities.js
+++ b/js/src/builtin/Utilities.js
@@ -154,29 +154,6 @@ function GetIterator(obj, method) {
return iterator;
}
-// ES2017 draft rev 7.4.6.
-// When completion.[[Type]] is throw.
-function IteratorCloseThrow(iter) {
- // Steps 1-2 (implicit)
-
- // Step 3.
- var returnMethod = GetMethod(iter, "return");
-
- // Step 4 (done in caller).
- if (returnMethod === undefined)
- return;
-
- try {
- // Step 5.
- callContentFunction(returnMethod, iter);
- } catch (e) {
- }
-
- // Step 6 (done in caller).
-
- // Steps 7-9 (skipped).
-}
-
var _builtinCtorsCache = {__proto__: null};
function GetBuiltinConstructor(builtinName) {
diff --git a/js/src/builtin/WeakMap.js b/js/src/builtin/WeakMap.js
index 708be8424..6755b7a7b 100644
--- a/js/src/builtin/WeakMap.js
+++ b/js/src/builtin/WeakMap.js
@@ -14,43 +14,13 @@ function WeakMapConstructorInit(iterable) {
if (!IsCallable(adder))
ThrowTypeError(JSMSG_NOT_FUNCTION, typeof adder);
- // Step 6.c.
- var iterFn = iterable[std_iterator];
- if (!IsCallable(iterFn))
- ThrowTypeError(JSMSG_NOT_ITERABLE, DecompileArg(0, iterable));
-
- var iter = callContentFunction(iterFn, iterable);
- if (!IsObject(iter))
- ThrowTypeError(JSMSG_NOT_NONNULL_OBJECT, typeof iter);
-
- // Step 7 (not applicable).
-
- // Step 8.
- while (true) {
- // Step 8.a.
- var next = callContentFunction(iter.next, iter);
- if (!IsObject(next))
- ThrowTypeError(JSMSG_NOT_NONNULL_OBJECT, typeof next);
-
- // Step 8.b.
- if (next.done)
- return;
-
- // Step 8.c.
- var nextItem = next.value;
-
+ // Steps 6.c-8.
+ for (var nextItem of allowContentIter(iterable)) {
// Step 8.d.
- if (!IsObject(nextItem)) {
- IteratorCloseThrow(iter);
+ if (!IsObject(nextItem))
ThrowTypeError(JSMSG_INVALID_MAP_ITERABLE, "WeakMap");
- }
// Steps 8.e-j.
- try {
- callContentFunction(adder, map, nextItem[0], nextItem[1]);
- } catch (e) {
- IteratorCloseThrow(iter);
- throw e;
- }
+ callContentFunction(adder, map, nextItem[0], nextItem[1]);
}
}
diff --git a/js/src/builtin/WeakSet.js b/js/src/builtin/WeakSet.js
index 8589f9dc6..b16b4634d 100644
--- a/js/src/builtin/WeakSet.js
+++ b/js/src/builtin/WeakSet.js
@@ -14,39 +14,9 @@ function WeakSetConstructorInit(iterable) {
if (!IsCallable(adder))
ThrowTypeError(JSMSG_NOT_FUNCTION, typeof adder);
- // Step 6.c.
- var iterFn = iterable[std_iterator];
- if (!IsCallable(iterFn))
- ThrowTypeError(JSMSG_NOT_ITERABLE, DecompileArg(0, iterable));
-
- var iter = callContentFunction(iterFn, iterable);
- if (!IsObject(iter))
- ThrowTypeError(JSMSG_NOT_NONNULL_OBJECT, typeof iter);
-
- // Step 7 (not applicable).
-
- // Step 8.
- while (true) {
- // Step 8.a.
- var next = callContentFunction(iter.next, iter);
- if (!IsObject(next))
- ThrowTypeError(JSMSG_NOT_NONNULL_OBJECT, typeof next);
-
- // Step 8.b.
- if (next.done)
- return;
-
- // Step 8.c.
- var nextValue = next.value;
-
- // Steps 8.d-e.
- try {
- callContentFunction(adder, set, nextValue);
- } catch (e) {
- IteratorCloseThrow(iter);
- throw e;
- }
- }
+ // Steps 6.c-8.
+ for (var nextValue of allowContentIter(iterable))
+ callContentFunction(adder, set, nextValue);
}
// 23.4.3.1