Simplify resource name handling (#3929)

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
This commit is contained in:
Dániel Bátyai
2020-06-26 12:10:14 +02:00
committed by GitHub
parent b7e3baeecb
commit 2523323310
25 changed files with 218 additions and 300 deletions
+28 -9
View File
@@ -1481,15 +1481,9 @@ ecma_compiled_code_get_tagged_template_collection (const ecma_compiled_code_t *b
ecma_value_t *base_p = ecma_compiled_code_resolve_function_name (bytecode_header_p);
#if ENABLED (JERRY_RESOURCE_NAME)
base_p--;
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
return ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, base_p[-1]);
} /* ecma_compiled_code_get_tagged_template_collection */
#endif /* ENABLED (JERRY_ESNEXT) */
#if ENABLED (JERRY_RESOURCE_NAME) || ENABLED (JERRY_ESNEXT)
/**
* Get the number of formal parameters of the compiled code
*
@@ -1517,7 +1511,7 @@ ecma_compiled_code_get_formal_params (const ecma_compiled_code_t *bytecode_heade
* @return start position of the arguments list start of the compiled code
*/
ecma_value_t *
ecma_compiled_code_resolve_arguments_start (const ecma_compiled_code_t *bytecode_header_p)
ecma_compiled_code_resolve_arguments_start (const ecma_compiled_code_t *bytecode_header_p) /**< compiled code */
{
JERRY_ASSERT (bytecode_header_p != NULL);
@@ -1533,7 +1527,7 @@ ecma_compiled_code_resolve_arguments_start (const ecma_compiled_code_t *bytecode
* @return position of the function name of the compiled code
*/
inline ecma_value_t * JERRY_ATTR_ALWAYS_INLINE
ecma_compiled_code_resolve_function_name (const ecma_compiled_code_t *bytecode_header_p)
ecma_compiled_code_resolve_function_name (const ecma_compiled_code_t *bytecode_header_p) /**< compiled code */
{
JERRY_ASSERT (bytecode_header_p != NULL);
ecma_value_t *base_p = ecma_compiled_code_resolve_arguments_start (bytecode_header_p);
@@ -1547,7 +1541,32 @@ ecma_compiled_code_resolve_function_name (const ecma_compiled_code_t *bytecode_h
return base_p;
} /* ecma_compiled_code_resolve_function_name */
#endif /* ENABLED (JERRY_RESOURCE_NAME) || ENABLED (JERRY_ESNEXT) */
#endif /* ENABLED (JERRY_ESNEXT) */
/**
* Get the resource name of a compiled code.
*
* @return resource name value
*/
ecma_value_t
ecma_get_resource_name (const ecma_compiled_code_t *bytecode_p) /**< compiled code */
{
#if ENABLED (JERRY_RESOURCE_NAME)
if (bytecode_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
{
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) bytecode_p;
ecma_value_t *lit_pool_p = (ecma_value_t *) ((uint8_t *) bytecode_p + sizeof (cbc_uint16_arguments_t));
return lit_pool_p[args_p->const_literal_end - args_p->register_end - 1];
}
cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) bytecode_p;
ecma_value_t *lit_pool_p = (ecma_value_t *) ((uint8_t *) bytecode_p + sizeof (cbc_uint8_arguments_t));
return lit_pool_p[args_p->const_literal_end - args_p->register_end - 1];
#else /* !ENABLED (JERRY_RESOURCE_NAME) */
JERRY_UNUSED (bytecode_p);
return ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
#endif /* !ENABLED (JERRY_RESOURCE_NAME) */
} /* ecma_get_resource_name */
#if (JERRY_STACK_LIMIT != 0)
/**
+3 -2
View File
@@ -500,11 +500,12 @@ void ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p);
#if ENABLED (JERRY_ESNEXT)
ecma_collection_t *ecma_compiled_code_get_tagged_template_collection (const ecma_compiled_code_t *bytecode_header_p);
#endif /* ENABLED (JERRY_ESNEXT) */
#if ENABLED (JERRY_RESOURCE_NAME) || ENABLED (JERRY_ESNEXT)
#if ENABLED (JERRY_ESNEXT)
ecma_length_t ecma_compiled_code_get_formal_params (const ecma_compiled_code_t *bytecode_p);
ecma_value_t *ecma_compiled_code_resolve_arguments_start (const ecma_compiled_code_t *bytecode_header_p);
ecma_value_t *ecma_compiled_code_resolve_function_name (const ecma_compiled_code_t *bytecode_header_p);
#endif /* ENABLED (JERRY_RESOURCE_NAME) || ENABLED (JERRY_ESNEXT) */
#endif /* ENABLED (JERRY_ESNEXT) */
ecma_value_t ecma_get_resource_name (const ecma_compiled_code_t *bytecode_p);
#if (JERRY_STACK_LIMIT != 0)
uintptr_t ecma_get_current_stack_usage (void);
#endif /* (JERRY_STACK_LIMIT != 0) */
@@ -543,7 +543,6 @@ ecma_snapshot_get_literal (const uint8_t *literal_base_p, /**< literal start */
* Related values:
* - function argument names, if CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED is present
* - function name, if CBC_CODE_FLAGS_CLASS_CONSTRUCTOR is not present and ES.next profile is enabled
* - resource name, if JERRY_RESOURCE_NAME is enabled
*
* @return pointer to the beginning of the serializable ecma-values
*/
@@ -576,11 +575,6 @@ ecma_snapshot_resolve_serializable_values (ecma_compiled_code_t *compiled_code_p
}
#endif /* ENABLED (JERRY_ESNEXT) */
#if ENABLED (JERRY_RESOURCE_NAME)
/* resource name */
base_p--;
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
return base_p;
} /* ecma_snapshot_resolve_serializable_values */
#endif /* ENABLED (JERRY_SNAPSHOT_EXEC) || ENABLED (JERRY_SNAPSHOT_SAVE) */
+9 -14
View File
@@ -877,28 +877,23 @@ ecma_module_parse (ecma_module_t *module_p) /**< module */
}
#endif /* ENABLED (JERRY_DEBUGGER) && ENABLED (JERRY_PARSER) */
JERRY_CONTEXT (resource_name) = ecma_make_string_value (module_p->path_p);
ecma_compiled_code_t *bytecode_data_p;
ecma_value_t ret_value = parser_parse_script (NULL,
0,
(jerry_char_t *) source_p,
source_size,
ECMA_PARSE_STRICT_MODE | ECMA_PARSE_MODULE,
&bytecode_data_p);
ecma_compiled_code_t *bytecode_p = parser_parse_script (NULL,
0,
(jerry_char_t *) source_p,
source_size,
ecma_make_string_value (module_p->path_p),
ECMA_PARSE_STRICT_MODE | ECMA_PARSE_MODULE);
JERRY_CONTEXT (module_top_context_p) = module_p->context_p->parent_p;
jerry_port_release_source (source_p);
if (ECMA_IS_VALUE_ERROR (ret_value))
if (JERRY_UNLIKELY (bytecode_p == NULL))
{
return ret_value;
return ECMA_VALUE_ERROR;
}
ecma_free_value (ret_value);
module_p->compiled_code_p = bytecode_data_p;
module_p->compiled_code_p = bytecode_p;
module_p->state = ECMA_MODULE_STATE_PARSED;
return ECMA_VALUE_EMPTY;
@@ -24,10 +24,6 @@
#include "js-parser.h"
#include "lit-magic-strings.h"
#if ENABLED (JERRY_RESOURCE_NAME)
#include "jcontext.h"
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
+10 -15
View File
@@ -82,8 +82,6 @@ ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, /**< code characters b
#if ENABLED (JERRY_PARSER)
JERRY_ASSERT (code_p != NULL);
ecma_compiled_code_t *bytecode_data_p;
uint32_t is_strict_call = ECMA_PARSE_STRICT_MODE | ECMA_PARSE_DIRECT_EVAL;
if ((parse_opts & is_strict_call) != is_strict_call)
@@ -93,27 +91,24 @@ ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, /**< code characters b
parse_opts |= ECMA_PARSE_EVAL;
#if ENABLED (JERRY_RESOURCE_NAME)
JERRY_CONTEXT (resource_name) = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_EVAL);
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
#if ENABLED (JERRY_ESNEXT)
ECMA_CLEAR_LOCAL_PARSE_OPTS ();
#endif /* ENABLED (JERRY_ESNEXT) */
ecma_value_t parse_status = parser_parse_script (NULL,
0,
code_p,
code_buffer_size,
parse_opts,
&bytecode_data_p);
ecma_value_t resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_EVAL);
ecma_compiled_code_t *bytecode_p = parser_parse_script (NULL,
0,
code_p,
code_buffer_size,
resource_name,
parse_opts);
if (ECMA_IS_VALUE_ERROR (parse_status))
if (JERRY_UNLIKELY (bytecode_p == NULL))
{
return parse_status;
return ECMA_VALUE_ERROR;
}
return vm_run_eval (bytecode_data_p, parse_opts);
return vm_run_eval (bytecode_p, parse_opts);
#else /* !ENABLED (JERRY_PARSER) */
JERRY_UNUSED (code_p);
JERRY_UNUSED (code_buffer_size);
@@ -36,21 +36,6 @@
* @{
*/
#if ENABLED (JERRY_RESOURCE_NAME)
/**
* Get the resource name from the compiled code header
*
* @return resource name as ecma-string
*/
ecma_value_t
ecma_op_resource_name (const ecma_compiled_code_t *bytecode_header_p)
{
JERRY_ASSERT (bytecode_header_p != NULL);
return ecma_compiled_code_resolve_function_name (bytecode_header_p)[-1];
} /* ecma_op_resource_name */
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
#if ENABLED (JERRY_ESNEXT)
/**
* SetFunctionName operation
@@ -367,87 +352,77 @@ ecma_op_create_dynamic_function (const ecma_value_t *arguments_list_p, /**< argu
ECMA_STRING_TO_UTF8_STRING (arguments_str_p, arguments_buffer_p, arguments_buffer_size);
ECMA_STRING_TO_UTF8_STRING (function_body_str_p, function_body_buffer_p, function_body_buffer_size);
#if ENABLED (JERRY_RESOURCE_NAME)
JERRY_CONTEXT (resource_name) = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
ecma_value_t resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
ecma_compiled_code_t *bytecode_p = parser_parse_script (arguments_buffer_p,
arguments_buffer_size,
function_body_buffer_p,
function_body_buffer_size,
resource_name,
parse_opts);
ecma_compiled_code_t *bytecode_data_p = NULL;
ECMA_FINALIZE_UTF8_STRING (function_body_buffer_p, function_body_buffer_size);
ECMA_FINALIZE_UTF8_STRING (arguments_buffer_p, arguments_buffer_size);
ecma_deref_ecma_string (arguments_str_p);
ecma_deref_ecma_string (function_body_str_p);
ecma_value_t ret_value = parser_parse_script (arguments_buffer_p,
arguments_buffer_size,
function_body_buffer_p,
function_body_buffer_size,
parse_opts,
&bytecode_data_p);
if (!ECMA_IS_VALUE_ERROR (ret_value))
if (JERRY_UNLIKELY (bytecode_p == NULL))
{
JERRY_ASSERT (ecma_is_value_true (ret_value));
return ECMA_VALUE_ERROR;
}
#if ENABLED (JERRY_ESNEXT)
ecma_value_t *func_name_p;
func_name_p = ecma_compiled_code_resolve_function_name ((const ecma_compiled_code_t *) bytecode_data_p);
*func_name_p = ecma_make_magic_string_value (LIT_MAGIC_STRING_ANONYMOUS);
ecma_value_t *func_name_p;
func_name_p = ecma_compiled_code_resolve_function_name ((const ecma_compiled_code_t *) bytecode_p);
*func_name_p = ecma_make_magic_string_value (LIT_MAGIC_STRING_ANONYMOUS);
#endif /* ENABLED (JERRY_ESNEXT) */
ecma_object_t *global_env_p = ecma_get_global_environment ();
ecma_builtin_id_t fallback_proto = ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE;
ecma_object_t *global_env_p = ecma_get_global_environment ();
ecma_builtin_id_t fallback_proto = ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE;
#if ENABLED (JERRY_ESNEXT)
ecma_object_t *new_target_p = JERRY_CONTEXT (current_new_target);
ecma_object_t *new_target_p = JERRY_CONTEXT (current_new_target);
if (JERRY_UNLIKELY (parse_opts & (ECMA_PARSE_GENERATOR_FUNCTION | ECMA_PARSE_ASYNC_FUNCTION)))
if (JERRY_UNLIKELY (parse_opts & (ECMA_PARSE_GENERATOR_FUNCTION | ECMA_PARSE_ASYNC_FUNCTION)))
{
fallback_proto = ECMA_BUILTIN_ID_GENERATOR;
if (parse_opts & ECMA_PARSE_ASYNC_FUNCTION)
{
fallback_proto = ECMA_BUILTIN_ID_GENERATOR;
fallback_proto = ECMA_BUILTIN_ID_ASYNC_GENERATOR;
if (parse_opts & ECMA_PARSE_ASYNC_FUNCTION)
if (new_target_p == NULL)
{
fallback_proto = ECMA_BUILTIN_ID_ASYNC_GENERATOR;
if (new_target_p == NULL)
{
new_target_p = ecma_builtin_get (ECMA_BUILTIN_ID_ASYNC_GENERATOR_FUNCTION);
}
}
else if (new_target_p == NULL)
{
new_target_p = ecma_builtin_get (ECMA_BUILTIN_ID_GENERATOR_FUNCTION);
new_target_p = ecma_builtin_get (ECMA_BUILTIN_ID_ASYNC_GENERATOR_FUNCTION);
}
}
else if (new_target_p == NULL)
{
new_target_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION);
new_target_p = ecma_builtin_get (ECMA_BUILTIN_ID_GENERATOR_FUNCTION);
}
ecma_object_t *proto = ecma_op_get_prototype_from_constructor (new_target_p, fallback_proto);
if (JERRY_UNLIKELY (proto == NULL))
{
ecma_bytecode_deref (bytecode_data_p);
ecma_deref_ecma_string (arguments_str_p);
ecma_deref_ecma_string (function_body_str_p);
return ECMA_VALUE_ERROR;
}
#endif /* ENABLED (JERRY_ESNEXT) */
ecma_object_t *func_obj_p = ecma_op_create_function_object (global_env_p, bytecode_data_p, fallback_proto);
#if ENABLED (JERRY_ESNEXT)
ECMA_SET_NON_NULL_POINTER (func_obj_p->u2.prototype_cp, proto);
ecma_deref_object (proto);
#endif /* ENABLED (JERRY_ESNEXT) */
ecma_bytecode_deref (bytecode_data_p);
ret_value = ecma_make_object_value (func_obj_p);
}
else if (new_target_p == NULL)
{
new_target_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION);
}
ECMA_FINALIZE_UTF8_STRING (function_body_buffer_p, function_body_buffer_size);
ECMA_FINALIZE_UTF8_STRING (arguments_buffer_p, arguments_buffer_size);
ecma_object_t *proto = ecma_op_get_prototype_from_constructor (new_target_p, fallback_proto);
ecma_deref_ecma_string (arguments_str_p);
ecma_deref_ecma_string (function_body_str_p);
if (JERRY_UNLIKELY (proto == NULL))
{
ecma_bytecode_deref (bytecode_p);
return ECMA_VALUE_ERROR;
}
#endif /* ENABLED (JERRY_ESNEXT) */
return ret_value;
ecma_object_t *func_obj_p = ecma_op_create_function_object (global_env_p, bytecode_p, fallback_proto);
#if ENABLED (JERRY_ESNEXT)
ECMA_SET_NON_NULL_POINTER (func_obj_p->u2.prototype_cp, proto);
ecma_deref_object (proto);
#endif /* ENABLED (JERRY_ESNEXT) */
ecma_bytecode_deref (bytecode_p);
return ecma_make_object_value (func_obj_p);
} /* ecma_op_create_dynamic_function */
/**
@@ -27,10 +27,6 @@
* @{
*/
#if ENABLED (JERRY_RESOURCE_NAME)
ecma_value_t ecma_op_resource_name (const ecma_compiled_code_t *bytecode_header_p);
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
#if ENABLED (JERRY_ESNEXT)
ecma_value_t ecma_op_function_form_name (ecma_string_t *prop_name_p, char *prefix_p, lit_utf8_size_t prefix_size);
#endif /* ENABLED (JERRY_ESNEXT) */