chenb•log

I don’t mind if I’m incomprehensible

Posts Tagged ‘google v8

Installing and Using Google V8’s sample shell

leave a comment »

The sample shell that comes with Google’s V8 javascript engine is pretty nice for playing with naked, DOM-free javascript.  Here are some notes to augment Google’s download and build documentation.

If you are building on a Mac, download and install Xcode with the the Unix development tools option selected.  This will take care of the compiler and libraries required for the build.

I symlinked the shell to /usr/local/bin/v8 for easy access.  v8 below refers to that, not the project name or the project source directory.

Naturally, typing in v8 starts the interactive shell. v8 --shell does the same thing.

v8 -e followed by a string of javascript allows you to execute that piece of code.

v8 followed by one or more file paths tells the shell to load and run the javascript files in the given order. Now if you add the aforementioned --shell, the sample shell will load and execute the file(s) and then starts the interactive shell.

You could also load files while in the shell by calling the load function. For example, load('hello-world.js'); will load and execute the file hello-world.js from the current working directory. Since the sample shell provides the load function, you could also use it in your javascript code. So instead of typing in v8 followed by over 9000 file paths, you could specify a file that in turn loads the other necessary files.

Another function the sample shell provides is print. That one’s self-explanatory.

There is also a read function, which reads a file into a javascript string.

If you know of a more advanced V8 shell, please leave a comment.

Written by Barry

April 3, 2010 at 8:12 pm

Posted in Nerdy

Tagged with , ,