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
+1 -1
View File
@@ -27,7 +27,7 @@ JERRY_STATIC_ASSERT ((sizeof (cbc_uint16_arguments_t) % sizeof (jmem_cpointer_t)
*/
JERRY_STATIC_ASSERT (CBC_END == 238,
number_of_cbc_opcodes_changed);
JERRY_STATIC_ASSERT (CBC_EXT_END == 122,
JERRY_STATIC_ASSERT (CBC_EXT_END == 121,
number_of_cbc_ext_opcodes_changed);
#if ENABLED (JERRY_PARSER)
-2
View File
@@ -592,8 +592,6 @@
VM_OC_CLONE_CONTEXT) \
CBC_OPCODE (CBC_EXT_CLONE_FULL_CONTEXT, CBC_NO_FLAG, 0, \
VM_OC_CLONE_CONTEXT) \
CBC_OPCODE (CBC_EXT_RESOURCE_NAME, CBC_NO_FLAG, 0, \
VM_OC_RESOURCE_NAME) \
CBC_OPCODE (CBC_EXT_LINE, CBC_NO_FLAG, 0, \
VM_OC_LINE) \
CBC_OPCODE (CBC_EXT_ERROR, CBC_NO_FLAG, 0, \
+7 -3
View File
@@ -585,12 +585,16 @@ typedef struct
#if ENABLED (JERRY_DEBUGGER)
parser_breakpoint_info_t breakpoint_info[PARSER_MAX_BREAKPOINT_INFO_COUNT]; /**< breakpoint info list */
uint16_t breakpoint_info_count; /**< current breakpoint index */
uint16_t breakpoint_info_count; /**< current breakpoint index */
parser_line_counter_t last_breakpoint_line; /**< last line where breakpoint has been inserted */
#endif /* ENABLED (JERRY_DEBUGGER) */
#if ENABLED (JERRY_RESOURCE_NAME)
ecma_value_t resource_name; /**< resource name */
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
#if ENABLED (JERRY_LINE_INFO)
parser_line_counter_t last_line_info_line; /**< last line where line info has been inserted */
parser_line_counter_t last_line_info_line; /**< last line where line info has been inserted */
#endif /* ENABLED (JERRY_LINE_INFO) */
} parser_context_t;
@@ -822,7 +826,7 @@ extern const lexer_lit_location_t lexer_default_literal;
void parser_module_add_export_node_to_context (parser_context_t *context_p);
void parser_module_add_import_node_to_context (parser_context_t *context_p);
void parser_module_check_request_place (parser_context_t *context_p);
void parser_module_context_init (void);
void parser_module_context_init (parser_context_t *context_p);
void parser_module_handle_module_specifier (parser_context_t *context_p);
void parser_module_handle_requests (parser_context_t *context_p);
void parser_module_parse_export_clause (parser_context_t *context_p);
+2 -2
View File
@@ -293,7 +293,7 @@ parser_module_add_names_to_node (parser_context_t *context_p, /**< parser contex
* Create module context if needed.
*/
void
parser_module_context_init (void)
parser_module_context_init (parser_context_t *context_p)
{
if (JERRY_CONTEXT (module_top_context_p) == NULL)
{
@@ -302,7 +302,7 @@ parser_module_context_init (void)
memset (module_context_p, 0, sizeof (ecma_module_context_t));
JERRY_CONTEXT (module_top_context_p) = module_context_p;
ecma_string_t *path_str_p = ecma_get_string_from_value (JERRY_CONTEXT (resource_name));
ecma_string_t *path_str_p = ecma_get_string_from_value (context_p->resource_name);
lit_utf8_size_t path_str_size;
uint8_t flags = ECMA_STRING_FLAG_EMPTY;
+2 -9
View File
@@ -2339,7 +2339,7 @@ parser_parse_import_statement (parser_context_t *context_p) /**< parser context
JERRY_ASSERT (context_p->token.type == LEXER_KEYW_IMPORT);
parser_module_check_request_place (context_p);
parser_module_context_init ();
parser_module_context_init (context_p);
context_p->module_current_node_p = parser_module_create_module_node (context_p);
@@ -2455,7 +2455,7 @@ parser_parse_export_statement (parser_context_t *context_p) /**< context */
JERRY_ASSERT (context_p->token.type == LEXER_KEYW_EXPORT);
parser_module_check_request_place (context_p);
parser_module_context_init ();
parser_module_context_init (context_p);
context_p->module_current_node_p = parser_module_create_module_node (context_p);
@@ -2646,13 +2646,6 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
}
#endif /* ENABLED (JERRY_DEBUGGER) */
#if ENABLED (JERRY_RESOURCE_NAME)
if (JERRY_CONTEXT (resource_name) != ECMA_VALUE_UNDEFINED)
{
parser_emit_cbc_ext (context_p, CBC_EXT_RESOURCE_NAME);
parser_flush_cbc (context_p);
}
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
#if ENABLED (JERRY_LINE_INFO)
context_p->last_line_info_line = 0;
#endif /* ENABLED (JERRY_LINE_INFO) */
-5
View File
@@ -465,11 +465,6 @@ parser_emit_line_info (parser_context_t *context_p, /**< context */
uint32_t line, /**< current line */
bool flush_cbc) /**< flush last byte code */
{
if (JERRY_CONTEXT (resource_name) == ECMA_VALUE_UNDEFINED)
{
return;
}
if (flush_cbc && context_p->last_cbc_opcode != PARSER_CBC_UNAVAILABLE)
{
parser_flush_cbc (context_p);
+58 -52
View File
@@ -62,6 +62,17 @@ parser_compute_indicies (parser_context_t *context_p, /**< context */
uint16_t ident_count = 0;
uint16_t const_literal_count = 0;
#if ENABLED (JERRY_RESOURCE_NAME)
/* Resource name will be stored as the last const literal. */
if (JERRY_UNLIKELY (context_p->literal_count >= PARSER_MAXIMUM_NUMBER_OF_LITERALS))
{
parser_raise_error (context_p, PARSER_ERR_LITERAL_LIMIT_REACHED);
}
const_literal_count++;
context_p->literal_count++;
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
uint16_t ident_index;
uint16_t const_literal_index;
uint16_t literal_index;
@@ -191,6 +202,11 @@ parser_compute_indicies (parser_context_t *context_p, /**< context */
}
}
#if ENABLED (JERRY_RESOURCE_NAME)
/* Resource name will be stored as the last const literal. */
const_literal_index++;
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
JERRY_ASSERT (ident_index == context_p->register_count + ident_count);
JERRY_ASSERT (const_literal_index == ident_index + const_literal_count);
JERRY_ASSERT (literal_index <= context_p->register_count + context_p->literal_count);
@@ -1242,13 +1258,6 @@ parser_post_processing (parser_context_t *context_p) /**< context */
}
#endif /* ENABLED (JERRY_ESNEXT) */
#if ENABLED (JERRY_RESOURCE_NAME)
if (JERRY_CONTEXT (resource_name) != ECMA_VALUE_UNDEFINED)
{
total_size += sizeof (ecma_value_t);
}
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
#if ENABLED (JERRY_SNAPSHOT_SAVE)
total_size_used = total_size;
#endif /* ENABLED (JERRY_SNAPSHOT_SAVE) */
@@ -1414,6 +1423,10 @@ parser_post_processing (parser_context_t *context_p) /**< context */
parser_init_literal_pool (context_p, literal_pool_p);
#if ENABLED (JERRY_RESOURCE_NAME)
literal_pool_p[const_literal_end - 1] = context_p->resource_name;
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
page_p = context_p->byte_code.first_p;
offset = 0;
real_offset = 0;
@@ -1699,16 +1712,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
{
*(--base_p) = ECMA_VALUE_EMPTY;
}
#endif /* ENABLED (JERRY_ESNEXT) */
#if ENABLED (JERRY_RESOURCE_NAME)
if (JERRY_CONTEXT (resource_name) != ECMA_VALUE_UNDEFINED)
{
*(--base_p) = JERRY_CONTEXT (resource_name);
}
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
#if ENABLED (JERRY_ESNEXT)
if (context_p->tagged_template_literal_cp != JMEM_CP_NULL)
{
base_p[-1] = (ecma_value_t) context_p->tagged_template_literal_cp;
@@ -2052,6 +2056,7 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
size_t arg_list_size, /**< size of function argument list */
const uint8_t *source_p, /**< valid UTF-8 source code */
size_t source_size, /**< size of the source code */
ecma_value_t resource_name, /**< resource name */
uint32_t parse_opts, /**< ecma_parse_opts_t option bits */
parser_error_location_t *error_location_p) /**< error location */
{
@@ -2096,6 +2101,11 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
context.token.flags = 0;
context.line = 1;
context.column = 1;
#if ENABLED (JERRY_RESOURCE_NAME)
context.resource_name = resource_name;
#else /* !ENABLED (JERRY_RESOURCE_NAME) */
JERRY_UNUSED (resource_name);
#endif /* !ENABLED (JERRY_RESOURCE_NAME) */
scanner_info_t scanner_info_end;
scanner_info_end.next_p = NULL;
@@ -2847,16 +2857,16 @@ parser_raise_error (parser_context_t *context_p, /**< context */
* if arg_list_p is not NULL, a function body is parsed
* returned value must be freed with ecma_free_value
*
* @return true - if success
* syntax error - otherwise
* @return pointer to compiled byte code - if success
* NULL - otherwise
*/
ecma_value_t
ecma_compiled_code_t *
parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */
size_t arg_list_size, /**< size of function argument list */
const uint8_t *source_p, /**< source code */
size_t source_size, /**< size of the source code */
uint32_t parse_opts, /**< ecma_parse_opts_t option bits */
ecma_compiled_code_t **bytecode_data_p) /**< [out] JS bytecode */
ecma_value_t resource_name, /**< resource name */
uint32_t parse_opts) /**< ecma_parse_opts_t option bits */
{
#if ENABLED (JERRY_PARSER)
parser_error_location_t parser_error;
@@ -2871,14 +2881,15 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */
}
#endif /* ENABLED (JERRY_DEBUGGER) */
*bytecode_data_p = parser_parse_source (arg_list_p,
arg_list_size,
source_p,
source_size,
parse_opts,
&parser_error);
ecma_compiled_code_t *bytecode_p = parser_parse_source (arg_list_p,
arg_list_size,
source_p,
source_size,
resource_name,
parse_opts,
&parser_error);
if (!*bytecode_data_p)
if (JERRY_UNLIKELY (bytecode_p == NULL))
{
#if ENABLED (JERRY_MODULE_SYSTEM)
if (JERRY_CONTEXT (module_top_context_p) != NULL)
@@ -2898,14 +2909,14 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */
/* It is unlikely that memory can be allocated in an out-of-memory
* situation. However, a simple value can still be thrown. */
jcontext_raise_exception (ECMA_VALUE_NULL);
return ECMA_VALUE_ERROR;
return NULL;
}
if (parser_error.error == PARSER_ERR_INVALID_REGEXP)
{
/* The RegExp compiler has already raised an exception. */
JERRY_ASSERT (jcontext_has_pending_exception ());
return ECMA_VALUE_ERROR;
return NULL;
}
#if ENABLED (JERRY_ERROR_MESSAGES)
@@ -2917,36 +2928,30 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */
ecma_value_t line_str_val = ecma_make_uint32_value (parser_error.line);
ecma_value_t col_str_val = ecma_make_uint32_value (parser_error.column);
ecma_value_t error_value = ecma_raise_standard_error_with_format (ECMA_ERROR_SYNTAX,
"% [%:%:%]",
err_str_val,
JERRY_CONTEXT (resource_name),
line_str_val,
col_str_val);
ecma_raise_standard_error_with_format (ECMA_ERROR_SYNTAX,
"% [%:%:%]",
err_str_val,
resource_name,
line_str_val,
col_str_val);
ecma_free_value (col_str_val);
ecma_free_value (line_str_val);
ecma_free_value (err_str_val);
return error_value;
#else /* !ENABLED (JERRY_ERROR_MESSAGES) */
return ecma_raise_syntax_error ("");
ecma_raise_syntax_error ("");
#endif /* ENABLED (JERRY_ERROR_MESSAGES) */
return NULL;
}
#if ENABLED (JERRY_MODULE_SYSTEM)
if (JERRY_CONTEXT (module_top_context_p) != NULL)
if (JERRY_CONTEXT (module_top_context_p) != NULL && ECMA_IS_VALUE_ERROR (ecma_module_parse_modules ()))
{
ecma_value_t ret_value = ecma_module_parse_modules ();
ecma_bytecode_deref (bytecode_p);
ecma_module_cleanup ();
if (ECMA_IS_VALUE_ERROR (ret_value))
{
ecma_bytecode_deref (*bytecode_data_p);
*bytecode_data_p = NULL;
ecma_module_cleanup ();
return ret_value;
}
return NULL;
}
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
@@ -2971,16 +2976,17 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */
}
#endif /* ENABLED (JERRY_DEBUGGER) */
return ECMA_VALUE_TRUE;
return bytecode_p;
#else /* !ENABLED (JERRY_PARSER) */
JERRY_UNUSED (arg_list_p);
JERRY_UNUSED (arg_list_size);
JERRY_UNUSED (source_p);
JERRY_UNUSED (source_size);
JERRY_UNUSED (parse_opts);
JERRY_UNUSED (bytecode_data_p);
JERRY_UNUSED (resource_name);
return ecma_raise_syntax_error (ECMA_ERR_MSG ("The parser has been disabled."));
ecma_raise_syntax_error (ECMA_ERR_MSG ("The parser has been disabled."));
return NULL;
#endif /* ENABLED (JERRY_PARSER) */
} /* parser_parse_script */
+7 -3
View File
@@ -185,9 +185,13 @@ typedef struct
} parser_error_location_t;
/* Note: source must be a valid UTF-8 string */
ecma_value_t parser_parse_script (const uint8_t *arg_list_p, size_t arg_list_size,
const uint8_t *source_p, size_t source_size,
uint32_t parse_opts, ecma_compiled_code_t **bytecode_data_p);
ecma_compiled_code_t *
parser_parse_script (const uint8_t *arg_list_p,
size_t arg_list_size,
const uint8_t *source_p,
size_t source_size,
ecma_value_t resource_name,
uint32_t parse_opts);
#if ENABLED (JERRY_ERROR_MESSAGES)
const char *parser_error_to_string (parser_error_t);