Skip to content
Browse files

Add the builtins.js

  • Loading branch information...
1 parent 7ba1ea8 commit 5def1396080b6dee25722418ff1d317f6bc4a12c @mitchellh committed Apr 26, 2012
Showing with 19 additions and 0 deletions.
  1. +6 −0 apps/lifeguard/priv/builtins.js
  2. +13 −0 apps/lifeguard/src/lifeguard_js_vm.erl
View
6 apps/lifeguard/priv/builtins.js
@@ -0,0 +1,6 @@
+(function() {
+ // This is the main lifeguard API that checks call into in order
+ // to call back into Erlang.
+ var Lifeguard = this.Lifeguard = {
+ };
+}).call(this);
View
13 apps/lifeguard/src/lifeguard_js_vm.erl
@@ -26,6 +26,7 @@ init([Number]) ->
% Create a new V8 VM
{ok, VM} = erlv8_vm:start(),
+ init_vm_globals(VM),
State = #vm_state{
id = Number,
@@ -47,3 +48,15 @@ terminate(_Reason, State) ->
erlv8_vm:stop(State#vm_state.vm).
code_change(_OldVsn, State, _Extra) -> {ok, State}.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Internal functions
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+init_vm_globals(VM) ->
+ % Load our builtins
+ Path = filename:join(code:priv_dir(lifeguard), "builtins.js"),
+ {ok, JSData} = file:read_file(Path),
+
+ % Add the builtins to this VM runtime
+ {ok, _} = erlv8_vm:run(VM, binary_to_list(JSData)).

0 comments on commit 5def139

Please sign in to comment.
Something went wrong with that request. Please try again.