summaryrefslogtreecommitdiffstats
path: root/js/src/vm/ForOfIterator.cpp
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/vm/ForOfIterator.cpp
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/vm/ForOfIterator.cpp')
-rw-r--r--js/src/vm/ForOfIterator.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/js/src/vm/ForOfIterator.cpp b/js/src/vm/ForOfIterator.cpp
index 7bd521a6a..a67b36774 100644
--- a/js/src/vm/ForOfIterator.cpp
+++ b/js/src/vm/ForOfIterator.cpp
@@ -151,6 +151,57 @@ ForOfIterator::next(MutableHandleValue vp, bool* done)
return GetProperty(cx_, resultObj, resultObj, cx_->names().value, vp);
}
+// ES 2017 draft 0f10dba4ad18de92d47d421f378233a2eae8f077 7.4.6.
+// When completion.[[Type]] is throw.
+void
+ForOfIterator::closeThrow()
+{
+ MOZ_ASSERT(iterator);
+
+ RootedValue completionException(cx_);
+ if (cx_->isExceptionPending()) {
+ if (!GetAndClearException(cx_, &completionException))
+ completionException.setUndefined();
+ }
+
+ // Steps 1-2 (implicit)
+
+ // Step 3 (partial).
+ RootedValue returnVal(cx_);
+ if (!GetProperty(cx_, iterator, iterator, cx_->names().return_, &returnVal))
+ return;
+
+ // Step 4.
+ if (returnVal.isUndefined()) {
+ cx_->setPendingException(completionException);
+ return;
+ }
+
+ // Step 3 (remaining part)
+ if (!returnVal.isObject()) {
+ JS_ReportErrorNumberASCII(cx_, GetErrorMessage, nullptr, JSMSG_RETURN_NOT_CALLABLE);
+ return;
+ }
+ RootedObject returnObj(cx_, &returnVal.toObject());
+ if (!returnObj->isCallable()) {
+ JS_ReportErrorNumberASCII(cx_, GetErrorMessage, nullptr, JSMSG_RETURN_NOT_CALLABLE);
+ return;
+ }
+
+ // Step 5.
+ RootedValue innerResultValue(cx_);
+ if (!js::Call(cx_, returnVal, iterator, &innerResultValue)) {
+ if (cx_->isExceptionPending())
+ cx_->clearPendingException();
+ }
+
+ // Step 6.
+ cx_->setPendingException(completionException);
+
+ // Steps 7-9 (skipped).
+ return;
+}
+
bool
ForOfIterator::materializeArrayIterator()
{