diff --git a/translated/issues-17.html b/translated/issues-17.html new file mode 100644 index 00000000000..74aa788ca63 --- /dev/null +++ b/translated/issues-17.html @@ -0,0 +1,1154 @@ + +

Executable Code and Execution Contexts

+ + + +

Lexical Environments

+

A Lexical Environment is a specification type used to define the association of |Identifier|s to specific variables and functions based upon the lexical nesting structure of ECMAScript code. A Lexical Environment consists of an Environment Record and a possibly null reference to an outer Lexical Environment. Usually a Lexical Environment is associated with some specific syntactic structure of ECMAScript code such as a |FunctionDeclaration|, a |BlockStatement|, or a |Catch| clause of a |TryStatement| and a new Lexical Environment is created each time such code is evaluated.

+

An Environment Record records the identifier bindings that are created within the scope of its associated Lexical Environment. It is referred to as the Lexical Environment's EnvironmentRecord

+

The outer environment reference is used to model the logical nesting of Lexical Environment values. The outer reference of a (inner) Lexical Environment is a reference to the Lexical Environment that logically surrounds the inner Lexical Environment. An outer Lexical Environment may, of course, have its own outer Lexical Environment. A Lexical Environment may serve as the outer environment for multiple inner Lexical Environments. For example, if a |FunctionDeclaration| contains two nested |FunctionDeclaration|s then the Lexical Environments of each of the nested functions will have as their outer Lexical Environment the Lexical Environment of the current evaluation of the surrounding function.

+

A global environment is a Lexical Environment which does not have an outer environment. The global environment's outer environment reference is *null*. A global environment's EnvironmentRecord may be prepopulated with identifier bindings and includes an associated global object whose properties provide some of the global environment's identifier bindings. As ECMAScript code is executed, additional properties may be added to the global object and the initial properties may be modified.

+

A module environment is a Lexical Environment that contains the bindings for the top level declarations of a |Module|. It also contains the bindings that are explicitly imported by the |Module|. The outer environment of a module environment is a global environment.

+

A function environment is a Lexical Environment that corresponds to the invocation of an ECMAScript function object. A function environment may establish a new `this` binding. A function environment also captures the state necessary to support `super` method invocations.

+

Lexical Environments and Environment Record values are purely specification mechanisms and need not correspond to any specific artefact of an ECMAScript implementation. It is impossible for an ECMAScript program to directly access or manipulate such values.

+ + + +

Environment Records

+

There are two primary kinds of Environment Record values used in this specification: declarative Environment Records and object Environment Records. Declarative Environment Records are used to define the effect of ECMAScript language syntactic elements such as |FunctionDeclaration|s, |VariableDeclaration|s, and |Catch| clauses that directly associate identifier bindings with ECMAScript language values. Object Environment Records are used to define the effect of ECMAScript elements such as |WithStatement| that associate identifier bindings with the properties of some object. Global Environment Records and function Environment Records are specializations that are used for specifically for |Script| global declarations and for top-level declarations within functions.

+

For specification purposes Environment Record values are values of the Record specification type and can be thought of as existing in a simple object-oriented hierarchy where Environment Record is an abstract class with three concrete subclasses, declarative Environment Record, object Environment Record, and global Environment Record. Function Environment Records and module Environment Records are subclasses of declarative Environment Record. The abstract class includes the abstract specification methods defined in . These abstract methods have distinct concrete algorithms for each of the concrete subclasses.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Method + + Purpose +
+ HasBinding(N) + + Determine if an Environment Record has a binding for the String value _N_. Return *true* if it does and *false* if it does not +
+ CreateMutableBinding(N, D) + + Create a new but uninitialized mutable binding in an Environment Record. The String value _N_ is the text of the bound name. If the Boolean argument _D_ is *true* the binding may be subsequently deleted. +
+ CreateImmutableBinding(N, S) + + Create a new but uninitialized immutable binding in an Environment Record. The String value _N_ is the text of the bound name. If _S_ is *true* then attempts to set it after it has been initialized will always throw an exception, regardless of the strict mode setting of operations that reference that binding. +
+ InitializeBinding(N, V) + + Set the value of an already existing but uninitialized binding in an Environment Record. The String value _N_ is the text of the bound name. _V_ is the value for the binding and is a value of any ECMAScript language type. +
+ SetMutableBinding(N, V, S) + + Set the value of an already existing mutable binding in an Environment Record. The String value _N_ is the text of the bound name. _V_ is the value for the binding and may be a value of any ECMAScript language type. _S_ is a Boolean flag. If _S_ is *true* and the binding cannot be set throw a *TypeError* exception. +
+ GetBindingValue(N, S) + + Returns the value of an already existing binding from an Environment Record. The String value _N_ is the text of the bound name. _S_ is used to identify references originating in strict mode code or that otherwise require strict mode reference semantics. If _S_ is *true* and the binding does not exist throw a *ReferenceError* exception. If the binding exists but is uninitialized a *ReferenceError* is thrown, regardless of the value of _S_. +
+ DeleteBinding(N) + + Delete a binding from an Environment Record. The String value _N_ is the text of the bound name. If a binding for _N_ exists, remove the binding and return *true*. If the binding exists but cannot be removed return *false*. If the binding does not exist return *true*. +
+ HasThisBinding() + + Determine if an Environment Record establishes a `this` binding. Return *true* if it does and *false* if it does not. +
+ HasSuperBinding() + + Determine if an Environment Record establishes a `super` method binding. Return *true* if it does and *false* if it does not. +
+ WithBaseObject() + + If this Environment Record is associated with a `with` statement, return the with object. Otherwise, return *undefined*. +
+
+ + + +

Declarative Environment Records

+

Each declarative Environment Record is associated with an ECMAScript program scope containing variable, constant, let, class, module, import, and/or function declarations. A declarative Environment Record binds the set of identifiers defined by the declarations contained within its scope.

+

The behaviour of the concrete specification methods for declarative Environment Records is defined by the following algorithms.

+ + + +

HasBinding ( _N_ )

+

The concrete Environment Record method HasBinding for declarative Environment Records simply determines if the argument identifier is one of the identifiers bound by the record:

+ + 1. Let _envRec_ be the declarative Environment Record for which the method was invoked. + 1. If _envRec_ has a binding for the name that is the value of _N_, return *true*. + 1. Return *false*. + +
+ + + +

CreateMutableBinding ( _N_, _D_ )

+

The concrete Environment Record method CreateMutableBinding for declarative Environment Records creates a new mutable binding for the name _N_ that is uninitialized. A binding must not already exist in this Environment Record for _N_. If Boolean argument _D_ has the value *true* the new binding is marked as being subject to deletion.

+ + 1. Let _envRec_ be the declarative Environment Record for which the method was invoked. + 1. Assert: _envRec_ does not already have a binding for _N_. + 1. Create a mutable binding in _envRec_ 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. + 1. Return NormalCompletion(~empty~). + +
+ + + +

CreateImmutableBinding ( _N_, _S_ )

+

The concrete Environment Record method CreateImmutableBinding for declarative Environment Records creates a new immutable binding for the name _N_ that is uninitialized. A binding must not already exist in this Environment Record for _N_. If the Boolean argument _S_ has the value *true* the new binding is marked as a strict binding.

+ + 1. Let _envRec_ be the declarative Environment Record for which the method was invoked. + 1. Assert: _envRec_ does not already have a binding for _N_. + 1. Create an immutable binding in _envRec_ for _N_ and record that it is uninitialized. If _S_ is *true*, record that the newly created binding is a strict binding. + 1. Return NormalCompletion(~empty~). + +
+ + + +

InitializeBinding ( _N_, _V_ )

+

The concrete Environment Record method InitializeBinding for declarative Environment Records is used to set the bound value of the current binding of the identifier whose name is the value of the argument _N_ to the value of argument _V_. An uninitialized binding for _N_ must already exist.

+ + 1. Let _envRec_ be the declarative Environment Record for which the method was invoked. + 1. Assert: _envRec_ must have an uninitialized binding for _N_. + 1. Set the bound value for _N_ in _envRec_ to _V_. + 1. Record that the binding for _N_ in _envRec_ has been initialized. + 1. Return NormalCompletion(~empty~). + +
+ + + +

SetMutableBinding ( _N_, _V_, _S_ )

+

The concrete Environment Record method SetMutableBinding for declarative Environment Records attempts to change the bound value of the current binding of the identifier whose name is the value of the argument _N_ to the value of argument _V_. A binding for _N_ normally already exists, but in rare cases it may not. If the binding is an immutable binding, a *TypeError* is thrown if _S_ is *true*.

+ + 1. Let _envRec_ be the declarative Environment Record for which the method was invoked. + 1. If _envRec_ does not have a binding for _N_, then + 1. If _S_ is *true*, throw a *ReferenceError* exception. + 1. Perform _envRec_.CreateMutableBinding(_N_, *true*). + 1. Perform _envRec_.InitializeBinding(_N_, _V_). + 1. Return NormalCompletion(~empty~). + 1. If the binding for _N_ in _envRec_ is a strict binding, set _S_ to *true*. + 1. If the binding for _N_ in _envRec_ has not yet been initialized, throw a *ReferenceError* exception. + 1. Else if the binding for _N_ in _envRec_ is a mutable binding, change its bound value to _V_. + 1. Else, + 1. Assert: This is an attempt to change the value of an immutable binding. + 1. If _S_ is *true*, throw a *TypeError* exception. + 1. Return NormalCompletion(~empty~). + + +

An example of ECMAScript code that results in a missing binding at step 2 is:

+
function f(){eval("var x; x = (delete x, 0);")}
+
+
+ + + +

GetBindingValue ( _N_, _S_ )

+

The concrete Environment Record method GetBindingValue for declarative Environment Records simply returns the value of its bound identifier whose name is the value of the argument _N_. If the binding exists but is uninitialized a *ReferenceError* is thrown, regardless of the value of _S_.

+ + 1. Let _envRec_ be the declarative Environment Record for which the method was invoked. + 1. Assert: _envRec_ has a binding for _N_. + 1. If the binding for _N_ in _envRec_ is an uninitialized binding, throw a *ReferenceError* exception. + 1. Return the value currently bound to _N_ in _envRec_. + +
+ + + +

DeleteBinding ( _N_ )

+

The concrete Environment Record method DeleteBinding for declarative Environment Records can only delete bindings that have been explicitly designated as being subject to deletion.

+ + 1. Let _envRec_ be the declarative Environment Record for which the method was invoked. + 1. Assert: _envRec_ has a binding for the name that is the value of _N_. + 1. If the binding for _N_ in _envRec_ cannot be deleted, return *false*. + 1. Remove the binding for _N_ from _envRec_. + 1. Return *true*. + +
+ + + +

HasThisBinding ( )

+

Regular declarative Environment Records do not provide a `this` binding.

+ + 1. Return *false*. + +
+ + + +

HasSuperBinding ( )

+

Regular declarative Environment Records do not provide a `super` binding.

+ + 1. Return *false*. + +
+ + + +

WithBaseObject ( )

+

Declarative Environment Records always return *undefined* as their WithBaseObject.

+ + 1. Return *undefined*. + +
+
+ + + +

Object Environment Records

+

Each object Environment Record is associated with an object called its binding object. An object Environment Record binds the set of string identifier names that directly correspond to the property names of its binding object. Property keys that are not strings in the form of an |IdentifierName| are not included in the set of bound identifiers. Both own and inherited properties are included in the set regardless of the setting of their [[Enumerable]] attribute. Because properties can be dynamically added and deleted from objects, the set of identifiers bound by an object Environment Record may potentially change as a side-effect of any operation that adds or deletes properties. Any bindings that are created as a result of such a side-effect are considered to be a mutable binding even if the Writable attribute of the corresponding property has the value *false*. Immutable bindings do not exist for object Environment Records.

+

Object Environment Records created for `with` statements () can provide their binding object as an implicit *this* value for use in function calls. The capability is controlled by a _withEnvironment_ Boolean value that is associated with each object Environment Record. By default, the value of _withEnvironment_ is *false* for any object Environment Record.

+

The behaviour of the concrete specification methods for object Environment Records is defined by the following algorithms.

+ + + +

HasBinding ( _N_ )

+

The concrete Environment Record method HasBinding for object Environment Records determines if its associated binding object has a property whose name is the value of the argument _N_:

+ + 1. Let _envRec_ be the object Environment Record for which the method was invoked. + 1. Let _bindings_ be the binding object for _envRec_. + 1. Let _foundBinding_ be ? HasProperty(_bindings_, _N_). + 1. If _foundBinding_ is *false*, return *false*. + 1. If the _withEnvironment_ flag of _envRec_ is *false*, return *true*. + 1. Let _unscopables_ be ? Get(_bindings_, @@unscopables). + 1. If Type(_unscopables_) is Object, then + 1. Let _blocked_ be ToBoolean(? Get(_unscopables_, _N_)). + 1. If _blocked_ is *true*, return *false*. + 1. Return *true*. + +
+ + + +

CreateMutableBinding ( _N_, _D_ )

+

The concrete Environment Record method CreateMutableBinding for object Environment Records creates in an Environment Record's associated binding object a property whose name is the String value and initializes it to the value *undefined*. If Boolean argument _D_ has the value *true* the new property's [[Configurable]] attribute is set to *true*; otherwise it is set to *false*.

+ + 1. Let _envRec_ be the object Environment Record for which the method was invoked. + 1. Let _bindings_ be the binding object for _envRec_. + 1. Return ? DefinePropertyOrThrow(_bindings_, _N_, PropertyDescriptor{[[Value]]: *undefined*, [[Writable]]: *true*, [[Enumerable]]: *true*, [[Configurable]]: _D_}). + + +

Normally _envRec_ will not have a binding for _N_ but if it does, the semantics of DefinePropertyOrThrow may result in an existing binding being replaced or shadowed or cause an abrupt completion to be returned.

+
+
+ + + +

CreateImmutableBinding ( _N_, _S_ )

+

The concrete Environment Record method CreateImmutableBinding is never used within this specification in association with object Environment Records.

+
+ + + +

InitializeBinding ( _N_, _V_ )

+

The concrete Environment Record method InitializeBinding for object Environment Records is used to set the bound value of the current binding of the identifier whose name is the value of the argument _N_ to the value of argument _V_. An uninitialized binding for _N_ must already exist.

+ + 1. Let _envRec_ be the object Environment Record for which the method was invoked. + 1. Assert: _envRec_ must have an uninitialized binding for _N_. + 1. Record that the binding for _N_ in _envRec_ has been initialized. + 1. Return ? _envRec_.SetMutableBinding(_N_, _V_, *false*). + + +

In this specification, all uses of CreateMutableBinding for object Environment Records are immediately followed by a call to InitializeBinding for the same name. Hence, implementations do not need to explicitly track the initialization state of individual object Environment Record bindings.

+
+
+ + + +

SetMutableBinding ( _N_, _V_, _S_ )

+

The concrete Environment Record method SetMutableBinding for object Environment Records attempts to set the value of the Environment Record's associated binding object's property whose name is the value of the argument _N_ to the value of argument _V_. A property named _N_ normally already exists but if it does not or is not currently writable, error handling is determined by the value of the Boolean argument _S_.

+ + 1. Let _envRec_ be the object Environment Record for which the method was invoked. + 1. Let _bindings_ be the binding object for _envRec_. + 1. Return ? Set(_bindings_, _N_, _V_, _S_). + +
+ + + +

GetBindingValue ( _N_, _S_ )

+

The concrete Environment Record method GetBindingValue for object Environment Records returns the value of its associated binding object's property whose name is the String value of the argument identifier _N_. The property should already exist but if it does not the result depends upon the value of the _S_ argument:

+ + 1. Let _envRec_ be the object Environment Record for which the method was invoked. + 1. Let _bindings_ be the binding object for _envRec_. + 1. Let _value_ be ? HasProperty(_bindings_, _N_). + 1. If _value_ is *false*, then + 1. If _S_ is *false*, return the value *undefined*; otherwise throw a *ReferenceError* exception. + 1. Return ? Get(_bindings_, _N_). + +
+ + + +

DeleteBinding ( _N_ )

+

The concrete Environment Record method DeleteBinding for object Environment Records can only delete bindings that correspond to properties of the environment object whose [[Configurable]] attribute have the value *true*.

+ + 1. Let _envRec_ be the object Environment Record for which the method was invoked. + 1. Let _bindings_ be the binding object for _envRec_. + 1. Return ? _bindings_.[[Delete]](_N_). + +
+ + + +

HasThisBinding ( )

+

Regular object Environment Records do not provide a `this` binding.

+ + 1. Return *false*. + +
+ + + +

HasSuperBinding ( )

+

Regular object Environment Records do not provide a `super` binding.

+ + 1. Return *false*. + +
+ + + +

WithBaseObject ( )

+

Object Environment Records return *undefined* as their WithBaseObject unless their _withEnvironment_ flag is *true*.

+ + 1. Let _envRec_ be the object Environment Record for which the method was invoked. + 1. If the _withEnvironment_ flag of _envRec_ is *true*, return the binding object for _envRec_. + 1. Otherwise, return *undefined*. + +
+
+ + + +

Function Environment Records

+

A function Environment Record is a declarative Environment Record that is used to represent the top-level scope of a function and, if the function is not an |ArrowFunction|, provides a `this` binding. If a function is not an |ArrowFunction| function and references `super`, its function Environment Record also contains the state that is used to perform `super` method invocations from within the function.

+

Function Environment Records have the additional state fields listed in .

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Field Name + + Value + + Meaning +
+ [[ThisValue]] + + Any + + This is the *this* value used for this invocation of the function. +
+ [[ThisBindingStatus]] + + `"lexical"` | `"initialized"` | `"uninitialized"` + + If the value is `"lexical"`, this is an |ArrowFunction| and does not have a local this value. +
+ [[FunctionObject]] + + Object + + The function object whose invocation caused this Environment Record to be created. +
+ [[HomeObject]] + + Object | *undefined* + + If the associated function has `super` property accesses and is not an |ArrowFunction|, [[HomeObject]] is the object that the function is bound to as a method. The default value for [[HomeObject]] is *undefined*. +
+ [[NewTarget]] + + Object | *undefined* + + If this Environment Record was created by the [[Construct]] internal method, [[NewTarget]] is the value of the [[Construct]] _newTarget_ parameter. Otherwise, its value is *undefined*. +
+
+

Function Environment Records support all of the declarative Environment Record methods listed in and share the same specifications for all of those methods except for HasThisBinding and HasSuperBinding. In addition, function Environment Records support the methods listed in :

+ + + + + + + + + + + + + + + + + + + + +
+ Method + + Purpose +
+ BindThisValue(V) + + Set the [[ThisValue]] and record that it has been initialized. +
+ GetThisBinding() + + Return the value of this Environment Record's `this` binding. Throws a *ReferenceError* if the `this` binding has not been initialized. +
+ GetSuperBase() + + Return the object that is the base for `super` property accesses bound in this Environment Record. The object is derived from this Environment Record's [[HomeObject]] field. The value *undefined* indicates that `super` property accesses will produce runtime errors. +
+
+

The behaviour of the additional concrete specification methods for function Environment Records is defined by the following algorithms:

+ + + +

BindThisValue ( _V_ )

+ + 1. Let _envRec_ be the function Environment Record for which the method was invoked. + 1. Assert: _envRec_.[[ThisBindingStatus]] is not `"lexical"`. + 1. If _envRec_.[[ThisBindingStatus]] is `"initialized"`, throw a *ReferenceError* exception. + 1. Set _envRec_.[[ThisValue]] to _V_. + 1. Set _envRec_.[[ThisBindingStatus]] to `"initialized"`. + 1. Return _V_. + +
+ + + +

HasThisBinding ( )

+ + 1. Let _envRec_ be the function Environment Record for which the method was invoked. + 1. If _envRec_.[[ThisBindingStatus]] is `"lexical"`, return *false*; otherwise, return *true*. + +
+ + + +

HasSuperBinding ( )

+ + 1. Let _envRec_ be the function Environment Record for which the method was invoked. + 1. If _envRec_.[[ThisBindingStatus]] is `"lexical"`, return *false*. + 1. If _envRec_.[[HomeObject]] has the value *undefined*, return *false*; otherwise, return *true*. + +
+ + + +

GetThisBinding ( )

+ + 1. Let _envRec_ be the function Environment Record for which the method was invoked. + 1. Assert: _envRec_.[[ThisBindingStatus]] is not `"lexical"`. + 1. If _envRec_.[[ThisBindingStatus]] is `"uninitialized"`, throw a *ReferenceError* exception. + 1. Return _envRec_.[[ThisValue]]. + +
+ + + +

GetSuperBase ( )

+ + 1. Let _envRec_ be the function Environment Record for which the method was invoked. + 1. Let _home_ be _envRec_.[[HomeObject]]. + 1. If _home_ has the value *undefined*, return *undefined*. + 1. Assert: Type(_home_) is Object. + 1. Return ? _home_.[[GetPrototypeOf]](). + +
+
+ + + +

Global Environment Records

+

A global Environment Record is used to represent the outer most scope that is shared by all of the ECMAScript |Script| elements that are processed in a common realm. A global Environment Record provides the bindings for built-in globals (clause ), properties of the global object, and for all top-level declarations (, ) that occur within a |Script|.

+

A global Environment Record is logically a single record but it is specified as a composite encapsulating an object Environment Record and a declarative Environment Record. The object Environment Record has as its base object the global object of the associated Realm Record. This global object is the value returned by the global Environment Record's GetThisBinding concrete method. The object Environment Record component of a global Environment Record contains the bindings for all built-in globals (clause ) and all bindings introduced by a |FunctionDeclaration|, |GeneratorDeclaration|, |AsyncFunctionDeclaration| or |VariableStatement| contained in global code. The bindings for all other ECMAScript declarations in global code are contained in the declarative Environment Record component of the global Environment Record.

+

Properties may be created directly on a global object. Hence, the object Environment Record component of a global Environment Record may contain both bindings created explicitly by |FunctionDeclaration|, |GeneratorDeclaration|, |AsyncFunctionDeclaration|, or |VariableDeclaration| declarations and bindings created implicitly as properties of the global object. In order to identify which bindings were explicitly created using declarations, a global Environment Record maintains a list of the names bound using its CreateGlobalVarBinding and CreateGlobalFunctionBinding concrete methods.

+

Global Environment Records have the additional fields listed in and the additional methods listed in .

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Field Name + + Value + + Meaning +
+ [[ObjectRecord]] + + Object Environment Record + + Binding object is the global object. It contains global built-in bindings as well as |FunctionDeclaration|, |GeneratorDeclaration|, |AsyncFunctionDeclaration|, and |VariableDeclaration| bindings in global code for the associated realm. +
+ [[GlobalThisValue]] + + Object + + The value returned by `this` in global scope. Hosts may provide any ECMAScript Object value. +
+ [[DeclarativeRecord]] + + Declarative Environment Record + + Contains bindings for all declarations in global code for the associated realm code except for |FunctionDeclaration|, |GeneratorDeclaration|, |AsyncFunctionDeclaration|, and |VariableDeclaration| _bindings_. +
+ [[VarNames]] + + List of String + + The string names bound by |FunctionDeclaration|, |GeneratorDeclaration|, |AsyncFunctionDeclaration|, and |VariableDeclaration| declarations in global code for the associated realm. +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Method + + Purpose +
+ GetThisBinding() + + Return the value of this Environment Record's `this` binding. +
+ HasVarDeclaration (N) + + Determines if the argument identifier has a binding in this Environment Record that was created using a |VariableDeclaration|, |FunctionDeclaration|, |GeneratorDeclaration|, or |AsyncFunctionDeclaration|. +
+ HasLexicalDeclaration (N) + + Determines if the argument identifier has a binding in this Environment Record that was created using a lexical declaration such as a |LexicalDeclaration| or a |ClassDeclaration|. +
+ HasRestrictedGlobalProperty (N) + + Determines if the argument is the name of a global object property that may not be shadowed by a global lexical binding. +
+ CanDeclareGlobalVar (N) + + Determines if a corresponding CreateGlobalVarBinding call would succeed if called for the same argument _N_. +
+ CanDeclareGlobalFunction (N) + + Determines if a corresponding CreateGlobalFunctionBinding call would succeed if called for the same argument _N_. +
+ CreateGlobalVarBinding(N, D) + + Used to create and initialize to *undefined* a global `var` binding in the [[ObjectRecord]] component of a global Environment Record. The binding will be a mutable binding. The corresponding global object property will have attribute values appropriate for a `var`. The String value _N_ is the bound name. If _D_ is *true* the binding may be deleted. Logically equivalent to CreateMutableBinding followed by a SetMutableBinding but it allows var declarations to receive special treatment. +
+ CreateGlobalFunctionBinding(N, V, D) + + Create and initialize a global `function` binding in the [[ObjectRecord]] component of a global Environment Record. The binding will be a mutable binding. The corresponding global object property will have attribute values appropriate for a `function`. The String value _N_ is the bound name. _V_ is the initialization value. If the Boolean argument _D_ is *true* the binding may be deleted. Logically equivalent to CreateMutableBinding followed by a SetMutableBinding but it allows function declarations to receive special treatment. +
+
+

The behaviour of the concrete specification methods for global Environment Records is defined by the following algorithms.

+ + + +

HasBinding ( _N_ )

+

The concrete Environment Record method HasBinding for global Environment Records simply determines if the argument identifier is one of the identifiers bound by the record:

+ + 1. Let _envRec_ be the global Environment Record for which the method was invoked. + 1. Let _DclRec_ be _envRec_.[[DeclarativeRecord]]. + 1. If _DclRec_.HasBinding(_N_) is *true*, return *true*. + 1. Let _ObjRec_ be _envRec_.[[ObjectRecord]]. + 1. Return ? _ObjRec_.HasBinding(_N_). + +
+ + + +

CreateMutableBinding ( _N_, _D_ )

+

The concrete Environment Record method CreateMutableBinding for global Environment Records creates a new mutable binding for the name _N_ that is uninitialized. The binding is created in the associated DeclarativeRecord. A binding for _N_ must not already exist in the DeclarativeRecord. If Boolean argument _D_ has the value *true* the new binding is marked as being subject to deletion.

+ + 1. Let _envRec_ be the global Environment Record for which the method was invoked. + 1. Let _DclRec_ be _envRec_.[[DeclarativeRecord]]. + 1. If _DclRec_.HasBinding(_N_) is *true*, throw a *TypeError* exception. + 1. Return _DclRec_.CreateMutableBinding(_N_, _D_). + +
+ + + +

CreateImmutableBinding ( _N_, _S_ )

+

The concrete Environment Record method CreateImmutableBinding for global Environment Records creates a new immutable binding for the name _N_ that is uninitialized. A binding must not already exist in this Environment Record for _N_. If the Boolean argument _S_ has the value *true* the new binding is marked as a strict binding.

+ + 1. Let _envRec_ be the global Environment Record for which the method was invoked. + 1. Let _DclRec_ be _envRec_.[[DeclarativeRecord]]. + 1. If _DclRec_.HasBinding(_N_) is *true*, throw a *TypeError* exception. + 1. Return _DclRec_.CreateImmutableBinding(_N_, _S_). + +
+ + + +

InitializeBinding ( _N_, _V_ )

+

The concrete Environment Record method InitializeBinding for global Environment Records is used to set the bound value of the current binding of the identifier whose name is the value of the argument _N_ to the value of argument _V_. An uninitialized binding for _N_ must already exist.

+ + 1. Let _envRec_ be the global Environment Record for which the method was invoked. + 1. Let _DclRec_ be _envRec_.[[DeclarativeRecord]]. + 1. If _DclRec_.HasBinding(_N_) is *true*, then + 1. Return _DclRec_.InitializeBinding(_N_, _V_). + 1. Assert: If the binding exists, it must be in the object Environment Record. + 1. Let _ObjRec_ be _envRec_.[[ObjectRecord]]. + 1. Return ? _ObjRec_.InitializeBinding(_N_, _V_). + +
+ + + +

SetMutableBinding ( _N_, _V_, _S_ )

+

The concrete Environment Record method SetMutableBinding for global Environment Records attempts to change the bound value of the current binding of the identifier whose name is the value of the argument _N_ to the value of argument _V_. If the binding is an immutable binding, a *TypeError* is thrown if _S_ is *true*. A property named _N_ normally already exists but if it does not or is not currently writable, error handling is determined by the value of the Boolean argument _S_.

+ + 1. Let _envRec_ be the global Environment Record for which the method was invoked. + 1. Let _DclRec_ be _envRec_.[[DeclarativeRecord]]. + 1. If _DclRec_.HasBinding(_N_) is *true*, then + 1. Return _DclRec_.SetMutableBinding(_N_, _V_, _S_). + 1. Let _ObjRec_ be _envRec_.[[ObjectRecord]]. + 1. Return ? _ObjRec_.SetMutableBinding(_N_, _V_, _S_). + +
+ + + +

GetBindingValue ( _N_, _S_ )

+

The concrete Environment Record method GetBindingValue for global Environment Records returns the value of its bound identifier whose name is the value of the argument _N_. If the binding is an uninitialized binding throw a *ReferenceError* exception. A property named _N_ normally already exists but if it does not or is not currently writable, error handling is determined by the value of the Boolean argument _S_.

+ + 1. Let _envRec_ be the global Environment Record for which the method was invoked. + 1. Let _DclRec_ be _envRec_.[[DeclarativeRecord]]. + 1. If _DclRec_.HasBinding(_N_) is *true*, then + 1. Return _DclRec_.GetBindingValue(_N_, _S_). + 1. Let _ObjRec_ be _envRec_.[[ObjectRecord]]. + 1. Return ? _ObjRec_.GetBindingValue(_N_, _S_). + +
+ + + +

DeleteBinding ( _N_ )

+

The concrete Environment Record method DeleteBinding for global Environment Records can only delete bindings that have been explicitly designated as being subject to deletion.

+ + 1. Let _envRec_ be the global Environment Record for which the method was invoked. + 1. Let _DclRec_ be _envRec_.[[DeclarativeRecord]]. + 1. If _DclRec_.HasBinding(_N_) is *true*, then + 1. Return _DclRec_.DeleteBinding(_N_). + 1. Let _ObjRec_ be _envRec_.[[ObjectRecord]]. + 1. Let _globalObject_ be the binding object for _ObjRec_. + 1. Let _existingProp_ be ? HasOwnProperty(_globalObject_, _N_). + 1. If _existingProp_ is *true*, then + 1. Let _status_ be ? _ObjRec_.DeleteBinding(_N_). + 1. If _status_ is *true*, then + 1. Let _varNames_ be _envRec_.[[VarNames]]. + 1. If _N_ is an element of _varNames_, remove that element from the _varNames_. + 1. Return _status_. + 1. Return *true*. + +
+ + + +

HasThisBinding ( )

+ + 1. Return *true*. + +
+ + + +

HasSuperBinding ( )

+ + 1. Return *false*. + +
+ + + +

WithBaseObject ( )

+

Global Environment Records always return *undefined* as their WithBaseObject.

+ + 1. Return *undefined*. + +
+ + + +

GetThisBinding ( )

+ + 1. Let _envRec_ be the global Environment Record for which the method was invoked. + 1. Return _envRec_.[[GlobalThisValue]]. + +
+ + + +

HasVarDeclaration ( _N_ )

+

The concrete Environment Record method HasVarDeclaration for global Environment Records determines if the argument identifier has a binding in this record that was created using a |VariableStatement| or a |FunctionDeclaration|:

+ + 1. Let _envRec_ be the global Environment Record for which the method was invoked. + 1. Let _varDeclaredNames_ be _envRec_.[[VarNames]]. + 1. If _varDeclaredNames_ contains _N_, return *true*. + 1. Return *false*. + +
+ + + +

HasLexicalDeclaration ( _N_ )

+

The concrete Environment Record method HasLexicalDeclaration for global Environment Records determines if the argument identifier has a binding in this record that was created using a lexical declaration such as a |LexicalDeclaration| or a |ClassDeclaration|:

+ + 1. Let _envRec_ be the global Environment Record for which the method was invoked. + 1. Let _DclRec_ be _envRec_.[[DeclarativeRecord]]. + 1. Return _DclRec_.HasBinding(_N_). + +
+ + + +

HasRestrictedGlobalProperty ( _N_ )

+

The concrete Environment Record method HasRestrictedGlobalProperty for global Environment Records determines if the argument identifier is the name of a property of the global object that must not be shadowed by a global lexical binding:

+ + 1. Let _envRec_ be the global Environment Record for which the method was invoked. + 1. Let _ObjRec_ be _envRec_.[[ObjectRecord]]. + 1. Let _globalObject_ be the binding object for _ObjRec_. + 1. Let _existingProp_ be ? _globalObject_.[[GetOwnProperty]](_N_). + 1. If _existingProp_ is *undefined*, return *false*. + 1. If _existingProp_.[[Configurable]] is *true*, return *false*. + 1. Return *true*. + + +

Properties may exist upon a global object that were directly created rather than being declared using a var or function declaration. A global lexical binding may not be created that has the same name as a non-configurable property of the global object. The global property `undefined` is an example of such a property.

+
+
+ + + +

CanDeclareGlobalVar ( _N_ )

+

The concrete Environment Record method CanDeclareGlobalVar for global Environment Records determines if a corresponding CreateGlobalVarBinding call would succeed if called for the same argument _N_. Redundant var declarations and var declarations for pre-existing global object properties are allowed.

+ + 1. Let _envRec_ be the global Environment Record for which the method was invoked. + 1. Let _ObjRec_ be _envRec_.[[ObjectRecord]]. + 1. Let _globalObject_ be the binding object for _ObjRec_. + 1. Let _hasProperty_ be ? HasOwnProperty(_globalObject_, _N_). + 1. If _hasProperty_ is *true*, return *true*. + 1. Return ? IsExtensible(_globalObject_). + +
+ + + +

CanDeclareGlobalFunction ( _N_ )

+

The concrete Environment Record method CanDeclareGlobalFunction for global Environment Records determines if a corresponding CreateGlobalFunctionBinding call would succeed if called for the same argument _N_.

+ + 1. Let _envRec_ be the global Environment Record for which the method was invoked. + 1. Let _ObjRec_ be _envRec_.[[ObjectRecord]]. + 1. Let _globalObject_ be the binding object for _ObjRec_. + 1. Let _existingProp_ be ? _globalObject_.[[GetOwnProperty]](_N_). + 1. If _existingProp_ is *undefined*, return ? IsExtensible(_globalObject_). + 1. If _existingProp_.[[Configurable]] is *true*, return *true*. + 1. If IsDataDescriptor(_existingProp_) is *true* and _existingProp_ has attribute values {[[Writable]]: *true*, [[Enumerable]]: *true*}, return *true*. + 1. Return *false*. + +
+ + + +

CreateGlobalVarBinding ( _N_, _D_ )

+

The concrete Environment Record method CreateGlobalVarBinding for global Environment Records creates and initializes a mutable binding in the associated object Environment Record and records the bound name in the associated [[VarNames]] List. If a binding already exists, it is reused and assumed to be initialized.

+ + 1. Let _envRec_ be the global Environment Record for which the method was invoked. + 1. Let _ObjRec_ be _envRec_.[[ObjectRecord]]. + 1. Let _globalObject_ be the binding object for _ObjRec_. + 1. Let _hasProperty_ be ? HasOwnProperty(_globalObject_, _N_). + 1. Let _extensible_ be ? IsExtensible(_globalObject_). + 1. If _hasProperty_ is *false* and _extensible_ is *true*, then + 1. Perform ? _ObjRec_.CreateMutableBinding(_N_, _D_). + 1. Perform ? _ObjRec_.InitializeBinding(_N_, *undefined*). + 1. Let _varDeclaredNames_ be _envRec_.[[VarNames]]. + 1. If _varDeclaredNames_ does not contain _N_, then + 1. Append _N_ to _varDeclaredNames_. + 1. Return NormalCompletion(~empty~). + +
+ + + +

CreateGlobalFunctionBinding ( _N_, _V_, _D_ )

+

The concrete Environment Record method CreateGlobalFunctionBinding for global Environment Records creates and initializes a mutable binding in the associated object Environment Record and records the bound name in the associated [[VarNames]] List. If a binding already exists, it is replaced.

+ + 1. Let _envRec_ be the global Environment Record for which the method was invoked. + 1. Let _ObjRec_ be _envRec_.[[ObjectRecord]]. + 1. Let _globalObject_ be the binding object for _ObjRec_. + 1. Let _existingProp_ be ? _globalObject_.[[GetOwnProperty]](_N_). + 1. If _existingProp_ is *undefined* or _existingProp_.[[Configurable]] is *true*, then + 1. Let _desc_ be the PropertyDescriptor{[[Value]]: _V_, [[Writable]]: *true*, [[Enumerable]]: *true*, [[Configurable]]: _D_}. + 1. Else, + 1. Let _desc_ be the PropertyDescriptor{[[Value]]: _V_ }. + 1. Perform ? DefinePropertyOrThrow(_globalObject_, _N_, _desc_). + 1. Record that the binding for _N_ in _ObjRec_ has been initialized. + 1. Perform ? Set(_globalObject_, _N_, _V_, *false*). + 1. Let _varDeclaredNames_ be _envRec_.[[VarNames]]. + 1. If _varDeclaredNames_ does not contain _N_, then + 1. Append _N_ to _varDeclaredNames_. + 1. Return NormalCompletion(~empty~). + + +

Global function declarations are always represented as own properties of the global object. If possible, an existing own property is reconfigured to have a standard set of attribute values. Steps 8-9 are equivalent to what calling the InitializeBinding concrete method would do and if _globalObject_ is a Proxy will produce the same sequence of Proxy trap calls.

+
+
+
+ + + +

Module Environment Records

+

A module Environment Record is a declarative Environment Record that is used to represent the outer scope of an ECMAScript |Module|. In additional to normal mutable and immutable bindings, module Environment Records also provide immutable import bindings which are bindings that provide indirect access to a target binding that exists in another Environment Record.

+

Module Environment Records support all of the declarative Environment Record methods listed in and share the same specifications for all of those methods except for GetBindingValue, DeleteBinding, HasThisBinding and GetThisBinding. In addition, module Environment Records support the methods listed in :

+ + + + + + + + + + + + + + + + +
+ Method + + Purpose +
+ CreateImportBinding(N, M, N2) + + Create an immutable indirect binding in a module Environment Record. The String value _N_ is the text of the bound name. _M_ is a Module Record, and _N2_ is a binding that exists in M's module Environment Record. +
+ GetThisBinding() + + Return the value of this Environment Record's `this` binding. +
+
+

The behaviour of the additional concrete specification methods for module Environment Records are defined by the following algorithms:

+ + + +

GetBindingValue ( _N_, _S_ )

+

The concrete Environment Record method GetBindingValue for module Environment Records returns the value of its bound identifier whose name is the value of the argument _N_. However, if the binding is an indirect binding the value of the target binding is returned. If the binding exists but is uninitialized a *ReferenceError* is thrown.

+ + 1. Assert: _S_ is *true*. + 1. Let _envRec_ be the module Environment Record for which the method was invoked. + 1. Assert: _envRec_ has a binding for _N_. + 1. If the binding for _N_ is an indirect binding, then + 1. Let _M_ and _N2_ be the indirection values provided when this binding for _N_ was created. + 1. Let _targetEnv_ be _M_.[[Environment]]. + 1. If _targetEnv_ is *undefined*, throw a *ReferenceError* exception. + 1. Let _targetER_ be _targetEnv_'s EnvironmentRecord. + 1. Return ? _targetER_.GetBindingValue(_N2_, *true*). + 1. If the binding for _N_ in _envRec_ is an uninitialized binding, throw a *ReferenceError* exception. + 1. Return the value currently bound to _N_ in _envRec_. + + +

_S_ will always be *true* because a |Module| is always strict mode code.

+
+
+ + + +

DeleteBinding ( _N_ )

+

The concrete Environment Record method DeleteBinding for module Environment Records refuses to delete bindings.

+ + 1. Assert: This method is never invoked. See . + + +

Module Environment Records are only used within strict code and an early error rule prevents the delete operator, in strict code, from being applied to a Reference that would resolve to a module Environment Record binding. See .

+
+
+ + + +

HasThisBinding ( )

+

Module Environment Records provide a `this` binding.

+ + 1. Return *true*. + +
+ + + +

GetThisBinding ( )

+ + 1. Return *undefined*. + +
+ + + +

CreateImportBinding ( _N_, _M_, _N2_ )

+

The concrete Environment Record method CreateImportBinding for module Environment Records creates a new initialized immutable indirect binding for the name _N_. A binding must not already exist in this Environment Record for _N_. _M_ is a Module Record, and _N2_ is the name of a binding that exists in M's module Environment Record. Accesses to the value of the new binding will indirectly access the bound value of the target binding.

+ + 1. Let _envRec_ be the module Environment Record for which the method was invoked. + 1. Assert: _envRec_ does not already have a binding for _N_. + 1. Assert: _M_ is a Module Record. + 1. Assert: When _M_.[[Environment]] is instantiated it will have a direct binding for _N2_. + 1. Create an immutable indirect binding in _envRec_ for _N_ that references _M_ and _N2_ as its target binding and record that the binding is initialized. + 1. Return NormalCompletion(~empty~). + +
+
+
+ + + +

Lexical Environment Operations

+

The following abstract operations are used in this specification to operate upon lexical environments:

+ + + +

GetIdentifierReference ( _lex_, _name_, _strict_ )

+

The abstract operation GetIdentifierReference is called with a Lexical Environment _lex_, a String _name_, and a Boolean flag _strict_. The value of _lex_ may be *null*. When called, the following steps are performed:

+ + 1. If _lex_ is the value *null*, then + 1. Return a value of type Reference whose base value component is *undefined*, whose referenced name component is _name_, and whose strict reference flag is _strict_. + 1. Let _envRec_ be _lex_'s EnvironmentRecord. + 1. Let _exists_ be ? _envRec_.HasBinding(_name_). + 1. If _exists_ is *true*, then + 1. Return a value of type Reference whose base value component is _envRec_, whose referenced name component is _name_, and whose strict reference flag is _strict_. + 1. Else, + 1. Let _outer_ be the value of _lex_'s outer environment reference. + 1. Return ? GetIdentifierReference(_outer_, _name_, _strict_). + +
+ + + +

NewDeclarativeEnvironment ( _E_ )

+

When the abstract operation NewDeclarativeEnvironment is called with a Lexical Environment as argument _E_ the following steps are performed:

+ + 1. Let _env_ be a new Lexical Environment. + 1. Let _envRec_ be a new declarative Environment Record containing no bindings. + 1. Set _env_'s EnvironmentRecord to _envRec_. + 1. Set the outer lexical environment reference of _env_ to _E_. + 1. Return _env_. + +
+ + + +

NewObjectEnvironment ( _O_, _E_ )

+

When the abstract operation NewObjectEnvironment is called with an Object _O_ and a Lexical Environment _E_ as arguments, the following steps are performed:

+ + 1. Let _env_ be a new Lexical Environment. + 1. Let _envRec_ be a new object Environment Record containing _O_ as the binding object. + 1. Set _env_'s EnvironmentRecord to _envRec_. + 1. Set the outer lexical environment reference of _env_ to _E_. + 1. Return _env_. + +
+ + + +

NewFunctionEnvironment ( _F_, _newTarget_ )

+

When the abstract operation NewFunctionEnvironment is called with arguments _F_ and _newTarget_ the following steps are performed:

+ + 1. Assert: _F_ is an ECMAScript function. + 1. Assert: Type(_newTarget_) is Undefined or Object. + 1. Let _env_ be a new Lexical Environment. + 1. Let _envRec_ be a new function Environment Record containing no bindings. + 1. Set _envRec_.[[FunctionObject]] to _F_. + 1. If _F_.[[ThisMode]] is ~lexical~, set _envRec_.[[ThisBindingStatus]] to `"lexical"`. + 1. Else, set _envRec_.[[ThisBindingStatus]] to `"uninitialized"`. + 1. Let _home_ be _F_.[[HomeObject]]. + 1. Set _envRec_.[[HomeObject]] to _home_. + 1. Set _envRec_.[[NewTarget]] to _newTarget_. + 1. Set _env_'s EnvironmentRecord to _envRec_. + 1. Set the outer lexical environment reference of _env_ to _F_.[[Environment]]. + 1. Return _env_. + +
+ + + +

NewGlobalEnvironment ( _G_, _thisValue_ )

+

When the abstract operation NewGlobalEnvironment is called with arguments _G_ and _thisValue_, the following steps are performed:

+ + 1. Let _env_ be a new Lexical Environment. + 1. Let _objRec_ be a new object Environment Record containing _G_ as the binding object. + 1. Let _dclRec_ be a new declarative Environment Record containing no bindings. + 1. Let _globalRec_ be a new global Environment Record. + 1. Set _globalRec_.[[ObjectRecord]] to _objRec_. + 1. Set _globalRec_.[[GlobalThisValue]] to _thisValue_. + 1. Set _globalRec_.[[DeclarativeRecord]] to _dclRec_. + 1. Set _globalRec_.[[VarNames]] to a new empty List. + 1. Set _env_'s EnvironmentRecord to _globalRec_. + 1. Set the outer lexical environment reference of _env_ to *null*. + 1. Return _env_. + +
+ + + +

NewModuleEnvironment ( _E_ )

+

When the abstract operation NewModuleEnvironment is called with a Lexical Environment argument _E_ the following steps are performed:

+ + 1. Let _env_ be a new Lexical Environment. + 1. Let _envRec_ be a new module Environment Record containing no bindings. + 1. Set _env_'s EnvironmentRecord to _envRec_. + 1. Set the outer lexical environment reference of _env_ to _E_. + 1. Return _env_. + +
+
+
\ No newline at end of file diff --git a/translated/issues-18.html b/translated/issues-18.html new file mode 100644 index 00000000000..007844e4db6 --- /dev/null +++ b/translated/issues-18.html @@ -0,0 +1,516 @@ + +

Realms

+

Before it is evaluated, all ECMAScript code must be associated with a realm. Conceptually, a realm consists of a set of intrinsic objects, an ECMAScript global environment, all of the ECMAScript code that is loaded within the scope of that global environment, and other associated state and resources.

+

A realm is represented in this specification as a Realm Record with the fields specified in :

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Field Name + + Value + + Meaning +
+ [[Intrinsics]] + + Record whose field names are intrinsic keys and whose values are objects + + The intrinsic values used by code associated with this realm +
+ [[GlobalObject]] + + Object + + The global object for this realm +
+ [[GlobalEnv]] + + Lexical Environment + + The global environment for this realm +
+ [[TemplateMap]] + + A List of Record { [[Strings]]: List, [[Array]]: Object}. + + Template objects are canonicalized separately for each realm using its Realm Record's [[TemplateMap]]. Each [[Strings]] value is a List containing, in source text order, the raw String values of a |TemplateLiteral| that has been evaluated. The associated [[Array]] value is the corresponding template object that is passed to a tag function. +
+ [[HostDefined]] + + Any, default value is *undefined*. + + Field reserved for use by host environments that need to associate additional information with a Realm Record. +
+
+ + + +

CreateRealm ( )

+

The abstract operation CreateRealm with no arguments performs the following steps:

+ + 1. Let _realmRec_ be a new Realm Record. + 1. Perform CreateIntrinsics(_realmRec_). + 1. Set _realmRec_.[[GlobalObject]] to *undefined*. + 1. Set _realmRec_.[[GlobalEnv]] to *undefined*. + 1. Set _realmRec_.[[TemplateMap]] to a new empty List. + 1. Return _realmRec_. + +
+ + + +

CreateIntrinsics ( _realmRec_ )

+

The abstract operation CreateIntrinsics with argument _realmRec_ performs the following steps:

+ + 1. Let _intrinsics_ be a new Record. + 1. Set _realmRec_.[[Intrinsics]] to _intrinsics_. + 1. Let _objProto_ be ObjectCreate(*null*). + 1. Set _intrinsics_.[[%ObjectPrototype%]] to _objProto_. + 1. Let _throwerSteps_ be the algorithm steps specified in for the %ThrowTypeError% function. + 1. Let _thrower_ be CreateBuiltinFunction(_realmRec_, _throwerSteps_, *null*). + 1. Set _intrinsics_.[[%ThrowTypeError%]] to _thrower_. + 1. Let _noSteps_ be an empty sequence of algorithm steps. + 1. Let _funcProto_ be CreateBuiltinFunction(_realmRec_, _noSteps_, _objProto_). + 1. Set _intrinsics_.[[%FunctionPrototype%]] to _funcProto_. + 1. Call _thrower_.[[SetPrototypeOf]](_funcProto_). + 1. Perform AddRestrictedFunctionProperties(_funcProto_, _realmRec_). + 1. Set fields of _intrinsics_ with the values listed in that have not already been handled above. The field names are the names listed in column one of the table. The value of each field is a new object value fully and recursively populated with property values as defined by the specification of each object in clauses 18-26. All object property values are newly created object values. All values that are built-in function objects are created by performing CreateBuiltinFunction(_realmRec_, <steps>, <prototype>, <slots>) where <steps> is the definition of that function provided by this specification, <prototype> is the specified value of the function's [[Prototype]] internal slot and <slots> is a list of the names, if any, of the function's specified internal slots. The creation of the intrinsics and their properties must be ordered to avoid any dependencies upon objects that have not yet been created. + 1. Return _intrinsics_. + +
+ + + +

SetRealmGlobalObject ( _realmRec_, _globalObj_, _thisValue_ )

+

The abstract operation SetRealmGlobalObject with arguments _realmRec_, _globalObj_, and _thisValue_ performs the following steps:

+ + 1. If _globalObj_ is *undefined*, then + 1. Let _intrinsics_ be _realmRec_.[[Intrinsics]]. + 1. Set _globalObj_ to ObjectCreate(_intrinsics_.[[%ObjectPrototype%]]). + 1. Assert: Type(_globalObj_) is Object. + 1. If _thisValue_ is *undefined*, set _thisValue_ to _globalObj_. + 1. Set _realmRec_.[[GlobalObject]] to _globalObj_. + 1. Let _newGlobalEnv_ be NewGlobalEnvironment(_globalObj_, _thisValue_). + 1. Set _realmRec_.[[GlobalEnv]] to _newGlobalEnv_. + 1. Return _realmRec_. + +
+ + + +

SetDefaultGlobalBindings ( _realmRec_ )

+

The abstract operation SetDefaultGlobalBindings with argument _realmRec_ performs the following steps:

+ + 1. Let _global_ be _realmRec_.[[GlobalObject]]. + 1. For each property of the Global Object specified in clause , do + 1. Let _name_ be the String value of the property name. + 1. Let _desc_ be the fully populated data property descriptor for the property containing the specified attributes for the property. For properties listed in , , or the value of the [[Value]] attribute is the corresponding intrinsic object from _realmRec_. + 1. Perform ? DefinePropertyOrThrow(_global_, _name_, _desc_). + 1. Return _global_. + +
+
+ + + +

Execution Contexts

+

An execution context is a specification device that is used to track the runtime evaluation of code by an ECMAScript implementation. At any point in time, there is at most one execution context per agent that is actually executing code. This is known as the agent's running execution context. All references to the running execution context in this specification denote the running execution context of the surrounding agent.

+

The execution context stack is used to track execution contexts. The running execution context is always the top element of this stack. A new execution context is created whenever control is transferred from the executable code associated with the currently running execution context to executable code that is not associated with that execution context. The newly created execution context is pushed onto the stack and becomes the running execution context.

+

An execution context contains whatever implementation specific state is necessary to track the execution progress of its associated code. Each execution context has at least the state components listed in .

+ + + + + + + + + + + + + + + + + + + + + + + + +
+ Component + + Purpose +
+ code evaluation state + + Any state needed to perform, suspend, and resume evaluation of the code associated with this execution context. +
+ Function + + If this execution context is evaluating the code of a function object, then the value of this component is that function object. If the context is evaluating the code of a |Script| or |Module|, the value is *null*. +
+ Realm + + The Realm Record from which associated code accesses ECMAScript resources. +
+ ScriptOrModule + + The Module Record or Script Record from which associated code originates. If there is no originating script or module, as is the case for the original execution context created in InitializeHostDefinedRealm, the value is *null*. +
+
+

Evaluation of code by the running execution context may be suspended at various points defined within this specification. Once the running execution context has been suspended a different execution context may become the running execution context and commence evaluating its code. At some later time a suspended execution context may again become the running execution context and continue evaluating its code at the point where it had previously been suspended. Transition of the running execution context status among execution contexts usually occurs in stack-like last-in/first-out manner. However, some ECMAScript features require non-LIFO transitions of the running execution context.

+

The value of the Realm component of the running execution context is also called the current Realm Record. The value of the Function component of the running execution context is also called the active function object.

+

Execution contexts for ECMAScript code have the additional state components listed in .

+ + + + + + + + + + + + + + + + +
+ Component + + Purpose +
+ LexicalEnvironment + + Identifies the Lexical Environment used to resolve identifier references made by code within this execution context. +
+ VariableEnvironment + + Identifies the Lexical Environment whose EnvironmentRecord holds bindings created by |VariableStatement|s within this execution context. +
+
+

The LexicalEnvironment and VariableEnvironment components of an execution context are always Lexical Environments.

+

Execution contexts representing the evaluation of generator objects have the additional state components listed in .

+ + + + + + + + + + + + +
+ Component + + Purpose +
+ Generator + + The GeneratorObject that this execution context is evaluating. +
+
+

In most situations only the running execution context (the top of the execution context stack) is directly manipulated by algorithms within this specification. Hence when the terms “LexicalEnvironment”, and “VariableEnvironment” are used without qualification they are in reference to those components of the running execution context.

+

An execution context is purely a specification mechanism and need not correspond to any particular artefact of an ECMAScript implementation. It is impossible for ECMAScript code to directly access or observe an execution context.

+ + +

GetActiveScriptOrModule ( )

+

The GetActiveScriptOrModule abstract operation is used to determine the running script or module, based on the running execution context. GetActiveScriptOrModule performs the following steps:

+ + + 1. If the execution context stack is empty, return *null*. + 1. Let _ec_ be the topmost execution context on the execution context stack whose ScriptOrModule component is not *null*. + 1. If no such execution context exists, return *null*. Otherwise, return _ec_'s ScriptOrModule component. + +
+ + + +

ResolveBinding ( _name_ [ , _env_ ] )

+

The ResolveBinding abstract operation is used to determine the binding of _name_ passed as a String value. The optional argument _env_ can be used to explicitly provide the Lexical Environment that is to be searched for the binding. During execution of ECMAScript code, ResolveBinding is performed using the following algorithm:

+ + 1. If _env_ is not present or if _env_ is *undefined*, then + 1. Set _env_ to the running execution context's LexicalEnvironment. + 1. Assert: _env_ is a Lexical Environment. + 1. If the code matching the syntactic production that is being evaluated is contained in strict mode code, let _strict_ be *true*, else let _strict_ be *false*. + 1. Return ? GetIdentifierReference(_env_, _name_, _strict_). + + +

The result of ResolveBinding is always a Reference value with its referenced name component equal to the _name_ argument.

+
+
+ + + +

GetThisEnvironment ( )

+

The abstract operation GetThisEnvironment finds the Environment Record that currently supplies the binding of the keyword `this`. GetThisEnvironment performs the following steps:

+ + 1. Let _lex_ be the running execution context's LexicalEnvironment. + 1. Repeat, + 1. Let _envRec_ be _lex_'s EnvironmentRecord. + 1. Let _exists_ be _envRec_.HasThisBinding(). + 1. If _exists_ is *true*, return _envRec_. + 1. Let _outer_ be the value of _lex_'s outer environment reference. + 1. Assert: _outer_ is not *null*. + 1. Set _lex_ to _outer_. + + +

The loop in step 2 will always terminate because the list of environments always ends with the global environment which has a `this` binding.

+
+
+ + + +

ResolveThisBinding ( )

+

The abstract operation ResolveThisBinding determines the binding of the keyword `this` using the LexicalEnvironment of the running execution context. ResolveThisBinding performs the following steps:

+ + 1. Let _envRec_ be GetThisEnvironment( ). + 1. Return ? _envRec_.GetThisBinding(). + +
+ + + +

GetNewTarget ( )

+

The abstract operation GetNewTarget determines the NewTarget value using the LexicalEnvironment of the running execution context. GetNewTarget performs the following steps:

+ + 1. Let _envRec_ be GetThisEnvironment( ). + 1. Assert: _envRec_ has a [[NewTarget]] field. + 1. Return _envRec_.[[NewTarget]]. + +
+ + + +

GetGlobalObject ( )

+

The abstract operation GetGlobalObject returns the global object used by the currently running execution context. GetGlobalObject performs the following steps:

+ + 1. Let _ctx_ be the running execution context. + 1. Let _currentRealm_ be _ctx_'s Realm. + 1. Return _currentRealm_.[[GlobalObject]]. + +
+
+ + + +

Jobs and Job Queues

+

A Job is an abstract operation that initiates an ECMAScript computation when no other ECMAScript computation is currently in progress. A Job abstract operation may be defined to accept an arbitrary set of job parameters.

+

Execution of a Job can be initiated only when there is no running execution context and the execution context stack is empty. A PendingJob is a request for the future execution of a Job. A PendingJob is an internal Record whose fields are specified in . Once execution of a Job is initiated, the Job always executes to completion. No other Job may be initiated until the currently running Job completes. However, the currently running Job or external events may cause the enqueuing of additional PendingJobs that may be initiated sometime after completion of the currently running Job.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Field Name + + Value + + Meaning +
+ [[Job]] + + The name of a Job abstract operation + + This is the abstract operation that is performed when execution of this PendingJob is initiated. +
+ [[Arguments]] + + A List + + The List of argument values that are to be passed to [[Job]] when it is activated. +
+ [[Realm]] + + A Realm Record + + The Realm Record for the initial execution context when this PendingJob is initiated. +
+ [[ScriptOrModule]] + + A Script Record or Module Record + + The script or module for the initial execution context when this PendingJob is initiated. +
+ [[HostDefined]] + + Any, default value is *undefined*. + + Field reserved for use by host environments that need to associate additional information with a pending Job. +
+
+

A Job Queue is a FIFO queue of PendingJob records. Each Job Queue has a name and the full set of available Job Queues are defined by an ECMAScript implementation. Every ECMAScript implementation has at least the Job Queues defined in .

+

Each agent has its own set of named Job Queues. All references to a named job queue in this specification denote the named job queue of the surrounding agent.

+ + + + + + + + + + + + + + + + +
+ Name + + Purpose +
+ ScriptJobs + + Jobs that validate and evaluate ECMAScript |Script| and |Module| source text. See clauses 10 and 15. +
+ PromiseJobs + + Jobs that are responses to the settlement of a Promise (see ). +
+
+

A request for the future execution of a Job is made by enqueueing, on a Job Queue, a PendingJob record that includes a Job abstract operation name and any necessary argument values. When there is no running execution context and the execution context stack is empty, the ECMAScript implementation removes the first PendingJob from a Job Queue and uses the information contained in it to create an execution context and starts execution of the associated Job abstract operation.

+

The PendingJob records from a single Job Queue are always initiated in FIFO order. This specification does not define the order in which multiple Job Queues are serviced. An ECMAScript implementation may interweave the FIFO evaluation of the PendingJob records of a Job Queue with the evaluation of the PendingJob records of one or more other Job Queues. An implementation must define what occurs when there are no running execution context and all Job Queues are empty.

+ +

Typically an ECMAScript implementation will have its Job Queues pre-initialized with at least one PendingJob and one of those Jobs will be the first to be executed. An implementation might choose to free all resources and terminate if the current Job completes and all Job Queues are empty. Alternatively, it might choose to wait for a some implementation specific agent or mechanism to enqueue new PendingJob requests.

+
+

The following abstract operations are used to create and manage Jobs and Job Queues:

+ + + +

EnqueueJob ( _queueName_, _job_, _arguments_ )

+

The EnqueueJob abstract operation requires three arguments: _queueName_, _job_, and _arguments_. It performs the following steps:

+ + 1. Assert: Type(_queueName_) is String and its value is the name of a Job Queue recognized by this implementation. + 1. Assert: _job_ is the name of a Job. + 1. Assert: _arguments_ is a List that has the same number of elements as the number of parameters required by _job_. + 1. Let _callerContext_ be the running execution context. + 1. Let _callerRealm_ be _callerContext_'s Realm. + 1. Let _callerScriptOrModule_ be _callerContext_'s ScriptOrModule. + 1. Let _pending_ be PendingJob{ [[Job]]: _job_, [[Arguments]]: _arguments_, [[Realm]]: _callerRealm_, [[ScriptOrModule]]: _callerScriptOrModule_, [[HostDefined]]: *undefined* }. + 1. Perform any implementation or host environment defined processing of _pending_. This may include modifying the [[HostDefined]] field or any other field of _pending_. + 1. Add _pending_ at the back of the Job Queue named by _queueName_. + 1. Return NormalCompletion(~empty~). + +
+
+ + +

InitializeHostDefinedRealm ( )

+

The abstract operation InitializeHostDefinedRealm performs the following steps:

+ + + 1. Let _realm_ be CreateRealm(). + 1. Let _newContext_ be a new execution context. + 1. Set the Function of _newContext_ to *null*. + 1. Set the Realm of _newContext_ to _realm_. + 1. Set the ScriptOrModule of _newContext_ to *null*. + 1. Push _newContext_ onto the execution context stack; _newContext_ is now the running execution context. + 1. If the host requires use of an exotic object to serve as _realm_'s global object, let _global_ be such an object created in an implementation-defined manner. Otherwise, let _global_ be *undefined*, indicating that an ordinary object should be created as the global object. + 1. If the host requires that the `this` binding in _realm_'s global scope return an object other than the global object, let _thisValue_ be such an object created in an implementation-defined manner. Otherwise, let _thisValue_ be *undefined*, indicating that _realm_'s global `this` binding should be the global object. + 1. Perform SetRealmGlobalObject(_realm_, _global_, _thisValue_). + 1. Let _globalObj_ be ? SetDefaultGlobalBindings(_realm_). + 1. Create any implementation-defined global object properties on _globalObj_. + 1. Return NormalCompletion(~empty~). + +
+ + +

RunJobs ( )

+

The abstract operation RunJobs performs the following steps:

+ + 1. Perform ? InitializeHostDefinedRealm(). + 1. In an implementation-dependent manner, obtain the ECMAScript source texts (see clause ) and any associated host-defined values for zero or more ECMAScript scripts and/or ECMAScript modules. For each such _sourceText_ and _hostDefined_, do + 1. If _sourceText_ is the source code of a script, then + 1. Perform EnqueueJob(`"ScriptJobs"`, ScriptEvaluationJob, « _sourceText_, _hostDefined_ »). + 1. Else _sourceText_ is the source code of a module, + 1. Perform EnqueueJob(`"ScriptJobs"`, TopLevelModuleEvaluationJob, « _sourceText_, _hostDefined_ »). + 1. Repeat, + 1. Suspend the running execution context and remove it from the execution context stack. + 1. Assert: The execution context stack is now empty. + 1. Let _nextQueue_ be a non-empty Job Queue chosen in an implementation-defined manner. If all Job Queues are empty, the result is implementation-defined. + 1. Let _nextPending_ be the PendingJob record at the front of _nextQueue_. Remove that record from _nextQueue_. + 1. Let _newContext_ be a new execution context. + 1. Set _newContext_'s Function to *null*. + 1. Set _newContext_'s Realm to _nextPending_.[[Realm]]. + 1. Set _newContext_'s ScriptOrModule to _nextPending_.[[ScriptOrModule]]. + 1. Push _newContext_ onto the execution context stack; _newContext_ is now the running execution context. + 1. Perform any implementation or host environment defined job initialization using _nextPending_. + 1. Let _result_ be the result of performing the abstract operation named by _nextPending_.[[Job]] using the elements of _nextPending_.[[Arguments]] as its arguments. + 1. If _result_ is an abrupt completion, perform HostReportErrors(« _result_.[[Value]] »). + +
\ No newline at end of file diff --git a/translated/issues-19.html b/translated/issues-19.html new file mode 100644 index 00000000000..a5973419c4d --- /dev/null +++ b/translated/issues-19.html @@ -0,0 +1,159 @@ + +

Agents

+ +

An agent comprises a set of ECMAScript execution contexts, an execution context stack, a running execution context, a set of named job queues, an Agent Record, and an executing thread. Except for the executing thread, the constituents of an agent belong exclusively to that agent.

+

An agent's executing thread executes the jobs in the agent's job queues on the agent's execution contexts independently of other agents, except that an executing thread may be used as the executing thread by multiple agents, provided none of the agents sharing the thread have an Agent Record whose [[CanBlock]] property is *true*.

+ +

Some web browsers share a single executing thread across multiple unrelated tabs of a browser window, for example.

+
+

While an agent's executing thread executes the jobs in the agent's job queues, the agent is the surrounding agent for the code in those jobs. The code uses the surrounding agent to access the specification level execution objects held within the agent: the running execution context, the execution context stack, the named job queues, and the Agent Record's fields.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Field NameValueMeaning
[[LittleEndian]]BooleanThe default value computed for the isLittleEndian parameter when it is needed by the algorithms GetValueFromBuffer and SetValueInBuffer. The choice is implementation-dependent and should be the alternative that is most efficient for the implementation. Once the value has been observed it cannot change.
[[CanBlock]]BooleanDetermines whether the agent can block or not.
[[Signifier]]Any globally-unique valueUniquely identifies the agent within its agent cluster.
[[IsLockFree1]]Boolean*true* if atomic operations on one-byte values are lock-free, *false* otherwise.
[[IsLockFree2]]Boolean*true* if atomic operations on two-byte values are lock-free, *false* otherwise.
[[CandidateExecution]]A candidate execution RecordSee the memory model.
+
+ +

Once the values of [[Signifier]], [[IsLockFree1]], and [[IsLockFree2]] have been observed by any agent in the agent cluster they cannot change.

+ + +

The values of [[IsLockFree1]] and [[IsLockFree2]] are not necessarily determined by the hardware, but may also reflect implementation choices that can vary over time and between ECMAScript implementations.

+ +

There is no [[IsLockFree4]] property: 4-byte atomic operations are always lock-free.

+ +

In practice, if an atomic operation is implemented with any type of lock the operation is not lock-free. Lock-free does not imply wait-free: there is no upper bound on how many machine steps may be required to complete a lock-free atomic operation.

+ +

That an atomic access of size n is lock-free does not imply anything about the (perceived) atomicity of non-atomic accesses of size n, specifically, non-atomic accesses may still be performed as a sequence of several separate memory accesses. See ReadSharedMemory and WriteSharedMemory for details.

+
+ + +

An agent is a specification mechanism and need not correspond to any particular artefact of an ECMAScript implementation.

+
+ + +

AgentSignifier( )

+

The abstract operation AgentSignifier takes no arguments. It performs the following steps:

+ + 1. Let _AR_ be the Agent Record of the surrounding agent. + 1. Return _AR_.[[Signifier]]. + +
+ + +

AgentCanSuspend( )

+

The abstract operation AgentCanSuspend takes no arguments. It performs the following steps:

+ + 1. Let _AR_ be the Agent Record of the surrounding agent. + 1. Return _AR_.[[CanBlock]]. + + +

In some environments it may not be reasonable for a given agent to suspend. For example, in a web browser environment, it may be reasonable to disallow suspending a document's main event handling thread, while still allowing workers' event handling threads to suspend.

+
+
+
+ + +

Agent Clusters

+ +

An agent cluster is a maximal set of agents that can communicate by operating on shared memory.

+ + +

Programs within different agents may share memory by unspecified means. At a minimum, the backing memory for SharedArrayBuffer objects can be shared among the agents in the cluster.

+ +

There may be agents that can communicate by message passing that cannot share memory; they are never in the same agent cluster.

+
+ +

Every agent belongs to exactly one agent cluster.

+ + +

The agents in a cluster need not all be alive at some particular point in time. If agent A creates another agent B, after which A terminates and B creates agent C, the three agents are in the same cluster if A could share some memory with B and B could share some memory with C.

+
+ +

All agents within a cluster must have the same value for the [[LittleEndian]] property in their respective Agent Records.

+ + +

If different agents within an agent cluster have different values of [[LittleEndian]] it becomes hard to use shared memory for multi-byte data.

+
+ +

All agents within a cluster must have the same values for the [[IsLockFree1]] property in their respective Agent Records; similarly for the [[IsLockFree2]] property.

+ +

All agents within a cluster must have different values for the [[Signifier]] property in their respective Agent Records.

+ +

An embedding may deactivate (stop forward progress) or activate (resume forward progress) an agent without the agent's knowledge or cooperation. If the embedding does so, it must not leave some agents in the cluster active while other agents in the cluster are deactivated indefinitely.

+ + +

The purpose of the preceding restriction is to avoid a situation where an agent deadlocks or starves because another agent has been deactivated. For example, if an HTML shared worker that has a lifetime independent of documents in any windows were allowed to share memory with the dedicated worker of such an independent document, and the document and its dedicated worker were to be deactivated while the dedicated worker holds a lock (say, the document is pushed into its window's history), and the shared worker then tries to acquire the lock, then the shared worker will be blocked until the dedicated worker is activated again, if ever. Meanwhile other workers trying to access the shared worker from other windows will starve.

+ +

The implication of the restriction is that it will not be possible to share memory between agents that don't belong to the same suspend/wake collective within the embedding.

+
+ +

An embedding may terminate an agent without any of the agent's cluster's other agents' prior knowledge or cooperation. If an agent is terminated not by programmatic action of its own or of another agent in the cluster but by forces external to the cluster, then the embedding must choose one of two strategies: Either terminate all the agents in the cluster, or provide reliable APIs that allow the agents in the cluster to coordinate so that at least one remaining member of the cluster will be able to detect the termination, with the termination data containing enough information to identify the agent that was terminated.

+ + +

Examples of that type of termination are: operating systems or users terminating agents that are running in separate processes; the embedding itself terminating an agent that is running in-process with the other agents when per-agent resource accounting indicates that the agent is runaway.

+
+ +

Prior to any evaluation of any ECMAScript code by any agent in a cluster, the [[CandidateExecution]] field of the Agent Record for all agents in the cluster is set to the initial candidate execution. The initial candidate execution is an empty candidate execution whose [[EventLists]] field is a List containing, for each agent, an Agent Events Record whose [[AgentSignifier]] field is that agent's signifier and whose [[EventList]] field is an empty List.

+ + +

All agents in an agent cluster share the same candidate execution in its Agent Record's [[CandidateExecution]] field. The candidate execution is a specification mechanism used by the memory model.

+
+ + +

An agent cluster is a specification mechanism and need not correspond to any particular artefact of an ECMAScript implementation.

+
+
+ + +

Forward Progress

+

For an agent to make forward progress is for it to perform an evaluation step according to this specification.

+

An agent becomes blocked when its running execution context waits synchronously and indefinitely for an external event. Only agents whose Agent Record's [[CanBlock]] property is *true* can become blocked in this sense. An unblocked agent is one that is not blocked.

+ +

Implementations must ensure that:

+ + + +

This, along with the liveness guarantee in the memory model, ensures that all `"SeqCst"` writes eventually become observable to all agents.

+
+
+ +
\ No newline at end of file