PageRenderTime 29ms CodeModel.GetById 12ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/src/erlv8_fun.erl

http://github.com/beamjs/erlv8
Erlang | 36 lines | 23 code | 13 blank | 0 comment | 0 complexity | be7ffafb5b3bd33b94ccecfd8729706f MD5 | raw file
 1-module(erlv8_fun).
 2
 3-include("erlv8.hrl").
 4
 5-extends(erlv8_object).
 6
 7-export([call/1,call/2,call/3,instantiate/1, instantiate/2, object/1,
 8
 9         new/1, new/2]).
10
11call(Self) ->
12    call([], Self).
13
14call({erlv8_object, _,_}=T, Self) ->
15    call(T,[], Self);
16
17call(Args, #erlv8_fun{resource = Resource, vm = VM}) when is_list(Args) ->
18    erlv8_vm:enqueue_tick(VM, {call, Resource, Args}).
19
20call({erlv8_object, _,_}=This, Args, #erlv8_fun{resource = Resource, vm = VM}) when is_list(Args) ->
21    erlv8_vm:enqueue_tick(VM, {call, Resource, Args, This}).
22
23instantiate(Self) ->
24    instantiate([], Self).
25
26instantiate(Args, #erlv8_fun{resource = Resource, vm = VM}) when is_list(Args) ->
27    erlv8_vm:enqueue_tick(VM, {inst, Resource, Args}).
28
29object(#erlv8_fun{resource = Resource, vm = VM}) ->
30    {erlv8_object, Resource, VM}.
31
32new(O) ->
33    new(O,undefined).
34
35new(O, V) ->
36    #erlv8_fun{resource = O, vm = V}.