To the extent possible under law, the editor has waived all copyright and
related or neighboring rights to this work. In addition, as of
4 August 2015, the editor has made this specification available
under the
Open Web Foundation Agreement Version 1.0,
which is available at
http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0.
var
statementsDate
RegExp
Function
Object
This specification aims to document the differences between the ECMAScript specification and the compatibility and interoperability requirements for ECMAScript implementations in web browsers. The ultimate goal of this document is to upstream its contents to the ECMAScript standard. [ECMASCRIPT]
Everything in this specification is normative except for examples, notes, and sections marked as non-normative.
A JavaScript implementation must be a conforming implementation of ECMAScript with the extensions described in this document. [ECMASCRIPT]
A user agent must also be a conforming implementation of HTML, if applicable. [HTML]
Script authors must not depend on the extensions defined in this specification.
The key words “must” and “should” in this document are to be interpreted as described in RFC 2119. [RFC2119]
Special symbols in this document are identified using their Unicode code points and names. [UNICODE]
When this specification uses the term ECMAScript character, it means a 16-bit unsigned value used to represent a single 16-bit unit of text. [ECMASCRIPT]
To clarify the semantics of certain constructs used throughout this document, it is useful to define a set of abstract operations. These abstract operations are not a part of the language, and must not be exposed to Web authors; they are only defined here to aid the specification of the semantics of the language.
CheckObjectCoercible(value)
The abstract operation CheckObjectCoercible(value)
throws an error if its argument is a value that cannot be converted to an object. It is defined in the ECMAScript specification.
EscapeAttributeValue(value)
The abstract operation EscapeAttributeValue(value)
produces a string suitable for use in an HTML attribute value wrapped in double quotes. [HTML] This is done according to the following algorithm:
"
” (U+0026 U+0071 U+0075 U+006F U+0074 U+003B).
For security reasons, Web authors should not rely on any such escaping, as older, non-JavaScript-compliant implementations might not perform this operation correctly.
IsCallable(value)
The abstract operation IsCallable(value)
determines if its argument is a callable function object. It is defined in the ECMAScript specification.
ToString(value)
The abstract operation ToString(value)
converts its argument to a value of type String
. It is defined in the ECMAScript specification.
ToHTML(tagName, content, attributeName, attributeValue)
The abstract operation ToHTML(tagName, content, attributeName, attributeValue)
produces an HTML string, according to the following algorithm:
<
” (U+003C), tagName, “>
” (U+003E), content, “</
” (U+003C U+002F), tagName, and “>
” (U+003E).
<
” (U+003C), tagName, “
” (U+0020), attributeName, “="
” (U+003D U+0022), EscapeAttributeValue(attributeValue)
, “">
” (U+0022 U+003E), content, “</
” (U+003C U+002F), tagName, and “>
” (U+003E).
JavaScript implementations must fully implement Annex B of the ECMAScript specification.
For optimal interoperability, JavaScript implementations should use the latest available Unicode database to determine which ECMAScript characters are allowed in Identifier
s and IdentifierName
s, and which ECMAScript characters are whitespace characters. [UNICODE]
var
statementsThe erratum in https://bugs.ecmascript.org/show_bug.cgi?id=78#c0 must be followed so that var
statements at the top level of scripts can shadow any properties from the global object’s prototype chain.
Date
Tests are available: https://mathias.html5.org/tests/javascript/date/.
Date.UTC(year, month, date, hours, minutes, seconds, ms)
When called with fewer than two arguments, Date.UTC
must return NaN
.
RegExp
The octal escape sequence syntax for string literals as described in Annex B of the ECMAScript spec must be supported, and must also apply to regular expression literals, even in strict mode code.
/\123/.test('S'); // true
RegExp.$1-$9
After a regexp is executed the RegExp
constructor object has properties $1...$9
which are assigned the values of the first 9 match groups from the previous regexp.
RegExp.lastMatch
/ RegExp["$&"]
Function
Tests are available: https://mathias.html5.org/tests/javascript/function/.
Function.prototype.toString()
Object
Tests are available: https://mathias.html5.org/tests/javascript/object/.
Object.prototype.__defineGetter__(propertyName, function)
Every Object
instance must have a __defineGetter__
method which binds a property of that object to a function that is called each time the property is accessed.
IsCallable(function)
is false
, throw a TypeError
and return; else, continue following these steps.
ToString(propertyName)
.
[[Enumerable]]
property of obj’s prop property to true
.
__lookupGetter__
method of the obj object is called with an argument arg for which prop is equal to ToString(arg)
, return a reference to function.
undefined
.
var object = {}, counter = 0; object.__defineGetter__('foo', function() { return ++counter; }); [object.foo, object.foo, object.foo]; // [1, 2, 3]
var myDate = new Date; myDate.__defineGetter__('year', function() { return this.getFullYear(); }); myDate; // Sun Jul 01 2012 13:33:37 GMT+0200 (CEST) myDate.year; // 2012
The length
property of the __defineGetter__
method is 2
.
Object.prototype.__defineSetter__(propertyName, function)
Every Object
instance must have a __defineSetter__
method which binds a property of that object to a function that is called each time the property is set.
IsCallable(function)
is false
, throw a TypeError
and return; else, continue following these steps.
ToString(propertyName)
.
[[Enumerable]]
property of obj’s prop property to true
.
undefined
.
__lookupSetter__
method of the obj object is called with an argument arg for which prop is equal to ToString(arg)
, return a reference to function.
undefined
.
var object = {}; object.__defineSetter__('degrees', function(degrees) { this.radians = degrees * Math.PI / 180; }); object.degrees = 180; object.degrees; // undefined object.radians; // 3.141592653589793
var myDate = new Date; myDate.__defineSetter__('year', function(y) { this.setFullYear(y); }); myDate; // Sun Jul 01 2012 13:33:37 GMT+0200 (CEST) myDate.year = 1988; myDate; // Fri Jul 01 1988 13:33:37 GMT+0200 (CEST)
The length
property of the __defineSetter__
method is 2
.
Object.prototype.__lookupGetter__(propertyName)
Every Object
instance must have a __lookupGetter__
method that implements the following algorithm:
ToString(propertyName)
.
__defineGetter__
or the get
syntax in the object initializer, return the getter function; else, return undefined
.
var object = { get foo() { return 1; } }; object.__lookupGetter__('foo'); // function foo() { return 1; }
The length
property of the __lookupGetter__
method is 1
.
Object.prototype.__lookupSetter__(propertyName)
Every Object
instance must have a __lookupSetter__
method that implements the following algorithm:
ToString(propertyName)
.
__defineSetter__
or the set
syntax in the object initializer, return the setter function; else, return undefined
.
var object = { set foo(value) { this.bar = value * 2; } }; object.__lookupSetter__('foo'); // function foo(value) { this.bar = value * 2; }
The length
property of the __lookupSetter__
method is 1
.
Thanks to Anne van Kesteren, Aryeh Gregor, David Håsäther, Domenic Denicola, James Graham, John-David Dalton, Masatoshi Kimura, Ms2ger, Simon Pieters, Simon Sapin, Steven Levithan, Mark ‘Tarquin’ Wilton-Jones, and Tom Schuster for their useful comments.
Special thanks to James Graham for collecting and documenting most of these requirements on the WHATWG Wiki, and Juriy ‘kangax’ Zaytsev (Юрий Зайцев) for his ECMAScript Extensions Compatibility Table.