Running V8 Javascript Engine Standalone

JavascriptV8

Javascript Problem Overview


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

Javascript Solutions


Solution 1 - 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:

$> 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("1010 = " + 1010)'
10*10 = 100

Many more features are documented in the help:

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

Solution 2 - Javascript

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

Solution 3 - Javascript

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
    > 

Solution 4 - Javascript

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 dont forget the parentheses!

Solution 5 - Javascript

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)

Solution 6 - 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! :)

Solution 7 - Javascript

If you use ArchLinux, you can use pacman -S v8 to install it. Then use d8 to start it in your shell. Enjoy it.

Solution 8 - Javascript

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.

Solution 9 - Javascript

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionManuelView Question on Stackoverflow
Solution 1 - JavascriptGeorg SchöllyView Answer on Stackoverflow
Solution 2 - JavascriptbukzorView Answer on Stackoverflow
Solution 3 - JavascriptTan LeView Answer on Stackoverflow
Solution 4 - JavascriptMario UherView Answer on Stackoverflow
Solution 5 - JavascriptMartin ThomaView Answer on Stackoverflow
Solution 6 - JavascriptJoe JohnsonView Answer on Stackoverflow
Solution 7 - JavascriptalswlView Answer on Stackoverflow
Solution 8 - JavascriptsgeorgiouView Answer on Stackoverflow
Solution 9 - JavascriptA RView Answer on Stackoverflow