PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/c_src/erlv8_equals.cc

http://github.com/beamjs/erlv8
C++ | 57 lines | 49 code | 8 blank | 0 comment | 4 complexity | da80d632e0e98e32e34a33e1f3d8d720 MD5 | raw file
 1#include "erlv8.hh"
 2
 3TickHandler(EqualsTickHandler) {
 4  ErlNifEnv *ref_env = enif_alloc_env();
 5  ERL_NIF_TERM equals_ref = enif_make_copy(ref_env, tick_ref);
 6  val_res_t *res1; 
 7  val_res_t *res2; 
 8  bool bres;
 9
10  if ((enif_get_resource(vm->env,array[1],val_resource,(void **)(&res1))) &&
11	  (enif_get_resource(vm->env,array[2],val_resource,(void **)(&res2)))) {
12	LHCS(vm->isolate, res1->ctx);
13    bres = res1->val->ToObject()->Equals(res2->val->ToObject());
14  } else {
15    LHCS(vm->isolate, vm->context);
16    bres = term_to_js(vm->context, vm->isolate, vm->env,array[1])->Equals(term_to_js(vm->context, vm->isolate, vm->env,array[2]));
17  };
18
19  SEND(vm->server,
20       enif_make_tuple3(env,
21                        enif_make_atom(env,"result"),
22                        enif_make_copy(env,equals_ref),
23                        enif_make_atom(env, bres ? "true" : "false")));
24
25  enif_free_env(ref_env);
26  TickHandlerResolution result;
27  result.type = DONE;
28  return result;
29}
30
31TickHandler(StrictEqualsTickHandler) {
32  ErlNifEnv *ref_env = enif_alloc_env();
33  ERL_NIF_TERM equals_ref = enif_make_copy(ref_env, tick_ref);
34  val_res_t *res1; 
35  val_res_t *res2; 
36  bool bres;
37
38  if ((enif_get_resource(vm->env,array[1],val_resource,(void **)(&res1))) &&
39	  (enif_get_resource(vm->env,array[2],val_resource,(void **)(&res2)))) {
40	LHCS(vm->isolate, res1->ctx);
41    bres = res1->val->ToObject()->StrictEquals(res2->val->ToObject());
42  } else {
43    LHCS(vm->isolate, vm->context);
44    bres = term_to_js(vm->context, vm->isolate, vm->env,array[1])->StrictEquals(term_to_js(vm->context, vm->isolate, vm->env,array[2]));
45  };
46
47  SEND(vm->server,
48       enif_make_tuple3(env,
49                        enif_make_atom(env,"result"),
50                        enif_make_copy(env,equals_ref),
51                        enif_make_atom(env, bres ? "true" : "false")));
52
53  enif_free_env(ref_env);
54  TickHandlerResolution result;
55  result.type = DONE;
56  return result;
57}