generated from tc39/template-for-proposals
-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathspec.emu
137 lines (131 loc) · 4.13 KB
/
spec.emu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!doctype html>
<meta charset="utf8">
<link rel="stylesheet" href="./spec.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
<script src="./spec.js"></script>
<pre class="metadata">
title: ECMAScript Try Operator
stage: -1
contributors: Arthur Fiorette, Arlen Beiler
</pre>
<emu-biblio href="node_modules/@tc39/ecma262-biblio/biblio.json"></emu-biblio>
<emu-clause id="sec-assignment-operators">
<h1>Assignment Operators</h1>
<h2>Syntax</h2>
<emu-grammar type="definition">
AssignmentExpression[In, Yield, Await] :
TryExpression[?In, ?Yield, ?Await]
TryExpression[In, Yield, Await] :
`try` [no LineTerminator here] [lookahead != `{`] AssignmentExpression[?In, ?Yield, ?Await]
</emu-grammar>
<emu-clause id="sec-comma-operator-runtime-semantics-evaluation" type="sdo">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>TryExpression : `try` AssignmentExpression</emu-grammar>
<emu-alg>
1. Let _A_ be Completion(Evaluation of |Expression|).
1. If _A_ is an abrupt completion, return ? TryExpressionResult(_A_).
1. Let _B_ be Completion(GetValue(_A_)).
1. Return ? TryExpressionResult(_B_).
</emu-alg>
<emu-note>
<p>GetValue must be called even though its value is not used because it may have observable side-effects.</p>
</emu-note>
</emu-clause>
<emu-clause id="sec-try-expression-result" type="abstract operation">
<h1>
TryExpressionResult (
_result_: a Completion Record,
): either a normal completion containing a Result or an abrupt completion
</h1>
<dl class="header">
</dl>
<emu-alg>
1. If _result_ is a normal completion, return Result.ok(_result_.[[VALUE]]).
1. If _result_ is a throw completion, return Result.error(_result_.[[VALUE]]).
1. Return ? _result_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-try-expression-result-ok" type="abstract operation">
<h1>
Result.ok (
_value_: an ECMAScript language value,
): a Result
</h1>
<dl class="header">
<dt>description</dt>
<dd>It is the abstract equivelant of calling `Result.ok(value)`</dd>
</dl>
</emu-clause>
<emu-clause id="sec-try-expression-result-error" type="abstract operation">
<h1>
Result.error (
_value_: an ECMAScript language value,
): a Result
</h1>
<dl class="header">
<dt>description</dt>
<dd>It is the abstract equivelant of calling `Result.error(value)`</dd>
</dl>
</emu-clause>
</emu-clause>
<emu-clause id="sec-well-known-intrinsic-objects">
<h1>Well-Known Intrinsic Objects</h1>
<emu-table id="table-well-known-intrinsic-objects" caption="Well-Known Intrinsic Objects" oldids="table-7">
<table>
<thead>
<tr>
<th>
Intrinsic Name
</th>
<th>
Global Name
</th>
<th>
ECMAScript Language Association
</th>
</tr>
</thead>
<tr>
<td>
%Result%
</td>
<td>
`Result`
</td>
<td>
The `Result` constructor (<emu-xref href="#sec-result-constructor"></emu-xref>)
</td>
</tr>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-result-constructor">
<h1>The Result Constructor</h1>
<p>The Result constructor:</p>
<ul>
<li>is <dfn variants="Result">%Result%</dfn>.</li>
<li>is the initial value of the *"Result"* property of the global object.</li>
<li>is the functional equivelant of the following code:
<pre><code class="javascript">
class Result {
constructor(ok, error, value) {
this.ok = ok
this.error = error
this.value = value
}
*[Symbol.iterator]() {
yield this.ok
yield this.error
yield this.value
}
static ok(value) {
return new Result(true, undefined, value)
}
static error(error) {
return new Result(false, error, undefined)
}
}
</code></pre>
</li>
</ul>
</emu-clause>