Annex B (normative) Additional ECMAScript Features for Web Browsers
The ECMAScript language syntax and semantics defined in this annex are required when the ECMAScript
Some features defined in this annex are specified in this annex, and some are specified in the main body of this document.
When a feature is specified in the main body, each point where it affects the document is marked with the words "
This annex describes various legacy features and other characteristics of web browser ECMAScript
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.
B.1 Additional Syntax
B.1.1 HTML-like Comments
The syntax and semantics of
Syntax
Similar to a
B.1.2 Regular Expressions Patterns
The syntax of
This alternative pattern grammar and semantics only changes the syntax and semantics of BMP patterns. The following grammar extensions include productions parameterized with the [UnicodeMode] parameter. However, none of these extensions change the syntax of Unicode patterns recognized when parsing with the [UnicodeMode] parameter present on the
Syntax
When the same left-hand sides occurs with both [+UnicodeMode] and [~UnicodeMode] guards it is to control the disambiguation priority.
B.1.2.1 Static Semantics: Early Errors
The semantics of
- It is a Syntax Error if any source text is matched by this production.
Additionally, the rules for the following productions are modified with the addition of the highlighted text:
-
It is a Syntax Error if
IsCharacterClass of the firstClassAtom istrue orIsCharacterClass of the secondClassAtom istrue and this production has a [UnicodeMode] parameter. -
It is a Syntax Error if
IsCharacterClass of the firstClassAtom isfalse ,IsCharacterClass of the secondClassAtom isfalse , and theCharacterValue of the firstClassAtom is strictly greater than theCharacterValue of the secondClassAtom .
-
It is a Syntax Error if
IsCharacterClass ofClassAtomNoDash istrue orIsCharacterClass ofClassAtom istrue and this production has a [UnicodeMode] parameter. -
It is a Syntax Error if
IsCharacterClass ofClassAtomNoDash isfalse ,IsCharacterClass ofClassAtom isfalse , and theCharacterValue ofClassAtomNoDash is strictly greater than theCharacterValue ofClassAtom .
B.1.2.2 Static Semantics: CountLeftCapturingParensWithin and CountLeftCapturingParensBefore
In the definitions of
B.1.2.3 Static Semantics: IsCharacterClass
The semantics of
- Return
false .
B.1.2.4 Static Semantics: CharacterValue
The semantics of
- Return the numeric value of U+005C (REVERSE SOLIDUS).
- Let ch be the code point matched by
ClassControlLetter . - Let i be the numeric value of ch.
- Return the remainder of dividing i by 32.
- Return the MV of
LegacyOctalEscapeSequence (see12.9.4.3 ).
B.1.2.5 Runtime Semantics: CompileSubpattern
The semantics of
The rule for
The rule for
The rule for
B.1.2.6 Runtime Semantics: CompileAssertion
B.1.2.7 Runtime Semantics: CompileAtom
- Let A be the
CharSet containing the single character\U+005C (REVERSE SOLIDUS). - Return
CharacterSetMatcher (rer, A,false , direction).
- Let ch be the character represented by
ExtendedPatternCharacter . - Let A be a one-element
CharSet containing the character ch. - Return
CharacterSetMatcher (rer, A,false , direction).
B.1.2.8 Runtime Semantics: CompileToCharSet
The semantics of
The following two rules replace the corresponding rules of
- Let A be
CompileToCharSet of the firstClassAtom with argument rer. - Let B be
CompileToCharSet of the secondClassAtom with argument rer. - Let C be
CompileToCharSet ofClassContents with argument rer. - Let D be CharacterRangeOrUnion(rer, A, B).
- Return the union of D and C.
- Let A be
CompileToCharSet ofClassAtomNoDash with argument rer. - Let B be
CompileToCharSet ofClassAtom with argument rer. - Let C be
CompileToCharSet ofClassContents with argument rer. - Let D be CharacterRangeOrUnion(rer, A, B).
- Return the union of D and C.
In addition, the following rules are added to
- Let cv be the
CharacterValue of thisClassEscape . - Let c be the character whose character value is cv.
- Return the
CharSet containing the single character c.
- Return the
CharSet containing the single character\U+005C (REVERSE SOLIDUS).
\c within a character class where it is not followed by an acceptable control character.B.1.2.8.1 CharacterRangeOrUnion ( rer, A, B )
The abstract operation CharacterRangeOrUnion takes arguments rer (a
- If
HasEitherUnicodeFlag (rer) isfalse , then - Return
CharacterRange (A, B).
B.1.2.9 Static Semantics: ParsePattern ( patternText, u, v )
The semantics of
The abstract operation
- If v is
true and u istrue , then- Let parseResult be a
List containing one or moreSyntaxError objects.
- Let parseResult be a
- Else if v is
true , then - Else if u is
true , then - Else,
- Return parseResult.
B.2 Additional Built-in Properties
When the ECMAScript
B.2.1 Additional Properties of the Global Object
The entries in
| Intrinsic Name | Global Name | ECMAScript Language Association |
|---|---|---|
|
|
escape
|
The escape function ( |
|
|
unescape
|
The unescape function ( |
B.2.1.1 escape ( string )
This function is a property of the
When replacing a code unit of numeric value less than or equal to 0x00FF, a two-digit escape sequence of the form %xx is used. When replacing a code unit of numeric value strictly greater than 0x00FF, a four-digit escape sequence of the form %uxxxx is used.
It is the
It performs the following steps when called:
- Set string to ?
ToString (string). - Let len be the length of string.
- Let R be the empty String.
- Let unescapedSet be the
string-concatenation ofthe ASCII word characters and"@*+-./" . - Let k be 0.
- Repeat, while k < len,
- Let C be the code unit at index k within string.
- If unescapedSet contains C, then
- Let S be C.
- Else,
- Let n be the numeric value of C.
- If n < 256, then
- Let hex be the String representation of n, formatted as an uppercase hexadecimal number.
- Let S be the
string-concatenation of"%" andStringPad (hex, 2,"0" ,start ).
- Else,
- Let hex be the String representation of n, formatted as an uppercase hexadecimal number.
- Let S be the
string-concatenation of"%u" andStringPad (hex, 4,"0" ,start ).
- Set R to the
string-concatenation of R and S. - Set k to k + 1.
- Return R.
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.
B.2.1.2 unescape ( string )
This function is a property of the escape function is replaced with the code unit that it represents.
It is the
It performs the following steps when called:
- Set string to ?
ToString (string). - Let len be the length of string.
- Let R be the empty String.
- Let k be 0.
- Repeat, while k < len,
- Let C be the code unit at index k within string.
- If C is the code unit 0x0025 (PERCENT SIGN), then
- Let hexDigits be the empty String.
- Let optionalAdvance be 0.
- If k + 5 < len and the code unit at index k + 1 within string is the code unit 0x0075 (LATIN SMALL LETTER U), then
- Set hexDigits to the
substring of string from k + 2 to k + 6. - Set optionalAdvance to 5.
- Set hexDigits to the
- Else if k + 3 ≤ len, then
- Set hexDigits to the
substring of string from k + 1 to k + 3. - Set optionalAdvance to 2.
- Set hexDigits to the
- Let parseResult be
ParseText (hexDigits,HexDigits ).[~Sep] - If parseResult is a
Parse Node , then- Let n be the MV of parseResult.
- Set C to the code unit whose numeric value is n.
- Set k to k + optionalAdvance.
- Set R to the
string-concatenation of R and C. - Set k to k + 1.
- Return R.
B.2.2 Additional Properties of the String.prototype Object
B.2.2.1 String.prototype.substr ( start, length )
This method returns a
It performs the following steps when called:
- Let O be the
this value. - Perform ?
RequireObjectCoercible (O). - Let S be ?
ToString (O). - Let size be the length of S.
- Let intStart be ?
ToIntegerOrInfinity (start). - If intStart = -∞, set intStart to 0.
- Else if intStart < 0, set intStart to
max (size + intStart, 0). - Else, set intStart to
min (intStart, size). - If length is
undefined , let intLength be size; else let intLength be ?ToIntegerOrInfinity (length). - Set intLength to the result of
clamping intLength between 0 and size. - Let intEnd be
min (intStart + intLength, size). - Return the
substring of S from intStart to intEnd.
This method is intentionally generic; it does not require that its
B.2.2.2 String.prototype.anchor ( name )
This method performs the following steps when called:
- Let S be the
this value. - Return ? CreateHTML(S,
"a" ,"name" , name).
B.2.2.2.1 CreateHTML ( string, tag, attribute, value )
The abstract operation CreateHTML takes arguments string (an
- Perform ?
RequireObjectCoercible (string). - Let S be ?
ToString (string). - Let p1 be the
string-concatenation of"<" and tag. - If attribute is not the empty String, then
- Let V be ?
ToString (value). - Let escapedV be the String value that is the same as V except that each occurrence of the code unit 0x0022 (QUOTATION MARK) in V has been replaced with the six code unit sequence
""" . - Set p1 to the
string-concatenation of:- p1
- the code unit 0x0020 (SPACE)
- attribute
- the code unit 0x003D (EQUALS SIGN)
- the code unit 0x0022 (QUOTATION MARK)
- escapedV
- the code unit 0x0022 (QUOTATION MARK)
- Let V be ?
- Let p2 be the
string-concatenation of p1 and">" . - Let p3 be the
string-concatenation of p2 and S. - Let p4 be the
string-concatenation of p3,"</" , tag, and">" . - Return p4.
B.2.2.3 String.prototype.big ( )
This method performs the following steps when called:
- Let S be the
this value. - Return ? CreateHTML(S,
"big" ,"" ,"" ).
B.2.2.4 String.prototype.blink ( )
This method performs the following steps when called:
- Let S be the
this value. - Return ? CreateHTML(S,
"blink" ,"" ,"" ).
B.2.2.5 String.prototype.bold ( )
This method performs the following steps when called:
- Let S be the
this value. - Return ? CreateHTML(S,
"b" ,"" ,"" ).
B.2.2.6 String.prototype.fixed ( )
This method performs the following steps when called:
- Let S be the
this value. - Return ? CreateHTML(S,
"tt" ,"" ,"" ).
B.2.2.7 String.prototype.fontcolor ( colour )
This method performs the following steps when called:
- Let S be the
this value. - Return ? CreateHTML(S,
"font" ,"color" , colour).
B.2.2.8 String.prototype.fontsize ( size )
This method performs the following steps when called:
- Let S be the
this value. - Return ? CreateHTML(S,
"font" ,"size" , size).
B.2.2.9 String.prototype.italics ( )
This method performs the following steps when called:
- Let S be the
this value. - Return ? CreateHTML(S,
"i" ,"" ,"" ).
B.2.2.10 String.prototype.link ( url )
This method performs the following steps when called:
- Let S be the
this value. - Return ? CreateHTML(S,
"a" ,"href" , url).
B.2.2.11 String.prototype.small ( )
This method performs the following steps when called:
- Let S be the
this value. - Return ? CreateHTML(S,
"small" ,"" ,"" ).
B.2.2.12 String.prototype.strike ( )
This method performs the following steps when called:
- Let S be the
this value. - Return ? CreateHTML(S,
"strike" ,"" ,"" ).
B.2.2.13 String.prototype.sub ( )
This method performs the following steps when called:
- Let S be the
this value. - Return ? CreateHTML(S,
"sub" ,"" ,"" ).
B.2.2.14 String.prototype.sup ( )
This method performs the following steps when called:
- Let S be the
this value. - Return ? CreateHTML(S,
"sup" ,"" ,"" ).
B.2.2.15 String.prototype.trimLeft ( )
The property
The initial value of the
B.2.2.16 String.prototype.trimRight ( )
The property
The initial value of the
B.2.3 Additional Properties of the Date.prototype Object
B.2.3.1 Date.prototype.getYear ( )
The getFullYear method is preferred for nearly all purposes, because it avoids the “year 2000 problem.”
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- If t is
NaN , returnNaN . - Return
YearFromTime (LocalTime (t)) -1900 𝔽.
B.2.3.2 Date.prototype.setYear ( year )
The setFullYear method is preferred for nearly all purposes, because it avoids the “year 2000 problem.”
This method performs the following steps when called:
- Let dateObject be the
this value. - Perform ?
RequireInternalSlot (dateObject, [[DateValue]]). - Let t be dateObject.[[DateValue]].
- Let y be ?
ToNumber (year). - If t is
NaN , set t to+0 𝔽; else set t toLocalTime (t). - Let yyyy be
MakeFullYear (y). - Let d be
MakeDay (yyyy,MonthFromTime (t),DateFromTime (t)). - Let date be
MakeDate (d,TimeWithinDay (t)). - Let u be
TimeClip (UTC (date)). - Set dateObject.[[DateValue]] to u.
- Return u.
B.2.3.3 Date.prototype.toGMTString ( )
The toUTCString method is preferred. This method is provided principally for compatibility with old code.
The initial value of the
B.2.4 Additional Properties of the RegExp.prototype Object
B.2.4.1 RegExp.prototype.compile ( pattern, flags )
This method performs the following steps when called:
- Let O be the
this value. - Perform ?
RequireInternalSlot (O, [[RegExpMatcher]]). - If pattern
is an Object and pattern has a [[RegExpMatcher]] internal slot, then- If flags is not
undefined , throw aTypeError exception. - Let P be pattern.[[OriginalSource]].
- Let F be pattern.[[OriginalFlags]].
- If flags is not
- Else,
- Let P be pattern.
- Let F be flags.
- Return ?
RegExpInitialize (O, P, F).
This method completely reinitializes the
B.3 Other Additional Features
B.3.1 Labelled Function Declarations
Prior to ECMAScript 2015, the specification of
The
B.3.2 Block-Level Function Declarations Web Legacy Compatibility Semantics
Prior to ECMAScript 2015, the ECMAScript specification did not define the occurrence of a
-
A function is declared and only referenced within a single block.
-
One or more
FunctionDeclaration s whoseBindingIdentifier is the name f occur within the function code of an enclosing function g and that declaration is nested within aBlock . -
No other declaration of f that is not a
vardeclaration occurs within the function code of g. -
All occurrences of f as an
IdentifierReference are within theStatementList of theBlock containing the declaration of f.
-
One or more
-
A function is declared and possibly used within a single
Block but also referenced by an inner function definition that is not contained within that sameBlock .-
One or more
FunctionDeclaration s whoseBindingIdentifier is the name f occur within the function code of an enclosing function g and that declaration is nested within aBlock . -
No other declaration of f that is not a
vardeclaration occurs within the function code of g. -
There may be occurrences of f as an
IdentifierReference within theStatementList of theBlock 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.
-
One or more
-
A function is declared and possibly used within a single block but also referenced within subsequent blocks.
-
One or more
FunctionDeclaration whoseBindingIdentifier is the name f occur within the function code of an enclosing function g and that declaration is nested within aBlock . -
No other declaration of f that is not a
vardeclaration occurs within the function code of g. -
There may be occurrences of f as an
IdentifierReference within theStatementList of theBlock 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 theBlock containing the declaration of f.
-
One or more
The first use case is interoperable with the semantics of
ECMAScript 2015 interoperability for the second and third use cases requires the following extensions to the clause
If an ECMAScript implementation has a mechanism for reporting diagnostic warning messages, a warning should be produced when code contains a
This feature involves special semantics at the following points:
- one of the
early error rules for inBlock : { StatementList } 14.2.1 - one of the
early error rules for inSwitchStatement : switch ( Expression ) CaseBlock 14.12.1 - step
32.a inFunctionDeclarationInstantiation - step
3.a.ii.1 inBlockDeclarationInstantiation - step
3.b.iii inBlockDeclarationInstantiation - step
12 inGlobalDeclarationInstantiation - step
13 inEvalDeclarationInstantiation
B.3.3 FunctionDeclarations in IfStatement Statement Clauses
The following augments the
This production only applies when parsing
B.3.4 VariableStatements in Catch Blocks
In this feature, the var declarations that bind a name that is also bound by the
At runtime, such bindings are instantiated in the VariableDeclarationEnvironment. They do not shadow the same-named bindings introduced by the var declarations will assign to the corresponding catch parameter rather than the var binding.
This modified behaviour also applies to var and function declarations introduced by
B.3.5 Initializers in ForIn Statement Heads
The following augments the
This production only applies when parsing
The
- Return
ContainsDuplicateLabels ofStatement with argument labelSet.
The
- Return
ContainsUndefinedBreakTarget ofStatement with argument labelSet.
The
- Return
ContainsUndefinedContinueTarget ofStatement with arguments iterationSet and « ».
The
- Return
false .
The
- Let names1 be the
BoundNames ofBindingIdentifier . - Let names2 be the
VarDeclaredNames ofStatement . - Return the
list-concatenation of names1 and names2.
The
- Let declarations1 be «
BindingIdentifier ». - Let declarations2 be the
VarScopedDeclarations ofStatement . - Return the
list-concatenation of declarations1 and declarations2.
The
- Let bindingId be the
StringValue ofBindingIdentifier . - Let lhs be ?
ResolveBinding (bindingId). - If
IsAnonymousFunctionDefinition (Initializer ) istrue , then- Let value be ?
NamedEvaluation ofInitializer with argument bindingId.
- Let value be ?
- Else,
- Let rhs be ?
Evaluation ofInitializer . - Let value be ?
GetValue (rhs).
- Let rhs be ?
- Perform ?
PutValue (lhs, value). - Let keyResult be ? ForIn/OfHeadEvaluation(« »,
Expression ,enumerate ). - Return ? ForIn/OfBodyEvaluation(
BindingIdentifier ,Statement , keyResult,enumerate ,var-binding , labelSet).
B.3.6 The [[IsHTMLDDA]] Internal Slot
An [[IsHTMLDDA]] internal slot may exist on typeof operator
Objects with an [[IsHTMLDDA]] internal slot are never created by this specification. However, the document.all object in web browsers is a document.all.
This feature involves special semantics at the following points:
- step
3 inToBoolean - step
4 inIsLooselyEqual - step
12 in the evaluation semantics fortypeof
B.3.7 Non-default behaviour in HostMakeJobCallback
The
B.3.8 Non-default behaviour in HostEnsureCanAddPrivateElement
The
B.3.9 Runtime Errors for Function Call Assignment Targets
When a function call (
When the assignment target is the = or an ??=, &&=, ||=).
See step