独立运行 V8 Javascript 引擎

发布于 2024-08-12 03:48:41 字数 40 浏览 5 评论 0原文

我想在 V8 之上运行 Javascript 控制台。我该怎么做?

I want to run a Javascript console on top of V8. How do I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

绻影浮沉 2024-08-19 03:48:41

V8 很容易构建,并且不会带来来自 Mozilla 独立 Javascript 解释器的 Java VM 开销。幸运的是,V8 附带了用于构建控制台的代码。构建方法如下:

gt; git clone https://chromium.googlesource.com/v8/v8
...
gt; cd v8-trunk
gt; scons
gt; g++ ./samples/shell.cc -o v8-shell -I include libv8.a 

现在,我们有一个名为 v8-shell 的独立二进制文件。

运行控制台:

gt; ./v8-shell 
V8 version 2.0.2
> var x = 10;
> x
10
> function foo(x) { return x * x; }
> foo
function foo(x) { return x * x; }
> quit()

从命令行执行 Javascript:

gt; ./v8-shell -e 'print("10*10 = " + 10*10)'
10*10 = 100

帮助中记录了更多功能:

gt; ./v8-shell --help
Usage:
...

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:

gt; git clone https://chromium.googlesource.com/v8/v8
...
gt; cd v8-trunk
gt; scons
gt; g++ ./samples/shell.cc -o v8-shell -I include libv8.a 

Now, we have a standalone binary called v8-shell.

Running the console:

gt; ./v8-shell 
V8 version 2.0.2
> var x = 10;
> x
10
> function foo(x) { return x * x; }
> foo
function foo(x) { return x * x; }
> quit()

Executing Javascript from the command line:

gt; ./v8-shell -e 'print("10*10 = " + 10*10)'
10*10 = 100

Many more features are documented in the help:

gt; ./v8-shell --help
Usage:
...
晨曦÷微暖 2024-08-19 03:48:41

要构建开发人员控制台,而不是示例“shell”玩具应用程序,请将以下命令复制粘贴到您的终端。

sudo apt-get install subversion scons libreadline-dev
svn co http://v8.googlecode.com/svn/trunk v8
cd v8/
scons console=readline d8

这些指令适用于具有“通用”内核的 Ubuntu/Debian。对于其他发行版,您需要将 apt-get 命令替换为可用的任何软件包工具。在 64 位系统上,您可能需要添加 arch=x64console=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.

sudo apt-get install subversion scons libreadline-dev
svn co http://v8.googlecode.com/svn/trunk v8
cd v8/
scons console=readline d8

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. The console=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:

enter image description here

See also: Building v8 with GYP

-黛色若梦 2024-08-19 03:48:41

如何使用 node.js 通过命令行运行 V8 Javascript?

Node.js 使用 v8 作为引擎,并在其之上添加了很多功能。


例如,在 Mac OSX 上,如果您安装了 Homebrew,只需发出:

    $ brew install node
    $ node
    > 

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:

    $ brew install node
    $ node
    > 
ι不睡觉的鱼゛ 2024-08-19 03:48:41

在 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 run v8 - Voilà!

Tip: To quit the console, just run quit() and don't forget the parentheses!

娇纵 2024-08-19 03:48:41

我想这可能已经改变了。我阅读手册并像这样构建 v8:

moose@pc08$ svn co http://v8.googlecode.com/svn/trunk v8-trunk
moose@pc08$ cd v8-trunk
moose@pc08$ make dependencies
moose@pc08$ make ia32.release

添加了 export PATH=${PATH} :/home/moose/Downloads/v8-trunk/out/ia32.release 到我的 .bashrc

moose@pc08 ~ $ source ~/.bashrc
moose@pc08 ~ $ d8 A_tic_tac_toe_Tomek.js < A-small-practice.in

(使用来自 aditsu 和 A-small-practice.in 来自 Google Code Jam)

I think this might have changed. I read the manual and build v8 like this:

moose@pc08$ svn co http://v8.googlecode.com/svn/trunk v8-trunk
moose@pc08$ cd v8-trunk
moose@pc08$ make dependencies
moose@pc08$ make ia32.release

added export PATH=${PATH}:/home/moose/Downloads/v8-trunk/out/ia32.release to my .bashrc

moose@pc08 ~ $ source ~/.bashrc
moose@pc08 ~ $ d8 A_tic_tac_toe_Tomek.js < A-small-practice.in

(With javascript from aditsu and A-small-practice.in from Google Code Jam)

绝不放开 2024-08-19 03:48:41

按照系统的构建说明(Google 的 V8 构建文档)进行操作后;

[v8 directory]$ cd out/native
[v8 directory]$ ./shell (sample shell)
[v8 directory]$ ./d8 (console: dumb)

我在 .bash_profile 中创建了一个别名以方便调用 shell。

alias v8='/Volumes/Dev/GitHub/v8/out/native/shell'

在 CLI 中输入 v8(在新的终端或 shell 中——以重新加载 bash 配置文件)会生成 v8 shell。命令提示符下的 JavaScript! :)

After following the build instructions (Google's V8 Build Docs) for your system;

[v8 directory]$ cd out/native
[v8 directory]$ ./shell (sample shell)
[v8 directory]$ ./d8 (console: dumb)

I created an alias in my .bash_profile to facilitate invocation of the shell.

alias v8='/Volumes/Dev/GitHub/v8/out/native/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! :)

假装不在乎 2024-08-19 03:48:41

如果您使用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.

り繁华旳梦境 2024-08-19 03:48:41

如果您想使用 v8 引擎或其任何版本运行 javascript 源代码,您可以使用 jsvu 命令行工具。它由 Google 工程师开发和维护,此外,它还提供安装除 v8 之外的其他 javascript 引擎的功能,例如 spidermonkeychakracore >、javascriptcorexs

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.

药祭#氼 2024-08-19 03:48:41

如果您打算嵌入 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.

生寂 2024-08-19 03:48:41

如果您使用的是 Windows:

  1. 安装 MSYS2
  2. 从开始菜单打开 MSYS2 终端。
  3. 安装编译器:pacman -Syu mingw-w64-i686-toolchain
  4. 安装 v8:mingw-w64-i686-v8
  5. 验证您是否有 d8作为您道路上的新翻译。
  6. 如果你想在 MSYS2 之外运行 d8,你必须将 msys2/mingw/bin 添加到 Windows 路径
测试它
  1. 导航到 c:\msys2\home\user\
  2. 创建一个 test.js 文件
console.log('Hello You!');
console.log('Would you tell me your name?');
const name = readline();
console.log('Hello '+name+' !!');
  1. 运行: d8 test.js

您还可以从 此处并使用pezip解压缩。

祝你好运 !!

If you are on Windows:

  1. Install MSYS2
  2. Open MSYS2 terminal from start menu.
  3. Install your compiler: pacman -Syu mingw-w64-i686-toolchain
  4. Install v8: mingw-w64-i686-v8
  5. Verify that you have d8 as a new interpreter in your path.
  6. If you want to run d8 outside MSYS2, you have to add msys2/mingw/bin to the windows path
Test it
  1. Navigate to c:\msys2\home\user\
  2. Create a test.js file
console.log('Hello You!');
console.log('Would you tell me your name?');
const name = readline();
console.log('Hello '+name+' !!');
  1. Run: d8 test.js

You can also download binaries from here and unzip with peazip.

Good luck !!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文