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

Code before:
                           &parse_options);
    TEST_ASSERT (!jerry_value_is_error (program));

    resource_value = jerry_get_resource_name (program);
    TEST_ASSERT (jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.resource_name));
    jerry_release_value (resource_value);

    run_result = jerry_module_link (program, NULL, NULL);
    TEST_ASSERT (!jerry_value_is_error (run_result));

    resource_value = jerry_get_resource_name (run_result);
    TEST_ASSERT (jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.resource_name));
    jerry_release_value (resource_value);
    jerry_release_value (run_result);

    run_result = jerry_module_evaluate (program);
    TEST_ASSERT (!jerry_value_is_error (run_result));

    resource_value = jerry_get_resource_name (run_result);
    TEST_ASSERT (jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.resource_name));
    jerry_release_value (resource_value);
    jerry_release_value (run_result);
    jerry_release_value (program);
    jerry_release_value (parse_options.resource_name);

    const char *source_4 = ("const module = { \n"
                            "  f3: function() {} \n"
                            "}; \n"
                            "const boundF3 =  module.f3.bind(module); \n"
                            "function f4 () {\n"
                            "  if (resourceName(boundF3) !== 'demo4.js') return false; \n"
                            "  return f4; \n"
                            "} \n"
                            "f4();");

    parse_options.options = JERRY_PARSE_HAS_RESOURCE;
    parse_options.resource_name = jerry_create_string ((jerry_char_t *) "demo4.js");

    program = jerry_parse ((const jerry_char_t *) source_4,
                           strlen (source_4),
                           &parse_options);
    TEST_ASSERT (!jerry_value_is_error (program));

    run_result = jerry_run (program);
    TEST_ASSERT (!jerry_value_is_error (run_result));
    TEST_ASSERT (jerry_value_is_object (run_result));

    resource_value = jerry_get_resource_name (run_result);
    TEST_ASSERT (jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.resource_name));

    jerry_release_value (resource_value);

Review comment (suggestion):
The `f4` does not check any bound function. I think this is a good enough testcase (test bind twice):
```
function f() {}
f().bind().bind()
```
The resourcename should be correct.

Furthermore JERRY_FEATURE_MODULE is not rquired for bound function tests.

Code after:
                           &parse_options);
    TEST_ASSERT (!jerry_value_is_error (program));

    resource_value = jerry_get_resource_name (program);
    TEST_ASSERT (jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.resource_name));
    jerry_release_value (resource_value);

    run_result = jerry_module_link (program, NULL, NULL);
    TEST_ASSERT (!jerry_value_is_error (run_result));

    resource_value = jerry_get_resource_name (run_result);
    TEST_ASSERT (jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.resource_name));
    jerry_release_value (resource_value);
    jerry_release_value (run_result);

    run_result = jerry_module_evaluate (program);
    TEST_ASSERT (!jerry_value_is_error (run_result));

    resource_value = jerry_get_resource_name (run_result);
    TEST_ASSERT (jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.resource_name));
    jerry_release_value (resource_value);
    jerry_release_value (run_result);
    jerry_release_value (program);
    jerry_release_value (parse_options.resource_name);
  }
  const char *source_4 = ("function f(){} \n"
                          "f.bind().bind();");

  parse_options.options = JERRY_PARSE_HAS_RESOURCE;
  parse_options.resource_name = jerry_create_string ((jerry_char_t *) "demo4.js");

  program = jerry_parse ((const jerry_char_t *) source_4,
                         strlen (source_4),
                         &parse_options);
  TEST_ASSERT (!jerry_value_is_error (program));

  run_result = jerry_run (program);
  TEST_ASSERT (!jerry_value_is_error (run_result));
  TEST_ASSERT (jerry_value_is_object (run_result));

  resource_value = jerry_get_resource_name (run_result);
  TEST_ASSERT (jerry_binary_operation (JERRY_BIN_OP_STRICT_EQUAL, resource_value, parse_options.resource_name));

  jerry_release_value (resource_value);
  jerry_release_value (parse_options.resource_name);
  jerry_release_value (run_result);
  jerry_release_value (program);

  jerry_cleanup ();

  return 0;