You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h1>Shorthands for Unwrapping Completion Records</h1>
1084
+
<p>Prefix `?` and `!` are used as shorthands which unwrap Completion Records. `?` is used to propagate an abrupt completion to the caller, or otherwise to unwrap a normal completion. `!` is used to assert that a Completion Record is normal and unwrap it. Formally, the step</p>
1085
1085
<emu-alg example>
1086
-
1. ReturnIfAbrupt(_argument_).
1086
+
1. Let _result_ be ? _record_.
1087
1087
</emu-alg>
1088
-
<p>mean the same thing as:</p>
1088
+
<p>is equivalent to</p>
1089
1089
<emu-alg example>
1090
-
1. Assert: _argument_ is a Completion Record.
1091
-
1. If _argument_ is an abrupt completion, return Completion(_argument_).
1092
-
1. Else, set _argument_ to _argument_.[[Value]].
1090
+
1. Assert: _record_ is a Completion Record.
1091
+
1. If _record_ is an abrupt completion, return _record_.
1092
+
1. Let _result_ be _record_.[[Value]].
1093
1093
</emu-alg>
1094
-
<p>Algorithms steps that say or are otherwise equivalent to:</p>
1094
+
<p>Likewise, the step</p>
1095
1095
<emu-alg example>
1096
-
1. ReturnIfAbrupt(AbstractOperation()).
1096
+
1. Let _result_ be ! _record_.
1097
1097
</emu-alg>
1098
-
<p>mean the same thing as:</p>
1098
+
<p>is equivalent to</p>
1099
1099
<emu-alg example>
1100
-
1. Let _hygienicTemp_ be AbstractOperation().
1101
-
1. Assert: _hygienicTemp_ is a Completion Record.
1102
-
1. If _hygienicTemp_ is an abrupt completion, return Completion(_hygienicTemp_).
1103
-
1. Else, set _hygienicTemp_ to _hygienicTemp_.[[Value]].
1100
+
1. Assert: _record_ is a normal completion.
1101
+
1. Let _result_ be _record_.[[Value]].
1104
1102
</emu-alg>
1105
-
<p>Where _hygienicTemp_ is ephemeral and visible only in the steps pertaining to ReturnIfAbrupt.</p>
1106
-
<p>Algorithms steps that say or are otherwise equivalent to:</p>
1103
+
<p>When `?` or `!` is used in any other context, first apply the rewrite given in <emu-xref href="#sec-evaluation-order" title></emu-xref> until this rule can be applied, then apply this rule. For example, the step</p>
1107
1104
<emu-alg example>
1108
-
1. Let _result_ be AbstractOperation(ReturnIfAbrupt(_argument_)).
1105
+
1. Perform AO(? Other()).
1109
1106
</emu-alg>
1110
-
<p>mean the same thing as:</p>
1107
+
<p>can be rewritten to</p>
1111
1108
<emu-alg example>
1112
-
1. Assert: _argument_ is a Completion Record.
1113
-
1. If _argument_ is an abrupt completion, return Completion(_argument_).
1114
-
1. Else, set _argument_ to _argument_.[[Value]].
1115
-
1. Let _result_ be AbstractOperation(_argument_).
1109
+
1. Let _tmp1_ be Other().
1110
+
1. Let _tmp2_ be ? _tmp1_.
1111
+
1. Perform AO(_tmp2_).
1116
1112
</emu-alg>
1117
-
</emu-clause>
1118
-
1119
-
<emu-clause id="sec-returnifabrupt-shorthands">
1120
-
<h1>ReturnIfAbrupt Shorthands</h1>
1121
-
<p>Invocations of abstract operations and syntax-directed operations that are prefixed by `?` indicate that ReturnIfAbrupt should be applied to the resulting Completion Record. For example, the step:</p>
1122
-
<emu-alg example>
1123
-
1. ? OperationName().
1124
-
</emu-alg>
1125
-
<p>is equivalent to the following step:</p>
1126
-
<emu-alg example>
1127
-
1. ReturnIfAbrupt(OperationName()).
1128
-
</emu-alg>
1129
-
<p>Similarly, for method application style, the step:</p>
1130
-
<emu-alg example>
1131
-
1. ? _someValue_.OperationName().
1132
-
</emu-alg>
1133
-
<p>is equivalent to:</p>
1134
-
<emu-alg example>
1135
-
1. ReturnIfAbrupt(_someValue_.OperationName()).
1136
-
</emu-alg>
1137
-
<p>Similarly, prefix `!` is used to indicate that the following invocation of an abstract or syntax-directed operation will never return an abrupt completion and that the resulting Completion Record's [[Value]] field should be used in place of the return value of the operation. For example, the step:</p>
1138
-
<emu-alg example>
1139
-
1. Let _val_ be ! OperationName().
1140
-
</emu-alg>
1141
-
<p>is equivalent to the following steps:</p>
1142
-
<emu-alg example>
1143
-
1. Let _val_ be OperationName().
1144
-
1. Assert: _val_ is a normal completion.
1145
-
1. Set _val_ to _val_.[[Value]].
1146
-
</emu-alg>
1147
-
<p>Syntax-directed operations for runtime semantics make use of this shorthand by placing `!` or `?` before the invocation of the operation:</p>
1113
+
<p>which in turn expands to</p>
1148
1114
<emu-alg example>
1149
-
1. Perform ! SyntaxDirectedOperation of |NonTerminal|.
1115
+
1. Let _tmp1_ be Other().
1116
+
1. Assert: _tmp1_ is a Completion Record.
1117
+
1. If _tmp1_ is an abrupt completion, return _tmp1_.
0 commit comments