开发者

When will v8 implement ECMAScript 5?

开发者 https://www.devze.com 2023-03-08 15:41 出处:网络
I noticed that v8 is rather mute on the issue of ECMAScript 5th edition. V8 implements ECMAScript as specified in ECMA-262, 3rd edition, and runs on Windows XP and Vista, Mac OS X 10.5 (Leopard), an

I noticed that v8 is rather mute on the issue of ECMAScript 5th edition.

V8 implements ECMAScript as specified in ECMA-262, 3rd edition, and runs on Windows XP and Vista, Mac OS X 10.5 (Leopard), and Linux systems that use IA-32 or ARM processors.

Even the bug tracker seems quiet...

On one bug you can find a commiter writing this:

V8 is an implementation of ECMAScript, not JavaScript. The latter is a non-standardized extension of ECMAScript made by Mozilla. V8 is intended to be plug-in compatible with JSC, the ECMAScript implementation in WebKit/Safari. As such it implements a number of non-standard extensions of ECMAScript that are also in JSC, and most of these are also in Mozilla's JavaScript languages. There is no plan to add non-standard features that are not in JSC to V8.

Interestingly enough he wrote that on Oct 8, 2010, when ECMAScript 5 was published on December 2009, and two months earlier Javascript 1.8.5 -- a superset of ECMAScript 5 -- was released.

So the question remains when will Google update v8 to run on ECMAScript 5th edition? Is there even a plan to upgrade to the latest standardization of ECMAScript?


ECMAScript 5 was actually designed in such way so that implementations don't need to be "updated to run" on it.

There are few changes in existing behavior but mainly ES5 adds new native objects (e.g. Object.create, Array.prototype.map, String.prototype.trim, etc.) and standardizes some of the existing de-facto features (from ubiquitous "line terminators in string literals", "property access on strings", and "indirect eval behavior" to less popular "accessors" and array/string extensions).

The biggest change in behavior — strict mode — was made opt-in for the very same reason; to make transition from ES3 to ES5 less painful.

Having said that, V8 does implement a noticeable chunk of ES5 features, including strict mode (one of the recent additions).

If you look at my ES5 compat. table you can see ES5 features implemented in Chrome — which should closely (and I would think — completely) correlate to V8.

You can also see that support for strict mode is largely implemented in Chrome which means that it should be in V8 as well. To double check, I just ran this code in console (v8 v3.2.3.1) and got SyntaxError as expected:

> (function(){"use strict"; with({x:1}) return x})()
(shell):1: SyntaxError: Strict mode code may not include a with statement
(function(){"use strict"; with({x:1}) return x})()
                          ^^^^

So there you have it. V8 definitely implements majority of ES5 features, including strict mode ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消