summaryrefslogtreecommitdiffstats
path: root/js/src/builtin
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-03-15 21:12:39 +0100
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-03-15 21:12:39 +0100
commit114794557687aebca601c38ba0f0a52a43b44d4a (patch)
tree1ca375db23843dcd4c593bcb28d7173856bddc10 /js/src/builtin
parent25550ce903d01f31bead59de945e4adf86819440 (diff)
downloadUXP-114794557687aebca601c38ba0f0a52a43b44d4a.tar
UXP-114794557687aebca601c38ba0f0a52a43b44d4a.tar.gz
UXP-114794557687aebca601c38ba0f0a52a43b44d4a.tar.lz
UXP-114794557687aebca601c38ba0f0a52a43b44d4a.tar.xz
UXP-114794557687aebca601c38ba0f0a52a43b44d4a.zip
Close iterator after error in Promise.{all,race}
Issue #17
Diffstat (limited to 'js/src/builtin')
-rw-r--r--js/src/builtin/Promise.cpp53
1 files changed, 36 insertions, 17 deletions
diff --git a/js/src/builtin/Promise.cpp b/js/src/builtin/Promise.cpp
index 59c97e529..c781a336d 100644
--- a/js/src/builtin/Promise.cpp
+++ b/js/src/builtin/Promise.cpp
@@ -1369,7 +1369,8 @@ PromiseObject::create(JSContext* cx, HandleObject executor, HandleObject proto /
static MOZ_MUST_USE bool PerformPromiseAll(JSContext *cx, JS::ForOfIterator& iterator,
HandleObject C, HandleObject promiseObj,
- HandleObject resolve, HandleObject reject);
+ HandleObject resolve, HandleObject reject,
+ bool* done);
// ES2016, 25.4.4.1.
static bool
@@ -1410,12 +1411,14 @@ Promise_static_all(JSContext* cx, unsigned argc, Value* vp)
// Step 6 (implicit).
// Step 7.
- bool result = PerformPromiseAll(cx, iter, C, resultPromise, resolve, reject);
+ bool done;
+ bool result = PerformPromiseAll(cx, iter, C, resultPromise, resolve, reject, &done);
// Step 8.
if (!result) {
// Step 8.a.
- // TODO: implement iterator closing.
+ if (!done)
+ iter.closeThrow();
// Step 8.b.
return AbruptRejectPromise(cx, args, resultPromise, reject);
@@ -1598,8 +1601,11 @@ RunResolutionFunction(JSContext *cx, HandleObject resolutionFun, HandleValue res
// ES2016, 25.4.4.1.1.
static MOZ_MUST_USE bool
PerformPromiseAll(JSContext *cx, JS::ForOfIterator& iterator, HandleObject C,
- HandleObject promiseObj, HandleObject resolve, HandleObject reject)
+ HandleObject promiseObj, HandleObject resolve, HandleObject reject,
+ bool* done)
{
+ *done = false;
+
RootedObject unwrappedPromiseObj(cx);
if (IsWrapper(promiseObj)) {
unwrappedPromiseObj = CheckedUnwrap(promiseObj);
@@ -1666,14 +1672,19 @@ PerformPromiseAll(JSContext *cx, JS::ForOfIterator& iterator, HandleObject C,
RootedValue rejectFunVal(cx, ObjectOrNullValue(reject));
while (true) {
- bool done;
- // Steps a, b, c, e, f, g.
- if (!iterator.next(&nextValue, &done))
+ // Steps a-c, e-g.
+ if (!iterator.next(&nextValue, done)) {
+ // Steps b, f.
+ *done = true;
+
+ // Steps c, g.
return false;
+ }
// Step d.
- if (done) {
+ if (*done) {
// Step d.i (implicit).
+
// Step d.ii.
int32_t remainingCount = dataHolder->decreaseRemainingCount();
@@ -1822,7 +1833,8 @@ PromiseAllResolveElementFunction(JSContext* cx, unsigned argc, Value* vp)
static MOZ_MUST_USE bool PerformPromiseRace(JSContext *cx, JS::ForOfIterator& iterator,
HandleObject C, HandleObject promiseObj,
- HandleObject resolve, HandleObject reject);
+ HandleObject resolve, HandleObject reject,
+ bool* done);
// ES2016, 25.4.4.3.
static bool
@@ -1863,12 +1875,14 @@ Promise_static_race(JSContext* cx, unsigned argc, Value* vp)
// Step 6 (implicit).
// Step 7.
- bool result = PerformPromiseRace(cx, iter, C, resultPromise, resolve, reject);
+ bool done;
+ bool result = PerformPromiseRace(cx, iter, C, resultPromise, resolve, reject, &done);
// Step 8.
if (!result) {
// Step 8.a.
- // TODO: implement iterator closing.
+ if (!done)
+ iter.closeThrow();
// Step 8.b.
return AbruptRejectPromise(cx, args, resultPromise, reject);
@@ -1882,25 +1896,30 @@ Promise_static_race(JSContext* cx, unsigned argc, Value* vp)
// ES2016, 25.4.4.3.1.
static MOZ_MUST_USE bool
PerformPromiseRace(JSContext *cx, JS::ForOfIterator& iterator, HandleObject C,
- HandleObject promiseObj, HandleObject resolve, HandleObject reject)
+ HandleObject promiseObj, HandleObject resolve, HandleObject reject,
+ bool* done)
{
+ *done = false;
MOZ_ASSERT(C->isConstructor());
RootedValue CVal(cx, ObjectValue(*C));
RootedValue nextValue(cx);
RootedValue resolveFunVal(cx, ObjectOrNullValue(resolve));
RootedValue rejectFunVal(cx, ObjectOrNullValue(reject));
- bool done;
while (true) {
// Steps a-c, e-g.
- if (!iterator.next(&nextValue, &done))
+ if (!iterator.next(&nextValue, done)) {
+ // Steps b, f.
+ *done = true;
+
+ // Steps c, g.
return false;
+ }
// Step d.
- if (done) {
- // Step d.i.
- // TODO: implement iterator closing.
+ if (*done) {
+ // Step d.i (implicit).
// Step d.ii.
return true;