Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable Harmony ES6 features in V8 at runtime in a module?

Node v0.10.20 provides many options pertaining to harmony,

--harmony_typeof (enable harmony semantics for typeof)
--harmony_scoping (enable harmony block scoping)
--harmony_modules (enable harmony modules (implies block scoping)
--harmony_proxies (enable harmony proxies)
--harmony_collections (enable harmony collections (sets, maps, and weak maps))
--harmony (enable all harmony features (except typeof))

I understand that these are not production-ready features and that they're under development, but many of them are good enough.

Is there a way to enable them at runtime?

"use strict";
"use harmony collections";

Something like the above. Even if it's not just module-level enabling of those features, it'd be nice to ensure they were enabled inside the module rather than assume they were enabled.

like image 525
NO WAR WITH RUSSIA Avatar asked Oct 17 '13 21:10

NO WAR WITH RUSSIA


2 Answers

No, you can't. In fact, some things might potentially go horribly wrong within V8 internals if you tried to sneak in multiple different settings of these flags within the same V8 instance (disclosure: I implemented most of these flags).

like image 119
Andreas Rossberg Avatar answered Sep 20 '22 08:09

Andreas Rossberg


There is no way to do this, the interpreter reads the content of the modules then validate them and then evaluate them. If you will use some ES6 specific syntax then the validation will fail and the code will not be evaluated.

You only could isolate the ES6 syntax files and run them as child processes (with the necessary options), but I guess this is not the way you want to do this.

like image 27
micnic Avatar answered Sep 18 '22 08:09

micnic