The ECMAScript language syntax and semantics defined in this annex are required when the ECMAScript host is a web browser. The content of this annex is normative but optional if the ECMAScript host is not a web browser.
NOTE This annex describes various legacy features and other characteristics of web browser based ECMAScript implementations. All of the language features and behaviours specified in this annex have one or more undesirable characteristics and in the absence of legacy usage would be removed from this specification. However, the usage of these features by large numbers of existing web pages means that web browsers must continue to support them. The specifications in this annex defined the requirements for interoperable implementations of these legacy features.
These features are not considered part of the core ECMAScript language. Programmers should not use or assume the existence of these features and behaviours when writing new ECMAScript code. ECMAScript implementations are discouraged from implementing these features unless the implementation is part of a web browser or is required to run the same legacy ECMAScript code that web browsers encounter.
The syntax and semantics of 11.8.3 is extended as follows except that this extension is not allowed for strict mode code:
0
OctalDigit0
0
NonOctalDigit0
OctalDigit8
9
B.1.1.1 Static Semantics
The MV of LegacyOctalIntegerLiteral :: 0
OctalDigit is the MV of OctalDigit.
The MV of LegacyOctalIntegerLiteral :: LegacyOctalIntegerLiteral OctalDigit is (the MV of LegacyOctalIntegerLiteral times 8) plus the MV of OctalDigit.
The MV of DecimalIntegerLiteral :: NonOctalDecimalIntegerLiteral is the MV of NonOctalDecimalIntegerLiteral.
The MV of NonOctalDecimalIntegerLiteral :: 0
NonOctalDigit is the MV of NonOctalDigit.
The MV of NonOctalDecimalIntegerLiteral :: LegacyOctalLikeDecimalIntegerLiteral NonOctalDigit is (the MV of LegacyOctalLikeDecimalIntegerLiteral times 10) plus the MV of NonOctalDigit.
The MV of NonOctalDecimalIntegerLiteral :: NonOctalDecimalIntegerLiteral DecimalDigit is (the MV of NonOctalDecimalIntegerLiteral times 10) plus the MV of DecimalDigit.
The MV of LegacyOctalLikeDecimalIntegerLiteral ::
0
OctalDigit is the MV of OctalDigit.
The MV of LegacyOctalLikeDecimalIntegerLiteral :: LegacyOctalLikeDecimalIntegerLiteral OctalDigit is (the MV of LegacyOctalLikeDecimalIntegerLiteral times 10) plus the MV of OctalDigit.
The MV of NonOctalDigit :: 8
is 8.
The MV of NonOctalDigit :: 9
is 9.
The syntax and semantics of 11.8.4 is extended as follows except that this extension is not allowed for strict mode code:
0
1
2
3
4
5
6
7
This definition of EscapeSequence is not used in strict mode or when parsing TemplateCharacter (11.8.6).
B.1.2.1 Static Semantics
0
is 0.1
is 1.2
is 2.3
is 3.4
is 4.5
is 5.6
is 6.7
is 7.The syntax and semantics of 11.4 is extended as follows except that this extension is not when parsing source code using the goal symbol Module :
/*
FirstCommentLineopt LineTerminator MultiLineCommentCharsopt */
HTMLCloseCommentopt<!--
SingleLineCommentCharsopt/*
SingleLineDelimitedCommentCharsopt */
-->
SingleLineCommentCharsopt*
SingleLinePostAsteriskCommentCharsopt*
or LineTerminator*
SingleLinePostAsteriskCommentCharsopt/
or *
or LineTerminatorSimilar to a MultiLineComment that contains a line terminator code point, a SingleLineHTMLCloseComment is considered to be a LineTerminator for purposes of parsing by the syntactic grammar.
The syntax of 21.2.1 is modified and extended as follows. These changes introduce ambiguities that are broken by the ordering of grammar productions and by contextual information. When parsing using the following grammar, each alternative is considered only if previous production alternatives do not match.
This alternative pattern grammar and semantics only changes the syntax and semantics of BMP patterns. The following grammar extensions include productions parameterized with the [U] parameter. However, none of these extensions change the syntax of Unicode patterns recognized when parsing with the [U] parameter present on the goal symbol.
Syntax
.
\
AtomEscape(
Disjunction )
(
?
:
Disjunction )
.
\
AtomEscape[?U](
Disjunction[?U] )
(
?
:
Disjunction[?U] )
^
$
\
.
*
+
?
(
)
[
]
{
}
|
^
$
\
.
*
+
?
(
)
[
]
|
(
?
=
Disjunction )
(
?
!
Disjunction )
^
$
\
b
\
B
(
?
=
Disjunction[U] )
(
?
!
Disjunction[U] )
but
only
if
the
integer
value
of
DecimalEscape is
<=
NCapturingParensc
ControlLetter/
c
-
ClassAtom[U] ClassRanges[U]-
ClassAtomInRange ClassRanges-
ClassAtom[U] ClassRanges[U]-
ClassAtomInRange ClassRanges-
\
or ]
or -
\
ClassEscape[?U]-
\
or ]
or -
\
ClassEscape but
only
if
ClassEscape evaluates
to
a
CharSet with
exactly
one
character
\
IdentityEscapeb
NOTE When the same left hand sides occurs with both [+U] and [~U] guards it is to control the disambiguation priority.
B.1.4.1 Pattern Semantics
The semantics of 21.2.2 is extended as follows:
Within 21.2.2.5 reference to “Atom :: (
Disjunction )
”
are to be interpreted as meaning “Atom :: (
Disjunction )
” or “AtomNoBrace :: (
Disjunction )
”.
Term (21.2.2.5) includes the following additional evaluation rule:
The production Term :: QuantifiableAssertion Quantifier evaluates the same as the production Term :: Atom Quantifier but with QuantifiableAssertion substituted for Atom.
Atom (21.2.2.8) evaluation rules for the Atom productions except for Atom :: PatternCharacter are also used for the AtomNoBrace productions, but with AtomNoBrace substituted for Atom. The following evaluation rule is also added:
The production AtomNoBrace :: PatternCharacterNoBrace evaluates as follows:
CharacterEscape (21.2.2.10) includes the following additional evaluation rule:
The production CharacterEscape :: LegacyOctalEscapeSequence evaluates by evaluating the SV of the LegacyOctalEscapeSequence (see B.1.2) and returning its character result.
ClassAtom (21.2.2.17) includes the following additional evaluation rules:
The production ClassAtomInRange :: -
evaluates by returning the CharSet containing the one character -
.
The production ClassAtomInRange :: ClassAtomNoDashInRange evaluates by evaluating ClassAtomNoDashInRange to obtain a CharSet and returning that CharSet.
ClassAtomNoDash (21.2.2.18) includes the following additional evaluation rules:
The production ClassAtomNoDashInRange :: SourceCharacter but not one of \
or ]
or -
evaluates
by returning a one-element CharSet containing the character represented by SourceCharacter.
The production ClassAtomNoDashInRange :: \
ClassEscape but only if…, evaluates by evaluating ClassEscape to obtain a CharSet and returning that CharSet.
The production ClassAtomNoDashInRange :: \
IdentityEscape evaluates by returning the character represented by IdentityEscape.
When the ECMAScript host is a web browser the following additional properties of the standard built-in objects are defined.
The escape
function is a property of the global object. It computes a new version of a String value in
which certain code units have been replaced by a hexadecimal escape sequence.
For those code units being replaced whose value is 0x00FF
or less, a two-digit escape sequence of the form
%
xx is used. For those characters being replaced whose code unit value is greater than
0x00FF
, a four-digit escape sequence of the form %u
xxxx is used.
The escape
function is the %escape% intrinsic object. When the escape
function is called with one argument string, the following steps are taken:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_+-./
", then
%u
wxyz" where
wxyz are the code units of the four hexadecimal digits encoding the value of char.%
xy" where xy
are the code units of two hexadecimal digits encoding the value of char.NOTE The encoding is partly based on the encoding described in RFC 1738, but the entire encoding specified in this standard is described above without regard to the contents of RFC 1738. This encoding does not reflect changes to RFC 1738 made by RFC 3986.
The unescape
function is a property of the global object. It computes a new version of a String value in
which each escape sequence of the sort that might be introduced by the escape
function is replaced with the
code unit that it represents.
The unescape
function is the %unescape% intrinsic object. When the
unescape
function is called with one argument string, the following steps are taken:
%
,
u
and the four code units at indices k+2, k+3, k+4, and k+5 within
string are all hexadecimal digits, then
Object.prototype.__proto__ is an accessor property with attributes { [[Enumerable]]: false, [[Configurable]]: true }. The [[Get]] and [[Set]] attributes are defined as follows
The value of the [[Get]] attribute is a built-in function that requires no arguments. It performs the following steps:
The value of the [[Set]] attribute is a built-in function that takes an argument proto. It performs the following steps:
The substr
method takes two arguments, start and length, and
returns a substring of the result of converting the this object to a String, starting from index start
and running for length code units (or through the end of the String if length is undefined).
If start is negative, it is treated as (sourceLength+start) where sourceLength is the length of the String. The result is
a String value, not a String object. The following steps are taken:
""
.The length
property of the substr
method is 2.
NOTE The substr
function is intentionally generic; it does not require that its
this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method.
When the anchor method is called with argument name, the following steps are taken:
"a"
, "name"
,
name).The abstract operation CreateHTML is called with arguments string, tag, attribute, and value. The arguments tag and attribute must be String values. The following steps are taken:
"<"
and tag."""
.">"
."</"
, tag, and
">"
.When the big method is called with no arguments, the following steps are taken:
"big"
, ""
,
""
).When the blink method is called with no arguments, the following steps are taken:
"blink"
, ""
,
""
).When the bold method is called with no arguments, the following steps are taken:
"b"
, ""
, ""
).When the fixed method is called with no arguments, the following steps are taken:
"tt"
, ""
, ""
).When the fontcolor method is called with argument color, the following steps are taken:
"font"
, "color"
,
color).When the fontsize method is called with argument size, the following steps are taken:
"font"
, "size"
,
size).When the italics method is called with no arguments, the following steps are taken:
"i"
, ""
, ""
).When the link method is called with argument url, the following steps are taken:
"a"
, "href"
, url).When the small method is called with no arguments, the following steps are taken:
"small"
, ""
,
""
).When the strike method is called with no arguments, the following steps are taken:
"strike"
, ""
,
""
).When the sub method is called with no arguments, the following steps are taken:
"sub"
, ""
,
""
).When the sup method is called with no arguments, the following steps are taken:
"sup"
, ""
,
""
).NOTE The getFullYear
method is preferred for nearly all purposes, because it
avoids the “year 2000 problem.”
When the getYear method is called with no arguments, the following steps are taken:
NOTE The setFullYear
method is preferred for nearly all purposes, because it
avoids the “year 2000 problem.”
When the setYear method is called with one argument year, the following steps are taken:
NOTE The property toUTCString
is preferred. The toGMTString
property is provided principally for compatibility with old code. It is recommended that the toUTCString
property be used in new ECMAScript code.
The function object that is the initial value of Date.prototype.toGMTString
is the same function object
that is the initial value of Date.prototype.toUTCString
.
When the compile method is called with arguments pattern and flags, the following steps are taken:
NOTE The compile
method completely reinitializes the this object RegExp
with a new pattern and flags. An implementation may interpret use of this method as an assertion that the resulting
RegExp object will be used multiple times and hence is a candidate for extra optimization.
The following Early Error rule is added to those in 12.2.6.1:
ObjectLiteral : {
PropertyDefinitionList }ObjectLiteral
:
{
PropertyDefinitionList ,
}
It is a Syntax Error if PropertyNameList of PropertyDefinitionList contains any duplicate entries for "__proto__"
and at least two of
those entries were obtained from productions of the form PropertyDefinition
: PropertyName :
AssignmentExpression .
NOTE The List returned by PropertyNameList does not include string literal property names defined as using a ComputedPropertyName.
In 12.2.6.9 the
PropertyDefinitionEvaluation algorithm for the production
PropertyDefinition
: PropertyName :
AssignmentExpression
is replaced with the following definition:
:
AssignmentExpression"__proto__"
and if IsComputedPropertyKey(propKey) is
false, then
"name"
).Prior to ECMAScript 2015, the specification of LabelledStatement did not allow for the association of a statement label with a FunctionDeclaration. However, a labelled FunctionDeclaration was an allowable extension for non-strict code and most browser-hosted ECMAScript implementations supported that extension. In ECMAScript 2015, the grammar productions for LabelledStatement permits use of FunctionDeclaration as a LabelledItem but 13.13.1 includes an Early Error rule that produces a Syntax Error if that occurs. For web browser compatibility, that rule is modified with the addition of the underlined text:
Prior to ECMAScript 2015, the ECMAScript specification did not define the occurrence of a FunctionDeclaration as an element of a Block statement's StatementList. However, support for that form of FunctionDeclaration was an allowable extension and most browser-hosted ECMAScript implementations permitted them. Unfortunately, the semantics of such declarations differ among those implementations. Because of these semantic differences, existing web ECMAScript code that uses Block level function declarations is only portable among browser implementation if the usage only depends upon the semantic intersection of all of the browser implementations for such declarations. The following are the use cases that fall within that intersection semantics:
A FunctionDeclaration whose BindingIdentifier is the name f occurs exactly once within the function code of an enclosing function g and that declaration is nested within a Block.
No other declaration of f that is not a var
declaration occurs within the function code
of g
All occurrences of f as an IdentifierReference are within the StatementList of the Block containing the declaration of f.
A FunctionDeclaration whose BindingIdentifier is the name f occurs exactly once within the function code of an enclosing function g and that declaration is nested within a Block.
No other declaration of f that is not a var
declaration occurs within the function code
of g
There may be occurrences of f as an IdentifierReference within the StatementList of the Block containing the declaration of f.
There is at least one occurrence of f as an IdentifierReference within the function code of g that lexically follows the Block containing the declaration of f.
A FunctionDeclaration whose BindingIdentifier is the name f occurs exactly once within the function code of an enclosing function g and that declaration is nested within a Block.
No other declaration of f that is not a var
declaration occurs within the function code
of g
There may be occurrences of f as an IdentifierReference within the StatementList of the Block containing the declaration of f.
There is at least one occurrence of f as an IdentifierReference within another function h that is nested within g and no other declaration of f shadows the references to f from within h.
All invocations of h occur after the declaration of f has been evaluated.
The first use case is interoperable with the semantics of Block level function declarations provided by ECMAScript 2015. Any pre-existing ECMAScript code that employees that use case will operate using the Block level function declarations semantics defined by clauses 9, 13, and 14 of this specification.
ECMAScript 2015 interoperability for the second and third use cases requires the following extensions to the clause 9 and clause 14 semantics. During FunctionDeclarationInstantiation (9.2.12) the following steps are performed in place of step 29:
If an ECMAScript implementation has a mechanism for reporting diagnostic warning messages, a warning should be produced for each function whose function code contains a FunctionDeclaration for which steps 1.a.ii.1-3 will be performed.
The following rules for IfStatement augment those in 13.6:
if
(
Expression[In, ?Yield] )
FunctionDeclaration[?Yield] else
Statement[?Yield, ?Return]if
(
Expression[In, ?Yield] )
Statement[?Yield, ?Return] else
FunctionDeclaration[?Yield]if
(
Expression[In, ?Yield] )
FunctionDeclaration[?Yield] else
FunctionDeclaration[?Yield]if
(
Expression[In, ?Yield] )
FunctionDeclaration[?Yield]The above rules are only applied when parsing code that is not strict mode code. If any such code is match by one of these rules subsequent processing of that code takes places as if each matching occurrence of FunctionDeclaration[?Yield] was the sole StatementListItem of a BlockStatement occupying that position in the source code. The semantics of such a synthetic BlockStatement includes the web legacy compatibility semantics specified in B.3.3.
The content of subclause 13.15.1 is replaced with the following:
catch
(
CatchParameter )
BlockIt is a Syntax Error if BoundNames of CatchParameter contains any duplicate elements.
It is a Syntax Error if any element of the BoundNames of CatchParameter also occurs in the LexicallyDeclaredNames of Block.
It is a Syntax Error if any element of the BoundNames of CatchParameter also occurs in the VarDeclaredNames of Block, unless that element is only bound by a VariableStatement or the VariableDeclarationList of a for statement, or the ForBinding of a for-in statement.
NOTE The Block of a Catch clause may contain
var
declarations that bind a name that is also bound by the CatchParameter. At
runtime, such bindings are instantiated in the VariableDeclarationEnvironment. They do not shadow the same-named bindings
introduced by the CatchParameter and hence the Initializer for such
var
declarations will assign to the corresponding catch parameter rather than the var
binding.
The relaxation of the normal static semantic rule does not apply to names only bound by for-of statements.
This modified behaviour also applies to var
and function
declarations introduced by direct
evals contained within the Block of a Catch clause. This change is
accomplished by modify the algorithm of 18.2.1.2 as follows:
Step 5.d.ii.2.a.i is replaced by:
i. If thisEnvRec is not the Environment Record for a Catch clause, throw a SyntaxError exception.
ii. If name is bound by any syntactic form other than a FunctionDeclaration, a VariableStatement, the VariableDeclarationList of a for statement, or the ForBinding of a for-in statement, throw a SyntaxError exception.