From 964c5cd17577c58d915da08d61dd480431291251 Mon Sep 17 00:00:00 2001 From: Dan Ehrenberg Date: Thu, 28 Jul 2016 10:47:12 -0700 Subject: [PATCH] Use method scope semantics for initializers 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 --- spec/new-productions.htm | 64 ++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/spec/new-productions.htm b/spec/new-productions.htm index 3c643ea..4deb61e 100644 --- a/spec/new-productions.htm +++ b/spec/new-productions.htm @@ -9,18 +9,6 @@

|PublicFieldDefinition|

- -

Static Semantics: Early Errors

- - PublicFieldDefinition : - PropertyName[?Yield] Initializer? - - - 1. It is a SyntaxError if |Initializer| contains |MetaProperty|. - 1. It is a SyntaxError if |Initializer| contains an |Identifier| with the StringValue `"arguments"`. - -
-

Static Semantics: ClassPublicFields

@@ -58,7 +46,9 @@

ClassPublicFieldDefinitionEvaluation

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_, @@ -68,6 +58,20 @@

ClassPublicFieldDefinitionEvaluation

+ +

Runtime Semantics: EvaluateBody

+ +

With parameter _functionObject_.

+ + + Initializer[In, Yield] : + `=` AssignmentExpression[?In, ?Yield] + + + 1. Return the result of evaluating |AssignmentExpression|. + +
+

InitializePublicStaticFields(_F_)

@@ -80,10 +84,7 @@

InitializePublicStaticFields(_F_)

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*, @@ -112,31 +113,22 @@

InitializePublicInstanceFields ( _O_, _constructor_ )

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.