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
Copy file name to clipboardExpand all lines: spec.emu
+69-61Lines changed: 69 additions & 61 deletions
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,9 @@ contributors: Arthur Fiorette, Arlen Beiler
12
12
13
13
<emu-intro id="sec-intro">
14
14
<h1>Introduction</h1>
15
+
<emu-note>
16
+
<p><strong>Important Notice:</strong> Until this proposal is accepted by ECMA, this spec.emu file might not reflect the latest updates to the proposal. Readers should base their understanding primarily on the current <a href="https://github.com/arthurfiorette/proposal-try-operator/blob/main/README.md">README.md</a> file, which serves as the authoritative source during the proposal stage. This specification is an imagination of what the final specification might look like and while it can be trusted as a reference, the README.md has higher importance at this stage of the project.</p>
17
+
</emu-note>
15
18
<p>This proposal introduces a `try` operator and `Result` class to JavaScript for improved error handling ergonomics. The `try` operator evaluates an expression within an implicit try-catch block and returns a `Result` instance containing either the successful value or the caught error.</p>
16
19
</emu-intro>
17
20
@@ -20,13 +23,25 @@ contributors: Arthur Fiorette, Arlen Beiler
20
23
21
24
<emu-clause id="sec-result-constructor">
22
25
<h1>The Result Constructor</h1>
23
-
<p>The Result constructor is not intended to be called as a constructor. It throws a *TypeError* exception if called with `new`.</p>
26
+
<p>The Result constructor is the %Result% intrinsic object. When called as a constructor, it creates and initializes a new Result object.</p>
24
27
25
28
<emu-clause id="sec-result">
26
-
<h1>Result ( )</h1>
27
-
<p>When `Result` is called, the following steps are taken:</p>
29
+
<h1>Result ( _ok_, _error_, _value_ )</h1>
30
+
<p>When `Result` is called with arguments _ok_, _error_, and _value_, the following steps are taken:</p>
28
31
<emu-alg>
29
-
1. Throw a *TypeError* exception.
32
+
1. If NewTarget is *undefined*, throw a *TypeError* exception.
33
+
1. Let _result_ be ? OrdinaryCreateFromConstructor(NewTarget, *"%Result.prototype%"*, « [[ResultState]], [[ResultValue]], [[ResultError]] »).
@@ -85,39 +119,6 @@ contributors: Arthur Fiorette, Arlen Beiler
85
119
<li>has a [[Prototype]] internal slot whose value is %Object.prototype%.</li>
86
120
</ul>
87
121
88
-
<emu-clause id="sec-result.prototype.ok">
89
-
<h1>get Result.prototype.ok</h1>
90
-
<p>`Result.prototype.ok` is an accessor property whose set accessor function is *undefined*. Its get accessor function performs the following steps:</p>
1. If _result_.[[ResultState]] is ~success~, return *true*.
95
-
1. Return *false*.
96
-
</emu-alg>
97
-
</emu-clause>
98
-
99
-
<emu-clause id="sec-result.prototype.value">
100
-
<h1>get Result.prototype.value</h1>
101
-
<p>`Result.prototype.value` is an accessor property whose set accessor function is *undefined*. Its get accessor function performs the following steps:</p>
1. If _result_.[[ResultState]] is ~failure~, throw a *TypeError* exception.
106
-
1. Return _result_.[[ResultValue]].
107
-
</emu-alg>
108
-
</emu-clause>
109
-
110
-
<emu-clause id="sec-result.prototype.error">
111
-
<h1>get Result.prototype.error</h1>
112
-
<p>`Result.prototype.error` is an accessor property whose set accessor function is *undefined*. Its get accessor function performs the following steps:</p>
0 commit comments