views:

1232

answers:

3

I know that google's v8 compiles javascript into native machine (binary if I understand correctly) code.
Is there a way to take the output and turn it into a exe?

+5  A: 

I don't think you can directly turn a piece of JavaScript into an executable using V8, but you can probably make an application that bundles the V8 engine with the JavaScript and runs it as a stand-alone.

You can find all information about V8 on its project page.

Also note that JavaScript can't be completely compiled as it's a dynamic language. With V8, it's JIT-compiled (like .NET, for example.) It's still possible to turn it into a stand-alone executable though (like .NET, for example.)

If you want to develop stand-alone applications that make use of HTML for rendering, you could have a look at Adobe Air as well.

Blixt
I'm trying to do something else.How can you bundle the javascript into the exe then?
the_drow
See the "embedding" part of the V8 project page.
Blixt
+4  A: 

Javascript cannot be compiled just once. The language has eval which is pretty widely used. (for JSON for instance) You need to carry around the JIT, and the whole runtime.

JIT here is only an optimization, not the way to get rid of the compiler/interpreter.

EFraim
"V8 compiles JavaScript source code directly into machine code when it is first executed. There are no intermediate byte codes, no interpreter. Property access is handled by inline cache code that may be patched with other machine instructions as V8 executes."
the_drow
Yeah, but note the "when it is first executed" part. JavaScript cannot be compiled entirely to byte-code, it has to be compiled as it runs, due to its dynamic nature.
Blixt
@the_drow: The problem is that with 'eval' you feed the new JavaScript code all the time.
EFraim
+1  A: 

Node.js embeds V8. This might be a good example to learn from.

z8000