Thursday, January 27, 2011

Trying out Google V8

Jeena pointed out today that Google V8 may be a good alternative to SpiderMonkey, and it indeed seems so. In short, here is how we can implement callbacks in JS->Erl using erlv8
-module(v8test).
-export([run/0]).
-include_lib("erlv8/include/erlv8.hrl").
run() ->
application:start(erlv8),
{ok, VM} = erlv8_vm:start(),
Global = erlv8_vm:global(VM),
Global:set_value("callback", erlv8_object:new([{"exec", fun (#erlv8_fun_invocation{}, []) -> myCallback() end}])),
erlv8_vm:run(VM,"callback.exec();").
myCallback() ->
io:format("Hello from myCallback!~n", []),
ok.
view raw v8test.erl hosted with ❤ by GitHub
I have forked the repo Jeena hosts on GitHub to one I host, while playing with V8.

Time Report
Jan 26, we had a meeting between 13-15, so 2 hours
I worked with V8 between 00.30-02.00, so 1.5 hours
In total: 3.5 hours.

5 comments:

  1. Yeah, I had major headaches today while I tried to implement exposing our host object to JavaCcript in a good and convinient way.

    ttepasse added a link to a example where sone guy uses proxy-inception in Firefox 4 beta (spidermonkey) the way I would like our API to work, it is not implemented in V8 that way (yet).

    ReplyDelete
  2. I read some of ttpasse's second article as well.. Isn't this what we want for V8?

    ReplyDelete
  3. Oh.. Seems like that was for node.js..

    ReplyDelete
  4. @john, I didn't encounter any note saying it wouldn't, but I didn't try either. We switched over to erlang_js which uses SpiderMonkey instead and this project explicitly states that erlang_js does not run on windows.

    ReplyDelete