独立运行 V8 Javascript 引擎
我想在 V8 之上运行 Javascript 控制台。我该怎么做?
I want to run a Javascript console on top of V8. How do I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我想在 V8 之上运行 Javascript 控制台。我该怎么做?
I want to run a Javascript console on top of V8. How do I do this?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(10)
V8 很容易构建,并且不会带来来自 Mozilla 独立 Javascript 解释器的 Java VM 开销。幸运的是,V8 附带了用于构建控制台的代码。构建方法如下:
现在,我们有一个名为
v8-shell
的独立二进制文件。运行控制台:
从命令行执行 Javascript:
帮助中记录了更多功能:
V8 is easy to build and does not come with the Java VM overhead from Mozilla's standalone Javascript interpreter. Luckily, V8 ships with code for building a console. Here is how to build this:
Now, we have a standalone binary called
v8-shell
.Running the console:
Executing Javascript from the command line:
Many more features are documented in the help:
要构建开发人员控制台,而不是示例“shell”玩具应用程序,请将以下命令复制粘贴到您的终端。
这些指令适用于具有“通用”内核的 Ubuntu/Debian。对于其他发行版,您需要将 apt-get 命令替换为可用的任何软件包工具。在 64 位系统上,您可能需要添加
arch=x64
。console=readline
选项启用 readline 系统,使其感觉更像是一个标准的外壳。更完整的文档在这里:
http://code.google.com/apis/v8/build.html
注意:
另请参阅:使用 GYP 构建 v8
To build the developer console, rather than the example 'shell' toy application, copy-paste the below commands to your terminal.
These instruction will work for Ubuntu/Debian with a "generic" kernel. For other distributions, you will need to replace the apt-get command with whatever package tool you have available. On 64-bit systems you may need to add
arch=x64
. Theconsole=readline
option enables the readline system, to make it feel a bit more like a standard shell.More complete documentation here:
http://code.google.com/apis/v8/build.html
Note:
See also: Building v8 with GYP
如何使用 node.js 通过命令行运行 V8 Javascript?
Node.js 使用 v8 作为引擎,并在其之上添加了很多功能。
例如,在 Mac OSX 上,如果您安装了 Homebrew,只需发出:
How about running V8 Javascript via command line using node.js?
node.js uses v8 as it's engine and adds a lot of functionality on top of it.
For example on Mac OSX if you have Homebrew installed, simply issue:
在 Mac OS X 上,请务必安装
brew
。然后只需运行命令(sudo)brew install v8
,这可能需要一些时间,具体取决于您的机器。要启动 V8 控制台,只需运行v8
- 瞧!提示:要退出控制台,只需运行
quit()
并且不要忘记括号!On Mac OS X be sure to have
brew
installed. Then just run the command(sudo) brew install v8
, depending on your machine this may take some time. To start the V8 console, just runv8
- Voilà!Tip: To quit the console, just run
quit()
and don't forget the parentheses!我想这可能已经改变了。我阅读手册并像这样构建 v8:
添加了
export PATH=${PATH} :/home/moose/Downloads/v8-trunk/out/ia32.release
到我的 .bashrc(使用来自 aditsu 和 A-small-practice.in 来自 Google Code Jam)
I think this might have changed. I read the manual and build v8 like this:
added
export PATH=${PATH}:/home/moose/Downloads/v8-trunk/out/ia32.release
to my .bashrc(With javascript from aditsu and A-small-practice.in from Google Code Jam)
按照系统的构建说明(Google 的 V8 构建文档)进行操作后;
我在 .bash_profile 中创建了一个别名以方便调用 shell。
在 CLI 中输入 v8(在新的终端或 shell 中——以重新加载 bash 配置文件)会生成 v8 shell。命令提示符下的 JavaScript! :)
After following the build instructions (Google's V8 Build Docs) for your system;
I created an alias in my .bash_profile to facilitate invocation of the shell.
Typing v8 at the CLI (in a new Terminal or shell -- to reload your bash profile) yields the v8 shell. JavaScript at the command prompt! :)
如果您使用ArchLinux,则可以使用
pacman -S v8
来安装它。然后使用 d8 在 shell 中启动它。
好好享受。
If you use ArchLinux, you can use
pacman -S v8
to install it.Then use
d8
to start it in your shell.Enjoy it.
如果您想使用 v8 引擎或其任何版本运行 javascript 源代码,您可以使用 jsvu 命令行工具。它由 Google 工程师开发和维护,此外,它还提供安装除 v8 之外的其他 javascript 引擎的功能,例如 spidermonkey、chakracore >、javascriptcore 和 xs。
In case you would like to run your javascript source code using the v8 engine or any version of it, you may utilize the jsvu command-line tool. It is developed and maintained by Google engineers and, besides, it offers the feature of installing other javascript engines apart from v8, such as spidermonkey, chakracore, javascriptcore, and xs.
如果您打算嵌入 V8,那么一定要构建它并使用“d8”。
另一方面,如果您不打算扩展 V8 或将其视为可选,
那么就使用 Node.JS 吧。不要为纯V8而烦恼。
Node.js 拥有真正丰富的 I/O、扩展、库(如 Perl CPAN、Python Eggs、Ruby Gems)和社区。
If you're planning to embed V8, then by all means build it and play with "d8".
If on the other hand, you do not plan to extend V8 or treat it as optional,
then just use Node.JS. Don't bother with pure V8.
Node.js has truly rich I/O, extensions, libraries (like Perl CPAN, Python Eggs, Ruby Gems), and community.
如果您使用的是 Windows:
pacman -Syu mingw-w64-i686-toolchain
mingw-w64-i686-v8
d8
作为您道路上的新翻译。测试它
c:\msys2\home\user\
d8 test.js
您还可以从 此处并使用pezip解压缩。
祝你好运 !!
If you are on Windows:
pacman -Syu mingw-w64-i686-toolchain
mingw-w64-i686-v8
d8
as a new interpreter in your path.Test it
c:\msys2\home\user\
d8 test.js
You can also download binaries from here and unzip with peazip.
Good luck !!