ECMAScript 4 Netscape Proposal
Core Language

Monday, June 30, 2003

Most of the behavior of expressions is the same as in ECMAScript 3. Differences are highlighted below.



|  get
|  set

The above keywords are not reserved and may be used in identifiers.

Qualified Identifiers

|  Identifier :: Identifier
|  ReservedNamespace :: Identifier
ExpressionQualifiedIdentifier  ParenExpression :: Identifier
|  ExpressionQualifiedIdentifier

Just like in ECMAScript Edition 3, an identifier evaluates to an internal data structure called a reference. However, ECMAScript 4 references can be qualified by a qualifier, which, in the general syntax, is a ParenExpression that evaluates to a namespace. For convenience, if the ParenExpression consists of a single identifier, the parentheses may be omitted: (a)::m may be written as a::m.

The reserved words public and private may also be used as qualifiers. public evaluates to the public namespace. internal (which is not a reserved word) evaluates to the containing package’s anonymous namespace. private can only be used inside a class and evaluates to the containing class’s anonymous namespace.

See the name lookup section for more information on the :: operator.

Primary Expressions

|  true
|  false
|  Number
|  String
|  this
|  RegularExpression
|  ReservedNamespace
|  ParenListExpression
|  ArrayLiteral
|  ObjectLiteral
|  FunctionExpression
|  private
ParenExpression  ( AssignmentExpressionallowIn )
|  ( ListExpressionallowIn , AssignmentExpressionallowIn )

public evaluates to the public namespace. private can be used only inside a class and evaluates to that class’s private namespace.

this may only be used in methods, constructors, or functions with the prototype attribute set.

Function Expressions

   function FunctionCommon
|  function Identifier FunctionCommon

A FunctionExpression creates and returns an anonymous function.

Object Literals

ObjectLiteral  { FieldList }
|  NonemptyFieldList
|  LiteralField , NonemptyFieldList
LiteralField  FieldName : AssignmentExpressionallowIn
|  String
|  Number
|  ParenExpression
The ParenExpression is evaluated at run time and its result coerced to a qualified name.

Array Literals

ArrayLiteral  [ ElementList ]
|  LiteralElement
|  , ElementList
|  LiteralElement , ElementList
LiteralElement  AssignmentExpressionallowIn

Super Expressions

|  super ParenExpression

super, which may only be used inside a class C, can be applied to a subexpression that evaluates to an instance v of C. That subexpression can be either a ParenExpression or omitted, in which case it defaults to this.

As specified in the grammar below, the SuperExpression must be embedded as the left operand of a . (property lookup) or [] (indexing) operator. super changes the behavior of the operator in which it is embedded by limiting its property search to definitions inherited from class C’s superclass. See property lookup.

Postfix Expressions

|  FullPostfixExpression
|  ShortNewExpression
|  AttributeExpression PropertyOperator
|  AttributeExpression Arguments
|  ExpressionQualifiedIdentifier
|  FullNewExpression
|  FullPostfixExpression PropertyOperator
|  SuperExpression PropertyOperator
|  FullPostfixExpression Arguments
|  PostfixExpression [no line break] ++
|  PostfixExpression [no line break] --
FullNewExpression  new FullNewSubexpression Arguments
|  QualifiedIdentifier
|  FullNewExpression
|  FullNewSubexpression PropertyOperator
|  SuperExpression PropertyOperator
ShortNewExpression  new ShortNewSubexpression
|  ShortNewExpression

A SimpleQualifiedIdentifier or ExpressionQualifiedIdentifier expression id resolves to the binding of id in the innermost enclosing scope that has a visible binding of id. If a qualifier q is present before the id, then the QualifiedIdentifier expression resolves to the binding of id in the innermost enclosing scope that has a visible binding of id in the namespace q.

Property Operators

   . QualifiedIdentifier
|  Brackets
   [ ]
|  [ ListExpressionallowIn ]
|  [ ExpressionsWithRest ]
   ( )
|  ParenListExpression
|  ( ExpressionsWithRest )
|  ListExpressionallowIn , RestExpression
RestExpression  ... AssignmentExpressionallowIn

The . operator accepts a QualifiedIdentifier as the second operand and performs a property lookup.

The grammar allows the [] operator to take multiple arguments. However, all built-in objects take at most one argument. Implementation-defined host objects may take more arguments.

For most objects other than arrays and some host objects, the expression o[m] explicitly coerces m to a qualified name q and returns the result of o.q. See property lookup.

An argument list may contain a final argument preceded by .... That argument must be an Array and cannot be null. The elements of that array become additional arguments to the function, following the arguments preceding the ..., if any; the array itself is not passed as an argument. The array must not contain holes.

Unary Operators

|  delete PostfixExpression
|  void UnaryExpression
|  typeof UnaryExpression
|  ++ PostfixExpression
|  -- PostfixExpression
|  + UnaryExpression
|  - UnaryExpression
|  - NegatedMinLong
|  ~ UnaryExpression
|  ! UnaryExpression

The typeof operator returns a string as in ECMAScript 3. There is no way to query the most specific class of an object — all one can ask is whether an object is a member of a specific class.

Multiplicative Operators

|  MultiplicativeExpression * UnaryExpression
|  MultiplicativeExpression / UnaryExpression
|  MultiplicativeExpression % UnaryExpression

Additive Operators

|  AdditiveExpression + MultiplicativeExpression
|  AdditiveExpression - MultiplicativeExpression

Bitwise Shift Operators

|  ShiftExpression << AdditiveExpression
|  ShiftExpression >> AdditiveExpression
|  ShiftExpression >>> AdditiveExpression

Relational Operators

|  RelationalExpressionallowIn < ShiftExpression
|  RelationalExpressionallowIn > ShiftExpression
|  RelationalExpressionallowIn <= ShiftExpression
|  RelationalExpressionallowIn >= ShiftExpression
|  RelationalExpressionallowIn is ShiftExpression
|  RelationalExpressionallowIn as ShiftExpression
|  RelationalExpressionallowIn in ShiftExpression
|  RelationalExpressionallowIn instanceof ShiftExpression
|  RelationalExpressionnoIn < ShiftExpression
|  RelationalExpressionnoIn > ShiftExpression
|  RelationalExpressionnoIn <= ShiftExpression
|  RelationalExpressionnoIn >= ShiftExpression
|  RelationalExpressionnoIn is ShiftExpression
|  RelationalExpressionnoIn as ShiftExpression
|  RelationalExpressionnoIn instanceof ShiftExpression

The expression a is b takes an expression that must evaluate to a type as its second operand b. When a is not null, the expression a is b returns true if a is a member of type b and false otherwise; this is equivalent to testing whether a can be stored in a variable of type b without coercion. When a is null, a is b behaves analogously to method dispatch and returns true if b is either Object or Null and false otherwise. As a special case, when a is –0.0 and b is sbyte, byte, short, ushort, int, or uint, a is b returns true.

The expression a as b returns a if a is a member of type b. Otherwise, if a can be implicitly coerced to type b, then the result is the result of that implicit coercion. Otherwise, a as b returns null if null is a member of type b or throws an exception otherwise. In any case b must evaluate to a type.

The instanceof operator behaves in the same way as in ECMAScript 3 — a instanceof b follows a’s prototype chain.

Equality Operators

|  EqualityExpression == RelationalExpression
|  EqualityExpression != RelationalExpression
|  EqualityExpression === RelationalExpression
|  EqualityExpression !== RelationalExpression

Binary Bitwise Operators

|  BitwiseAndExpression & EqualityExpression
|  BitwiseXorExpression ^ BitwiseAndExpression
|  BitwiseOrExpression | BitwiseXorExpression

Binary Logical Operators

|  LogicalAndExpression && BitwiseOrExpression
|  LogicalXorExpression ^^ LogicalAndExpression

The ^^ operator is a logical exclusive-or operator. It evaluates both operands. If they both convert to true or both convert to false, then ^^ returns false; otherwise ^^ returns the unconverted value of whichever argument converted to true.

|  LogicalOrExpression || LogicalXorExpression

Conditional Operator

|  LogicalOrExpression ? AssignmentExpression : AssignmentExpression
|  LogicalOrExpression ? NonAssignmentExpression : NonAssignmentExpression

Assignment Operators

|  PostfixExpression = AssignmentExpression
|  PostfixExpression CompoundAssignment AssignmentExpression
|  PostfixExpression LogicalAssignment AssignmentExpression
|  /=
|  %=
|  +=
|  -=
|  <<=
|  >>=
|  >>>=
|  &=
|  ^=
|  |=
|  ^^=
|  ||=

Comma Expressions

|  ListExpression , AssignmentExpression

Type Expressions

TypeExpression  NonAssignmentExpression

Compile-Time Constant Expressions

A compile-time constant expression is an expression that either produces an error or evaluates to a value that can be determined at compile time.

The reason that a compile-time constant expression is not guaranteed to always evaluate successfully at run time is that global name lookup cannot be guaranteed to succeed. It is possible for a program to import a package P that defines a global constant P::A that can be accessed as A and then dynamically define another top-level variable Q::A that collides with A. It does not appear to be practical to restrict compile-time constant expressions to only qualified names to eliminate the possibility of such collisions.

A compile-time expression can consist of the following:

A pure function cannot have any read or write side effects or create any objects. A pure function’s result depends only on its arguments. An ECMAScript host embedding may define some pure functions. Currently there is no way for a script to define any such functions, but a future language extension may permit that.

A reference R to a definition D of a compile-time constant is allowed inside a compile-time constant expression as long as the conditions below are met. If D was imported from another package, then the location of D is considered to be the location of the import directive. If D is visible to R by virtue of an intervening use directive U, then the conditions below have to be satisfied both with respect to D and R and with respect to U and R.

Some compile-time constant expressions only allow references to definitions that are textually prior to the point of the reference. Other compile-time constant expressions allow forward references to later compile-time constant definitions.


ECMAScript 4 imposes the following restrictions:

A statement A dominates statement B if any of the following conditions are met:

Note that the above definition is conservative. If statement A dominates statement B, then it is guaranteed that, if B is executed then A must have been executed earlier; however, there may be some other statements A' that also are guaranteed to have been executed before B but which do not dominate B by the above definition.

A statement A is dead if any of the following conditions are met:

Note that the above definition is conservative. If a statement is dead, then it is guaranteed that it cannot be executed; however, there may be statements that cannot be executed that are not dead by the above definition.

A statement is live if it is not dead.

Waldemar Horwat
Last modified Monday, June 30, 2003