Travis-CI ::
erlang-mozjs
is a NIF library, and API that embeds Mozilla’s Spidermonkey
Javascript Virtual Machine in Erlang. Originally created to facilitate usage
of Riak’s MapReduce by non-Erlang programmers, it supports multiple
concurrent Javascript VMs, runtime evaluation of Javascript code, and
invocation of Javascript functions.
erlang-mozjs
builds and executes only on Unix-based platforms, including
Linux, Mac OS/X, and Solaris. It requires Spidermonkey 52 and includes Douglas
Crockford’s json2.js JSON parser. More information about the features
available to Javascript inside erlang-mozjs
are detailed on the
Mozilla Developer Center.
You must have Erlang/OTP 18 or later and a GNU-style make
system to compile and run erlang-mozjs
.
git clone git://github.com/erlang-mozjs/erlang-mozjs.git
make all test
Start up an Erlang shell with the path to erlang-mozjs
included.
erl -pa path/to/erlang-mozjs/ebin -boot start_sasl
Create a Javascript VM.
1> {ok, JS} = js_driver:new().
{ok,#Ref<0.557298074.1409679362.105432>}
Now you can evaluate Javascript expressions and call Javascript functions.
2> js:define(JS, <<"var addOne = function(a){ return a + 1; }">>).
ok
3> js:call(JS, <<"addOne">>, [3]).
{ok,4}
Release JS resource when no longer needed.
4> js_driver:destroy(JS).
ok
Documentation about the API is extensive and can be generated by
edoc
.
$ make docs
$ open docs/index.html
We encourage contributions to erlang-mozjs
from the community.
- Fork the
erlang-mozjs
repository on Github. - Clone your fork or add the remote if you already have a clone of the repository.
git clone [email protected]:yourusername/erlang-mozjs.git
# or
git remote add mine [email protected]:yourusername/erlang-mozjs.git
- Create a topic branch for your change.
git checkout -b some-topic-branch
- Make your change and commit. Use a clear and descriptive commit message, spanning multiple lines if detailed explanation is needed.
- Push to your fork of the repository and then send a pull-request through Github.
git push mine some-topic-branch
- A community maintainer will review your patch and merge it into the main repository or send you feedback.