-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suppress GetMethod(iterator.return) errors in IteratorClose #1398
Comments
This seems like another nice simplification to the iterator protocol (previously: #976, #988, #1021), unless there is a good reason for the currently specified behavior. @kmiller68 @bterlson |
zenparsing
pushed a commit
to zenparsing/ecma262
that referenced
this issue
Jan 14, 2019
llebout
pushed a commit
to llebout/chromium_v8
that referenced
this issue
Jun 16, 2019
As per the new specs, when the exception is thrown by iterator's return method while doing iterator close because it is not callable, the exception is suppressed in the same way as if the return method is called and threw an exception. tc39/ecma262#1398 Bug: v8:9056 Change-Id: I21abd5fdd01d3a957c3c16d9d3aaab9091e43142 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1648256 Reviewed-by: Leszek Swirski <[email protected]> Commit-Queue: Swapnil Gaikwad <[email protected]> Cr-Commit-Position: refs/heads/master@{#62035}
ljharb
pushed a commit
to zenparsing/ecma262
that referenced
this issue
Apr 6, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IteratorClose is currently specified as
IteratorClose ( iteratorRecord, completion )
Type(iteratorRecord.[[Iterator]])
isObject
.completion
is a Completion Record.iterator
beiteratorRecord.[[Iterator]]
.return
be? GetMethod(iterator, "return")
.return
is undefined, returnCompletion(completion)
.innerResult
beCall(return, iterator, « »)
.completion.[[Type]]
isthrow
, returnCompletion(completion)
.innerResult.[[Type]]
isthrow
, returnCompletion(innerResult)
.Type(innerResult.[[Value]])
is notObject
, throw aTypeError
exception.Completion(completion)
.If the outer completion is
throw
, then it is commonly understood that exceptions throw by iterator.return() should be suppressed. However, there is one exception that is not suppressed, which is iterator.return not being callable -- on 4.,? GetMethod(iterator, "return")
will return the abrupt completion of GetMethod (caused by IsCallable failing), rather than the outer completion.Therefore, errors in
GetMethod(iterator, "return")
and inCall(return, iterator, « »)
are inconsistent, and the access and call have to be split across an exception handling boundary (try-catch or similar). I suggest that we amend this to:return
beGetMethod(iterator, "return")
.return.[[Value]]
is undefined, returnCompletion(completion)
.return.[[Type]]
isthrow
andcompletion.[[Type]]
isthrow
, returnCompletion(completion)
.innerResult
beCall(return.[[Value]], iterator, « »)
.This is now consistent, and can be desugared more simply to wrap iterator.return() in a try-catch (or the equivalent of such an operation in an engine's IR).
This should not be a web-compat issue, as it is already currently inconsistent across implementations: current versions of V8 and SpiderMonkey are spec compatible, but JSC, Chakra and XS are not. This can be tested with:
Additionally, babel desugaring currently does not take this into account, desugaring the loop to something that does not check IsCallable:
A similar spec incompatibility can be constructed for array destructuring.
The text was updated successfully, but these errors were encountered: