Kevin Smith  committed 2b95d2b

Syncing up w/public erlang_js version

  • Participants
  • Parent commits 8ec7810

Comments (0)

Files changed (3)

File apps/erlang_js/c_src/spidermonkey.c

   JS_InitStandardClasses(vm->context, vm->global);
   JS_SetErrorReporter(vm->context, on_error);
   JSNative *funptr = (JSNative *) *js_log;
-  JS_DefineFunction(vm->context, JS_GetGlobalObject(vm->context), "ejsLog", (JSNative *) funptr,
+  JS_DefineFunction(vm->context, JS_GetGlobalObject(vm->context), "ejsLog", funptr,
   return vm;

File apps/erlang_js/overview.edoc

 js:call(Port, <<"constant_mult">>, [5], [{<<"my_constant">>, 200}]).
 {ok, 1000}
+<h4>Using ejsLog to debug</h4>
+JS = &lt;&lt;"function my_add(x, y) { ejsLog(\"/tmp/foo.txt\", \"Hello, world!\"); return x + y; }"&gt;&gt;.
+ok = js:define(Port, JS).
+%% Logging output is automatically timestamped and written to /tmp/foo.txt
+%% when the function runs
+{ok, 84} = js:call(Port, &lt;&lt;"my_add"&gt;&gt;, [42, 42]).

File apps/erlang_js/src/js_driver.erl

 -export([load_driver/0, new/0, new/1, destroy/1, shutdown/1]).
--export([define_js/2, define_js/3, eval_js/2, eval_js/3]).
+-export([define_js/2, define_js/3, define_js/4, eval_js/2, eval_js/3]).
 -define(SCRIPT_TIMEOUT, 5000).
 -define(DRIVER_NAME, "spidermonkey_drv").
 define_js(Ctx, Js, Timeout) when is_binary(Js) ->
     define_js(Ctx, <<"unnamed">>, Js, Timeout).
+%% @spec define_js(port(), binary(), binary(), integer()) -> {ok, binary()} | {error, any()}
+%% @doc Define a Javascript expression:
+%% js_driver:define(Port, &lt;&lt;var blah = new Wubba();"&gt;&gt;).
+%% Note: Filename is used only as a label for error reporting.
 define_js(Ctx, FileName, Js, Timeout) when is_binary(FileName),
                                            is_binary(Js) ->
     case call_driver(Ctx, "dj", [FileName, Js], Timeout) of