Example #1
0
static bool
handler_construct (const jerry_api_object_t *function_obj_p,
                   const jerry_api_value_t *this_p,
                   jerry_api_value_t *ret_val_p,
                   const jerry_api_value_t args_p[],
                   const jerry_api_length_t args_cnt)
{
  printf ("ok construct %p %p %p %d %p\n", function_obj_p, this_p, args_p, args_cnt, ret_val_p);

  JERRY_ASSERT (this_p != NULL);
  JERRY_ASSERT (this_p->type == JERRY_API_DATA_TYPE_OBJECT);

  JERRY_ASSERT (args_cnt == 1);
  JERRY_ASSERT (args_p[0].type == JERRY_API_DATA_TYPE_BOOLEAN);
  JERRY_ASSERT (args_p[0].v_bool == true);

  jerry_api_set_object_field_value (this_p->v_object, (jerry_api_char_t *) "value_field", &args_p[0]);

  jerry_api_set_object_native_handle (this_p->v_object,
                                      (uintptr_t) 0x0000000000000000ull,
                                      handler_construct_freecb);

  uintptr_t ptr;
  bool is_ok = jerry_api_get_object_native_handle (this_p->v_object, &ptr);
  JERRY_ASSERT (is_ok && ptr == (uintptr_t) 0x0000000000000000ull);

  /* check if setting handle for second time is handled correctly */
  jerry_api_set_object_native_handle (this_p->v_object,
                                      (uintptr_t) 0x0012345678abcdefull,
                                      handler_construct_freecb);

  return true;
} /* handler_construct */
Example #2
0
void JObject::SetNative(uintptr_t ptr, JFreeHandlerType free_handler) {
  IOTJS_ASSERT(IsObject());
  jerry_api_set_object_native_handle(_obj_val.v_object, ptr, free_handler);
}