Running V8 Javascript Engine Standalone

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


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
    > 

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 

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

Running the console:

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

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

Many more features are documented in the help:

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

Tags:

Javascript

V8