Run Javascript code on Google's V8 via Python
C++ JavaScript C Python
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


What is it?
This is a small module that runs Javascript code go Google's V8 engine.
The module takes any valid Javascript string, compiles it, runs and returns the result of 
the of the command as a (Python) string object. Think of this as eval() in Python.
This is released under the BSD license.

To build this, you will need to build v8, of course. You will also need to add 
the path to the library to your LD_LIBRARY_PATH. You will also need to install Cython. I am
sure this can also run on Pyrex, but I have not formally tried it yet.

Building it
$ python build_ext --inplace
$ mv v8-src/ .

This should build and let you import the module.

After building it, import it.

>>> import v8onpython
>>> v = v8onpython.Script()
>>> js_code = "for (i=0;i<100000000;i++){\n j=i+1\n}"
>>> v.compile(js_code)
>>> v.compile("'Hello' + ', World!'")
'Hello, World!'
>>> v.compile("1.32w")
>>> 'SyntaxError: Unexpected token ILLEGAL'

That's all! 

What would be cool
* Code contributions

* Performance numbers of CPython vs JS on V8.

* expand this and make Python and JS talk faster using native strings, integers
  objects, etc