mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
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:
parent
b7e3baeecb
commit
2523323310
@ -745,21 +745,16 @@ jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< scr
|
||||
JERRY_UNUSED (resource_name_p);
|
||||
JERRY_UNUSED (resource_name_length);
|
||||
|
||||
ecma_value_t resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
|
||||
#if ENABLED (JERRY_RESOURCE_NAME)
|
||||
if (resource_name_length == 0)
|
||||
if (resource_name_length > 0)
|
||||
{
|
||||
JERRY_CONTEXT (resource_name) = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_CONTEXT (resource_name) = ecma_find_or_create_literal_string (resource_name_p,
|
||||
(lit_utf8_size_t) resource_name_length);
|
||||
resource_name = ecma_find_or_create_literal_string (resource_name_p, (lit_utf8_size_t) resource_name_length);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
|
||||
snapshot_globals_t globals;
|
||||
ecma_value_t parse_status;
|
||||
ecma_compiled_code_t *bytecode_data_p;
|
||||
const uint32_t aligned_header_size = JERRY_ALIGNUP (sizeof (jerry_snapshot_header_t),
|
||||
JMEM_ALIGNMENT);
|
||||
|
||||
@ -771,20 +766,18 @@ jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< scr
|
||||
uint32_t status_flags = ((generate_snapshot_opts & JERRY_SNAPSHOT_SAVE_STRICT) ? ECMA_PARSE_STRICT_MODE
|
||||
: ECMA_PARSE_NO_OPTS);
|
||||
|
||||
parse_status = parser_parse_script (args_p,
|
||||
args_size,
|
||||
source_p,
|
||||
source_size,
|
||||
status_flags,
|
||||
&bytecode_data_p);
|
||||
ecma_compiled_code_t *bytecode_data_p = parser_parse_script (args_p,
|
||||
args_size,
|
||||
source_p,
|
||||
source_size,
|
||||
resource_name,
|
||||
status_flags);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (parse_status))
|
||||
if (JERRY_UNLIKELY (bytecode_data_p == NULL))
|
||||
{
|
||||
return ecma_create_error_reference_from_context ();
|
||||
}
|
||||
|
||||
JERRY_ASSERT (bytecode_data_p != NULL);
|
||||
|
||||
if (generate_snapshot_opts & JERRY_SNAPSHOT_SAVE_STATIC)
|
||||
{
|
||||
static_snapshot_add_compiled_code (bytecode_data_p, (uint8_t *) buffer_p, buffer_size, &globals);
|
||||
|
||||
@ -429,35 +429,27 @@ jerry_parse (const jerry_char_t *resource_name_p, /**< resource name (usually a
|
||||
#if ENABLED (JERRY_PARSER)
|
||||
jerry_assert_api_available ();
|
||||
|
||||
ecma_value_t resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
|
||||
#if ENABLED (JERRY_RESOURCE_NAME)
|
||||
if (resource_name_length == 0)
|
||||
if (resource_name_length > 0)
|
||||
{
|
||||
JERRY_CONTEXT (resource_name) = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_CONTEXT (resource_name) = ecma_find_or_create_literal_string (resource_name_p,
|
||||
(lit_utf8_size_t) resource_name_length);
|
||||
resource_name = ecma_find_or_create_literal_string (resource_name_p, (lit_utf8_size_t) resource_name_length);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
|
||||
ecma_compiled_code_t *bytecode_data_p;
|
||||
ecma_value_t parse_status;
|
||||
ecma_compiled_code_t *bytecode_data_p = parser_parse_script (NULL,
|
||||
0,
|
||||
source_p,
|
||||
source_size,
|
||||
resource_name,
|
||||
parse_opts);
|
||||
|
||||
parse_status = parser_parse_script (NULL,
|
||||
0,
|
||||
source_p,
|
||||
source_size,
|
||||
parse_opts,
|
||||
&bytecode_data_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (parse_status))
|
||||
if (JERRY_UNLIKELY (bytecode_data_p == NULL))
|
||||
{
|
||||
return ecma_create_error_reference_from_context ();
|
||||
}
|
||||
|
||||
ecma_free_value (parse_status);
|
||||
|
||||
ecma_object_t *lex_env_p = ecma_get_global_environment ();
|
||||
ecma_object_t *func_obj_p = ecma_op_create_simple_function_object (lex_env_p, bytecode_data_p);
|
||||
ecma_bytecode_deref (bytecode_data_p);
|
||||
@ -504,18 +496,12 @@ jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (u
|
||||
#if ENABLED (JERRY_PARSER)
|
||||
jerry_assert_api_available ();
|
||||
|
||||
ecma_compiled_code_t *bytecode_data_p;
|
||||
ecma_value_t parse_status;
|
||||
ecma_value_t resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
|
||||
#if ENABLED (JERRY_RESOURCE_NAME)
|
||||
if (resource_name_length == 0)
|
||||
if (resource_name_length > 0)
|
||||
{
|
||||
JERRY_CONTEXT (resource_name) = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_CONTEXT (resource_name) = ecma_find_or_create_literal_string (resource_name_p,
|
||||
(lit_utf8_size_t) resource_name_length);
|
||||
resource_name = ecma_find_or_create_literal_string (resource_name_p, (lit_utf8_size_t) resource_name_length);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
|
||||
@ -525,23 +511,21 @@ jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (u
|
||||
arg_list_p = (const jerry_char_t *) "";
|
||||
}
|
||||
|
||||
parse_status = parser_parse_script (arg_list_p,
|
||||
arg_list_size,
|
||||
source_p,
|
||||
source_size,
|
||||
parse_opts,
|
||||
&bytecode_data_p);
|
||||
ecma_compiled_code_t *bytecode_p = parser_parse_script (arg_list_p,
|
||||
arg_list_size,
|
||||
source_p,
|
||||
source_size,
|
||||
resource_name,
|
||||
parse_opts);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (parse_status))
|
||||
if (JERRY_UNLIKELY (bytecode_p == NULL))
|
||||
{
|
||||
return ecma_create_error_reference_from_context ();
|
||||
}
|
||||
|
||||
ecma_free_value (parse_status);
|
||||
|
||||
ecma_object_t *lex_env_p = ecma_get_global_environment ();
|
||||
ecma_object_t *func_obj_p = ecma_op_create_simple_function_object (lex_env_p, bytecode_data_p);
|
||||
ecma_bytecode_deref (bytecode_data_p);
|
||||
ecma_object_t *func_obj_p = ecma_op_create_simple_function_object (lex_env_p, bytecode_p);
|
||||
ecma_bytecode_deref (bytecode_p);
|
||||
|
||||
return ecma_make_object_value (func_obj_p);
|
||||
#else /* !ENABLED (JERRY_PARSER) */
|
||||
@ -3551,11 +3535,9 @@ jerry_get_resource_name (const jerry_value_t value) /**< jerry api value */
|
||||
{
|
||||
if (JERRY_CONTEXT (vm_top_context_p) != NULL)
|
||||
{
|
||||
return ecma_copy_value (JERRY_CONTEXT (vm_top_context_p)->resource_name);
|
||||
return ecma_copy_value (ecma_get_resource_name (JERRY_CONTEXT (vm_top_context_p)->bytecode_header_p));
|
||||
}
|
||||
}
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
#if ENABLED (JERRY_LINE_INFO)
|
||||
else if (ecma_is_value_object (value))
|
||||
{
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (value);
|
||||
@ -3567,10 +3549,10 @@ jerry_get_resource_name (const jerry_value_t value) /**< jerry api value */
|
||||
|
||||
const ecma_compiled_code_t *bytecode_data_p = ecma_op_function_get_compiled_code (ext_func_p);
|
||||
|
||||
return ecma_copy_value (ecma_op_resource_name (bytecode_data_p));
|
||||
return ecma_copy_value (ecma_get_resource_name (bytecode_data_p));
|
||||
}
|
||||
}
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) */
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
|
||||
JERRY_UNUSED (value);
|
||||
return ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
|
||||
@ -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)
|
||||
/**
|
||||
|
||||
@ -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) */
|
||||
|
||||
@ -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"
|
||||
|
||||
|
||||
@ -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) */
|
||||
|
||||
@ -30,7 +30,7 @@ extern "C"
|
||||
/**
|
||||
* Jerry snapshot format version.
|
||||
*/
|
||||
#define JERRY_SNAPSHOT_VERSION (50u)
|
||||
#define JERRY_SNAPSHOT_VERSION (51u)
|
||||
|
||||
/**
|
||||
* Flags for jerry_generate_snapshot and jerry_generate_function_snapshot.
|
||||
|
||||
@ -210,10 +210,6 @@ struct jerry_context_t
|
||||
uint8_t debugger_max_receive_size; /**< maximum amount of data that can be received */
|
||||
#endif /* ENABLED (JERRY_DEBUGGER) */
|
||||
|
||||
#if ENABLED (JERRY_RESOURCE_NAME)
|
||||
ecma_value_t resource_name; /**< resource name (usually a file name) */
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
|
||||
#if ENABLED (JERRY_MEM_STATS)
|
||||
jmem_heap_stats_t jmem_heap_stats; /**< heap's memory usage statistics */
|
||||
#endif /* ENABLED (JERRY_MEM_STATS) */
|
||||
|
||||
@ -306,7 +306,7 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_THROW, "throw")
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_TRUNC, "trunc")
|
||||
#endif
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_VALUE, "value")
|
||||
#if ENABLED (JERRY_PARSER) && ENABLED (JERRY_RESOURCE_NAME)
|
||||
#if ENABLED (JERRY_PARSER)
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_RESOURCE_EVAL, "<eval>")
|
||||
#endif
|
||||
#if ENABLED (JERRY_BUILTIN_MATH)
|
||||
@ -953,7 +953,7 @@ LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (4, LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_G
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (4, LIT_MAGIC_STRING_DATE_UL)
|
||||
#endif
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (5, LIT_MAGIC_STRING_ARRAY_UL)
|
||||
#if ENABLED (JERRY_PARSER) && ENABLED (JERRY_RESOURCE_NAME)
|
||||
#if ENABLED (JERRY_PARSER)
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (6, LIT_MAGIC_STRING_RESOURCE_EVAL)
|
||||
#elif ENABLED (JERRY_BUILTIN_MATH)
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (6, LIT_MAGIC_STRING_LOG10E_U)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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, \
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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) */
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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 */
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -49,9 +49,6 @@ typedef struct vm_frame_ctx_t
|
||||
struct vm_frame_ctx_t *prev_context_p; /**< previous context */
|
||||
ecma_value_t this_binding; /**< this binding */
|
||||
ecma_value_t block_result; /**< block result */
|
||||
#if ENABLED (JERRY_RESOURCE_NAME)
|
||||
ecma_value_t resource_name; /**< current resource name (usually a file name) */
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
#if ENABLED (JERRY_LINE_INFO)
|
||||
uint32_t current_line; /**< currently executed line */
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) */
|
||||
|
||||
@ -76,13 +76,8 @@ vm_get_backtrace (uint32_t max_depth) /**< maximum backtrace depth, 0 = unlimite
|
||||
|
||||
while (context_p != NULL)
|
||||
{
|
||||
if (context_p->resource_name == ECMA_VALUE_UNDEFINED)
|
||||
{
|
||||
context_p = context_p->prev_context_p;
|
||||
continue;
|
||||
}
|
||||
|
||||
ecma_string_t *str_p = ecma_get_string_from_value (context_p->resource_name);
|
||||
ecma_value_t resource_name = ecma_get_resource_name (context_p->bytecode_header_p);
|
||||
ecma_string_t *str_p = ecma_get_string_from_value (resource_name);
|
||||
ecma_stringbuilder_t builder = ecma_stringbuilder_create ();
|
||||
|
||||
if (ecma_string_is_empty (str_p))
|
||||
|
||||
@ -4090,13 +4090,6 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
continue;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_DEBUGGER) */
|
||||
#if ENABLED (JERRY_RESOURCE_NAME)
|
||||
case VM_OC_RESOURCE_NAME:
|
||||
{
|
||||
frame_ctx_p->resource_name = ecma_op_resource_name (bytecode_header_p);
|
||||
continue;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
#if ENABLED (JERRY_LINE_INFO)
|
||||
case VM_OC_LINE:
|
||||
{
|
||||
@ -4380,9 +4373,6 @@ vm_init_exec (vm_frame_ctx_t *frame_ctx_p, /**< frame context */
|
||||
{
|
||||
frame_ctx_p->prev_context_p = JERRY_CONTEXT (vm_top_context_p);
|
||||
frame_ctx_p->block_result = ECMA_VALUE_UNDEFINED;
|
||||
#if ENABLED (JERRY_RESOURCE_NAME)
|
||||
frame_ctx_p->resource_name = ECMA_VALUE_UNDEFINED;
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
#if ENABLED (JERRY_LINE_INFO)
|
||||
frame_ctx_p->current_line = 0;
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) */
|
||||
|
||||
@ -229,9 +229,6 @@ typedef enum
|
||||
VM_OC_BREAKPOINT_ENABLED, /**< enabled breakpoint for debugger */
|
||||
VM_OC_BREAKPOINT_DISABLED, /**< disabled breakpoint for debugger */
|
||||
#endif /* ENABLED (JERRY_DEBUGGER) */
|
||||
#if ENABLED (JERRY_RESOURCE_NAME)
|
||||
VM_OC_RESOURCE_NAME, /**< resource name of the current function */
|
||||
#endif /* ENABLED (JERRY_RESOURCE_NAME) */
|
||||
#if ENABLED (JERRY_LINE_INFO)
|
||||
VM_OC_LINE, /**< line number of the next statement */
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) */
|
||||
@ -299,9 +296,6 @@ typedef enum
|
||||
VM_OC_BREAKPOINT_ENABLED = VM_OC_NONE, /**< enabled breakpoint for debugger is unused */
|
||||
VM_OC_BREAKPOINT_DISABLED = VM_OC_NONE, /**< disabled breakpoint for debugger is unused */
|
||||
#endif /* !ENABLED (JERRY_DEBUGGER) */
|
||||
#if !ENABLED (JERRY_RESOURCE_NAME)
|
||||
VM_OC_RESOURCE_NAME = VM_OC_NONE, /**< resource name of the current function is unused */
|
||||
#endif /* !ENABLED (JERRY_RESOURCE_NAME) */
|
||||
#if !ENABLED (JERRY_LINE_INFO)
|
||||
VM_OC_LINE = VM_OC_NONE, /**< line number of the next statement is unused */
|
||||
#endif /* !ENABLED (JERRY_LINE_INFO) */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user