Fork me on GitHub

browserl by svahne

An Erlang Emulator written in javascript


How to set up and start

1. Clone or download source code to a local directory:

git clone git://github.com/svahne/browserl
cd browserl
2. Start a web server of your choice

For instance, with inets you would start Erlang in the browserl base directory and then at the Erlang shell prompt do:

inets:start(), inets:start(httpd, [{port, 3333}, {server_name,""},
{server_root,"."},  {document_root,"."}]).
You would typically want to be behind a firewall if you do this.

3. Open 127.0.0.1:3333/index.html in your browser.

Optionally:

4. Add your own beam files.

You can either add your files to beams/beamfiles.tar, e.g:

tar --append --file beams/beamfiles.tar myfile.beam
or you could add them to the list of arguments given to the run() function (in this example the run() function is called from index.html).
run(mod, fun, args, ['start.boot', 'beamfiles.tar', 'mybeam']); 

run() takes as its' arguments the initial module, function and arguments and a list of beamfiles (without the .beam extension!) or tarballs containing beamfiles. The initial module, function and arguments can point directly to your own module which might typically be what you want for simple programs with limited dependencies towards the Erlang/OTP libraries. If you point to your own initial function you should be prepared for that e.g. io:format() will not work since it requires some basic io servers to be started which is normally done during the boot. BIF calls like js:eval/1, js:call/3, etc will always work.

Dependencies

Known to boot in: Chrome 3-8, 11-16 (fastest, loads to shell prompt in less than a second when hosted on same network), Firefox 3.0, 3.5, 3.6, 4, 5, 6, 7, 8, Internet Explorer 8, 9, Safari 4.0, 5.0.5, 5.1, Opera 11, 11.5, 11.6, Epiphany 3.2, Konqueror 4.7, iPhone 4, HTC Wildfire running Android 2.2. Currently, the Erlang/OTP system will boot, but the terminal javascript will not accept user input in IE and the mobile browsers.

Only limited support for binaries and ets tables have been added so far. Floats will not always work, especially not the presentation in the shell due to a dependency on binaries. In the example above math.beam is missing so no floats.

Only the most commonly used bifs have been implemented, and arguments are not always checked. Files and networking is not supported or expected to work, although some initial hacks have been made in order to get the test server running.

Is able to start Common test and the test server, and passes the standard OTP tests suites for lists, arrays, dicts, random numbers and queues.

Accessing javascript objects and the DOM

The following functions are likely to change, and only shown here as a proof of concept.

js:eval(String) -> true

String = string()

Example:

js:eval("document.getElementById('first').innerHTML = 'some text'").

js:call(JsObject, Function, Arguments) -> js_object()
js:get(JsObject, Property) -> js_object()
js:set(JsObject, Property, Value) -> true

JsObject = window | document | js_object()
Function = atom()
Property = atom()
Arguments = [ atom() ]
Value = atom() | string() | js_object()

Examples:

Doc = js:get(window, document). 
MyElem = js:call(Doc, getElementById, [first]).
MyElem = js:call(document, getElementById, [first]).
OldContents = js:get(MyElem, innerHTML).
js:set(MyElem, innerHTML, "some text").
js:set(MyElem, innerHTML, OldContents).

License

Dual licensed under the MIT and GPL v3 licenses.

Authors

Fredrik Svahn (fredrik.svahn@gmail.com)

Contact

Fredrik Svahn (fredrik.svahn@gmail.com)

Download

You can download this project in either zip or tar formats.

You can also clone the project with Git by running:

$ git clone git://github.com/svahne/browserl