Skip to content

Commit 973fcce

Browse files
committed
First spec draft
1 parent 8145c33 commit 973fcce

File tree

1 file changed

+115
-28
lines changed

1 file changed

+115
-28
lines changed

spec.emu

Lines changed: 115 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,123 @@
44
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
55
<script src="./spec.js"></script>
66
<pre class="metadata">
7-
title: Proposal Title Goes Here
8-
stage: -1
9-
contributors: Your Name(s) Here
7+
title: Native Promise Adoption
8+
stage: 0
9+
contributors: Mathieu Hofman
1010
</pre>
1111

12-
<emu-clause id="sec-demo-clause">
13-
<h1>This is an emu-clause</h1>
14-
<p>This is an algorithm:</p>
15-
<emu-alg>
16-
1. Let _proposal_ be *undefined*.
17-
1. If IsAccepted(_proposal_) is *true*, then
18-
1. Let _stage_ be *0*<sub>ℤ</sub>.
19-
1. Else,
20-
1. Let _stage_ be *-1*<sub>ℤ</sub>.
21-
1. Return ? ToString(_stage_).
22-
</emu-alg>
12+
<emu-clause id="sec-ecmascript-data-types-and-values" number="6">
13+
<h1>ECMAScript Data Types and Values</h1>
14+
15+
<emu-clause id="sec-ecmascript-language-types" number="1">
16+
<h1>ECMAScript Language Types</h1>
17+
18+
<emu-clause id="sec-object-type" number="7">
19+
<h1>The Object Type</h1>
20+
21+
<emu-clause id="sec-well-known-intrinsic-objects" number="4">
22+
<h1>Well-Known Intrinsic Objects</h1>
23+
<emu-table id="table-well-known-intrinsic-objects" caption="Well-Known Intrinsic Objects" number="6">
24+
<table>
25+
<thead>
26+
<tr>
27+
<th>
28+
Intrinsic Name
29+
</th>
30+
<th>
31+
Global Name
32+
</th>
33+
<th>
34+
ECMAScript Language Association
35+
</th>
36+
</tr>
37+
</thead>
38+
<tr>
39+
<td>
40+
<ins>%PromiseThenAction%</ins>
41+
</td>
42+
<td>
43+
</td>
44+
<td>
45+
<ins>An internal function object for PerformPromiseThen</ins>
46+
</td>
47+
</tr>
48+
</table>
49+
</emu-table>
50+
</emu-clause>
51+
</emu-clause>
52+
</emu-clause>
2353
</emu-clause>
2454

25-
<emu-clause id="sec-is-accepted" type="abstract operation">
26-
<h1>
27-
IsAccepted (
28-
_proposal_: an ECMAScript language value
29-
): a Boolean
30-
</h1>
31-
<dl class="header">
32-
<dt>description</dt>
33-
<dd>Tells you if the proposal was accepted</dd>
34-
</dl>
35-
<emu-alg>
36-
1. If _proposal_ is not a String, or is not accepted, return *false*.
37-
1. Return *true*.
38-
</emu-alg>
55+
<emu-clause id="sec-control-abstraction-objects" number="27">
56+
<h1>Control Abstraction Objects</h1>
57+
58+
<emu-clause id="sec-promise-objects" number="2">
59+
<h1>Promise Objects</h1>
60+
61+
<emu-clause id="sec-promise-abstract-operations" number="1">
62+
<h1>Promise Abstract Operations</h1>
63+
64+
<emu-clause id="sec-createresolvingfunctions" type="abstract operation" number="3">
65+
<h1>CreateResolvingFunctions ( _promise_ )</h1>
66+
67+
<emu-clause id="sec-promise-resolve-functions" number="2">
68+
<h1>Promise Resolve Functions</h1>
69+
<p>A promise resolve function is an anonymous built-in function that has [[Promise]] and [[AlreadyResolved]] internal slots.</p>
70+
<p>When a promise resolve function is called with argument _resolution_, the following steps are taken:</p>
71+
<emu-alg>
72+
1. Let _F_ be the active function object.
73+
1. Assert: _F_ has a [[Promise]] internal slot whose value is an Object.
74+
1. Let _promise_ be _F_.[[Promise]].
75+
1. Let _alreadyResolved_ be _F_.[[AlreadyResolved]].
76+
1. If _alreadyResolved_.[[Value]] is *true*, return *undefined*.
77+
1. Set _alreadyResolved_.[[Value]] to *true*.
78+
1. If SameValue(_resolution_, _promise_) is *true*, then
79+
1. Let _selfResolutionError_ be a newly created *TypeError* object.
80+
1. Perform RejectPromise(_promise_, _selfResolutionError_).
81+
1. Return *undefined*.
82+
1. If _resolution_ is not an Object, then
83+
1. Perform FulfillPromise(_promise_, _resolution_).
84+
1. Return *undefined*.
85+
1. <ins>Let _thenAction_ be *null*.</ins>
86+
1. <ins>If IsPromise(_resolution_) is *true*, then</ins>
87+
1. <ins>Assert: _resolution_ is an ordinary object.</ins>
88+
1. <ins>Let _proto_ be ! _resolution_.[[GetPrototypeOf]]().</ins>
89+
1. <ins>If SameValue(_proto_, %Promise.prototype%) is *true*, set _thenAction_ to %PromiseThenAction%.</ins>
90+
1. <ins>If _thenAction_ is *null*, then</ins>
91+
1. Let _then_ be Completion(Get(_resolution_, *"then"*)).
92+
1. If _then_ is an abrupt completion, then
93+
1. Perform RejectPromise(_promise_, _then_.[[Value]]).
94+
1. Return *undefined*.
95+
1. <del>Let</del><ins>Set</ins> _thenAction_ <del>be</del><ins>to</ins> _then_.[[Value]].
96+
1. If IsCallable(_thenAction_) is *false*, then
97+
1. Perform FulfillPromise(_promise_, _resolution_).
98+
1. Return *undefined*.
99+
1. Let _thenJobCallback_ be HostMakeJobCallback(_thenAction_).
100+
1. <ins>NOTE: _thenAction_ may be %PromiseThenAction%, a value never directly accessible to ECMAScript code.</ins>
101+
1. Let _job_ be NewPromiseResolveThenableJob(_promise_, _resolution_, _thenJobCallback_).
102+
1. Perform HostEnqueuePromiseJob(_job_.[[Job]], _job_.[[Realm]]).
103+
1. Return *undefined*.
104+
</emu-alg>
105+
<p>The *"length"* property of a promise resolve function is *1*<sub>𝔽</sub>.</p>
106+
</emu-clause>
107+
108+
<emu-clause id="sec-%promisethenaction%">
109+
<h1>%PromiseThenAction% ( _onFulfilled_, _onRejected_ )</h1>
110+
<p>The <dfn>%PromiseThenAction%</dfn> intrinsic function:</p>
111+
<ul>
112+
<li>is an anonymous built-in function object that is defined once for each realm.</li>
113+
<li>is never directly accessible to ECMAScript code.</li>
114+
<li>is used by the promise resolve functions to adopt the state of the promise passed as the receiver.</li>
115+
<li>performs the following steps when called:</li>
116+
</ul>
117+
<emu-alg>
118+
1. Let _promise_ be the *this* value.
119+
1. Assert: IsPromise(_promise_) is *true*.
120+
1. Return PerformPromiseThen(_promise_, _onFulfilled_, _onRejected_).
121+
</emu-alg>
122+
</emu-clause>
123+
</emu-clause>
124+
</emu-clause>
125+
</emu-clause>
39126
</emu-clause>

0 commit comments

Comments
 (0)