Skip to content

Commit 160318f

Browse files
committed
Editorial: Model a declarative binding as a Record
1 parent bd02a48 commit 160318f

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

1001910058
<emu-clause id="sec-declarative-environment-records-hasbinding-n" type="concrete method">
@@ -10030,7 +10069,7 @@ <h1>
1003010069
<dd>It determines if the argument identifier is one of the identifiers bound by the record.</dd>
1003110070
</dl>
1003210071
<emu-alg>
10033-
1. If _envRec_.[[Bindings]] contains a binding for _N_, return *true*.
10072+
1. If _envRec_.[[Bindings]] contains a DeclarativeBinding whose [[BoundName]] field equals _N_, return *true*.
1003410073
1. Return *false*.
1003510074
</emu-alg>
1003610075
</emu-clause>
@@ -10051,7 +10090,7 @@ <h1>
1005110090
</dl>
1005210091
<emu-alg>
1005310092
1. Assert: _envRec_.HasBinding(_N_) is *false*.
10054-
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.
10093+
1. Let _binding_ be SimpleDeclarativeBinding { [[BoundName]]: _N_, [[BoundValue]]: ~uninitialized~, [[IsMutable]]: *true*, [[IsDeletable]]: _D_, [[IsStrict]]: *false* }.
1005510094
1. Append _binding_ to _envRec_.[[Bindings]].
1005610095
1. Return ~unused~.
1005710096
</emu-alg>
@@ -10073,7 +10112,7 @@ <h1>
1007310112
</dl>
1007410113
<emu-alg>
1007510114
1. Assert: _envRec_.HasBinding(_N_) is *false*.
10076-
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.
10115+
1. Let _binding_ be SimpleDeclarativeBinding { [[BoundName]]: _N_, [[BoundValue]]: ~uninitialized~, [[IsMutable]]: *false*, [[IsDeletable]]: *false*, [[IsStrict]]: _S_ }.
1007710116
1. Append _binding_ to _envRec_.[[Bindings]].
1007810117
1. Return ~unused~.
1007910118
</emu-alg>
@@ -10095,10 +10134,10 @@ <h1>
1009510134
</dl>
1009610135
<emu-alg>
1009710136
1. Assert: _envRec_.HasBinding(_N_) is *true*.
10098-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
10099-
1. Assert: _binding_ is uninitialized.
10100-
1. Set the bound value of _binding_ to _V_.
10101-
1. <emu-not-ref>Record</emu-not-ref> that _binding_ has been initialized.
10137+
1. Let _binding_ be the DeclarativeBinding in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
10138+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
10139+
1. Assert: _binding_.[[BoundValue]] is ~uninitialized~.
10140+
1. Set _binding_.[[BoundValue]] to _V_.
1010210141
1. Return ~unused~.
1010310142
</emu-alg>
1010410143
</emu-clause>
@@ -10124,11 +10163,13 @@ <h1>
1012410163
1. Perform ! _envRec_.CreateMutableBinding(_N_, *true*).
1012510164
1. Perform ! _envRec_.InitializeBinding(_N_, _V_).
1012610165
1. Return ~unused~.
10127-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
10128-
1. If _binding_ is a strict binding, set _S_ to *true*.
10129-
1. If _binding_ has not yet been initialized, then
10166+
1. Let _binding_ be the DeclarativeBinding in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
10167+
1. If _binding_ is an ImportDeclarativeBinding, throw a *TypeError* exception.
10168+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
10169+
1. If _binding_.[[IsStrict]] is *true*, set _S_ to *true*.
10170+
1. If _binding_.[[BoundValue]] is ~uninitialized~, then
1013010171
1. Throw a *ReferenceError* exception.
10131-
1. Else if _binding_ is a mutable binding, then
10172+
1. Else if _binding_.[[IsMutable]] is *true*, then
1013210173
1. Change its bound value to _V_.
1013310174
1. Else,
1013410175
1. Assert: This is an attempt to change the value of an immutable binding.
@@ -10157,9 +10198,10 @@ <h1>
1015710198
</dl>
1015810199
<emu-alg>
1015910200
1. Assert: _envRec_.HasBinding(_N_) is *true*.
10160-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
10161-
1. If _binding_ is an uninitialized binding, throw a *ReferenceError* exception.
10162-
1. Return the value currently bound in _binding_.
10201+
1. Let _binding_ be the DeclarativeBinding in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
10202+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
10203+
1. If _binding_.[[BoundValue]] is ~uninitialized~, throw a *ReferenceError* exception.
10204+
1. Return _binding_.[[BoundValue]].
1016310205
</emu-alg>
1016410206
</emu-clause>
1016510207

@@ -10178,8 +10220,9 @@ <h1>
1017810220
</dl>
1017910221
<emu-alg>
1018010222
1. Assert: _envRec_.HasBinding(_N_) is *true*.
10181-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
10182-
1. If _binding_ cannot be deleted, return *false*.
10223+
1. Let _binding_ be the DeclarativeBinding in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
10224+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
10225+
1. If _binding_.[[IsDeletable]] is *false*, return *false*.
1018310226
1. Remove _binding_ from _envRec_.[[Bindings]].
1018410227
1. Return *true*.
1018510228
</emu-alg>
@@ -11188,6 +11231,31 @@ <h1>Module Environment Records</h1>
1118811231
</tr>
1118911232
</table>
1119011233
</emu-table>
11234+
<p>The [[Bindings]] of a Module Environment Record can include both SimpleDeclarativeBindings and ImportDeclarativeBindings. An <dfn>ImportDeclarativeBinding</dfn> has the following fields:</p>
11235+
<emu-table id="table-fields-of-importdeclarativebindings" caption="ImportDeclarativeBinding Fields">
11236+
<table>
11237+
<tr>
11238+
<th>Field Name</th>
11239+
<th>Value</th>
11240+
<th>Meaning</th>
11241+
</tr>
11242+
<tr>
11243+
<td>[[BoundName]]</td>
11244+
<td>a String</td>
11245+
<td>the name being bound.</td>
11246+
</tr>
11247+
<tr>
11248+
<td>[[TargetModuleRec]]</td>
11249+
<td>a Module Record</td>
11250+
<td>the imported module that provides the binding.</td>
11251+
</tr>
11252+
<tr>
11253+
<td>[[TargetName]]</td>
11254+
<td>a String</td>
11255+
<td>the name of a binding that exists in the target module.</td>
11256+
</tr>
11257+
</table>
11258+
</emu-table>
1119111259
<p>The behaviour of the additional concrete specification methods for Module Environment Records are defined by the following algorithms:</p>
1119211260

1119311261
<emu-clause id="sec-module-environment-records-getbindingvalue-n-s" type="concrete method">
@@ -11207,14 +11275,16 @@ <h1>
1120711275
<emu-alg>
1120811276
1. Assert: _S_ is *true*.
1120911277
1. Assert: _envRec_.HasBinding(_N_) is *true*.
11210-
1. Let _binding_ be the binding for _N_ in _envRec_.[[Bindings]].
11211-
1. If _binding_ is an indirect binding, then
11212-
1. Let _M_ and _N2_ be the indirection values provided when this binding for _N_ was created.
11278+
1. Let _binding_ be the DeclarativeBinding in _envRec_.[[Bindings]] whose [[BoundName]] field equals _N_.
11279+
1. If _binding_ is an ImportDeclarativeBinding, then
11280+
1. Let _M_ be _binding_.[[TargetModuleRec]].
11281+
1. Let _N2_ be _binding_.[[TargetName]].
1121311282
1. Let _targetEnv_ be _M_.[[Environment]].
1121411283
1. If _targetEnv_ is ~empty~, throw a *ReferenceError* exception.
1121511284
1. Return ? <emu-meta effects="user-code">_targetEnv_.GetBindingValue</emu-meta>(_N2_, *true*).
11216-
1. If _binding_ is an uninitialized binding, throw a *ReferenceError* exception.
11217-
1. Return the value currently bound in _binding_.
11285+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
11286+
1. If _binding_.[[BoundValue]] is ~uninitialized~, throw a *ReferenceError* exception.
11287+
1. Return _binding_.[[BoundValue]].
1121811288
</emu-alg>
1121911289
<emu-note>
1122011290
<p>_S_ will always be *true* because a |Module| is always strict mode code.</p>
@@ -11272,7 +11342,7 @@ <h1>
1127211342
<emu-alg>
1127311343
1. Assert: _envRec_.HasBinding(_N_) is *false*.
1127411344
1. Assert: When _M_.[[Environment]] is instantiated, it will have a direct binding for _N2_.
11275-
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.
11345+
1. Let _binding_ be ImportDeclarativeBinding { [[BoundName]]: _N_, [[TargetModuleRec]]: _M_, [[TargetName]]: _N2_ }.
1127611346
1. Append _binding_ to _envRec_.[[Bindings]].
1127711347
1. Return ~unused~.
1127811348
</emu-alg>
@@ -49889,8 +49959,9 @@ <h1>Changes to BlockDeclarationInstantiation</h1>
4988949959
<p>During BlockDeclarationInstantiation the following steps are performed in place of step <emu-xref href="#step-blockdeclarationinstantiation-initializebinding"></emu-xref>:</p>
4989049960
<emu-alg replaces-step="step-blockdeclarationinstantiation-initializebinding">
4989149961
1. Perform the following steps:
49892-
1. Let _binding_ be the binding for _fn_ in _env_.[[Bindings]].
49893-
1. If _binding_ is an uninitialized binding, then
49962+
1. Let _binding_ be the DeclarativeBinding in _env_.[[Bindings]] whose [[BoundName]] field equals _fn_.
49963+
1. Assert: _binding_ is a SimpleDeclarativeBinding.
49964+
1. If _binding_.[[BoundValue]] is ~uninitialized~, then
4989449965
1. Perform ! _env_.InitializeBinding(_fn_, _fo_).
4989549966
1. Else,
4989649967
1. Assert: _d_ is a |FunctionDeclaration|.

0 commit comments

Comments
 (0)