diff options
author | Moonchild <mcwerewolf@gmail.com> | 2018-03-16 08:36:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-16 08:36:30 +0100 |
commit | 11bdaa144d8a38ecd897dde278cb1db9b8313961 (patch) | |
tree | 1ca375db23843dcd4c593bcb28d7173856bddc10 /js/src/vm | |
parent | 0d3ee51ad2d61bffba14232b2df913d3a773d771 (diff) | |
parent | 114794557687aebca601c38ba0f0a52a43b44d4a (diff) | |
download | UXP-11bdaa144d8a38ecd897dde278cb1db9b8313961.tar UXP-11bdaa144d8a38ecd897dde278cb1db9b8313961.tar.gz UXP-11bdaa144d8a38ecd897dde278cb1db9b8313961.tar.lz UXP-11bdaa144d8a38ecd897dde278cb1db9b8313961.tar.xz UXP-11bdaa144d8a38ecd897dde278cb1db9b8313961.zip |
Merge pull request #66 from janekptacijarabaci/js_iterable_closures_1
Close iterator after error in: Map, Set, WeakMap, WeakSet, Array.from, Promise.{all,race}
Diffstat (limited to 'js/src/vm')
-rw-r--r-- | js/src/vm/ForOfIterator.cpp | 51 |
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() { |