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

/c_src/erlv8_get.cc

http://github.com/beamjs/erlv8
C++ | 91 lines | 79 code | 12 blank | 0 comment | 9 complexity | 673c19d8c9959b15029ec5651ebb9e98 MD5 | raw file
 1#include "erlv8.hh"
 2
 3TickHandler(GetTickHandler) {
 4  val_res_t *obj_res;
 5  if (enif_get_resource(vm->env,array[1],val_resource,(void **)(&obj_res))) {
 6    LHCS(vm->isolate, obj_res->ctx);
 7    v8::Local<v8::Value> get_result = obj_res->val->ToObject()->Get(term_to_js(obj_res->ctx,vm->isolate, vm->env,array[2]));
 8    
 9    SEND(vm->server,
10	 enif_make_tuple3(env,
11			  enif_make_atom(env,"result"),
12			  enif_make_copy(env,tick_ref),
13			  js_to_term(obj_res->ctx, vm->isolate, env,get_result)));
14  }
15  TickHandlerResolution result;
16  result.type = DONE;
17  return result;
18}
19
20TickHandler(GetProtoTickHandler) {
21  val_res_t *obj_res;
22  if (enif_get_resource(vm->env,array[1],val_resource,(void **)(&obj_res))) {
23    LHCS(vm->isolate, obj_res->ctx);
24    v8::Local<v8::Value> get_result = obj_res->val->ToObject()->GetPrototype();
25    
26    SEND(vm->server,
27	 enif_make_tuple3(env,
28			  enif_make_atom(env,"result"),
29			  enif_make_copy(env,tick_ref),
30			  js_to_term(obj_res->ctx, vm->isolate, env,get_result)));
31  }
32  TickHandlerResolution result;
33  result.type = DONE;
34  return result;
35}
36
37TickHandler(GetHiddenTickHandler) {
38  val_res_t *obj_res;
39  if (enif_get_resource(vm->env,array[1],val_resource,(void **)(&obj_res))) {
40    LHCS(vm->isolate, obj_res->ctx);
41    v8::Local<v8::Value> get_result = obj_res->val->ToObject()->GetHiddenValue(term_to_js(obj_res->ctx,vm->isolate,vm->env,array[2])->ToString());
42    
43    SEND(vm->server,
44	 enif_make_tuple3(env,
45			  enif_make_atom(env,"result"),
46			  enif_make_copy(env,tick_ref),
47			  js_to_term(obj_res->ctx, vm->isolate, env,get_result)));
48  }
49  TickHandlerResolution result;
50  result.type = DONE;
51  return result;
52}
53
54TickHandler(GetInternalTickHandler) {
55  val_res_t *obj_res;
56  if (enif_get_resource(vm->env,array[1],val_resource,(void **)(&obj_res))) {
57    LHCS(vm->isolate, obj_res->ctx);
58	
59    int index;
60    enif_get_int(vm->env, array[2], &index);
61    
62    if (index < 0 || (index + 1 > obj_res->val->ToObject()->InternalFieldCount())) {
63      SEND(vm->server,
64	   enif_make_tuple3(env,
65			    enif_make_atom(env,"result"),
66			    enif_make_copy(env,tick_ref),
67			    enif_make_atom(env,"error")));
68    } else {
69      
70      v8::Local<v8::Value> get_result = obj_res->val->ToObject()->GetInternalField(index);
71      
72      if (get_result->IsExternal()) {
73	SEND(vm->server,
74	     enif_make_tuple3(env,
75			      enif_make_atom(env,"result"),
76			      enif_make_copy(env,tick_ref),
77			      external_to_term(get_result)));
78      } else {
79	SEND(vm->server,
80	     enif_make_tuple3(env,
81			      enif_make_atom(env,"result"),
82			      enif_make_copy(env,tick_ref),
83			      js_to_term(obj_res->ctx, vm->isolate, env,get_result)));
84      }
85      
86    }
87  }
88  TickHandlerResolution result;
89  result.type = DONE;
90  return result;
91}