views:

423

answers:

4

Is it really possible, with Google's V8 Engine, to compile JavaScript into Native Code, save it as a binary file, and execute it whenever I want through my software envorinment, on any machine?

+1  A: 

As far as I know, V8 is purely a just-in-time compiler, and does not have an ahead-of-time option.

As discussed at the articles I linked, JITs allow better, more flexible optimizations.

Matthew Flaschen
A: 

No, it's not possible, V8 is not designed to do that. Like Java, JVM compiles bytecode to machine code JIT but you cannot see the machine code.

SHiNKiROU
A: 

Instead, it might be possible to use a .NET javscript/JScript compiler to create a .NET exe, then convert the .NET exe to a native .exe using the Mono ahead-of-time compiler.

Jack Nock
+3  A: 

You can use the V8 snapshot functionality to precompile the code. This still means that you have to have a full version of V8 running to load the snapshot (i.e., you don't get stand-alone native code, it needs to run inside the V8 VM), so all you save is the compilation time. Also, the quality of snapshot code isn't necessarily as good as JIT'ed code because JIT code can use, e.g., SSE2/SSE3 if it's available, which snapshots can't assume.

Lasse Reichstein