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 codePoint be the code point matched by
ClassControlLetter . - Let i be the numeric value of codePoint.
- 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 charSet be the
CharSet containing the single character\U+005C (REVERSE SOLIDUS). - Return
CharacterSetMatcher (regexpRecord, charSet,false , direction).
- Let char be the character represented by
ExtendedPatternCharacter . - Let charSet be a one-element
CharSet containing the character char. - Return
CharacterSetMatcher (regexpRecord, charSet,false , direction).
B.1.2.8 Runtime Semantics: CompileToCharSet
The semantics of
The following two rules replace the corresponding rules of
- Let charSet be
CompileToCharSet of the firstClassAtom with argument regexpRecord. - Let otherSet be
CompileToCharSet of the secondClassAtom with argument regexpRecord. - Let remainingSet be
CompileToCharSet ofClassContents with argument regexpRecord. - Let rangeSet be CharacterRangeOrUnion(regexpRecord, charSet, otherSet).
- Return the union of rangeSet and remainingSet.
- Let charSet be
CompileToCharSet ofClassAtomNoDash with argument regexpRecord. - Let otherSet be
CompileToCharSet ofClassAtom with argument regexpRecord. - Let remainingSet be
CompileToCharSet ofClassContents with argument regexpRecord. - Let rangeSet be CharacterRangeOrUnion(regexpRecord, charSet, otherSet).
- Return the union of rangeSet and remainingSet.
In addition, the following rules are added to
- Let charValue be the
CharacterValue of thisClassEscape . - Let char be the character whose character value is charValue.
- Return the
CharSet containing the single character char.
- 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 ( regexpRecord, charSet, otherSet )
The abstract operation CharacterRangeOrUnion takes arguments regexpRecord (a
- If
HasEitherUnicodeFlag (regexpRecord) isfalse , then - Return
CharacterRange (charSet, otherSet).
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 |
|---|---|---|
|
|
|
The escape function ( |
|
|
|
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 length be the length of string.
- Let result be the empty String.
- Let unescapedSet be the
string-concatenation ofthe ASCII word characters and"@*+-./" . - Let k be 0.
- Repeat, while k < length,
- Let codeUnit be the code unit at index k within string.
- If unescapedSet contains codeUnit, then
- Let nextPart be codeUnit.
- Else,
- Let codeUnitNumber be the numeric value of codeUnit.
- If codeUnitNumber < 256, then
- Let hex be the String representation of codeUnitNumber, formatted as an uppercase hexadecimal number.
- Let nextPart be the
string-concatenation of"%" andStringPad (hex, 2,"0" ,start ).
- Else,
- Let hex be the String representation of codeUnitNumber, formatted as an uppercase hexadecimal number.
- Let nextPart be the
string-concatenation of"%u" andStringPad (hex, 4,"0" ,start ).
- Set result to the
string-concatenation of result and nextPart. - Set k to k + 1.
- Return result.
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 length be the length of string.
- Let result be the empty String.
- Let k be 0.
- Repeat, while k < length,
- Let codeUnit be the code unit at index k within string.
- If codeUnit is the code unit 0x0025 (PERCENT SIGN), then
- Let hexDigits be the empty String.
- Let optionalAdvance be 0.
- If k + 5 < length 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 ≤ length, 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 codeUnitNumber be the MV of parseResult.
- Set codeUnit to the code unit whose numeric value is codeUnitNumber.
- Set k to k + optionalAdvance.
- Set result to the
string-concatenation of result and codeUnit. - Set k to k + 1.
- Return result.
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 obj be the
this value. - Perform ?
RequireObjectCoercible (obj). - Let string be ?
ToString (obj). - Let size be the length of string.
- 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 string 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 string be the
this value. - Return ? CreateHTML(string,
"a" ,"name" , name).
B.2.2.2.1 CreateHTML ( contents, tag, attr, attrValue )
The abstract operation CreateHTML takes arguments contents (an
- Perform ?
RequireObjectCoercible (contents). - Let contentsString be ?
ToString (contents). - Let part1 be the
string-concatenation of"<" and tag. - If attr is not the empty String, then
- Let attrValueString be ?
ToString (attrValue). - Let escapedAttrValue be the String value that is the same as attrValueString except that each occurrence of the code unit 0x0022 (QUOTATION MARK) in attrValueString has been replaced with the six code unit sequence
""" . - Set part1 to the
string-concatenation of:- part1
- the code unit 0x0020 (SPACE)
- attr
- the code unit 0x003D (EQUALS SIGN)
- the code unit 0x0022 (QUOTATION MARK)
- escapedAttrValue
- the code unit 0x0022 (QUOTATION MARK)
- Let attrValueString be ?
- Let part2 be the
string-concatenation of part1 and">" . - Let part3 be the
string-concatenation of part2 and contentsString. - Let part4 be the
string-concatenation of part3,"</" , tag, and">" . - Return part4.
B.2.2.3 String.prototype.big ( )
This method performs the following steps when called:
- Let string be the
this value. - Return ? CreateHTML(string,
"big" ,"" ,"" ).
B.2.2.4 String.prototype.blink ( )
This method performs the following steps when called:
- Let string be the
this value. - Return ? CreateHTML(string,
"blink" ,"" ,"" ).
B.2.2.5 String.prototype.bold ( )
This method performs the following steps when called:
- Let string be the
this value. - Return ? CreateHTML(string,
"b" ,"" ,"" ).
B.2.2.6 String.prototype.fixed ( )
This method performs the following steps when called:
- Let string be the
this value. - Return ? CreateHTML(string,
"tt" ,"" ,"" ).
B.2.2.7 String.prototype.fontcolor ( colour )
This method performs the following steps when called:
- Let string be the
this value. - Return ? CreateHTML(string,
"font" ,"color" , colour).
B.2.2.8 String.prototype.fontsize ( size )
This method performs the following steps when called:
- Let string be the
this value. - Return ? CreateHTML(string,
"font" ,"size" , size).
B.2.2.9 String.prototype.italics ( )
This method performs the following steps when called:
- Let string be the
this value. - Return ? CreateHTML(string,
"i" ,"" ,"" ).
B.2.2.10 String.prototype.link ( url )
This method performs the following steps when called:
- Let string be the
this value. - Return ? CreateHTML(string,
"a" ,"href" , url).
B.2.2.11 String.prototype.small ( )
This method performs the following steps when called:
- Let string be the
this value. - Return ? CreateHTML(string,
"small" ,"" ,"" ).
B.2.2.12 String.prototype.strike ( )
This method performs the following steps when called:
- Let string be the
this value. - Return ? CreateHTML(string,
"strike" ,"" ,"" ).
B.2.2.13 String.prototype.sub ( )
This method performs the following steps when called:
- Let string be the
this value. - Return ? CreateHTML(string,
"sub" ,"" ,"" ).
B.2.2.14 String.prototype.sup ( )
This method performs the following steps when called:
- Let string be the
this value. - Return ? CreateHTML(string,
"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 dateObj be the
this value. - Perform ?
RequireInternalSlot (dateObj, [[DateValue]]). - Let tv be dateObj.[[DateValue]].
- If tv is
NaN , returnNaN . - Return
YearFromTime (LocalTime (tv)) -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 dateObj be the
this value. - Perform ?
RequireInternalSlot (dateObj, [[DateValue]]). - Let time be dateObj.[[DateValue]].
- Let year be ?
ToNumber (year). - If time is
NaN , set time to+0 𝔽; else set time toLocalTime (time). - Let fullYear be
MakeFullYear (year). - Let day be
MakeDay (fullYear,MonthFromTime (time),DateFromTime (time)). - Let date be
MakeDate (day,TimeWithinDay (time)). - Let utcTimestamp be
TimeClip (UTC (date)). - Set dateObj.[[DateValue]] to utcTimestamp.
- Return utcTimestamp.
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 obj be the
this value. - Perform ?
RequireInternalSlot (obj, [[RegExpMatcher]]). - If pattern
is an Object and pattern has a [[RegExpMatcher]] internal slot, then- If flags is not
undefined , throw aTypeError exception. - Set flags to pattern.[[OriginalFlags]].
- Set pattern to pattern.[[OriginalSource]].
- If flags is not
- Return ?
RegExpInitialize (obj, pattern, flags).
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 decls1 be «
BindingIdentifier ». - Let decls2 be the
VarScopedDeclarations ofStatement . - Return the
list-concatenation of decls1 and decls2.
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