Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Use method scope semantics for initializers
Browse files Browse the repository at this point in the history
This patch regularizes initializer scopes to make them just
like a method, as discussed at the July 2016 TC39 meeting.

Effects of this patch:
- new.target becomes undefined
- arguments becomes an empty arguments object
  • Loading branch information
littledan committed Jul 28, 2016
1 parent 4fce087 commit 964c5cd
Showing 1 changed file with 28 additions and 36 deletions.
64 changes: 28 additions & 36 deletions spec/new-productions.htm
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ <h1>|PublicFieldDefinition|</h1>
</emu-grammar>
</emu-clause>

<emu-clause id="public-field-definition-early-errors">
<h1>Static Semantics: Early Errors</h1>
<emu-grammar>
PublicFieldDefinition :
PropertyName[?Yield] Initializer?
</emu-grammar>
<emu-alg>
1. It is a SyntaxError if |Initializer| contains |MetaProperty|.
1. It is a SyntaxError if |Initializer| contains an |Identifier| with the StringValue `"arguments"`.
</emu-alg>
</emu-clause>

<emu-clause id="static-semantics-class-public-fields">
<h1>Static Semantics: ClassPublicFields</h1>

Expand Down Expand Up @@ -58,7 +46,9 @@ <h1>ClassPublicFieldDefinitionEvaluation</h1>
</emu-grammar>
<emu-alg>
1. Let _fieldName_ be the result of performing PropName of |PropertyName|.
1. If |Initializer_opt| is present, let _initializer_ be |Initializer_opt|
1. If |Initializer_opt| is present,
1. Let _lex_ be the Lexical Environment of the running execution context.
1. Let _initializer_ be FunctionCreate(~Method~, ~empty~, |Initializer_opt|, _lex_, *true*).
1. Else, let _initializer_ be ~empty~.
1. Return Record{
[[name]]: _fieldName_,
Expand All @@ -68,6 +58,20 @@ <h1>ClassPublicFieldDefinitionEvaluation</h1>
</emu-alg>
</emu-clause>

<emu-clause id="runtime-semantics-class-public-field-definition-evaluation">
<h1>Runtime Semantics: EvaluateBody</h1>

<p>With parameter _functionObject_.</p>

<emu-grammar>
Initializer[In, Yield] :
`=` AssignmentExpression[?In, ?Yield]
</emu-grammar>
<emu-alg>
1. Return the result of evaluating |AssignmentExpression|.
</emu-alg>
</emu-clause>

<emu-clause id="initialize-public-static-fields">
<h1>InitializePublicStaticFields(_F_)</h1>

Expand All @@ -80,10 +84,7 @@ <h1>InitializePublicStaticFields(_F_)</h1>
1. Let _fieldName_ be _fieldRecord_.[[name]].
1. Let _initializer_ be _fieldRecord_.[[initializer]].
1. If _initializer_ is not ~empty~, then
1. Let _result_ be the result of evaluating _initializer_.
1. Let _initValue_ be the result of GetValue(_result_).
1. If _initValue_ is an abrupt completion, return
Completion(_initValue_).
1. Let _initValue_ be ? Call(_initializer_, *undefined*).
1. Else, let _initValue_ be *undefined*.
1. Let _desc_ be PropertyDescriptor {
[[configurable]]: *false*,
Expand Down Expand Up @@ -112,31 +113,22 @@ <h1>InitializePublicInstanceFields ( _O_, _constructor_ )</h1>
<emu-alg>
1. Assert: Type ( _O_ ) is Object.
1. Assert: Assert _constructor_ is an ECMAScript function object.
1. Let _lex_ be the Lexical Environment of the running execution context.
1. Let _initializerEnv_ be NewFunctionEnvironment ( _constructor_, *undefined* ).
1. Let _initializerEnvRec_ be the value of _initializerEnv_'s EnvironmentRecord.
1. Perform ! _initializerEnvRec_.CreateImmutableBinding(`"arguments"`, ~false~).
1. Perform ! _initializerEnvRec_.InitializeBinding(`"arguments"`, ~undefined~).
1. Perform _initializerER_.BindThisValue ( _O_ ).
1. Set the running execution context's LexicalEnvironment to _initializerEnv_.
1. Let _publicFieldRecords_ be the value of _constructor_'s [[PublicFields]] internal slot.
1. For each item _fieldRecord_ in order from _publicFieldRecords_,
1. If _fieldRecord_.[[static]] is *false*, then
1. Let _fieldName_ be _fieldRecord_.[[name]]
1. Let _initializer_ be _fieldRecord_.[[initializer]].
1. If _initializer_ is not ~empty~, then
1. Let _result_ be the result of evaluating _initializer_.
1. Let _initValue_ be GetValue(_result_).
1. If _initValue_ is an abrupt completion, then
1. Set the running execution context's LexicalEnvironment to _lex_.
1. Return Completion(_initValue_).
1. Let _desc_ be PropertyDescriptor {
[[configurable]]: *false*,
[[enumerable]]: *true*,
[[writable]]: *true*,
[[value]]: _initValue_
}
1. Perform ?DefinePropertyOrThrow (_O_, _fieldName_, _desc_)
1. Let _initValue_ be ? Call(_initializer_, _O_).
1. Else,
1. Let _initValue_ be ~undefined~.
1. Let _desc_ be PropertyDescriptor {
[[configurable]]: *false*,
[[enumerable]]: *true*,
[[writable]]: *true*,
[[value]]: _initValue_
}
1. Perform ? DefinePropertyOrThrow (_O_, _fieldName_, _desc_)
1. Set the running execution context's LexicalEnvironment to _lex_.
1. Return.
</emu-alg>
Expand Down

0 comments on commit 964c5cd

Please sign in to comment.