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

Code before:
 *
 * @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))
  {
    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 && JERRY_CONTEXT (vm_top_context_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 */

/**

Review comment (suggestion):
Your `JERRY_CONTEXT (vm_top_context_p) != NULL` check was correct here.

Code after:
  return NULL;
} /* jerry_backtrace_get_this */

/**
 * Returns true, if the code bound to the backtrace frame is strict mode code.
 *
 * @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 */