-
Notifications
You must be signed in to change notification settings - Fork 677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supporting ECMAScript 2015 #205
Comments
I'd argue against re-defining our target unless we are also ready to change our schedule considerably. We are somewhere halfway (a bit better than that) to ES5.1 conformance. We know (and are determined) to reach the conformant status by end of summer/early fall, however I'm sure that ES6 conformance will need quite some extra work. If we change our target now, then we may have an engine at our original deadline which is neither ES5.1 nor ES6 conformant. This will postpone the applicability of JerryScript in real use cases, which can be risky IMHO. I'd suggest going with the original target and setting up a new schedule for reaching ES6 confirmance only after ES5.1 is reached (or very close to that). |
Personally, I appreciate the idea of supporting the latest standard - it's very important from any point of view. But aligning our target with ES6 will definitely require to correct our schedule - it may take time:
I suppose that we'll clarify all plans only by the end of July. Our current deadlines are very tight and I assume that within them we won't be able to support ES6 fully. If we are not able to reassess current deadline we should continue with our current plans.
|
I agree with @egavrin. |
Perhaps we should not forget our other goals, such as memory consumption, performance, binary size. And I also have another goal in my mind: making Jerry a popular JS engine. Creating something which is valuable to others. |
I agree that it is great to add ES6 support, starting working on it after ES5.1 support would be completed. |
@akiss77 @egavrin @sand1k @zherczeg @ruben-ayrapetyan, thank you for having good feedback. First, we have to focus our original plan, implementing ES5.1, in schedule. And we also need to start investigation of ES6. Then let's talk about investigation of ES6. |
@lemmaa since we're going to start optimize Jerry since July, we should take into account new language features and try to avoid engine modifications that may hardener further implementation. Some of them are briefly listed here: What we shall do:
|
I would say at least supporting Promises should be considered, as it is a requirement for most new Web APIs as defined by W3C, WHATWG etc. It is also heavily used by the Generic Sensor API which we would love to support node.js at some point, instead of just web browsers. Wouldn't supporting "let" instead of just "var", potentially be able to improve memory usage? |
Supporting promises is probably possible at some point. Supporting let is very challenging but we might try to do it sometimes.. Lots of engine changes will be required, heavy binary size increase, memory consumption increase, performance drop is expected, so the costs might outweight the gain at the end. So this is not a high priority for us at the moment. |
I think it is worth discussing the ""let" problem, because somebody might have a good idea to do it efficiently. In ES5.1, you can simulate "let" in the following way:
The catch creates a new lexical environment, which only has one binding, the "a" symbol. This symbol shadows the "var a" symbol (if exists). Hence a new object is created and added it to the lexical environment, which consumes memory and makes resolving slower. You cannot really avoid this because:
This prints 5 and 6. The other problem is control flow. Statements such as try, with, and for-in create contexts which needs to be destroyed when these statements are finished. Furthermore break/continue/throw/return statements can also abort these contexts. This is done by context breaker gotos whose are much more costly than normal gotos. Since try, etc. statements are rare, they don't really slow down Jerry at this moment. However, I would assume that people would use "let" much more frequently than those others which would add a lot of context management and would cause considerable slowdown. Telling people that you have "let" but don't use it does not makes much sense. Hence there are two issues needs to be solved:
And there is a third: we don't have AST and enough time to do complex code analysis. So the solution must be lightweight and must work with little available information. Let is know if anybody has a clever idea. Otherwise I don't think it is worth supporting "let". |
try/catch might become more popular in ES2017 where async/await are expected for making common promise based code easier to write. This is already in Edge and Chrome (behind flags, I believe) Btw, the best place to see what goes into future versions is here: https://github.com/tc39/proposals/blob/master/finished-proposals.md ES2016: http://www.ecma-international.org/ecma-262/7.0/ |
As good async support is quite interesting for IoT (AIO might for instance be on another core, like on the Arduino 101), what I would like the most from > ES5.1 would be
Did anyone look at how hard it would be supporting these? |
Even more interesting example for let:
This prints numbers from 0 to 4. Lexical environment magic. I think the implementation difficulty depends on the standard. Does promises has ES5 implementation? If so, implementing it should not be too hard since no engine rework is needed. Generators require suspending execution which means the call stack needs to be saved (or they need a separate call stack allocator) somewhere. Nesting generators could have some interesting corner cases if the standard allows it. And also the combination of features could be interesting. E.g. with, eval, and function declaration is easy in theory but if you do:
Doing that properly is challenging. Mix this with declaring generators. Anyway, these could be useful for long term plans. Probably will be challenging but not impossible. |
That seems a bit like magic indeed. Promises were done before ES2015 and originally in the HTML/DOM spec and then moved to JS, so it should not depend on anything else, but they did introduce the notion of micro-tasks though. http://www.ecma-international.org/ecma-262/7.0/#sec-promise-constructor I don't think that I have ever seen any examples of nested generators, and eval is pretty much discouraged today :-) |
By nesting do you mean
That seems to work in Chrome
|
Yes. Even if it is unlikely that people use such thing if we implement generators we need to support every possible corner case. This is the bulk of the work. |
But if this is to serve as the implementation of async/await (without exposing the generator support to devs) would that be the same amount of work? The implementation of async/await on top of generators, can be seen here: |
Do you mean implement async without generators? That is probably possible. And later extend the implementation to support generators if needed. |
Yes, or just the parts of generators (without exposing it) that are needed in order to implement and expose async/await. I expect that async/await will be enabled by default soon in most browsers and it will probably make promises even more popular, while making async code much easier to write and read. I mean, 'let', generators etc and lot of other things in ES2015+ are pretty cool, but for IoT, the biggest pain point right now with JS is async code, which promises and async/await could really help with. That combined with newer Web APIs requiring promises and well as users asking for similar APIs across Web and Node.js, makes it a very welcome feature. |
It seems this is not working, which is great news, since generators can use the normal call stack when calling other functions. Only their own call frame needs to be allocated in the memory, which simplify heavily the complexity of this task. Is this true? |
I would say that is correct,
|
Yes, yield is some kind of unary operator with a unique precedence (still much easier than the arrow operator, which requires look-ahead operation in an AST less parser). Anyway at least we don't need to support cases where a generator calls a native function, and that calls a JS callback function, which yields something. This is a huge simplification. So we just need to allocate a call frame for the generator function only, and we can simply suspend the execution at the point of yield. This is quite easy to do in jerry. So it is likely these two features can be implemented in jerry without much trouble. However it is still a lot of new code, so it definitely takes time. |
Yes, that is expected :-) but it would be very nice if you considered it next time you do plannings. Is JerryScript already 100% ES5.1 compliant? |
Yes, except internalization support. (Note: ES6 is not fully backward compatible) |
Hi, I was curious if there were plans to eventually implement ES6 module support in JerryScript? |
I suggest do not implement the full es6 standard, but implement those are not easily or properly to be implement by polyfill or transpiler |
Intel has already started to implement typed arrays. Promises might be the next. So this is underway. |
JFYI, tracking ES6 Promise support separately over here: |
The General Assembly of Ecma International has announced the approval of ECMA-262 6th edition.
Should we need to change our target to support ES6 immediately? or keep going to finish current target first?
Please share your opinion.
Thanks!
The text was updated successfully, but these errors were encountered: