如何将V8编译的javascript变成EXE?

时间:2021-11-26 06:57:12

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?

我知道谷歌的v8编译javascript到本机(二进制,如果我理解正确)代码。有没有办法获取输出并将其转换为exe?

4 个解决方案

#1


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.

我不认为你可以使用V8将一段JavaScript直接转换为可执行文件,但你可以创建一个将V8引擎与JavaScript捆绑在一起并将其作为独立程序运行的应用程序。

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

您可以在其项目页面上找到有关V8的所有信息。

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.)

另请注意,JavaScript无法完全编译,因为它是动态语言。使用V8,它是JIT编译的(例如.NET。)。仍然可以将它变成一个独立的可执行文件(例如.NET)。

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.

如果您想开发使用HTML进行渲染的独立应用程序,您也可以查看Adobe Air。

#2


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.

Javascript不能只编译一次。该语言具有非常广泛使用的eval。 (例如,对于JSON)您需要随身携带JIT和整个运行时。

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

这里的JIT只是一种优化,而不是摆脱编译器/解释器的方法。

#3


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

Node.js嵌入了V8。这可能是一个值得学习的好例子。

#4


There have been a few tries at making js into native code, it's not something that can be used in production by any means, more of an academic interest. The Rhino interpreter for java has an option to make js into (java) bytecode so one approach is to convert to bytecode and then from bytecode to native with GCJ. There is some discussion about Rhino and GCJ but I don't know if anyone ever tried exactly that. https://groups.google.com/forum/#!msg/netscape.public.mozilla.jseng/c3tqyLZ19fw/8V4HeuMtIXUJ

尝试将js变成本机代码已经有了一些尝试,它不是可以通过任何方式在生产中使用的东西,更多的是学术兴趣。用于java的Rhino解释器有一个选项可以将js转换为(java)字节码,因此一种方法是转换为字节码,然后从字节码转换为GCJ本机代码。有一些关于Rhino和GCJ的讨论,但我不知道是否有人曾经尝试过。 https://groups.google.com/forum/#!msg/netscape.public.mozilla.jseng/c3tqyLZ19fw/8V4HeuMtIXUJ

Another approach is using Python, specifically Py-Py which itself is written in a non-standard subset of Python called rPython. rPython is not meant for human consumption but it has the benefit of being something which can be compiled to native. One interesting (albeit wacky) experiment was to compile Javascript to Python and then in some cases that Python happens to be valid as rPython and can be compiled down to native with the rPython compiler.

另一种方法是使用Python,特别是Py-Py,它本身是用非标准的Python子集rPython编写的。 rPython并不适合人类消费,但它具有可以编译为本机的优点。一个有趣的(尽管是古怪的)实验是将Javascript编译为Python,然后在某些情况下,Python恰好作为rPython有效,并且可以使用rPython编译器编译为本机。

http://mozakai.blogspot.com/2010/07/experiments-with-static-javascript-as.html

If a .exe file is really important, I would bundle V8 with your app since even if you can compile js to native, you still need a full interpreter if you use any eval() or similar. It would not be hard to write a tool for bundling everything into an .exe file as long as your users don't mind either an 8MB exe or 8MB V8.dll file.

如果.exe文件非常重要,我会将V8与您的应用程序捆绑在一起,因为即使您可以将js编译为本机,如果您使用任何eval()或类似内容,仍需要完整的解释器。只要您的用户不介意8MB exe或8MB V8.dll文件,编写将所有内容捆绑到.exe文件中的工具就不难了。

As a last thought, Big G has started allowing "native" apps based on chrome (google: "chrome packaged apps"). They have low level system access and can use the WebKit renderer allowing you to create your GUI in CSS and HTML and they have their own windows and icons so it is not obvious that they are running inside of chrome. This is probably still premature but it's something to keep an eye on in the desktop applications field.

作为最后一个想法,Big G已经开始允许基于chrome的“原生”应用程序(谷歌:“Chrome打包应用程序”)。它们具有低级系统访问权限,并且可以使用WebKit渲染器,允许您使用CSS和HTML创建GUI,并且它们具有自己的窗口和图标,因此它们在chrome内部运行并不明显。这可能还为时过早,但需要关注桌面应用程序领域。

#1


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.

我不认为你可以使用V8将一段JavaScript直接转换为可执行文件,但你可以创建一个将V8引擎与JavaScript捆绑在一起并将其作为独立程序运行的应用程序。

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

您可以在其项目页面上找到有关V8的所有信息。

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.)

另请注意,JavaScript无法完全编译,因为它是动态语言。使用V8,它是JIT编译的(例如.NET。)。仍然可以将它变成一个独立的可执行文件(例如.NET)。

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.

如果您想开发使用HTML进行渲染的独立应用程序,您也可以查看Adobe Air。

#2


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.

Javascript不能只编译一次。该语言具有非常广泛使用的eval。 (例如,对于JSON)您需要随身携带JIT和整个运行时。

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

这里的JIT只是一种优化,而不是摆脱编译器/解释器的方法。

#3


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

Node.js嵌入了V8。这可能是一个值得学习的好例子。

#4


There have been a few tries at making js into native code, it's not something that can be used in production by any means, more of an academic interest. The Rhino interpreter for java has an option to make js into (java) bytecode so one approach is to convert to bytecode and then from bytecode to native with GCJ. There is some discussion about Rhino and GCJ but I don't know if anyone ever tried exactly that. https://groups.google.com/forum/#!msg/netscape.public.mozilla.jseng/c3tqyLZ19fw/8V4HeuMtIXUJ

尝试将js变成本机代码已经有了一些尝试,它不是可以通过任何方式在生产中使用的东西,更多的是学术兴趣。用于java的Rhino解释器有一个选项可以将js转换为(java)字节码,因此一种方法是转换为字节码,然后从字节码转换为GCJ本机代码。有一些关于Rhino和GCJ的讨论,但我不知道是否有人曾经尝试过。 https://groups.google.com/forum/#!msg/netscape.public.mozilla.jseng/c3tqyLZ19fw/8V4HeuMtIXUJ

Another approach is using Python, specifically Py-Py which itself is written in a non-standard subset of Python called rPython. rPython is not meant for human consumption but it has the benefit of being something which can be compiled to native. One interesting (albeit wacky) experiment was to compile Javascript to Python and then in some cases that Python happens to be valid as rPython and can be compiled down to native with the rPython compiler.

另一种方法是使用Python,特别是Py-Py,它本身是用非标准的Python子集rPython编写的。 rPython并不适合人类消费,但它具有可以编译为本机的优点。一个有趣的(尽管是古怪的)实验是将Javascript编译为Python,然后在某些情况下,Python恰好作为rPython有效,并且可以使用rPython编译器编译为本机。

http://mozakai.blogspot.com/2010/07/experiments-with-static-javascript-as.html

If a .exe file is really important, I would bundle V8 with your app since even if you can compile js to native, you still need a full interpreter if you use any eval() or similar. It would not be hard to write a tool for bundling everything into an .exe file as long as your users don't mind either an 8MB exe or 8MB V8.dll file.

如果.exe文件非常重要,我会将V8与您的应用程序捆绑在一起,因为即使您可以将js编译为本机,如果您使用任何eval()或类似内容,仍需要完整的解释器。只要您的用户不介意8MB exe或8MB V8.dll文件,编写将所有内容捆绑到.exe文件中的工具就不难了。

As a last thought, Big G has started allowing "native" apps based on chrome (google: "chrome packaged apps"). They have low level system access and can use the WebKit renderer allowing you to create your GUI in CSS and HTML and they have their own windows and icons so it is not obvious that they are running inside of chrome. This is probably still premature but it's something to keep an eye on in the desktop applications field.

作为最后一个想法,Big G已经开始允许基于chrome的“原生”应用程序(谷歌:“Chrome打包应用程序”)。它们具有低级系统访问权限,并且可以使用WebKit渲染器,允许您使用CSS和HTML创建GUI,并且它们具有自己的窗口和图标,因此它们在chrome内部运行并不明显。这可能还为时过早,但需要关注桌面应用程序领域。