Repository: jerryscript-project/jerryscript
File: tests/unit-core/test-api.c (C)

Code before:
    .free_cb = (jerry_object_native_free_callback_t) native_free_cb, \
    .number_of_references = 0, \
    .offset_of_references = 0, \
  }

JERRY_DEFINE_NATIVE_HANDLE_INFO (bind1, handler_construct_1_freecb);
JERRY_DEFINE_NATIVE_HANDLE_INFO (bind2, handler_construct_2_freecb);
JERRY_DEFINE_NATIVE_HANDLE_INFO (bind3, NULL);

static jerry_value_t
handler_construct (const jerry_call_info_t *call_info_p, /**< call information */
                   const jerry_value_t args_p[], /**< arguments list */
                   const jerry_length_t args_cnt) /**< arguments length */
{
  printf ("ok construct %u %u %p %u\n",
          (unsigned int) call_info_p->function,
          (unsigned int) call_info_p->this_value,
          (void *) args_p,
          (unsigned int) args_cnt);

  TEST_ASSERT (jerry_value_is_object (call_info_p->this_value));

  TEST_ASSERT (args_cnt == 1);
  TEST_ASSERT (jerry_value_is_boolean (args_p[0]));
  TEST_ASSERT (jerry_get_boolean_value (args_p[0]) == true);
  TEST_ASSERT(jerry_is_value_false(args_p[0]) == false);
  TEST_ASSERT(jerry_is_value_true(args_p[0]) == true);

  jerry_value_t this_value = call_info_p->this_value;
  jerry_value_t field_name = jerry_create_string ((jerry_char_t *) "value_field");
  jerry_value_t res = jerry_set_property (this_value, field_name, args_p[0]);
  TEST_ASSERT (!jerry_value_is_error (res));
  TEST_ASSERT (jerry_value_is_boolean (res) && jerry_get_boolean_value (res));
  TEST_ASSERT(jerry_is_value_true(res));
  TEST_ASSERT(!jerry_is_value_false(res));
  jerry_release_value (res);
  jerry_release_value (field_name);

  /* Set a native pointer. */
  jerry_set_object_native_pointer (this_value,
                                   (void *) 0x0000000000000000ull,
                                   &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind1));

  /* Check that the native pointer was set. */
  void *ptr = NULL;
  bool is_ok = jerry_get_object_native_pointer (this_value, &ptr, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind1));
  TEST_ASSERT (is_ok
               && (uintptr_t) ptr == (uintptr_t) 0x0000000000000000ull);

  /* Set a second native pointer. */
  jerry_set_object_native_pointer (this_value,

Review comment (suggestion):
Space missing before `(`
I would also change `jerry_value_is_boolean && jerry_get_boolean_value` pairs in the tests whenever it is possible.

Code after:
    .free_cb = (jerry_object_native_free_callback_t) native_free_cb, \
    .number_of_references = 0, \
    .offset_of_references = 0, \
  }

JERRY_DEFINE_NATIVE_HANDLE_INFO (bind1, handler_construct_1_freecb);
JERRY_DEFINE_NATIVE_HANDLE_INFO (bind2, handler_construct_2_freecb);
JERRY_DEFINE_NATIVE_HANDLE_INFO (bind3, NULL);

static jerry_value_t
handler_construct (const jerry_call_info_t *call_info_p, /**< call information */
                   const jerry_value_t args_p[], /**< arguments list */
                   const jerry_length_t args_cnt) /**< arguments length */
{
  printf ("ok construct %u %u %p %u\n",
          (unsigned int) call_info_p->function,
          (unsigned int) call_info_p->this_value,
          (void *) args_p,
          (unsigned int) args_cnt);

  TEST_ASSERT (jerry_value_is_object (call_info_p->this_value));

  TEST_ASSERT (args_cnt == 1);
  TEST_ASSERT (jerry_value_is_boolean (args_p[0]));
  TEST_ASSERT (jerry_get_boolean_value (args_p[0]) == true);

  TEST_ASSERT (jerry_value_is_true (args_p[0]));

  jerry_value_t this_value = call_info_p->this_value;
  jerry_value_t field_name = jerry_create_string ((jerry_char_t *) "value_field");
  jerry_value_t res = jerry_set_property (this_value, field_name, args_p[0]);
  TEST_ASSERT (!jerry_value_is_error (res));
  TEST_ASSERT (jerry_value_is_boolean (res) && jerry_get_boolean_value (res));
  jerry_release_value (res);
  jerry_release_value (field_name);

  /* Set a native pointer. */
  jerry_set_object_native_pointer (this_value,
                                   (void *) 0x0000000000000000ull,
                                   &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind1));

  /* Check that the native pointer was set. */
  void *ptr = NULL;
  bool is_ok = jerry_get_object_native_pointer (this_value, &ptr, &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind1));
  TEST_ASSERT (is_ok
               && (uintptr_t) ptr == (uintptr_t) 0x0000000000000000ull);

  /* Set a second native pointer. */
  jerry_set_object_native_pointer (this_value,
                                   (void *) 0x0012345678abcdefull,
                                   &JERRY_NATIVE_HANDLE_INFO_FOR_CTYPE (bind2));