Skip to content

Commit 15b7e06

Browse files
committed
Editorial: Model a declarative binding as a Record
1 parent 38c7e31 commit 15b7e06

File tree

1 file changed

+97
-26
lines changed

1 file changed

+97
-26
lines changed

spec.html

Lines changed: 97 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10162,14 +10162,53 @@ <h1>Declarative Environment Records</h1>
1016210162
[[Bindings]]
1016310163
</td>
1016410164
<td>
10165-
List of bindings
10165+
a List of DeclarativeBindings
1016610166
</td>
1016710167
<td>
10168-
Satisfies the invariant that no two bindings in [[Bindings]] are bindings for the same name.
10168+
Satisfies the invariant that no two records in [[Bindings]] have the same [[BoundName]].
1016910169
</td>
1017010170
</tr>
1017110171
</table>
1017210172
</emu-table>
10173+
10174+
<p>A <dfn>DeclarativeBinding</dfn> is either a SimpleDeclarativeBinding or an ImportDeclarativeBinding. SimpleDeclarativeBindings can appear in any declarative Environment Record, but ImportDeclarativeBindings can only appear in a module Environment Record.</p>
10175+
10176+
<p>A <dfn>SimpleDeclarativeBinding</dfn> has the following fields:</p>
10177+
<emu-table id="table-fields-of-simpledeclarativebindings" caption="SimpleDeclarativeBinding Fields">
10178+
<table>
10179+
<tr>
10180+
<th>Field Name</th>
10181+
<th>Value</th>
10182+
<th>Meaning</th>
10183+
</tr>
10184+
<tr>
10185+
<td>[[BoundName]]</td>
10186+
<td>a String</td>
10187+
<td>the name being bound.</td>
10188+
</tr>
10189+
<tr>
10190+
<td>[[BoundValue]]</td>
10191+
<td>an ECMAScript language value or ~uninitialized~</td>
10192+
<td>the value that the name is bound to.</td>
10193+
</tr>
10194+
<tr>
10195+
<td>[[IsMutable]]</td>
10196+
<td>a Boolean</td>
10197+
<td>if *true*, indicates that the binding is mutable.</td>
10198+
</tr>
10199+
<tr>
10200+
<td>[[IsDeletable]]</td>
10201+
<td>a Boolean</td>
10202+
<td>if *true*, indicates that the binding may be deleted by a subsequent DeleteBinding call.</td>
10203+
</tr>
10204+
<tr>
10205+
<td>[[IsStrict]]</td>
10206+
<td>a Boolean</td>
10207+
<td>if *true*, indicates that the binding is a strict binding.</td>
10208+
</tr>
10209+
</table>
10210+
</emu-table>
10211+
1017310212
<p>The behaviour of the concrete specification methods for declarative Environment Records is defined by the following algorithms.</p>
1017410213

1017510214
<emu-clause id="sec-declarative-environment-records-hasbinding-n" type="concrete method">
@@ -10186,7 +10225,7 @@ <h1>
1018610225
<dd>It determines if the argument identifier is one of the identifiers bound by the record.</dd>
1018710226
</dl>
1018810227
<emu-alg>
10189-
1. If _envRec_.[[Bindings]] contains a binding for the name that is the value of _N_, return *true*.
10228+
1. If _envRec_.[[Bindings]] contains a DeclarativeBinding whose [[BoundName]] field is equal to the value of _N_, return *true*.
1019010229
1. Return *false*.
1019110230
</emu-alg>
1019210231
</emu-clause>
@@ -10207,7 +10246,7 @@ <h1>
1020710246
</dl>
1020810247
<emu-alg>
1020910248
1. Assert: _envRec_.HasBinding(_N_) is *false*.
10210-
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.
10249+
1. Let _binding_ be SimpleDeclarativeBinding { [[BoundName]]: _N_, [[BoundValue]]: ~uninitialized~, [[IsMutable]]: *true*, [[IsDeletable]]: _D_, [[IsStrict]]: *false* }.
1021110250
1. Append _binding_ to _envRec_.[[Bindings]].
1021210251
1. Return ~unused~.
1021310252
</emu-alg>
@@ -10229,7 +10268,7 @@ <h1>
1022910268
</dl>
1023010269
<emu-alg>
1023110270
1. Assert: _envRec_.HasBinding(_N_) is *false*.
10232-
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.
10271+
1. Let _binding_ be SimpleDeclarativeBinding { [[BoundName]]: _N_, [[BoundValue]]: ~uninitialized~, [[IsMutable]]: *false*, [[IsDeletable]]: *false*, [[IsStrict]]: _S_ }.
1023310272
1. Append _binding_ to _envRec_.[[Bindings]].
1023410273
1. Return ~unused~.
1023510274
</emu-alg>
@@ -10251,10 +10290,10 @@ <h1>
1025110290
</dl>
1025210291
<emu-alg>
1025310292
1. Assert: _envRec_.HasBinding(_N_) is *true*.
10254-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
10255-
1. Assert: _binding_ is uninitialized.
10256-
1. Set the bound value of _binding_ to _V_.
10257-
1. <emu-not-ref>Record</emu-not-ref> that _binding_ has been initialized.
10293+
1. Let _binding_ be the DeclarativeBinding in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
10294+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
10295+
1. Assert: _binding_.[[BoundValue]] is ~uninitialized~.
10296+
1. Set _binding_.[[BoundValue]] to _V_.
1025810297
1. Return ~unused~.
1025910298
</emu-alg>
1026010299
</emu-clause>
@@ -10280,10 +10319,12 @@ <h1>
1028010319
1. Perform _envRec_.CreateMutableBinding(_N_, *true*).
1028110320
1. Perform ! _envRec_.InitializeBinding(_N_, _V_).
1028210321
1. Return ~unused~.
10283-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
10284-
1. If _binding_ is a strict binding, set _S_ to *true*.
10285-
1. If _binding_ has not yet been initialized, throw a *ReferenceError* exception.
10286-
1. Else if _binding_ is a mutable binding, change its bound value to _V_.
10322+
1. Let _binding_ be the DeclarativeBinding in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
10323+
1. If _binding_ is an ImportDeclarativeBinding, throw a *TypeError* exception.
10324+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
10325+
1. If _binding_.[[IsStrict]] is *true*, set _S_ to *true*.
10326+
1. If _binding_.[[BoundValue]] is ~uninitialized~, throw a *ReferenceError* exception.
10327+
1. Else if _binding_.[[IsMutable]] is *true*, change its bound value to _V_.
1028710328
1. Else,
1028810329
1. Assert: This is an attempt to change the value of an immutable binding.
1028910330
1. If _S_ is *true*, throw a *TypeError* exception.
@@ -10311,9 +10352,10 @@ <h1>
1031110352
</dl>
1031210353
<emu-alg>
1031310354
1. Assert: _envRec_.HasBinding(_N_) is *true*.
10314-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
10315-
1. If _binding_ is an uninitialized binding, throw a *ReferenceError* exception.
10316-
1. Return the value currently bound in _binding_.
10355+
1. Let _binding_ be the DeclarativeBinding in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
10356+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
10357+
1. If _binding_.[[BoundValue]] is ~uninitialized~, throw a *ReferenceError* exception.
10358+
1. Return _binding_.[[BoundValue]].
1031710359
</emu-alg>
1031810360
</emu-clause>
1031910361

@@ -10332,8 +10374,9 @@ <h1>
1033210374
</dl>
1033310375
<emu-alg>
1033410376
1. Assert: _envRec_.HasBinding(_N_) is *true*.
10335-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
10336-
1. If _binding_ cannot be deleted, return *false*.
10377+
1. Let _binding_ be the DeclarativeBinding in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
10378+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
10379+
1. If _binding_.[[IsDeletable]] is *false*, return *false*.
1033710380
1. Remove _binding_ from _envRec_.[[Bindings]].
1033810381
1. Return *true*.
1033910382
</emu-alg>
@@ -11345,6 +11388,31 @@ <h1>Module Environment Records</h1>
1134511388
</tr>
1134611389
</table>
1134711390
</emu-table>
11391+
<p>The [[Bindings]] of a module Environment Record can include both SimpleDeclarativeBindings and ImportDeclarativeBindings. An <dfn>ImportDeclarativeBinding</dfn> has the following fields:</p>
11392+
<emu-table id="table-fields-of-importdeclarativebindings" caption="ImportDeclarativeBinding Fields">
11393+
<table>
11394+
<tr>
11395+
<th>Field Name</th>
11396+
<th>Value</th>
11397+
<th>Meaning</th>
11398+
</tr>
11399+
<tr>
11400+
<td>[[BoundName]]</td>
11401+
<td>a String</td>
11402+
<td>the name being bound.</td>
11403+
</tr>
11404+
<tr>
11405+
<td>[[TargetModuleRec]]</td>
11406+
<td>a Module Record</td>
11407+
<td>the imported module that provides the binding.</td>
11408+
</tr>
11409+
<tr>
11410+
<td>[[TargetName]]</td>
11411+
<td>a String</td>
11412+
<td>the name of a binding that exists in the target module.</td>
11413+
</tr>
11414+
</table>
11415+
</emu-table>
1134811416
<p>The behaviour of the additional concrete specification methods for module Environment Records are defined by the following algorithms:</p>
1134911417

1135011418
<emu-clause id="sec-module-environment-records-getbindingvalue-n-s" type="concrete method">
@@ -11364,14 +11432,16 @@ <h1>
1136411432
<emu-alg>
1136511433
1. Assert: _S_ is *true*.
1136611434
1. Assert: _envRec_.HasBinding(_N_) is *true*.
11367-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
11368-
1. If _binding_ is an indirect binding, then
11369-
1. Let _M_ and _N2_ be the indirection values provided when this binding for _N_ was created.
11435+
1. Let _binding_ be the DeclarativeBinding in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
11436+
1. If _binding_ is an ImportDeclarativeBinding, then
11437+
1. Let _M_ be _binding_.[[TargetModuleRec]].
11438+
1. Let _N2_ be _binding_.[[TargetName]].
1137011439
1. Let _targetEnv_ be _M_.[[Environment]].
1137111440
1. If _targetEnv_ is ~empty~, throw a *ReferenceError* exception.
1137211441
1. Return ? <emu-meta effects="user-code">_targetEnv_.GetBindingValue</emu-meta>(_N2_, *true*).
11373-
1. If _binding_ is an uninitialized binding, throw a *ReferenceError* exception.
11374-
1. Return the value currently bound in _binding_.
11442+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
11443+
1. If _binding_.[[BoundValue]] is ~uninitialized~, throw a *ReferenceError* exception.
11444+
1. Return _binding_.[[BoundValue]].
1137511445
</emu-alg>
1137611446
<emu-note>
1137711447
<p>_S_ will always be *true* because a |Module| is always strict mode code.</p>
@@ -11429,7 +11499,7 @@ <h1>
1142911499
<emu-alg>
1143011500
1. Assert: _envRec_.HasBinding(_N_) is *false*.
1143111501
1. Assert: When _M_.[[Environment]] is instantiated it will have a direct binding for _N2_.
11432-
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.
11502+
1. Let _binding_ be ImportDeclarativeBinding { [[BoundName]]: _N_, [[TargetModuleRec]]: _M_, [[TargetName]]: _N2_ }.
1143311503
1. Append _binding_ to _envRec_.[[Bindings]].
1143411504
1. Return ~unused~.
1143511505
</emu-alg>
@@ -47683,8 +47753,9 @@ <h1>Changes to BlockDeclarationInstantiation</h1>
4768347753
<p>During BlockDeclarationInstantiation the following steps are performed in place of step <emu-xref href="#step-blockdeclarationinstantiation-initializebinding"></emu-xref>:</p>
4768447754
<emu-alg replaces-step="step-blockdeclarationinstantiation-initializebinding">
4768547755
1. Perform the following steps:
47686-
1. Let _binding_ be the binding for _fn_ in _env_.[[Bindings]].
47687-
1. If _binding_ is an uninitialized binding, then
47756+
1. Let _binding_ be the DeclarativeBinding in _env_.[[Bindings]] whose [[BoundName]] field equals _fn_.
47757+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
47758+
1. If _binding_.[[BoundValue]] is ~uninitialized~, then
4768847759
1. Perform ! _env_.InitializeBinding(_fn_, _fo_).
4768947760
1. Else,
4769047761
1. Assert: _d_ is a |FunctionDeclaration|.

0 commit comments

Comments
 (0)