Skip to content

Commit

Permalink
Fixed arg len bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustaf Sjöberg committed Aug 19, 2015
1 parent 91c360b commit cff3f13
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
7 changes: 5 additions & 2 deletions c_src/erlang_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,16 @@ void call(Isolate* isolate, string input) {
int len = args->Length();
Handle<Value> argz[len];

for (uint32_t i = 0; i < len; i++) {

// debug(static_cast<ostringstream*>( &(ostringstream() << len) )->str());
for (int i = 0; i < len; i++) {
argz[i] = args->Get(i);
}

Handle<Function> function = Handle<Function>::Cast(global->Get(function_name));

Handle<Value> result = function->Call(global, 2, argz);
Handle<Value> result;
result = function->Call(global, len, argz);

if (result.IsEmpty()) {
Handle<Value> exception = trycatch.Exception();
Expand Down
19 changes: 0 additions & 19 deletions src/erlang_v8_vm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -221,22 +221,3 @@ parse_opt({file, F}, #state{initial_source = InitialSource} = State) ->

%% @doc Ignore unknown options.
parse_opt(_, State) -> State.

%% valid_utf8(B) ->
%% case unicode:characters_to_list(B) of
%% {_Type, Data, _Rest} -> Data;
%% _ -> B
%% end.
%%
%% escape_args(Args) ->
%% lists:map(fun(Arg) when is_binary(Arg) -> escape_binary(valid_utf8(Arg));
%% (Arg) -> Arg
%% end, Args).
%%
%% escape_binary(B) ->
%% escape_binary(B, [{<<"\n">>, <<"\\n">>}, {<<"\r">>, <<"\\r">>},
%% {<<"\b">>, <<"\\b">>}, {<<"\t">>, <<"\\t">>}]).
%% escape_binary(B, []) ->
%% B;
%% escape_binary(B, [{X, Y}|T]) ->
%% escape_binary(binary:replace(B, X, Y, [global]), T).
10 changes: 10 additions & 0 deletions test/port_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,22 @@ call(_Config) ->
{ok, 4} = erlang_v8:call(P, <<"sum">>, [2, 2]),
{ok, <<"helloworld">>} =
erlang_v8:call(P, <<"sum">>, [<<"hello">>, <<"world">>]),

%% a few arguments
{ok, undefined} =
erlang_v8:eval(P, <<"function mul(a, b, c, d) { return a * b * c * d }">>),
{ok, 1} = erlang_v8:call(P, <<"mul">>, [1, 1, 1, 1]),

%% object arguments
{ok, undefined} =
erlang_v8:eval(P, <<"function get(o) { return o.a; }">>),
{ok, undefined} = erlang_v8:call(P, <<"get">>, [2, 2]),
{ok, 1} = erlang_v8:call(P, <<"get">>, [[{a, 1}]]),

%% object fun
%% {ok, undefined} =
%% erlang_v8:eval(P, <<"var x = { y: function z() { return 1; } }">>),
%% {ok, 1} = erlang_v8:call(P, <<"x.y">>, []),

erlang_v8:stop_vm(P),
ok.
Expand Down

0 comments on commit cff3f13

Please sign in to comment.