I know there are a few posts about this, but I have yet to find a good explanation of what a ReturnIfAbrupt(AbstractOperation())
statement evaluates to when the AbstractOperation()
is not an abrupt completion?
According to ECMAScript ReturnIfAbrupt(AbstractOperation()) means:
- Let hygienicTemp be AbstractOperation().
- If hygienicTemp is an abrupt completion, return hygienicTemp.
- Else if hygienicTemp is a Completion Record, set hygienicTemp to hygienicTemp.[[Value]].
Where hygienicTemp is ephemeral and visible only in the steps pertaining to ReturnIfAbrupt.
Taking the last line in the [[Construct]] operation as an example:
Return ? envRec.GetThisBinding()
Return ReturnIfAbrupt(envRec.GetThisBinding())
GetThisBinding()
does not throw an Error
(i.e. no abrupt completion), I have no idea what is actually returnedReturnIfAbrupt
definition above specifically says hygenicTemp
only relates to the steps within the definition itself. It gives no hint of what the expression as a whole evaluates toThe bit you've quoted is for when the value isn't used. But your [[Construct]]
example is using the value.
For that, you needed to scroll down a little bit:
Algorithms steps that say or are otherwise equivalent to:
- Let result be AbstractOperation(ReturnIfAbrupt(argument)).
mean the same thing as:
If argument is an abrupt completion, return argument.
If argument is a Completion Record, set argument to argument.[[Value]].
Let result be AbstractOperation(argument).
So for Return ? envRec.GetThisBinding()
, when envRec.GetThisBinding()
doesn't return an abrupt completion, that line in [[Construct]]
returns the [[Value]]
of the non-abrupt completion record from envRec.GetThisBinding()
(the this
value).