PageRenderTime 33ms CodeModel.GetById 12ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 1ms

/c_src/erlv8_list.cc

http://github.com/beamjs/erlv8
C++ | 32 lines | 27 code | 5 blank | 0 comment | 3 complexity | 223c9f76629fc57ce25ee1675dfa9535 MD5 | raw file
 1#include "erlv8.hh"
 2
 3TickHandler(ListTickHandler) {
 4  ErlNifEnv *ref_env = enif_alloc_env();
 5  ERL_NIF_TERM list_ref = enif_make_copy(ref_env, tick_ref);
 6  
 7  val_res_t *res;
 8  if (enif_get_resource(vm->env,array[1],val_resource,(void **)(&res))) {
 9    LHCS(vm->isolate, res->ctx);
10    
11    if (res->val->IsArray()) {
12      v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(res->val->ToObject());
13      
14      ERL_NIF_TERM *arr = (ERL_NIF_TERM *) malloc(sizeof(ERL_NIF_TERM) * array->Length());
15      for (unsigned int i=0;i<array->Length();i++) {
16	arr[i] = js_to_term(res->ctx, vm->isolate, vm->env, array->Get(v8::Integer::NewFromUnsigned(i)));
17      }
18      ERL_NIF_TERM list = enif_make_list_from_array(vm->env, arr, array->Length());
19      free(arr);
20      SEND(vm->server,
21	   enif_make_tuple3(env,
22			    enif_make_atom(env, "result"),
23			    enif_make_copy(env, list_ref),
24			    enif_make_copy(env, list)));
25    }
26  }
27  
28  enif_free_env(ref_env);
29  TickHandlerResolution result;
30  result.type = DONE;
31  return result;
32}