Repository: jerryscript-project/jerryscript
File: jerry-core/api/jerry.c (C)

Code before:
jerry_backtrace_is_strict (jerry_backtrace_frame_t *frame_p) /**< frame pointer */
{
  return (frame_p->frame_type == JERRY_BACKTRACE_FRAME_JS
          && (frame_p->context_p->status_flags & VM_FRAME_CTX_IS_STRICT) != 0);
} /* jerry_backtrace_is_strict */

/**
 * Get the resource name (usually a file name) of the currently executed script or the given function object
 *
 * Note: returned value must be freed with jerry_release_value, when it is no longer needed
 *
 * @return JS string constructed from
 *         - the currently executed function object's resource name, if the given value is undefined
 *         - resource name of the function object, if the given value is a function object
 *         - "<anonymous>", otherwise
 */
jerry_value_t
jerry_get_resource_name (const jerry_value_t value) /**< jerry api value */
{
#if JERRY_RESOURCE_NAME
  if (ecma_is_value_undefined (value) && JERRY_CONTEXT (vm_top_context_p) != NULL)
  {
    return ecma_copy_value (ecma_get_resource_name (JERRY_CONTEXT (vm_top_context_p)->shared_p->bytecode_header_p));
  }
  else if (ecma_is_value_object (value))
  {
    ecma_object_t *obj_p = ecma_get_object_from_value (value);

    if (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION
        && !ecma_get_object_is_builtin (obj_p))
    {
      ecma_extended_object_t *ext_func_p = (ecma_extended_object_t *) obj_p;

      return ecma_copy_value (ecma_get_resource_name (ecma_op_function_get_compiled_code (ext_func_p)));
    }
  }
#endif /* JERRY_RESOURCE_NAME */

  JERRY_UNUSED (value);
  return ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
} /* jerry_get_resource_name */

/**
 * Returns the user value assigned to a script / module / function.
 *
 * Note:
 *    This value is usually set by the parser when
 *    the JERRY_PARSE_HAS_USER_VALUE flag is passed.
 *
 * @return user value
 */

Review comment (refactor):
I would like to be this function as the `jerry_get_user_value` function below. It starts with:
```
  const ecma_compiled_code_t *bytecode_p = ecma_bytecode_get_from_value (value);
  if (bytecode_p == NULL)
  {
    return ECMA_VALUE_UNDEFINED;
  }
```

Then extract the string value. This will support more forms (e.g bound object, module) than the current one, you can even add some tests for the new forms.

This particular case can be kept though. Maybe this could be added to `jerry_get_user_value` for consistency (with tests)

Code after:
 *
 * @return true - if strict mode code is bound to the frame,
 *         false - otherwise
 */
bool
jerry_backtrace_is_strict (jerry_backtrace_frame_t *frame_p) /**< frame pointer */
{
  return (frame_p->frame_type == JERRY_BACKTRACE_FRAME_JS
          && (frame_p->context_p->status_flags & VM_FRAME_CTX_IS_STRICT) != 0);
} /* jerry_backtrace_is_strict */

/**
 * Get the resource name (usually a file name) of the currently executed script or the given function object
 *
 * Note: returned value must be freed with jerry_release_value, when it is no longer needed
 *
 * @return JS string constructed from
 *         - the currently executed function object's resource name, if the given value is undefined
 *         - resource name of the function object, if the given value is a function object
 *         - "<anonymous>", otherwise
 */
jerry_value_t
jerry_get_resource_name (const jerry_value_t value) /**< jerry api value */
{
#if JERRY_RESOURCE_NAME
  if (ecma_is_value_undefined (value) && JERRY_CONTEXT (vm_top_context_p) != NULL)
  {
    return ecma_copy_value (ecma_get_resource_name (JERRY_CONTEXT (vm_top_context_p)->shared_p->bytecode_header_p));
  }

  const ecma_compiled_code_t *bytecode_p = ecma_bytecode_get_from_value (value);

  if (bytecode_p == NULL)
  {
    return ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
  }

  ecma_value_t script_value = ((cbc_uint8_arguments_t *) bytecode_p)->script_value;
  cbc_script_t *script_p = ECMA_GET_INTERNAL_VALUE_POINTER (cbc_script_t, script_value);

  if (CBC_SCRIPT_GET_TYPE (script_p) == CBC_SCRIPT_GENERIC)
  {
    return ecma_copy_value (script_p->resource_name);
  }
#endif /* JERRY_RESOURCE_NAME */

  JERRY_UNUSED (value);
  return ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
} /* jerry_get_resource_name */

/**