-
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
Editorial: use abstract closures for anonymous functions in more places #2439
Conversation
e266aad
to
96c0b63
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
1. Let _thenFinallyClosure_ be a new Abstract Closure with parameters (_value_) that captures _onFinally_ and _C_ and performs the following steps when called: | ||
1. Let _result_ be ? Call(_onFinally_, *undefined*). | ||
1. Let _promise_ be ? PromiseResolve(_C_, _result_). | ||
1. Let _returnValue_ be a new Abstract Closure with no parameters that captures _value_ and performs the following steps when called: | ||
1. Return _value_. | ||
1. Let _valueThunk_ be ! CreateBuiltinFunction(_returnValue_, 0, *""*, « »). | ||
1. Return ? Invoke(_promise_, *"then"*, « _valueThunk_ »). | ||
1. Let _thenFinally_ be ! CreateBuiltinFunction(_thenFinallyClosure_, 1, *""*, « »). | ||
1. Let _catchFinallyClosure_ be a new Abstract Closure with parameters (_reason_) that captures _onFinally_ and _C_ and performs the following steps when called: | ||
1. Let _result_ be ? Call(_onFinally_, *undefined*). | ||
1. Let _promise_ be ? PromiseResolve(_C_, _result_). | ||
1. Let _throwReason_ be a new Abstract Closure with no parameters that captures _reason_ and performs the following steps when called: | ||
1. Return ThrowCompletion(_reason_). | ||
1. Let _thrower_ be ! CreateBuiltinFunction(_throwReason_, 0, *""*, « »). | ||
1. Return ? Invoke(_promise_, *"then"*, « _thrower_ »). | ||
1. Let _catchFinally_ be ! CreateBuiltinFunction(_catchFinallyClosure_, 1, *""*, « »). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fwiw, confirmed these exact changes pass in https://npmjs.com/promise.prototype.finally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm modulo the Proxy revoke comment.
073baa2
to
9eb54b2
Compare
9eb54b2
to
6d3c629
Compare
Followup to #2109. Fixes #1894, fixes #933, fixes #1077 (in passing, in the "less handwaving" commit).
There's still six places where I haven't adopted the new style: two (x, x) in CreateResolvingFunctions (used mainly in the Promise constructor), one in PerformPromiseAll, two (x, x) in PerformPromiseAllSettled, and one in PerformPromiseAny.
These remaining cases generally seemed nontrivial enough that I didn't think it worth inlining them. I could, I suppose, replace each with an abstract operation which returns the appropriate abstract closure (or built-in function), but that doesn't seem like it would be much of an improvement.
This is mostly a mechanical transformation. Where there was non-mutable state provided by setting internal slots, I have instead had the abstract closure capture the relevant aliases. I've left mutable state as internal slots, since abstract closures can't write to captured aliases.
One thing of note is that the Default Constructor Functions took a rest parameter, which isn't something we have established syntax for with abstract closures; I decided to mostly mimic what we do in the function constructor and refer to "the List of arguments that was passed to this function by [[Call]] or [[Construct]]" explicitly, rather than introducing syntax for rest parameters in Abstract Closures.