A user account is required in order to edit this wiki, but we've had to disable public user registrations due to spam.

To request an account, ask an autoconfirmed user on Chat (such as one of these permanent autoconfirmed members).

Web ECMAScript: Difference between revisions

From WHATWG Wiki
Jump to navigation Jump to search
No edit summary
 
(35 intermediate revisions by 8 users not shown)
Line 1: Line 1:
This page is for documenting the differences between the ES5 draft and the requirements for ECMAScript implementations in web browsers.
{{obsolete|spec=[http://javascript.spec.whatwg.org/ JavaScript, aka. Web ECMAScript]}}
 
This page is for documenting the differences between ES5 specification and the requirements for ECMAScript implementations in web browsers.
 
'''It is now maintained as specification: [http://javascript.spec.whatwg.org/ JavaScript, aka. Web ECMAScript]'''


== Identifiers ==
== Identifiers ==
Line 18: Line 22:


# Let content be ToString(this)
# Let content be ToString(this)
# Let n be ToString(name)
# Let attribute_value be ToString(name)
# Return ToHTMLTag("a", content, "name", n)
# Return ToHTMLTag("a", content, "name", attribute_value)


=== String.prototype.big() ===
=== String.prototype.big() ===
Line 83: Line 87:
# Let content be ToString(this)
# Let content be ToString(this)
# Return ToHTMLTag("sup", content)
# Return ToHTMLTag("sup", content)
== RegExp ==
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. (more detail here)
DecimalEscapes in CharacterRanges all behave like \0 rather than throwing syntax errors i.e. /[\1-Z]/ will match any character with a codepoint between 0 and 90.
RegExp.prototype.compile changes the regexp in place. In Carakan/Nitro/V8 the method returns undefined; in SpiderMonkey it returns the regexp object.
== Date ==
=== 15.9.4.3 Date.UTC ===
When called with fewer than 2 arguments Date.UTC must return NaN.
=== toString ===
TODO


== Global scope ==
== Global scope ==


ES3.1 claims the global scope "this" is the same as the global object, which is not always true in HTML5.
ES5 claims the global scope "this" is the same as the global object, which is not always true in HTML5.
 
== var statements ==
 
The erratum in https://bugs.ecmascript.org/show_bug.cgi?id=78#c0 needs to be followed so that var statements at the top level of scripts can shadow any properties from the global object's prototype chain.


== Eval ==
== Eval ==


Use of eval not called "eval". Shoud work but implementations differ on the scope (Spidermonkey first tries global and then local if the object as not found globally, JScript uses local scope, others use global scope), may not have strong compat requirements
Use of eval not called "eval". Should work but implementations differ on the scope (Spidermonkey first tries global and then local if the object as not found globally, JScript uses local scope, others use global scope), may not have strong compat requirements


eval.apply(this, code) should work but scope again varies when "this" is not the global object
eval.apply(this, code) should work but scope again varies when "this" is not the global object


eval.apply({}, code) should throw EvalError
=== Eval and Global Scopes ===
 
See: http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2011-March/030798.html


== Date Parsing ==
== Date Parsing ==
Line 104: Line 132:
<!-- is a line comment (same as //)
<!-- is a line comment (same as //)


In JScript, the following are ignored if they are at the end of the script (i.e. just followed by whitespace lines): either (1) a line that starts with just whitespace and comments and consists of "-->" followed by anything except new lines and finally followed by another "-->", or (2) one or two lines that start with just whitespace and comments and consist of just "-->". Moreover, a script can end with an open multiline comment if it ends with "-->" on the same line.
In JScript, the following are ignored if they are at the end of the script (i.e. just followed by whitespace lines): either (1) a line that starts with just whitespace and comments and consists of "-->" followed by anything except new lines and finally followed by another "-->", or (2) one or two lines that start with just whitespace and comments and consist of just "-->". --> at the end of the last line of the script causes the line to be ignored unless the "-->" occurs within a comment. The last non-whitespace line of the script is ignored if it ends with "-->" and doesn't contain "//" or "<!--" (but not in eval).
 
In SpiderMonkey, "-->" on any line that starts with just whitespace and comments is treated as a line comment (same as //). (Also, ;version=1.6, 1.7 or 1.8 or ;e4x=1 enables E4X <!-- --> comments.)
 
In Carakan, "-->" on any line that starts with just whitespace (but not comments) is treated as a line comment (same as //).
 
Chakra (IE) doesn’t support these syntax extensions.
 
== Property Enumeration ==
 
Enumeration of objects is in insertion order (but host property order compared to user defined property order does not seem to be significant). Property order seems to survive the use of "delete" (i.e. removing then readding a property doesn't change its position), at least in Chrome and Firefox.
 
== Object Properties ==
 
All objects have a mutable __proto__ property that is a reference to the prototype of the object. Note that ES5 defines that objects with extensible:false must not have their prototype mutated. In the case that setting an objects __proto__ would cause a prototype chain to become cyclic, the setter must fail and throw Error().
 
Note: __proto__ will be fully specced in ES6.
 
== Getters and Setters ==
 
* __lookupGetter__
* __lookupSetter__
* __defineGetter__
* __defineSetter__


In Futhark, the following is ignored if it is at the end of the script (i.e. just followed by whitespace lines): a line that starts with just whitespace and comments and consists of "-->", and <em>optionally</em> followed by anything except new lines and finally followed by another "-->". Moreover, a script can end with an open multiline comment if it ends with "-->" on the same line.
== foo.arguments ==


In SpiderMonkey, "-->" on any line that starts with just whitespace and comments is treated as a line comment (same as //). (Also, ;version=1.6, 1.7 or 1.8 or ;e4x=1 enables E4X <!-- --> comments.)
TODO http://www.w3.org/mid/4B02C72B.6020106@opera.com


In Nitro and V8, "-->" on any line that starts with just whitespace (but not comments) is treated as a line comment (same as //).
== Also see ==


== Stuff that needs a home ==
* http://kangax.github.com/es5-compat-table/non-standard/
* https://bugs.ecmascript.org/buglist.cgi?product=ECMA-262&component=technical%20content&resolution=--- – open bugs on the ES spec


Enumeration of objects is in insertion order (but host property order compared to user defined property order does not seem to be significant)
[[Category:Spec_coordination]]

Latest revision as of 16:54, 26 November 2012

This document is obsolete.

For the current specification, see: JavaScript, aka. Web ECMAScript


This page is for documenting the differences between ES5 specification and the requirements for ECMAScript implementations in web browsers.

It is now maintained as specification: JavaScript, aka. Web ECMAScript

Identifiers

(this is very rough)

Identifiers containing escape sequences are not equivalent to fully unescaped identifiers in the case that, after fully unescaping identifier, it is a ReservedWord. In particular it is possible to create Identifiers that unescape to a reserved word so long as at least one character is fully escaped. Subsequent use of such identifiers must also have at least one character escaped (otherwise the reserved word will be used instead) but it need not be the same character(s) as that originally used to create the identifier.

15.5.4 Properties of the String Prototype Object

Several extra methods are found on String.prototype for wrapping text in HTML elements (these are all generic; the this value need not be a String object):

Algorithm ToHTMLTag(tag_name, content, attribute_name, attribute_value):

  1. if attribute_name is undefined return "<" + tag_name + ">" + content + "</" + tag_name + ">"
  2. otherwise return "<" + tag_name + " " + attribute_name + "=\"" + attribute_value + "\">" + content + "</" + tag_name + ">"

String.prototype.anchor(name)

  1. Let content be ToString(this)
  2. Let attribute_value be ToString(name)
  3. Return ToHTMLTag("a", content, "name", attribute_value)

String.prototype.big()

  1. Let content be ToString(this)
  2. Return ToHTMLTag("big", content)

String.prototype.blink()

  1. Let content be ToString(this)
  2. Return ToHTMLTag("blink", content)

String.prototype.bold()

  1. Let content be ToString(this)
  2. Return ToHTMLTag("b", content)

String.prototype.fixed()

  1. Let content be ToString(this)
  2. Return ToHTMLTag("tt", content)

String.prototype.fontcolor(color)

  1. Let content be ToString(this)
  2. Let attribute_value be ToString(color)
  3. Return ToHTMLTag("font", content, "color", attribute_value)

String.prototype.fontsize(size)

  1. Let content be ToString(this)
  2. Let attribute_value be ToString(size)
  3. Return ToHTMLTag("font", content, "size", attribute_value)

String.prototype.italics()

  1. Let content be ToString(this)
  2. Return ToHTMLTag("i", content)

String.prototype.link(href)

  1. Let content be ToString(this)
  2. Let attribute_value be ToString(href)
  3. Return ToHTMLTag("a", content, "href", attribute_value)

String.prototype.small()

  1. Let content be ToString(this)
  2. Return ToHTMLTag("small", content)

String.prototype.strike()

  1. Let content be ToString(this)
  2. Return ToHTMLTag("strike", content)

String.prototype.sub()

  1. Let content be ToString(this)
  2. Return ToHTMLTag("sub", content)

String.prototype.sup()

  1. Let content be ToString(this)
  2. Return ToHTMLTag("sup", content)

RegExp

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. (more detail here)

DecimalEscapes in CharacterRanges all behave like \0 rather than throwing syntax errors i.e. /[\1-Z]/ will match any character with a codepoint between 0 and 90.

RegExp.prototype.compile changes the regexp in place. In Carakan/Nitro/V8 the method returns undefined; in SpiderMonkey it returns the regexp object.

Date

15.9.4.3 Date.UTC

When called with fewer than 2 arguments Date.UTC must return NaN.

toString

TODO

Global scope

ES5 claims the global scope "this" is the same as the global object, which is not always true in HTML5.

var statements

The erratum in https://bugs.ecmascript.org/show_bug.cgi?id=78#c0 needs to be followed so that var statements at the top level of scripts can shadow any properties from the global object's prototype chain.

Eval

Use of eval not called "eval". Should work but implementations differ on the scope (Spidermonkey first tries global and then local if the object as not found globally, JScript uses local scope, others use global scope), may not have strong compat requirements

eval.apply(this, code) should work but scope again varies when "this" is not the global object

Eval and Global Scopes

See: http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2011-March/030798.html

Date Parsing

TODO:This is a mess

HTML comments

<!-- is a line comment (same as //)

In JScript, the following are ignored if they are at the end of the script (i.e. just followed by whitespace lines): either (1) a line that starts with just whitespace and comments and consists of "-->" followed by anything except new lines and finally followed by another "-->", or (2) one or two lines that start with just whitespace and comments and consist of just "-->". --> at the end of the last line of the script causes the line to be ignored unless the "-->" occurs within a comment. The last non-whitespace line of the script is ignored if it ends with "-->" and doesn't contain "//" or "<!--" (but not in eval).

In SpiderMonkey, "-->" on any line that starts with just whitespace and comments is treated as a line comment (same as //). (Also, ;version=1.6, 1.7 or 1.8 or ;e4x=1 enables E4X <!-- --> comments.)

In Carakan, "-->" on any line that starts with just whitespace (but not comments) is treated as a line comment (same as //).

Chakra (IE) doesn’t support these syntax extensions.

Property Enumeration

Enumeration of objects is in insertion order (but host property order compared to user defined property order does not seem to be significant). Property order seems to survive the use of "delete" (i.e. removing then readding a property doesn't change its position), at least in Chrome and Firefox.

Object Properties

All objects have a mutable __proto__ property that is a reference to the prototype of the object. Note that ES5 defines that objects with extensible:false must not have their prototype mutated. In the case that setting an objects __proto__ would cause a prototype chain to become cyclic, the setter must fail and throw Error().

Note: __proto__ will be fully specced in ES6.

Getters and Setters

* __lookupGetter__
* __lookupSetter__
* __defineGetter__
* __defineSetter__

foo.arguments

TODO http://www.w3.org/mid/[email protected]

Also see