运行V8 Javascript Engine Standalone [英] Running V8 Javascript Engine Standalone

查看:169
本文介绍了运行V8 Javascript Engine Standalone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

V8很容易构建,并没有附带Mozilla独立Javascript解释器的Java VM开销。幸运的是,V8附带了用于构建控制台的代码。以下是如何建立这个:

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:


$> svn co http://v8.googlecode.com/svn/trunk v8-trunk
...
$> cd v8-trunk
$> scons
$> g++ ./samples/shell.cc -o v8-shell -I include libv8.a 

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

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

运行控制台:


$> ./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:

Executing Javascript from the command line:


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

帮助中记录了更多功能:

Many more features are documented in the help:


$> ./v8-shell --help
Usage:
...

这篇关于运行V8 Javascript Engine Standalone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆