Skip to content

Commit bf50d79

Browse files
committed
Merge pull request #58 from caridy/SetStateToMax
fixes issue #16: abstract operation `SetStateToMax()`
2 parents 551d06a + fca03ed commit bf50d79

File tree

1 file changed

+46
-13
lines changed

1 file changed

+46
-13
lines changed

index.bs

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,24 @@ mean the same thing as:
103103
1. Return the result of calling OrdinaryDefineOwnProperty(_obj_, _name_, _value_).
104104
</emu-alg>
105105

106+
<h4 id="get-state-value" aoid="GetStateValue">GetStateValue(state)</h4>
106107

108+
<emu-alg>
109+
1. If _state_ is the string "fetch" return 0.
110+
1. If _state_ is the string "translate" return 1.
111+
1. If _state_ is the string "instantiate" return 2.
112+
1. If _state_ is the string "link" return 3.
113+
1. If _state_ is the string "ready" return 4.
114+
</emu-alg>
115+
116+
<h4 id="set-state-to-max" aoid="SetStateToMax">SetStateToMax(entry, newState)</h4>
117+
118+
<emu-alg>
119+
1. Let _state_ be _entry_.[[State]].
120+
1. Let _stateValue_ be GetStateValue(_state_).
121+
1. Let _newStateValue_ be GetStateValue(_newState_).
122+
1. If _newStateValue_ is larger than _stateValue_, set _entry_.[[State]] to _newState_.
123+
</emu-alg>
107124

108125
<h2 id="loader-object">Loader Object</h2>
109126

@@ -239,15 +256,15 @@ A <dfn>registry entry</dfn> is a record with the following fields:
239256
<emu-alg>
240257
1. If _entry_.[[Fetch]] is *undefined*, then set _entry_.[[Fetch]] to a new promise.
241258
1. Fulfill _entry_.[[Fetch]] with _payload_.
242-
1. Set _entry_.[[State]] to the max of _entry_.[[State]] and "translate".
259+
1. SetStateToMax(_entry_, "translate").
243260
</emu-alg>
244261

245262
<h4 id="fulfill-translate" aoid="FulfillTranslate">FulfillTranslate(loader, entry, source)</h4>
246263

247264
<emu-alg>
248265
1. If _entry_.[[Translate]] is *undefined*, then set _entry_.[[Translate]] to a new promise.
249266
1. Fulfill _entry_.[[Translate]] with _source_.
250-
1. Set _entry_.[[State]] to the max of _entry_.[[State]] and "instantiate".
267+
1. SetStateToMax(_entry_, "instantiate").
251268
</emu-alg>
252269

253270
<h4 id="fulfill-instantiate" aoid="FulfillInstantiate">FulfillInstantiate(loader, entry, optionalInstance, source)</h4>
@@ -271,7 +288,7 @@ A <dfn>registry entry</dfn> is a record with the following fields:
271288
1. Append the record { [[key]]: _dep_, [[value]]: *undefined* } to _deps_.
272289
1. Set _entry_.[[Dependencies]] to _deps_.
273290
1. Set _entry_.[[Module]] to _instance_.
274-
1. Set _entry_.[[State]] to the max of _entry_.[[State]] and "link".
291+
1. SetStateToMax(_entry_, "link").
275292
1. Set _instance_.[[RegistryEntry]] to _entry_.
276293
</emu-alg>
277294

@@ -290,13 +307,15 @@ A <dfn>registry entry</dfn> is a record with the following fields:
290307

291308
<emu-alg>
292309
1. Let _entry_ be EnsureRegistered(_loader_, _key_).
293-
1. If _entry_.[[State]] is greater than "link", return a new error promise.
310+
1. Let _stateValue_ be GetStateValue(_entry_.[[State]]).
311+
1. Let _linkStateValue_ be GetStateValue("link").
312+
1. If _stateValue_ is greater than _linkStateValue_, return a new error promise.
294313
1. If _entry_.[[Fetch]] is not *undefined*, return _entry_.[[Fetch]].
295314
1. Let _hook_ be _loader_.[[Fetch]].
296315
1. // TODO: metadata object
297316
1. Let _p0_ be the result of promise-calling _hook_(_key_).
298317
1. Let _p_ be the result of transforming _p0_ with a fulfillment handler that, when called with argument _payload_, runs the following steps:
299-
1. Set _entry_.[[State]] to the max of _entry_.[[State]] and "translate".
318+
1. SetStateToMax(_entry_, "translate").
300319
1. Return _payload_.
301320
1. Set _entry_.[[Fetch]] to _p_.
302321
1. Return _p_.
@@ -306,14 +325,16 @@ A <dfn>registry entry</dfn> is a record with the following fields:
306325

307326
<emu-alg>
308327
1. Let _entry_ be EnsureRegistered(_loader_, _key_).
309-
1. If _entry_.[[State]] is greater than "link", return a new error promise.
328+
1. Let _stateValue_ be GetStateValue(_entry_.[[State]]).
329+
1. Let _linkStateValue_ be GetStateValue("link").
330+
1. If _stateValue_ is greater than _linkStateValue_, return a new error promise.
310331
1. If _entry_.[[Translate]] is not *undefined*, return _entry_.[[Translate]].
311332
1. Let _hook_ be _loader_.[[Translate]].
312333
1. Let _p_ be the result of transforming RequestFetch(_loader_, _key_) with a fulfillment handler that, when called with argument _payload_, runs the following steps:
313334
1. // TODO: metadata
314335
1. Let _p1_ be the result of promise-calling _hook_(_key_, _payload_).
315336
1. Return the result of transforming _p1_ with a fulfillment handler that, when called with argument _source_, runs the following steps:
316-
1. Set _entry_.[[State]] to the max of _entry_.[[State]] and "instantiate".
337+
1. SetStateToMax(_entry_, "instantiate").
317338
1. Return _source_.
318339
1. Set _entry_.[[Translate]] to _p_.
319340
1. Return _p_.
@@ -397,7 +418,9 @@ The modules spec should only invoke this operation from methods of Source Text M
397418
1. Let _pair_ be the pair in _entry_.[[Dependencies]] such that _pair_.[[key]] is equal to _requestName_.
398419
1. Assert: _pair_ is defined.
399420
1. Let _dep_ be _pair_.[[value]].
400-
1. Assert: _dep_.[[State]] is greater than or equal to "link".
421+
1. Let _stateValue_ be GetStateValue(_dep_.[[State]]).
422+
1. Let _linkStateValue_ be GetStateValue("link").
423+
1. Assert: _stateValue_ is greater than or equal to _linkStateValue_.
401424
1. Return _dep_.[[Module]].
402425
</emu-alg>
403426

@@ -510,16 +533,22 @@ The modules spec should only invoke this operation from methods of Source Text M
510533
1. If _loader_ does not have a [[Registry]] internal slot throw a *TypeError* exception.
511534
1. Let _entry_ be EnsureRegistered(_loader_, _key_).
512535
1. If _stage_ is "fetch", then:
513-
1. If _entry_.[[State]] is greater than "fetch", throw a new TypeError.
536+
1. Let _stateValue_ be GetStateValue(_entry_.[[State]]).
537+
1. Let _fetchStateValue_ be GetStateValue("fetch").
538+
1. If _stateValue_ is greater than _fetchStateValue_, throw a new TypeError.
514539
1. Call FulfillFetch(_loader_, _entry_, _value_).
515540
1. Return *undefined*.
516541
1. If _stage_ is "translate", then:
517-
1. If _entry_.[[State]] is greater than "translate", throw a new TypeError.
542+
1. Let _stateValue_ be GetStateValue(_entry_.[[State]]).
543+
1. Let _translateStateValue_ be GetStateValue("translate").
544+
1. If _stateValue_ is greater than _translateStateValue_, throw a new TypeError.
518545
1. Call FulfillFetch(_loader_, _entry_, *undefined*).
519546
1. Call FulfillTranslate(_loader_, _entry_, _value_).
520547
1. Return *undefined*.
521548
1. If _stage_ is "instantiate", then:
522-
1. If _entry_.[[State]] is greater than "instantiate", throw a new TypeError.
549+
1. Let _stateValue_ be GetStateValue(_entry_.[[State]]).
550+
1. Let _instantiateStateValue_ be GetStateValue("instantiate").
551+
1. If _stateValue_ is greater than _instantiateStateValue_, throw a new TypeError.
523552
1. Call FulfillFetch(_loader_, _entry_, *undefined*).
524553
1. Call FulfillTranslate(_loader_, _entry_, *undefined*).
525554
1. Assert: _entry_.[[Translate]] is resolved or rejected.
@@ -593,7 +622,9 @@ The modules spec should only invoke this operation from methods of Source Text M
593622
1. If _loader_ does not have a [[Registry]] internal slot throw a *TypeError* exception.
594623
1. Let _pair_ be the entry in _loader_.[[Registry]] such that _pair_.[[key]] is equal to _key_.
595624
1. If _pair_ does not exist, then throw a new TypeError.
596-
1. If _pair_.[[value]].[[State]] is less than "link", then throw a new TypeError.
625+
1. Let _stateValue_ be GetStateValue(_pair_.[[value]].[[State]]).
626+
1. Let _linkStateValue_ be GetStateValue("link").
627+
1. If _stateValue_ is less than _linkStateValue_, then throw a new TypeError.
597628
1. Remove _pair_ from _loader_.[[Registry]].
598629
</emu-alg>
599630

@@ -606,7 +637,9 @@ The modules spec should only invoke this operation from methods of Source Text M
606637
1. Let _pair_ be the entry in _loader_.[[Registry]] such that _pair_.[[key]] is equal to _key_.
607638
1. If _pair_ does not exist, then throw a new TypeError.
608639
1. Let _entry_ be _pair_.[[value]].
609-
1. If _entry_.[[State]] is "link" or greater, throw a new TypeError.
640+
1. Let _stateValue_ be GetStateValue(_entry_.[[State]]).
641+
1. Let _linkStateValue_ be GetStateValue("link").
642+
1. If _stateValue_ is greater than or equal to _linkStateValue_, throw a new TypeError.
610643
1. Remove _pair_ from _loader_.[[Registry]].
611644
</emu-alg>
612645

0 commit comments

Comments
 (0)