Skip to content

Commit 475dc26

Browse files
committed
Editorial: Model a declarative binding as a Record
1 parent 24b2f6e commit 475dc26

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
@@ -10008,14 +10008,53 @@ <h1>Declarative Environment Records</h1>
1000810008
[[Bindings]]
1000910009
</td>
1001010010
<td>
10011-
a List of bindings
10011+
a List of DeclarativeBindings
1001210012
</td>
1001310013
<td>
10014-
Satisfies the invariant that no two bindings in [[Bindings]] are bindings for the same name.
10014+
Satisfies the invariant that no two records in [[Bindings]] have the same [[BoundName]].
1001510015
</td>
1001610016
</tr>
1001710017
</table>
1001810018
</emu-table>
10019+
10020+
<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>
10021+
10022+
<p>A <dfn>SimpleDeclarativeBinding</dfn> has the following fields:</p>
10023+
<emu-table id="table-fields-of-simpledeclarativebindings" caption="SimpleDeclarativeBinding Fields">
10024+
<table>
10025+
<tr>
10026+
<th>Field Name</th>
10027+
<th>Value</th>
10028+
<th>Meaning</th>
10029+
</tr>
10030+
<tr>
10031+
<td>[[BoundName]]</td>
10032+
<td>a String</td>
10033+
<td>the name being bound.</td>
10034+
</tr>
10035+
<tr>
10036+
<td>[[BoundValue]]</td>
10037+
<td>an ECMAScript language value or ~uninitialized~</td>
10038+
<td>the value that the name is bound to.</td>
10039+
</tr>
10040+
<tr>
10041+
<td>[[IsMutable]]</td>
10042+
<td>a Boolean</td>
10043+
<td>if *true*, indicates that the binding is mutable.</td>
10044+
</tr>
10045+
<tr>
10046+
<td>[[IsDeletable]]</td>
10047+
<td>a Boolean</td>
10048+
<td>if *true*, indicates that the binding may be deleted by a subsequent DeleteBinding call.</td>
10049+
</tr>
10050+
<tr>
10051+
<td>[[IsStrict]]</td>
10052+
<td>a Boolean</td>
10053+
<td>if *true*, indicates that the binding is a strict binding.</td>
10054+
</tr>
10055+
</table>
10056+
</emu-table>
10057+
1001910058
<p>The behaviour of the concrete specification methods for Declarative Environment Records is defined by the following algorithms.</p>
1002010059

1002110060
<emu-clause id="sec-declarative-environment-records-hasbinding-n" type="concrete method">
@@ -10032,7 +10071,7 @@ <h1>
1003210071
<dd>It determines if the argument identifier is one of the identifiers bound by the record.</dd>
1003310072
</dl>
1003410073
<emu-alg>
10035-
1. If _envRec_.[[Bindings]] contains a binding for _N_, return *true*.
10074+
1. If _envRec_.[[Bindings]] contains a DeclarativeBinding whose [[BoundName]] field equals _N_, return *true*.
1003610075
1. Return *false*.
1003710076
</emu-alg>
1003810077
</emu-clause>
@@ -10053,7 +10092,7 @@ <h1>
1005310092
</dl>
1005410093
<emu-alg>
1005510094
1. Assert: _envRec_.HasBinding(_N_) is *false*.
10056-
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.
10095+
1. Let _binding_ be SimpleDeclarativeBinding { [[BoundName]]: _N_, [[BoundValue]]: ~uninitialized~, [[IsMutable]]: *true*, [[IsDeletable]]: _D_, [[IsStrict]]: *false* }.
1005710096
1. Append _binding_ to _envRec_.[[Bindings]].
1005810097
1. Return ~unused~.
1005910098
</emu-alg>
@@ -10075,7 +10114,7 @@ <h1>
1007510114
</dl>
1007610115
<emu-alg>
1007710116
1. Assert: _envRec_.HasBinding(_N_) is *false*.
10078-
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.
10117+
1. Let _binding_ be SimpleDeclarativeBinding { [[BoundName]]: _N_, [[BoundValue]]: ~uninitialized~, [[IsMutable]]: *false*, [[IsDeletable]]: *false*, [[IsStrict]]: _S_ }.
1007910118
1. Append _binding_ to _envRec_.[[Bindings]].
1008010119
1. Return ~unused~.
1008110120
</emu-alg>
@@ -10097,10 +10136,10 @@ <h1>
1009710136
</dl>
1009810137
<emu-alg>
1009910138
1. Assert: _envRec_.HasBinding(_N_) is *true*.
10100-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
10101-
1. Assert: _binding_ is uninitialized.
10102-
1. Set the bound value of _binding_ to _V_.
10103-
1. <emu-not-ref>Record</emu-not-ref> that _binding_ has been initialized.
10139+
1. Let _binding_ be the DeclarativeBinding in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
10140+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
10141+
1. Assert: _binding_.[[BoundValue]] is ~uninitialized~.
10142+
1. Set _binding_.[[BoundValue]] to _V_.
1010410143
1. Return ~unused~.
1010510144
</emu-alg>
1010610145
</emu-clause>
@@ -10126,11 +10165,13 @@ <h1>
1012610165
1. Perform ! _envRec_.CreateMutableBinding(_N_, *true*).
1012710166
1. Perform ! _envRec_.InitializeBinding(_N_, _V_).
1012810167
1. Return ~unused~.
10129-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
10130-
1. If _binding_ is a strict binding, set _S_ to *true*.
10131-
1. If _binding_ has not yet been initialized, then
10168+
1. Let _binding_ be the DeclarativeBinding in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
10169+
1. If _binding_ is an ImportDeclarativeBinding, throw a *TypeError* exception.
10170+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
10171+
1. If _binding_.[[IsStrict]] is *true*, set _S_ to *true*.
10172+
1. If _binding_.[[BoundValue]] is ~uninitialized~, then
1013210173
1. Throw a *ReferenceError* exception.
10133-
1. Else if _binding_ is a mutable binding, then
10174+
1. Else if _binding_.[[IsMutable]] is *true*, then
1013410175
1. Change its bound value to _V_.
1013510176
1. Else,
1013610177
1. Assert: This is an attempt to change the value of an immutable binding.
@@ -10159,9 +10200,10 @@ <h1>
1015910200
</dl>
1016010201
<emu-alg>
1016110202
1. Assert: _envRec_.HasBinding(_N_) is *true*.
10162-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
10163-
1. If _binding_ is an uninitialized binding, throw a *ReferenceError* exception.
10164-
1. Return the value currently bound in _binding_.
10203+
1. Let _binding_ be the DeclarativeBinding in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
10204+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
10205+
1. If _binding_.[[BoundValue]] is ~uninitialized~, throw a *ReferenceError* exception.
10206+
1. Return _binding_.[[BoundValue]].
1016510207
</emu-alg>
1016610208
</emu-clause>
1016710209

@@ -10180,8 +10222,9 @@ <h1>
1018010222
</dl>
1018110223
<emu-alg>
1018210224
1. Assert: _envRec_.HasBinding(_N_) is *true*.
10183-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
10184-
1. If _binding_ cannot be deleted, return *false*.
10225+
1. Let _binding_ be the DeclarativeBinding in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
10226+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
10227+
1. If _binding_.[[IsDeletable]] is *false*, return *false*.
1018510228
1. Remove _binding_ from _envRec_.[[Bindings]].
1018610229
1. Return *true*.
1018710230
</emu-alg>
@@ -11190,6 +11233,31 @@ <h1>Module Environment Records</h1>
1119011233
</tr>
1119111234
</table>
1119211235
</emu-table>
11236+
<p>The [[Bindings]] of a Module Environment Record can include both SimpleDeclarativeBindings and ImportDeclarativeBindings. An <dfn>ImportDeclarativeBinding</dfn> has the following fields:</p>
11237+
<emu-table id="table-fields-of-importdeclarativebindings" caption="ImportDeclarativeBinding Fields">
11238+
<table>
11239+
<tr>
11240+
<th>Field Name</th>
11241+
<th>Value</th>
11242+
<th>Meaning</th>
11243+
</tr>
11244+
<tr>
11245+
<td>[[BoundName]]</td>
11246+
<td>a String</td>
11247+
<td>the name being bound.</td>
11248+
</tr>
11249+
<tr>
11250+
<td>[[TargetModuleRec]]</td>
11251+
<td>a Module Record</td>
11252+
<td>the imported module that provides the binding.</td>
11253+
</tr>
11254+
<tr>
11255+
<td>[[TargetName]]</td>
11256+
<td>a String</td>
11257+
<td>the name of a binding that exists in the target module.</td>
11258+
</tr>
11259+
</table>
11260+
</emu-table>
1119311261
<p>The behaviour of the additional concrete specification methods for Module Environment Records are defined by the following algorithms:</p>
1119411262

1119511263
<emu-clause id="sec-module-environment-records-getbindingvalue-n-s" type="concrete method">
@@ -11209,14 +11277,16 @@ <h1>
1120911277
<emu-alg>
1121011278
1. Assert: _S_ is *true*.
1121111279
1. Assert: _envRec_.HasBinding(_N_) is *true*.
11212-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
11213-
1. If _binding_ is an indirect binding, then
11214-
1. Let _M_ and _N2_ be the indirection values provided when this binding for _N_ was created.
11280+
1. Let _binding_ be the DeclarativeBinding in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
11281+
1. If _binding_ is an ImportDeclarativeBinding, then
11282+
1. Let _M_ be _binding_.[[TargetModuleRec]].
11283+
1. Let _N2_ be _binding_.[[TargetName]].
1121511284
1. Let _targetEnv_ be _M_.[[Environment]].
1121611285
1. If _targetEnv_ is ~empty~, throw a *ReferenceError* exception.
1121711286
1. Return ? <emu-meta effects="user-code">_targetEnv_.GetBindingValue</emu-meta>(_N2_, *true*).
11218-
1. If _binding_ is an uninitialized binding, throw a *ReferenceError* exception.
11219-
1. Return the value currently bound in _binding_.
11287+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
11288+
1. If _binding_.[[BoundValue]] is ~uninitialized~, throw a *ReferenceError* exception.
11289+
1. Return _binding_.[[BoundValue]].
1122011290
</emu-alg>
1122111291
<emu-note>
1122211292
<p>_S_ will always be *true* because a |Module| is always strict mode code.</p>
@@ -11274,7 +11344,7 @@ <h1>
1127411344
<emu-alg>
1127511345
1. Assert: _envRec_.HasBinding(_N_) is *false*.
1127611346
1. Assert: When _M_.[[Environment]] is instantiated, it will have a direct binding for _N2_.
11277-
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.
11347+
1. Let _binding_ be ImportDeclarativeBinding { [[BoundName]]: _N_, [[TargetModuleRec]]: _M_, [[TargetName]]: _N2_ }.
1127811348
1. Append _binding_ to _envRec_.[[Bindings]].
1127911349
1. Return ~unused~.
1128011350
</emu-alg>
@@ -48639,8 +48709,9 @@ <h1>Changes to BlockDeclarationInstantiation</h1>
4863948709
<p>During BlockDeclarationInstantiation the following steps are performed in place of step <emu-xref href="#step-blockdeclarationinstantiation-initializebinding"></emu-xref>:</p>
4864048710
<emu-alg replaces-step="step-blockdeclarationinstantiation-initializebinding">
4864148711
1. Perform the following steps:
48642-
1. Let _binding_ be the binding for _fn_ in _env_.[[Bindings]].
48643-
1. If _binding_ is an uninitialized binding, then
48712+
1. Let _binding_ be the DeclarativeBinding in _env_.[[Bindings]] whose [[BoundName]] field equals _fn_.
48713+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
48714+
1. If _binding_.[[BoundValue]] is ~uninitialized~, then
4864448715
1. Perform ! _env_.InitializeBinding(_fn_, _fo_).
4864548716
1. Else,
4864648717
1. Assert: _d_ is a |FunctionDeclaration|.

0 commit comments

Comments
 (0)