Skip to content

Commit 894539c

Browse files
committed
Editorial: Model a binding as a Record
1 parent 465d21c commit 894539c

File tree

1 file changed

+153
-26
lines changed

1 file changed

+153
-26
lines changed

spec.html

Lines changed: 153 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8529,22 +8529,108 @@ <h1>Declarative Environment Records</h1>
85298529
[[Bindings]]
85308530
</td>
85318531
<td>
8532-
List of bindings
8532+
List of DeclarativeBindingRecord
85338533
</td>
85348534
<td>
8535-
Satisfies the invariant that no two bindings in [[Bindings]] are bindings for the same name.
8535+
Satisfies the invariant that no two records in [[Bindings]] have the same [[BoundName]].
85368536
</td>
85378537
</tr>
85388538
</tbody>
85398539
</table>
85408540
</emu-table>
8541+
8542+
<p>A <dfn>DeclarativeBindingRecord</dfn> has the following fields:</p>
8543+
<emu-table id="table-fields-of-declarative-binding-records" caption="DeclarativeBindingRecord Fields">
8544+
<table>
8545+
<tbody>
8546+
<tr>
8547+
<th>
8548+
Field Name
8549+
</th>
8550+
<th>
8551+
Value
8552+
</th>
8553+
<th>
8554+
Meaning
8555+
</th>
8556+
</tr>
8557+
<tr>
8558+
<td>
8559+
[[BoundName]]
8560+
</td>
8561+
<td>
8562+
a String
8563+
</td>
8564+
<td>
8565+
the name being bound.
8566+
</td>
8567+
</tr>
8568+
<tr>
8569+
<td>
8570+
[[IsInitialized]]
8571+
</td>
8572+
<td>
8573+
a Boolean
8574+
</td>
8575+
<td>
8576+
indicates whether the binding is initialized.
8577+
</td>
8578+
</tr>
8579+
<tr>
8580+
<td>
8581+
[[BoundValue]]
8582+
</td>
8583+
<td>
8584+
an ECMAScript language value
8585+
</td>
8586+
<td>
8587+
the value that the name is bound to.
8588+
</td>
8589+
</tr>
8590+
<tr>
8591+
<td>
8592+
[[IsMutable]]
8593+
</td>
8594+
<td>
8595+
a Boolean
8596+
</td>
8597+
<td>
8598+
if *true*, indicates that the binding is mutable.
8599+
</td>
8600+
</tr>
8601+
<tr>
8602+
<td>
8603+
[[IsDeletable]]
8604+
</td>
8605+
<td>
8606+
a Boolean
8607+
</td>
8608+
<td>
8609+
if *true*, indicates that the binding may be deleted by a subsequent DeleteBinding call.
8610+
</td>
8611+
</tr>
8612+
<tr>
8613+
<td>
8614+
[[IsStrict]]
8615+
</td>
8616+
<td>
8617+
a Boolean
8618+
</td>
8619+
<td>
8620+
if *true*, indicates that the binding is a strict binding.
8621+
</td>
8622+
</tr>
8623+
</tbody>
8624+
</table>
8625+
</emu-table>
8626+
85418627
<p>The behaviour of the concrete specification methods for declarative Environment Records is defined by the following algorithms.</p>
85428628

85438629
<emu-clause id="sec-declarative-environment-records-hasbinding-n">
85448630
<h1>HasBinding ( _N_ )</h1>
85458631
<p>The HasBinding concrete method of a declarative Environment Record _envRec_ takes argument _N_ (a String). It determines if the argument identifier is one of the identifiers bound by the record. It performs the following steps when called:</p>
85468632
<emu-alg>
8547-
1. If _envRec_.[[Bindings]] contains a binding for the name that is the value of _N_, return *true*.
8633+
1. If _envRec_.[[Bindings]] contains a DeclarativeBindingRecord whose [[BoundName]] field is equal to the value of _N_, return *true*.
85488634
1. Return *false*.
85498635
</emu-alg>
85508636
</emu-clause>
@@ -8554,7 +8640,7 @@ <h1>CreateMutableBinding ( _N_, _D_ )</h1>
85548640
<p>The CreateMutableBinding concrete method of a declarative Environment Record _envRec_ takes arguments _N_ (a String) and _D_ (a Boolean). It creates a new mutable binding for the name _N_ that is uninitialized. A binding must not already exist in this Environment Record for _N_. If _D_ has the value *true*, the new binding is marked as being subject to deletion. It performs the following steps when called:</p>
85558641
<emu-alg>
85568642
1. Assert: _envRec_.HasBinding(_N_) is *false*.
8557-
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.
8643+
1. Let _binding_ be DeclarativeBindingRecord { [[BoundName]]: _N_, [[IsInitialized]]: *false*, [[BoundValue]]: *undefined*, [[IsMutable]]: *true*, [[IsDeletable]]: _D_, [[IsStrict]]: *false* }.
85588644
1. Append _binding_ to _envRec_.[[Bindings]].
85598645
1. Return NormalCompletion(~empty~).
85608646
</emu-alg>
@@ -8565,7 +8651,7 @@ <h1>CreateImmutableBinding ( _N_, _S_ )</h1>
85658651
<p>The CreateImmutableBinding concrete method of a declarative Environment Record _envRec_ takes arguments _N_ (a String) and _S_ (a Boolean). It creates a new immutable binding for the name _N_ that is uninitialized. A binding must not already exist in this Environment Record for _N_. If _S_ has the value *true*, the new binding is marked as a strict binding. It performs the following steps when called:</p>
85668652
<emu-alg>
85678653
1. Assert: _envRec_.HasBinding(_N_) is *false*.
8568-
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.
8654+
1. Let _binding_ be DeclarativeBindingRecord { [[BoundName]]: _N_, [[IsInitialized]]: *false*, [[BoundValue]]: *undefined*, [[IsMutable]]: *false*, [[IsDeletable]]: *false*, [[IsStrict]]: _S_ }.
85698655
1. Append _binding_ to _envRec_.[[Bindings]].
85708656
1. Return NormalCompletion(~empty~).
85718657
</emu-alg>
@@ -8576,10 +8662,10 @@ <h1>InitializeBinding ( _N_, _V_ )</h1>
85768662
<p>The InitializeBinding concrete method of a declarative Environment Record _envRec_ takes arguments _N_ (a String) and _V_ (an ECMAScript language value). It is used to set the bound value of the current binding of the identifier whose name is the value of the argument _N_ to the value of argument _V_. An uninitialized binding for _N_ must already exist. It performs the following steps when called:</p>
85778663
<emu-alg>
85788664
1. Assert: _envRec_.HasBinding(_N_) is *true*.
8579-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
8580-
1. Assert: _binding_ is uninitialized.
8581-
1. Set the bound value of _binding_ to _V_.
8582-
1. <emu-not-ref>Record</emu-not-ref> that _binding_ has been initialized.
8665+
1. Let _binding_ be the DeclarativeBindingRecord in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
8666+
1. Assert: _binding_.[[IsInitialized]] is *false*.
8667+
1. Set _binding_.[[BoundValue]] to _V_.
8668+
1. Set _binding_.[[IsInitialized]] to *true*.
85838669
1. Return NormalCompletion(~empty~).
85848670
</emu-alg>
85858671
</emu-clause>
@@ -8593,10 +8679,10 @@ <h1>SetMutableBinding ( _N_, _V_, _S_ )</h1>
85938679
1. Perform _envRec_.CreateMutableBinding(_N_, *true*).
85948680
1. Perform _envRec_.InitializeBinding(_N_, _V_).
85958681
1. Return NormalCompletion(~empty~).
8596-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
8597-
1. If _binding_ is a strict binding, set _S_ to *true*.
8598-
1. If _binding_ has not yet been initialized, throw a *ReferenceError* exception.
8599-
1. Else if _binding_ is a mutable binding, change its bound value to _V_.
8682+
1. Let _binding_ be the DeclarativeBindingRecord in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
8683+
1. If _binding_.[[IsStrict]] is *true*, set _S_ to *true*.
8684+
1. If _binding_.[[IsInitialized]] is *false*, throw a *ReferenceError* exception.
8685+
1. Else if _binding_.[[IsMutable]] is *true*, change its bound value to _V_.
86008686
1. Else,
86018687
1. Assert: This is an attempt to change the value of an immutable binding.
86028688
1. If _S_ is *true*, throw a *TypeError* exception.
@@ -8613,9 +8699,9 @@ <h1>GetBindingValue ( _N_, _S_ )</h1>
86138699
<p>The GetBindingValue concrete method of a declarative Environment Record _envRec_ takes arguments _N_ (a String) and _S_ (a Boolean). It returns the value of its bound identifier whose name is the value of the argument _N_. If the binding exists but is uninitialized a *ReferenceError* is thrown, regardless of the value of _S_. It performs the following steps when called:</p>
86148700
<emu-alg>
86158701
1. Assert: _envRec_.HasBinding(_N_) is *true*.
8616-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
8617-
1. If _binding_ is an uninitialized binding, throw a *ReferenceError* exception.
8618-
1. Return the value currently bound in _binding_.
8702+
1. Let _binding_ be the DeclarativeBindingRecord in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
8703+
1. If _binding_.[[IsInitialized]] is *false*, throw a *ReferenceError* exception.
8704+
1. Return _binding_.[[BoundValue]].
86198705
</emu-alg>
86208706
</emu-clause>
86218707

@@ -8624,8 +8710,8 @@ <h1>DeleteBinding ( _N_ )</h1>
86248710
<p>The DeleteBinding concrete method of a declarative Environment Record _envRec_ takes argument _N_ (a String). It can only delete bindings that have been explicitly designated as being subject to deletion. It performs the following steps when called:</p>
86258711
<emu-alg>
86268712
1. Assert: _envRec_.HasBinding(_N_) is *true*.
8627-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
8628-
1. If _binding_ cannot be deleted, return *false*.
8713+
1. Let _binding_ be the DeclarativeBindingRecord in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
8714+
1. If _binding_.[[IsDeletable]] is *false*, return *false*.
86298715
1. Remove _binding_ from _envRec_.[[Bindings]].
86308716
1. Return *true*.
86318717
</emu-alg>
@@ -9343,6 +9429,46 @@ <h1>Module Environment Records</h1>
93439429
</tbody>
93449430
</table>
93459431
</emu-table>
9432+
<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>
9433+
<emu-table id="table-additional-fields-of-importdeclarativebindingrecords" caption="Additional Fields of ImportDeclarativeBindingRecords">
9434+
<table>
9435+
<tbody>
9436+
<tr>
9437+
<th>
9438+
Field Name
9439+
</th>
9440+
<th>
9441+
Value
9442+
</th>
9443+
<th>
9444+
Meaning
9445+
</th>
9446+
</tr>
9447+
<tr>
9448+
<td>
9449+
[[TargetModuleRec]]
9450+
</td>
9451+
<td>
9452+
a Module Record
9453+
</td>
9454+
<td>
9455+
?
9456+
</td>
9457+
</tr>
9458+
<tr>
9459+
<td>
9460+
[[TargetName]]
9461+
</td>
9462+
<td>
9463+
a String
9464+
</td>
9465+
<td>
9466+
the name of a binding that exists in [[TargetModuleRec]]'s module Environment Record.
9467+
</td>
9468+
</tr>
9469+
</tbody>
9470+
</table>
9471+
</emu-table>
93469472
<p>The behaviour of the additional concrete specification methods for module Environment Records are defined by the following algorithms:</p>
93479473

93489474
<emu-clause id="sec-module-environment-records-getbindingvalue-n-s">
@@ -9351,14 +9477,15 @@ <h1>GetBindingValue ( _N_, _S_ )</h1>
93519477
<emu-alg>
93529478
1. Assert: _S_ is *true*.
93539479
1. Assert: _envRec_.HasBinding(_N_) is *true*.
9354-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
9355-
1. If _binding_ is an indirect binding, then
9356-
1. Let _M_ and _N2_ be the indirection values provided when this binding for _N_ was created.
9480+
1. Let _binding_ be the DeclarativeBindingRecord in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
9481+
1. If _binding_ is an ImportDeclarativeBindingRecord, then
9482+
1. Let _M_ be _binding_.[[TargetModuleRec]].
9483+
1. Let _N2_ be _binding_.[[TargetName]].
93579484
1. Let _targetEnv_ be _M_.[[Environment]].
93589485
1. If _targetEnv_ is *undefined*, throw a *ReferenceError* exception.
93599486
1. Return ? _targetEnv_.GetBindingValue(_N2_, *true*).
9360-
1. If _binding_ is an uninitialized binding, throw a *ReferenceError* exception.
9361-
1. Return the value currently bound in _binding_.
9487+
1. If _binding_.[[IsInitialized]] is *false*, throw a *ReferenceError* exception.
9488+
1. Return _binding_.[[BoundValue]].
93629489
</emu-alg>
93639490
<emu-note>
93649491
<p>_S_ will always be *true* because a |Module| is always strict mode code.</p>
@@ -9399,7 +9526,7 @@ <h1>CreateImportBinding ( _N_, _M_, _N2_ )</h1>
93999526
1. Assert: _envRec_.HasBinding(_N_) is *false*.
94009527
1. Assert: _M_ is a Module Record.
94019528
1. Assert: When _M_.[[Environment]] is instantiated it will have a direct binding for _N2_.
9402-
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.
9529+
1. Let _binding_ be ImportDeclarativeBindingRecord { [[BoundName]]: _N_, [[IsInitialized]]: *true*, [[BoundValue]]: *undefined*, [[IsMutable]]: *false*, [[IsDeletable]]: *false*, [[IsStrict]]: *false*, [[TargetModuleRec]]: _M_, [[TargetName]]: _N2_ }.
94039530
1. Append _binding_ to _envRec_.[[Bindings]].
94049531
1. Return NormalCompletion(~empty~).
94059532
</emu-alg>
@@ -41886,8 +42013,8 @@ <h1>Changes to BlockDeclarationInstantiation</h1>
4188642013
</emu-alg>
4188742014
<p>During BlockDeclarationInstantiation the following steps are performed in place of step <emu-xref href="#step-blockdeclarationinstantiation-initializebinding"></emu-xref>:</p>
4188842015
<emu-alg replaces-step="step-blockdeclarationinstantiation-initializebinding">
41889-
1. Let _binding_ be the binding for _fn_ in _env_.[[Bindings]].
41890-
1. If _binding_ is an uninitialized binding, then
42016+
1. Let _binding_ be the DeclarativeBindingRecord in _env_.[[Bindings]] whose [[BoundName]] field equals _fn_.
42017+
1. If _binding_.[[IsInitialized]] is *false*, then
4189142018
1. Perform _env_.InitializeBinding(_fn_, _fo_).
4189242019
1. Else,
4189342020
1. Assert: _d_ is a |FunctionDeclaration|.

0 commit comments

Comments
 (0)