basho/erlang_js

A linked-in driver for Erlang to Mozilla's Spidermonkey Javascript runtime.

Erlang

237

88 commits

updated Nov 18, 2021

See the code

README

* erlang_js
** Overview

   [[http://travis-ci.org/basho/erlang_js][Travis-CI]] :: [[https://secure.travis-ci.org/basho/erlang_js.png]]

   =erlang_js= is a linked-in driver, API, and OTP application 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_js= builds and executes only on Unix-based platforms,
   including Linux, Mac OS/X, and Solaris. It includes version 1.8.0
   of Spidermonkey and Douglas Crockford's =json2.js= JSON
   parser. More information about the features available to Javascript
   inside =erlang_js= are detailed on the [[https://developer.mozilla.org/en/JavaScript/Reference][Mozilla Developer Center]].

** Quick Start
   You must have [[http://erlang.org/download.html][Erlang/OTP R13B04]] or later and a GNU-style build
   system to compile and run =erlang_js=.

#+BEGIN_SRC shell
git clone git://github.com/basho/erlang_js.git
make all test
#+END_SRC

   Start up an Erlang shell with the path to =erlang_js= included.

#+BEGIN_SRC shell
erl -pa path/to/erlang_js/ebin -boot start_sasl
#+END_SRC

   Start the =erlang_js= application and create a Javascript VM.
#+BEGIN_SRC erlang
1> application:start(erlang_js).

=PROGRESS REPORT==== 17-Feb-2011::11:31:51 ===
          supervisor: {local,erlang_js_sup}
             started: [{pid,<0.46.0>},
                       {name,cache},
                       {mfargs,{js_cache,start_link,[]}},
                       {restart_type,permanent},
                       {shutdown,2000},
                       {child_type,worker}]

=PROGRESS REPORT==== 17-Feb-2011::11:31:51 ===
         application: erlang_js
          started_at: nonode@nohost
ok
2> {ok, JS} = js_driver:new().
#+END_SRC

   Now you can evaluate Javascript expressions and call Javascript
   functions.

#+BEGIN_SRC erlang
3> js:define(JS, <<"var addOne = function(a){ return a + 1; }">>).
ok
4> js:call(JS, <<"addOne">>, [3]).
{ok,4}
#+END_SRC

** Documentation
   Documentation about the API is extensive and can be generated by
   =edoc=.

#+BEGIN_SRC shell
$ make docs
$ open docs/index.html
#+END_SRC

** Contributing
   We encourage contributions to =erlang_js= from the community.

   1) Fork the =erlang_js= repository on [[https://github.com/basho/erlang_js][Github]].
   2) Clone your fork or add the remote if you already have a clone of
      the repository.
#+BEGIN_SRC shell
git clone git@github.com:yourusername/erlang_js.git
# or
git remote add mine git@github.com:yourusername/erlang_js.git
#+END_SRC
   3) Create a topic branch for your change.
#+BEGIN_SRC shell
git checkout -b some-topic-branch
#+END_SRC
   4) Make your change and commit. Use a clear and descriptive commit
      message, spanning multiple lines if detailed explanation is
      needed.
   5) Push to your fork of the repository and then send a pull-request
      through Github.
#+BEGIN_SRC shell
git push mine some-topic-branch
#+END_SRC
   6) A Basho engineer or community maintainer will review your patch
      and merge it into the main repository or send you feedback.

Not written in Markdown, so it's shown here as plain text — view it formatted on GitHub.

Contributors

jaredmorrow

20 commits

cmeiklejohn

13 commits

dizzyd

12 commits

argv0

9 commits

basho/erlang_js

A linked-in driver for Erlang to Mozilla's Spidermonkey Javascript runtime.

Erlang

237

88 commits

updated Nov 18, 2021

See the code

README

* erlang_js
** Overview

   [[http://travis-ci.org/basho/erlang_js][Travis-CI]] :: [[https://secure.travis-ci.org/basho/erlang_js.png]]

   =erlang_js= is a linked-in driver, API, and OTP application 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_js= builds and executes only on Unix-based platforms,
   including Linux, Mac OS/X, and Solaris. It includes version 1.8.0
   of Spidermonkey and Douglas Crockford's =json2.js= JSON
   parser. More information about the features available to Javascript
   inside =erlang_js= are detailed on the [[https://developer.mozilla.org/en/JavaScript/Reference][Mozilla Developer Center]].

** Quick Start
   You must have [[http://erlang.org/download.html][Erlang/OTP R13B04]] or later and a GNU-style build
   system to compile and run =erlang_js=.

#+BEGIN_SRC shell
git clone git://github.com/basho/erlang_js.git
make all test
#+END_SRC

   Start up an Erlang shell with the path to =erlang_js= included.

#+BEGIN_SRC shell
erl -pa path/to/erlang_js/ebin -boot start_sasl
#+END_SRC

   Start the =erlang_js= application and create a Javascript VM.
#+BEGIN_SRC erlang
1> application:start(erlang_js).

=PROGRESS REPORT==== 17-Feb-2011::11:31:51 ===
          supervisor: {local,erlang_js_sup}
             started: [{pid,<0.46.0>},
                       {name,cache},
                       {mfargs,{js_cache,start_link,[]}},
                       {restart_type,permanent},
                       {shutdown,2000},
                       {child_type,worker}]

=PROGRESS REPORT==== 17-Feb-2011::11:31:51 ===
         application: erlang_js
          started_at: nonode@nohost
ok
2> {ok, JS} = js_driver:new().
#+END_SRC

   Now you can evaluate Javascript expressions and call Javascript
   functions.

#+BEGIN_SRC erlang
3> js:define(JS, <<"var addOne = function(a){ return a + 1; }">>).
ok
4> js:call(JS, <<"addOne">>, [3]).
{ok,4}
#+END_SRC

** Documentation
   Documentation about the API is extensive and can be generated by
   =edoc=.

#+BEGIN_SRC shell
$ make docs
$ open docs/index.html
#+END_SRC

** Contributing
   We encourage contributions to =erlang_js= from the community.

   1) Fork the =erlang_js= repository on [[https://github.com/basho/erlang_js][Github]].
   2) Clone your fork or add the remote if you already have a clone of
      the repository.
#+BEGIN_SRC shell
git clone git@github.com:yourusername/erlang_js.git
# or
git remote add mine git@github.com:yourusername/erlang_js.git
#+END_SRC
   3) Create a topic branch for your change.
#+BEGIN_SRC shell
git checkout -b some-topic-branch
#+END_SRC
   4) Make your change and commit. Use a clear and descriptive commit
      message, spanning multiple lines if detailed explanation is
      needed.
   5) Push to your fork of the repository and then send a pull-request
      through Github.
#+BEGIN_SRC shell
git push mine some-topic-branch
#+END_SRC
   6) A Basho engineer or community maintainer will review your patch
      and merge it into the main repository or send you feedback.

Not written in Markdown, so it's shown here as plain text — view it formatted on GitHub.

Contributors

jaredmorrow

20 commits

cmeiklejohn

13 commits

dizzyd

12 commits

argv0

9 commits

Languages

Erlang

48.1%

Makefile

21.5%

C

17.8%

JavaScript

12.4%