[ Pobierz całość w formacie PDF ]
property and its attributes are not changed. Semantically, this step must follow the creation of the
FormalParameterList and FunctionDeclaration properties. In particular, if a declared variable has
the same name as a declared function or formal parameter, the variable declaration does not disturb
the existing property.
10.1.4 Scope Chain and Identifier Resolution
Every execution context has associated with it a scope chain. A scope chain is a list of objects that are
searched when evaluating an Identifier. When control enters an execution context, a scope chain is
created and populated with an initial set of objects, depending on the type of code. During execution
within an execution context, the scope chain of the execution context is affected only by with
statements (see 12.10) andcatchclauses (see 12.14).
During execution, the syntactic production PrimaryExpression : Identifier is evaluated using the
following algorithm:
1. Get the next object in the scope chain. If there isn't one, go to step 5.
2. Call the [[HasProperty]] method of Result(1), passing the Identifier as the property.
3. If Result(2) is true, return a value of type Reference whose base object is Result(1) and whose
property name is the Identifier.
4. Go to step 1.
5. Return a value of type Reference whose base object isnulland whose property name is the
Identifier.
The result of evaluating an identifier is always a value of type Reference with its member name
component equal to the identifier string.
10.1.5 Global Object
There is a unique global object (15.1), which is created before control enters any execution context.
Initially the global object has the following properties:
" Built-in objects such as Math, String, Date, parseInt, etc. These have attributes { DontEnum }.
" Additional host defined properties. This may include a property whose value is the global object
itself; for example, in the HTML document object model thewindowproperty of the global object is
the global object itself.
As control enters execution contexts, and as ECMAScript code is executed, additional properties may be
added to the global object and the initial properties may be changed.
10.1.6 Activation Object
When control enters an execution context for function code, an object called the activation object is
created and associated with the execution context. The activation object is initialised with a property
with nameargumentsand attributes { DontDelete }. The initial value of this property is the arguments
object described below.
The activation object is then used as the variable object for the purposes of variable instantiation.
The activation object is purely a specification mechanism. It is impossible for an ECMAScript program
to access the activation object. It can access members of the activation object, but not the activation
object itself. When the call operation is applied to a Reference value whose base object is an activation
object,nullis used as the this value of the call.
- 39 -
10.1.7 This
There is a this value associated with every active execution context. The this value depends on the caller
and the type of code being executed and is determined when control enters the execution context. The
this value associated with an execution context is immutable.
10.1.8 Arguments Object
When control enters an execution context for function code, an arguments object is created and
initialised as follows:
" The value of the internal [[Prototype]] property of the arguments object is the original Object
prototype object, the one that is the initial value ofObject.prototype(see 15.2.3.1).
" A property is created with namecalleeand property attributes { DontEnum }. The initial value of
this property is the Function object being executed. This allows anonymous functions to be recursive.
" A property is created with namelengthand property attributes { DontEnum }. The initial value of
this property is the number of actual parameter values supplied by the caller.
" For each non-negative integer, arg, less than the value of thelengthproperty, a property is created
with name ToString(arg) and property attributes { DontEnum }. The initial value of this property is
the value of the corresponding actual parameter supplied by the caller. The first actual parameter
value corresponds to arg = 0, the second to arg = 1, and so on. In the case when arg is less than the
number of formal parameters for the Function object, this property shares its value with the
corresponding property of the activation object. This means that changing this property changes the
corresponding property of the activation object and vice versa.
10.2 Entering An Execution Context
Every function and constructor call enters a new execution context, even if a function is calling itself
recursively. Every return exits an execution context. A thrown exception, if not caught, may also exit one
or more execution contexts.
When control enters an execution context, the scope chain is created and initialised, variable instantiation
is performed, and the this value is determined.
The initialisation of the scope chain, variable instantiation, and the determination of the this value depend
on the type of code being entered.
10.2.1 Global Code
" The scope chain is created and initialised to contain the global object and no others.
" Variable instantiation is performed using the global object as the variable object and using property
attributes { DontDelete }.
" The this value is the global object.
10.2.2 Eval Code
When control enters an execution context for eval code, the previous active execution context, referred
to as the calling context, is used to determine the scope chain, the variable object, and the this value. If
there is no calling context, then initialising the scope chain, variable instantiation, and determination of
the this value are performed just as for global code.
" The scope chain is initialised to contain the same objects, in the same order, as the calling context's
scope chain. This includes objects added to the calling context's scope chain bywithstatements and
catchclauses.
" Variable instantiation is performed using the calling context's variable object and using empty
property attributes.
" The this value is the same as the this value of the calling context.
10.2.3 Function Code
" The scope chain is initialised to contain the activation object followed by the objects in the scope
chain stored in the [[Scope]] property of the Function object.
- 40 -
" Variable instantiation is performed using the activation object as the variable object and using
property attributes { DontDelete }.
" The caller provides the this value. If the this value provided by the caller is not an object (including
the case where it isnull), then the this value is the global object.
11 Expressions
11.1 Primary Expressions
Syntax
PrimaryExpression :
this
Identifier
Literal
ArrayLiteral
ObjectLiteral
(Expression)
11.1.1 ThethisKeyword
Thethiskeyword evaluates to the this value of the execution context.
11.1.2 Identifier Reference
An Identifier is evaluated using the scoping rules stated in 10.1.4. The result of evaluating an Identifier
is always a value of type Reference.
11.1.3 Literal Reference
A Literal is evaluated as described in 7.8.
11.1.4 Array Initialiser
An array initialiser is an expression describing the initialisation of an Array object, written in a form of a
[ Pobierz całość w formacie PDF ]