Coder Social home page Coder Social logo

erlang_js's Introduction

erlang_js

Overview

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 Mozilla Developer Center.

Quick Start

You must have Erlang/OTP R13B04 or later and a GNU-style build system to compile and run erlang_js.

git clone git://github.com/basho/erlang_js.git
make all test

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

erl -pa path/to/erlang_js/ebin -boot start_sasl

Start the erlang_js application and create a Javascript VM.

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().

Now you can evaluate Javascript expressions and call Javascript functions.

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

Documentation

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

$ make docs
$ open docs/index.html

Contributing

We encourage contributions to erlang_js from the community.

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

erlang_js's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

erlang_js's Issues

The future of erlang_js

We're working on figuring out the best future for the erlang_js project. If I've tagged you, it's because you've either made a contribution or expressed an interest in the project somewhere on GitHub. (Apologies if I've missed anyone, these are just the names that I've seen from scrolling through open pull requests.)

@marianoguerra @lemenkov @tisba @zackehh @sebastian @superstructor

So first off, thanks for all the contributions and for your interest in the project! I'm very sorry that we haven't been more responsive: there are multiple pull requests that have been sitting untouched for a long time, and that's a shame. Basho has not been so great about working with the OSS community lately, but we're working hard to rectify the situation.

That said, the erlang_js project is especially tricky, because Basho has no real reasons for updating it anymore. The only thing it's used for in Riak is for submitting JS MapReduce functions, but that functionality has been deprecated for years (since the Riak 2.0 release). We've been using the same 1.3.0 tag of erlang_js for numerous releases in a row, and eventually we may just remove erlang_js from Riak altogether.

Since there is clearly interest from the outside community, I don't want to just let this project rot, but we also don't necessarily have the resources to maintain it and deal with outside contributions. For example, updating the javascript engine would be great, but it would require a lot of testing to put that into a new release of Riak, and it's very hard to justify doing that work for a little-used, deprecated feature.

So, would any of you potentially be interested in taking over as a maintainer? In the past, we've successfully spun out popular Erlang OSS projects into their own external organizations (webmachine being perhaps the best example of this). If any of you who are using this project would like to see it continue to grow and evolve, I think this may be our best bet for allowing that to happen.

Thanks again, and let me know what you all think! I'm very open to any suggestions anyone might have on this matter, so feel free to speak your minds :)

erlang_js doesn't build on darwin11

My machine reports this:

Darwin dhcp-218.dyn81-121.trifork.com 11.4.0 
Darwin Kernel Version 11.4.0: Mon Apr  9 19:32:15 PDT 2012; 
root:xnu 1699.26.8~1/RELEASE_X86_64 x86_64

During configure, I get

checking host system type... i386-apple-darwin11.4.0

Which is not a platform being matched in current rebar.config

Compiling fails with some header file isses.

I tried to upgrade to nspr-4.9.1 (erlang_js is currently using 4.8), and it seems to compile just fine.

js:call() not behaving as expected

Hi,
I was playing aroung with erlang_js and encountered the following behavior:
I want to run the following js function with a string as the argument:

function(x)
{
    return x.split(" ");
}

there are three ways I can think of doing this and two work, whereas the third does not.

{ok, JS} = js_driver:new().
js:eval(JS, <<"function(x) {return x.split(\" \")}(\"foo bar\")">>).

and

{ok, JS} = js_driver:new().
js:define(JS, <<"var doSplit = function(x) {return x.split(\" \")}">>).
js:call(JS, <<"doSplit">>, [<<"foo bar">>]).

both return the expected {ok, [<<"foo">>, <<"bar">>]}

when I try to do call an anonymous function I get an error:

{ok, JS} = js_driver:new().
js:call(JS, <<"function(x) {return x.split(\" \")}">>, [<<"foo bar">>]).
{error,[{<<"lineno">>,1},
        {<<"message">>,
         <<"SyntaxError: missing ) in parenthetical">>},
        {<<"source">>,
         <<"JSON.stringify(function() { if (function(x) {return x.split(\" \");} === undefined) { thro"...>>}]}

something is going wrong with the space character in split(). If I pass it in as an argument it works fine again:

{ok, JS} = js_driver:new().
js:call(JS, <<"function(x, s) {return x.split(s)}">>, [<<"foo bar">>, <<" ">>]).

In OTP19: Error loading "erlang_js_drv": "undefined symbol: erl_exit"

Is this project still can be use now?

os:

[root@db-01 erlang_js]# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)

erl:

[root@db-01 erlang_js]# erl
Erlang/OTP 19 [erts-8.3.3] [source] [64-bit] [smp:32:32] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V8.3.3 (abort with ^G)
1>

I run:

git clone git://github.com/basho/erlang_js.git
make all test

It result:

=PROGRESS REPORT==== 17-Sep-2018::10:16:50 ===
application: sasl
started_at: nonode@nohost

=ERROR REPORT==== 17-Sep-2018::10:16:50 ===
Error loading "erlang_js_drv": "undefined symbol: erl_exit"

=CRASH REPORT==== 17-Sep-2018::10:16:50 ===
crasher:
initial call: supervisor:erlang_js_sup/1
pid: <0.298.0>
registered_name: erlang_js_sup
exception exit: {bad_return_value,
{error,
{load_error,"Failed to load erlang_js_drv.so"}}}
in function gen_server:init_it/6 (gen_server.erl, line 356)
ancestors: [<0.297.0>]
messages: []
links: [<0.297.0>]
dictionary: []
trap_exit: true
status: running
heap_size: 376
stack_size: 27
reductions: 145
neighbours:

=CRASH REPORT==== 17-Sep-2018::10:16:50 ===
crasher:
initial call: application_master:init/4
pid: <0.296.0>
registered_name: []
exception exit: {{bad_return_value,
{error,
{load_error,"Failed to load erlang_js_drv.so"}}},
{erlang_js,start,[normal,[]]}}
in function application_master:init/4 (application_master.erl, line 134)
ancestors: [<0.295.0>]
messages: [{'EXIT',<0.297.0>,normal}]
links: [<0.295.0>,<0.31.0>]
dictionary: []
trap_exit: true
status: running
heap_size: 376
stack_size: 27
reductions: 129
neighbours:

make fails with undecipherable error on OS X 10.9.3

I'm not very familiar with Erlang & rebar, but I'd like to play around with erlang_js. I'm trying to compile master (07467d8) and 1.3.0 but I'm getting the same error[0]. I have no idea where to start debugging this and I'd appreciate any hints.

I'm on OS X 10.9.3, using (via homebrew) Erlang 17.0 and I think I have a "GNU-style build system" (whatever that exactly means).

With Ubuntu 12.04 and R16B03-1, make test succeeds and I can run the example described in the README.

[0]

$ make test
./rebar get-deps
Uncaught error in rebar_core: {'EXIT',
                               {badarg,
                                [{re,replace,
                                  [[36,40,114,118,109,95,112,114,111,109,112,
                                    116,41,37,123,37,40,63,46,37,123,37,98,37,
                                    115,37,117,27,91,48,48,109,37,125,46,37,
                                    83,41,37,125,37,123,27,91,51,50,109,37,
                                    125,36,40,103,101,116,95,103,105,116,95,
                                    112,114,111,109,112,116,95,105,110,102,
                                    111,32,37,98,41,37,123,27,91,51,49,109,37,
                                    125,36,40,103,101,116,95,103,105,116,95,
                                    112,114,111,109,112,116,95,105,110,102,
                                    111,32,37,115,41,37,123,37,40,63,46,37,
                                    123,37,98,37,115,37,117,27,91,48,48,109,
                                    37,125,46,37,83,41,37,125,37,123,27,91,51,
                                    55,109,37,125,37,66,37,49,126,37,98,37,
                                    123,37,98,37,115,37,117,27,91,48,48,109,
                                    37,125,32,37,123,37,83,36,102,103,91,36,
                                    90,76,69,95,67,79,76,79,82,93,37,125,37,
                                    123,37,98,37,115,37,117,27,91,48,48,109,
                                    37,125,37,123,27,91,51,52,109,37,125,
                                    10140,37,123,37,98,37,115,37,117,27,91,48,
                                    48,109,37,125,32],
                                   [92,36,40,"PROMPT",40,92,115,124,36,41,124,
                                    123,"PROMPT",125,41],
                                   [[],"\\2"],
                                   [global,{return,list}]],
                                  [{file,"re.erl"},{line,355}]},
                                 {rebar_port_compiler,merge_each_var,2,[]},
                                 {rebar_port_compiler,setup_env,2,[]},
                                 {rebar_core,'-setup_envs/2-fun-0-',2,[]},
                                 {lists,foldl,3,
                                  [{file,"lists.erl"},{line,1261}]},
                                 {rebar_core,process_dir1,6,[]},
                                 {rebar_core,process_commands,2,[]},
                                 {rebar,main,1,[]}]}}
make: *** [deps] Error 1

Memory leak?

Maybe I'm doing something wrong, but if I continuously create and destroy JavaScript VM instances the process memory increases all the time:

runjs() ->
  {ok, Js} = js_driver:new(),
  js_driver:destroy(Js),
  runjs().

Any thoughts? Should I do this in some other way?

OTP 18 support

Compiling src/js_benchmark.erl failed:
src/js_benchmark.erl:41: erlang:now/0: Deprecated BIF. See the "Time and Time Correction in Erlang" chapter of the ERTS User's Guide for more information.
src/js_benchmark.erl:43: erlang:now/0: Deprecated BIF. See the "Time and Time Correction in Erlang" chapter of the ERTS User's Guide for more information.
ERROR: compile failed while processing /project_path/erlang_js: rebar_abort
** (Mix) Could not compile dependency :erlang_js, "$HOME/.mix/rebar" command failed. You can recompile this dependency with "mix deps.compile erlang_js", update it with "mix deps.update erlang_js" or clean it with "mix deps.clean erlang_js"

Xcode 4.4 and Mountain Lion

erlang_js will not build on Xcode 4.4 with Mountain Lion.

Couple things I'm noticing with nsprpub:

  • The header files are no longer in the location assumed by the Makefile, even after symlinking /Developer to /Applications/Xcode.app/Contents/Developer.
  • The header files appear only present in the MacOSX10.7.sdk (/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/Developer/Headers/FlatCarbon) and are not present in the MacOSX10.8.sdk at all. I'm assuming the 10.7.sdk is only present if you've specifically installed it through the developer portal or have upgraded Lion (with Xcode) to Mountain Lion.

Unable to compile Erlang_js against the latest version of Erlang

I am getting this error when I attempt to compile erlang_js - I need it's support in an Elixir library called "coffee_rotor"... I have added the issue I raised on that project below..

Here is the compile error I am getting - it relates to time issues not working when compiling erlang_js against the latest version of Erlang. Any chance this can be fixed in Erlang 18..? THANKS :)

Compiled src/erlang_js.erl Compiled src/js.erl src/js_benchmark.erl:41: erlang:now/0: Deprecated BIF. See the "Time and Time Correction in Erlang" chapter of the ERTS User's Guide for more information. src/js_benchmark.erl:43: erlang:now/0: Deprecated BIF. See the "Time and Time Correction in Erlang" chapter of the ERTS User's Guide for more information. ERROR: compile failed while processing /Users/steveforkin/Work/elixir-workbench/erlang_js: rebar_abort make: *** [compile] Error 1

HashNuke/coffee_rotor#2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.