Skip to content

Commit 03eeaf8

Browse files
committed
Editorial: Model a binding as a Record
1 parent 685bfff commit 03eeaf8

File tree

1 file changed

+149
-26
lines changed

1 file changed

+149
-26
lines changed

spec.html

Lines changed: 149 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10139,14 +10139,98 @@ <h1>Declarative Environment Records</h1>
1013910139
[[Bindings]]
1014010140
</td>
1014110141
<td>
10142-
List of bindings
10142+
List of DeclarativeBindingRecord
1014310143
</td>
1014410144
<td>
10145-
Satisfies the invariant that no two bindings in [[Bindings]] are bindings for the same name.
10145+
Satisfies the invariant that no two records in [[Bindings]] have the same [[BoundName]].
1014610146
</td>
1014710147
</tr>
1014810148
</table>
1014910149
</emu-table>
10150+
10151+
<p>A <dfn>DeclarativeBindingRecord</dfn> has the following fields:</p>
10152+
<emu-table id="table-fields-of-declarative-binding-records" caption="DeclarativeBindingRecord Fields">
10153+
<table>
10154+
<tr>
10155+
<th>
10156+
Field Name
10157+
</th>
10158+
<th>
10159+
Value
10160+
</th>
10161+
<th>
10162+
Meaning
10163+
</th>
10164+
</tr>
10165+
<tr>
10166+
<td>
10167+
[[BoundName]]
10168+
</td>
10169+
<td>
10170+
a String
10171+
</td>
10172+
<td>
10173+
the name being bound.
10174+
</td>
10175+
</tr>
10176+
<tr>
10177+
<td>
10178+
[[IsInitialized]]
10179+
</td>
10180+
<td>
10181+
a Boolean
10182+
</td>
10183+
<td>
10184+
indicates whether the binding is initialized.
10185+
</td>
10186+
</tr>
10187+
<tr>
10188+
<td>
10189+
[[BoundValue]]
10190+
</td>
10191+
<td>
10192+
an ECMAScript language value
10193+
</td>
10194+
<td>
10195+
the value that the name is bound to.
10196+
</td>
10197+
</tr>
10198+
<tr>
10199+
<td>
10200+
[[IsMutable]]
10201+
</td>
10202+
<td>
10203+
a Boolean
10204+
</td>
10205+
<td>
10206+
if *true*, indicates that the binding is mutable.
10207+
</td>
10208+
</tr>
10209+
<tr>
10210+
<td>
10211+
[[IsDeletable]]
10212+
</td>
10213+
<td>
10214+
a Boolean
10215+
</td>
10216+
<td>
10217+
if *true*, indicates that the binding may be deleted by a subsequent DeleteBinding call.
10218+
</td>
10219+
</tr>
10220+
<tr>
10221+
<td>
10222+
[[IsStrict]]
10223+
</td>
10224+
<td>
10225+
a Boolean
10226+
</td>
10227+
<td>
10228+
if *true*, indicates that the binding is a strict binding.
10229+
</td>
10230+
</tr>
10231+
</table>
10232+
</emu-table>
10233+
1015010234
<p>The behaviour of the concrete specification methods for declarative Environment Records is defined by the following algorithms.</p>
1015110235

1015210236
<emu-clause id="sec-declarative-environment-records-hasbinding-n" type="concrete method">
@@ -10163,7 +10247,7 @@ <h1>
1016310247
<dd>It determines if the argument identifier is one of the identifiers bound by the record.</dd>
1016410248
</dl>
1016510249
<emu-alg>
10166-
1. If _envRec_.[[Bindings]] contains a binding for the name that is the value of _N_, return *true*.
10250+
1. If _envRec_.[[Bindings]] contains a DeclarativeBindingRecord whose [[BoundName]] field is equal to the value of _N_, return *true*.
1016710251
1. Return *false*.
1016810252
</emu-alg>
1016910253
</emu-clause>
@@ -10184,7 +10268,7 @@ <h1>
1018410268
</dl>
1018510269
<emu-alg>
1018610270
1. Assert: _envRec_.HasBinding(_N_) is *false*.
10187-
1. Let _binding_ be a mutable binding for _N_ and record that it is uninitialized. If _D_ is *true*, record that the newly created binding may be deleted by a subsequent DeleteBinding call.
10271+
1. Let _binding_ be DeclarativeBindingRecord { [[BoundName]]: _N_, [[IsInitialized]]: *false*, [[BoundValue]]: *undefined*, [[IsMutable]]: *true*, [[IsDeletable]]: _D_, [[IsStrict]]: *false* }.
1018810272
1. Append _binding_ to _envRec_.[[Bindings]].
1018910273
1. Return NormalCompletion(~empty~).
1019010274
</emu-alg>
@@ -10206,7 +10290,7 @@ <h1>
1020610290
</dl>
1020710291
<emu-alg>
1020810292
1. Assert: _envRec_.HasBinding(_N_) is *false*.
10209-
1. Let _binding_ be an immutable binding for _N_ and record that it is uninitialized. If _S_ is *true*, record that the newly created binding is a strict binding.
10293+
1. Let _binding_ be DeclarativeBindingRecord { [[BoundName]]: _N_, [[IsInitialized]]: *false*, [[BoundValue]]: *undefined*, [[IsMutable]]: *false*, [[IsDeletable]]: *false*, [[IsStrict]]: _S_ }.
1021010294
1. Append _binding_ to _envRec_.[[Bindings]].
1021110295
1. Return NormalCompletion(~empty~).
1021210296
</emu-alg>
@@ -10228,10 +10312,10 @@ <h1>
1022810312
</dl>
1022910313
<emu-alg>
1023010314
1. Assert: _envRec_.HasBinding(_N_) is *true*.
10231-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
10232-
1. Assert: _binding_ is uninitialized.
10233-
1. Set the bound value of _binding_ to _V_.
10234-
1. <emu-not-ref>Record</emu-not-ref> that _binding_ has been initialized.
10315+
1. Let _binding_ be the DeclarativeBindingRecord in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
10316+
1. Assert: _binding_.[[IsInitialized]] is *false*.
10317+
1. Set _binding_.[[BoundValue]] to _V_.
10318+
1. Set _binding_.[[IsInitialized]] to *true*.
1023510319
1. Return NormalCompletion(~empty~).
1023610320
</emu-alg>
1023710321
</emu-clause>
@@ -10257,10 +10341,10 @@ <h1>
1025710341
1. Perform _envRec_.CreateMutableBinding(_N_, *true*).
1025810342
1. Perform _envRec_.InitializeBinding(_N_, _V_).
1025910343
1. Return NormalCompletion(~empty~).
10260-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
10261-
1. If _binding_ is a strict binding, set _S_ to *true*.
10262-
1. If _binding_ has not yet been initialized, throw a *ReferenceError* exception.
10263-
1. Else if _binding_ is a mutable binding, change its bound value to _V_.
10344+
1. Let _binding_ be the DeclarativeBindingRecord in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
10345+
1. If _binding_.[[IsStrict]] is *true*, set _S_ to *true*.
10346+
1. If _binding_.[[IsInitialized]] is *false*, throw a *ReferenceError* exception.
10347+
1. Else if _binding_.[[IsMutable]] is *true*, change its bound value to _V_.
1026410348
1. Else,
1026510349
1. Assert: This is an attempt to change the value of an immutable binding.
1026610350
1. If _S_ is *true*, throw a *TypeError* exception.
@@ -10288,9 +10372,9 @@ <h1>
1028810372
</dl>
1028910373
<emu-alg>
1029010374
1. Assert: _envRec_.HasBinding(_N_) is *true*.
10291-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
10292-
1. If _binding_ is an uninitialized binding, throw a *ReferenceError* exception.
10293-
1. Return the value currently bound in _binding_.
10375+
1. Let _binding_ be the DeclarativeBindingRecord in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
10376+
1. If _binding_.[[IsInitialized]] is *false*, throw a *ReferenceError* exception.
10377+
1. Return _binding_.[[BoundValue]].
1029410378
</emu-alg>
1029510379
</emu-clause>
1029610380

@@ -10309,8 +10393,8 @@ <h1>
1030910393
</dl>
1031010394
<emu-alg>
1031110395
1. Assert: _envRec_.HasBinding(_N_) is *true*.
10312-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
10313-
1. If _binding_ cannot be deleted, return *false*.
10396+
1. Let _binding_ be the DeclarativeBindingRecord in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
10397+
1. If _binding_.[[IsDeletable]] is *false*, return *false*.
1031410398
1. Remove _binding_ from _envRec_.[[Bindings]].
1031510399
1. Return *true*.
1031610400
</emu-alg>
@@ -11319,6 +11403,44 @@ <h1>Module Environment Records</h1>
1131911403
</tr>
1132011404
</table>
1132111405
</emu-table>
11406+
<p>The [[Bindings]] of a Module Environment Record can include ImportDeclarativeBindingRecords. These have all the fields of DeclarativeBindingRecords, plus the additional state fields listed in the following table.</p>
11407+
<emu-table id="table-additional-fields-of-importdeclarativebindingrecords" caption="Additional Fields of ImportDeclarativeBindingRecords">
11408+
<table>
11409+
<tr>
11410+
<th>
11411+
Field Name
11412+
</th>
11413+
<th>
11414+
Value
11415+
</th>
11416+
<th>
11417+
Meaning
11418+
</th>
11419+
</tr>
11420+
<tr>
11421+
<td>
11422+
[[TargetModuleRec]]
11423+
</td>
11424+
<td>
11425+
a Module Record
11426+
</td>
11427+
<td>
11428+
?
11429+
</td>
11430+
</tr>
11431+
<tr>
11432+
<td>
11433+
[[TargetName]]
11434+
</td>
11435+
<td>
11436+
a String
11437+
</td>
11438+
<td>
11439+
the name of a binding that exists in [[TargetModuleRec]]'s module Environment Record.
11440+
</td>
11441+
</tr>
11442+
</table>
11443+
</emu-table>
1132211444
<p>The behaviour of the additional concrete specification methods for module Environment Records are defined by the following algorithms:</p>
1132311445

1132411446
<emu-clause id="sec-module-environment-records-getbindingvalue-n-s" type="concrete method">
@@ -11338,14 +11460,15 @@ <h1>
1133811460
<emu-alg>
1133911461
1. Assert: _S_ is *true*.
1134011462
1. Assert: _envRec_.HasBinding(_N_) is *true*.
11341-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
11342-
1. If _binding_ is an indirect binding, then
11343-
1. Let _M_ and _N2_ be the indirection values provided when this binding for _N_ was created.
11463+
1. Let _binding_ be the DeclarativeBindingRecord in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
11464+
1. If _binding_ is an ImportDeclarativeBindingRecord, then
11465+
1. Let _M_ be _binding_.[[TargetModuleRec]].
11466+
1. Let _N2_ be _binding_.[[TargetName]].
1134411467
1. Let _targetEnv_ be _M_.[[Environment]].
1134511468
1. If _targetEnv_ is ~empty~, throw a *ReferenceError* exception.
1134611469
1. Return ? _targetEnv_.GetBindingValue(_N2_, *true*).
11347-
1. If _binding_ is an uninitialized binding, throw a *ReferenceError* exception.
11348-
1. Return the value currently bound in _binding_.
11470+
1. If _binding_.[[IsInitialized]] is *false*, throw a *ReferenceError* exception.
11471+
1. Return _binding_.[[BoundValue]].
1134911472
</emu-alg>
1135011473
<emu-note>
1135111474
<p>_S_ will always be *true* because a |Module| is always strict mode code.</p>
@@ -11403,7 +11526,7 @@ <h1>
1140311526
<emu-alg>
1140411527
1. Assert: _envRec_.HasBinding(_N_) is *false*.
1140511528
1. Assert: When _M_.[[Environment]] is instantiated it will have a direct binding for _N2_.
11406-
1. Let _binding_ be an immutable indirect binding for _N_ that references _M_ and _N2_ as its target binding and record that the binding is initialized.
11529+
1. Let _binding_ be ImportDeclarativeBindingRecord { [[BoundName]]: _N_, [[IsInitialized]]: *true*, [[BoundValue]]: *undefined*, [[IsMutable]]: *false*, [[IsDeletable]]: *false*, [[IsStrict]]: *false*, [[TargetModuleRec]]: _M_, [[TargetName]]: _N2_ }.
1140711530
1. Append _binding_ to _envRec_.[[Bindings]].
1140811531
1. Return NormalCompletion(~empty~).
1140911532
</emu-alg>
@@ -47560,8 +47683,8 @@ <h1>Changes to BlockDeclarationInstantiation</h1>
4756047683
</emu-alg>
4756147684
<p>During BlockDeclarationInstantiation the following steps are performed in place of step <emu-xref href="#step-blockdeclarationinstantiation-initializebinding"></emu-xref>:</p>
4756247685
<emu-alg replaces-step="step-blockdeclarationinstantiation-initializebinding">
47563-
1. Let _binding_ be the binding for _fn_ in _env_.[[Bindings]].
47564-
1. If _binding_ is an uninitialized binding, then
47686+
1. Let _binding_ be the DeclarativeBindingRecord in _env_.[[Bindings]] whose [[BoundName]] field equals _fn_.
47687+
1. If _binding_.[[IsInitialized]] is *false*, then
4756547688
1. Perform _env_.InitializeBinding(_fn_, _fo_).
4756647689
1. Else,
4756747690
1. Assert: _d_ is a |FunctionDeclaration|.

0 commit comments

Comments
 (0)