Add custom configuration to jerry_parse and its variants (#4620)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -757,28 +757,27 @@ snapshot_load_compiled_code (const uint8_t *base_addr_p, /**< base address of th
|
||||
* error object otherwise
|
||||
*/
|
||||
static jerry_value_t
|
||||
jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< script resource name */
|
||||
size_t resource_name_length, /**< script resource name length */
|
||||
const jerry_char_t *source_p, /**< script source */
|
||||
jerry_generate_snapshot_with_args (const jerry_char_t *source_p, /**< script source */
|
||||
size_t source_size, /**< script source size */
|
||||
const jerry_char_t *args_p, /**< arguments string */
|
||||
size_t args_size, /**< arguments string size */
|
||||
const jerry_parse_options_t *options_p, /**< parsing options,
|
||||
* can be NULL if not used */
|
||||
uint32_t generate_snapshot_opts, /**< jerry_generate_snapshot_opts_t option bits */
|
||||
uint32_t *buffer_p, /**< buffer to save snapshot to */
|
||||
size_t buffer_size) /**< the buffer's size */
|
||||
{
|
||||
/* Currently unused arguments. */
|
||||
JERRY_UNUSED (resource_name_p);
|
||||
JERRY_UNUSED (resource_name_length);
|
||||
uint32_t allowed_options = JERRY_SNAPSHOT_SAVE_STATIC;
|
||||
uint32_t allowed_parse_options = (JERRY_PARSE_STRICT_MODE
|
||||
| JERRY_PARSE_HAS_RESOURCE
|
||||
| JERRY_PARSE_HAS_START);
|
||||
|
||||
ecma_value_t resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
|
||||
#if JERRY_RESOURCE_NAME
|
||||
if (resource_name_length > 0)
|
||||
if ((generate_snapshot_opts & ~allowed_options) != 0
|
||||
|| (options_p != NULL && (options_p->options & ~allowed_parse_options) != 0))
|
||||
{
|
||||
resource_name = ecma_find_or_create_literal_string (resource_name_p, (lit_utf8_size_t) resource_name_length);
|
||||
const char * const error_message_p = "Unsupported generate snapshot flags specified";
|
||||
return jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) error_message_p);
|
||||
}
|
||||
#endif /* JERRY_RESOURCE_NAME */
|
||||
|
||||
snapshot_globals_t globals;
|
||||
const uint32_t aligned_header_size = JERRY_ALIGNUP (sizeof (jerry_snapshot_header_t),
|
||||
@@ -789,15 +788,19 @@ jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< scr
|
||||
globals.regex_found = false;
|
||||
globals.class_found = false;
|
||||
|
||||
uint32_t status_flags = ((generate_snapshot_opts & JERRY_SNAPSHOT_SAVE_STRICT) ? ECMA_PARSE_STRICT_MODE
|
||||
: ECMA_PARSE_NO_OPTS);
|
||||
uint32_t status_flags = ECMA_PARSE_NO_OPTS;
|
||||
|
||||
if (options_p != NULL)
|
||||
{
|
||||
status_flags |= (options_p->options & ECMA_PARSE_STRICT_MODE);
|
||||
}
|
||||
|
||||
ecma_compiled_code_t *bytecode_data_p = parser_parse_script (args_p,
|
||||
args_size,
|
||||
source_p,
|
||||
source_size,
|
||||
resource_name,
|
||||
status_flags);
|
||||
status_flags,
|
||||
(const ecma_parse_options_t *) options_p);
|
||||
|
||||
if (JERRY_UNLIKELY (bytecode_data_p == NULL))
|
||||
{
|
||||
@@ -883,37 +886,27 @@ jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< scr
|
||||
* error object otherwise
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_generate_snapshot (const jerry_char_t *resource_name_p, /**< script resource name */
|
||||
size_t resource_name_length, /**< script resource name length */
|
||||
const jerry_char_t *source_p, /**< script source */
|
||||
jerry_generate_snapshot (const jerry_char_t *source_p, /**< script source */
|
||||
size_t source_size, /**< script source size */
|
||||
const jerry_parse_options_t *options_p, /**< parsing options,
|
||||
* can be NULL if not used */
|
||||
uint32_t generate_snapshot_opts, /**< jerry_generate_snapshot_opts_t option bits */
|
||||
uint32_t *buffer_p, /**< buffer to save snapshot to */
|
||||
size_t buffer_size) /**< the buffer's size */
|
||||
{
|
||||
#if JERRY_SNAPSHOT_SAVE
|
||||
uint32_t allowed_opts = (JERRY_SNAPSHOT_SAVE_STATIC | JERRY_SNAPSHOT_SAVE_STRICT);
|
||||
|
||||
if ((generate_snapshot_opts & ~(allowed_opts)) != 0)
|
||||
{
|
||||
const char * const error_message_p = "Unsupported generate snapshot flags specified";
|
||||
return jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) error_message_p);
|
||||
}
|
||||
|
||||
return jerry_generate_snapshot_with_args (resource_name_p,
|
||||
resource_name_length,
|
||||
source_p,
|
||||
return jerry_generate_snapshot_with_args (source_p,
|
||||
source_size,
|
||||
NULL,
|
||||
0,
|
||||
options_p,
|
||||
generate_snapshot_opts,
|
||||
buffer_p,
|
||||
buffer_size);
|
||||
#else /* !JERRY_SNAPSHOT_SAVE */
|
||||
JERRY_UNUSED (resource_name_p);
|
||||
JERRY_UNUSED (resource_name_length);
|
||||
JERRY_UNUSED (source_p);
|
||||
JERRY_UNUSED (source_size);
|
||||
JERRY_UNUSED (options_p);
|
||||
JERRY_UNUSED (generate_snapshot_opts);
|
||||
JERRY_UNUSED (buffer_p);
|
||||
JERRY_UNUSED (buffer_size);
|
||||
@@ -1806,41 +1799,31 @@ jerry_get_literals_from_snapshot (const uint32_t *snapshot_p, /**< input snapsho
|
||||
* error object otherwise
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_generate_function_snapshot (const jerry_char_t *resource_name_p, /**< script resource name */
|
||||
size_t resource_name_length, /**< script resource name length */
|
||||
const jerry_char_t *source_p, /**< script source */
|
||||
jerry_generate_function_snapshot (const jerry_char_t *source_p, /**< script source */
|
||||
size_t source_size, /**< script source size */
|
||||
const jerry_char_t *args_p, /**< arguments string */
|
||||
size_t args_size, /**< arguments string size */
|
||||
const jerry_parse_options_t *options_p, /**< parsing options,
|
||||
* can be NULL if not used */
|
||||
uint32_t generate_snapshot_opts, /**< jerry_generate_snapshot_opts_t option bits */
|
||||
uint32_t *buffer_p, /**< buffer to save snapshot to */
|
||||
size_t buffer_size) /**< the buffer's size */
|
||||
{
|
||||
#if JERRY_SNAPSHOT_SAVE
|
||||
uint32_t allowed_opts = (JERRY_SNAPSHOT_SAVE_STATIC | JERRY_SNAPSHOT_SAVE_STRICT);
|
||||
|
||||
if ((generate_snapshot_opts & ~(allowed_opts)) != 0)
|
||||
{
|
||||
const char * const error_message_p = "Unsupported generate snapshot flags specified";
|
||||
return jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) error_message_p);
|
||||
}
|
||||
|
||||
return jerry_generate_snapshot_with_args (resource_name_p,
|
||||
resource_name_length,
|
||||
source_p,
|
||||
return jerry_generate_snapshot_with_args (source_p,
|
||||
source_size,
|
||||
args_p,
|
||||
args_size,
|
||||
options_p,
|
||||
generate_snapshot_opts,
|
||||
buffer_p,
|
||||
buffer_size);
|
||||
#else /* !JERRY_SNAPSHOT_SAVE */
|
||||
JERRY_UNUSED (resource_name_p);
|
||||
JERRY_UNUSED (resource_name_length);
|
||||
JERRY_UNUSED (source_p);
|
||||
JERRY_UNUSED (source_size);
|
||||
JERRY_UNUSED (args_p);
|
||||
JERRY_UNUSED (args_size);
|
||||
JERRY_UNUSED (options_p);
|
||||
JERRY_UNUSED (generate_snapshot_opts);
|
||||
JERRY_UNUSED (buffer_p);
|
||||
JERRY_UNUSED (buffer_size);
|
||||
|
||||
+83
-53
@@ -82,6 +82,15 @@ JERRY_STATIC_ASSERT ((int) JERRY_PROP_NO_OPTS == (int) ECMA_PROP_NO_OPTS
|
||||
&& (int) JERRY_PROP_SHOULD_THROW == (int) ECMA_PROP_SHOULD_THROW,
|
||||
jerry_prop_desc_flags_must_be_equal_to_ecma_prop_desc_flags);
|
||||
|
||||
JERRY_STATIC_ASSERT ((int) ECMA_PARSE_STRICT_MODE == (int) JERRY_PARSE_STRICT_MODE
|
||||
&& (int) ECMA_PARSE_MODULE == (int) JERRY_PARSE_MODULE
|
||||
&& (int) ECMA_PARSE_HAS_RESOURCE == (int) JERRY_PARSE_HAS_RESOURCE
|
||||
&& (int) ECMA_PARSE_HAS_START == (int) JERRY_PARSE_HAS_START,
|
||||
ecma_parse_config_options_t_must_be_equal_to_jerry_parse_config_options_t);
|
||||
|
||||
JERRY_STATIC_ASSERT (sizeof (jerry_parse_options_t) == sizeof (ecma_parse_options_t),
|
||||
ecma_parse_options_t_and_jerry_parse_options_t_must_be_the_same);
|
||||
|
||||
#if JERRY_BUILTIN_REGEXP
|
||||
JERRY_STATIC_ASSERT ((int) RE_FLAG_GLOBAL == (int) JERRY_REGEXP_FLAG_GLOBAL
|
||||
&& (int) RE_FLAG_MULTILINE == (int) JERRY_REGEXP_FLAG_MULTILINE
|
||||
@@ -445,7 +454,7 @@ jerry_run_simple (const jerry_char_t *script_source_p, /**< script source */
|
||||
|
||||
jerry_init (flags);
|
||||
|
||||
jerry_value_t parse_ret_val = jerry_parse (NULL, 0, script_source_p, script_source_size, JERRY_PARSE_NO_OPTS);
|
||||
jerry_value_t parse_ret_val = jerry_parse (script_source_p, script_source_size, NULL);
|
||||
|
||||
if (!ecma_is_value_error_reference (parse_ret_val))
|
||||
{
|
||||
@@ -473,42 +482,49 @@ jerry_run_simple (const jerry_char_t *script_source_p, /**< script source */
|
||||
* thrown error - otherwise
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_parse (const jerry_char_t *resource_name_p, /**< resource name (usually a file name) */
|
||||
size_t resource_name_length, /**< length of resource name */
|
||||
const jerry_char_t *source_p, /**< script source */
|
||||
jerry_parse (const jerry_char_t *source_p, /**< script source */
|
||||
size_t source_size, /**< script source size */
|
||||
uint32_t parse_opts) /**< jerry_parse_opts_t option bits */
|
||||
const jerry_parse_options_t *options_p) /**< parsing options, can be NULL if not used */
|
||||
{
|
||||
#if JERRY_DEBUGGER && JERRY_PARSER
|
||||
if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
|
||||
&& resource_name_length > 0)
|
||||
{
|
||||
jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE_NAME,
|
||||
JERRY_DEBUGGER_NO_SUBTYPE,
|
||||
resource_name_p,
|
||||
resource_name_length);
|
||||
}
|
||||
#else /* !(JERRY_DEBUGGER && JERRY_PARSER) */
|
||||
JERRY_UNUSED (resource_name_p);
|
||||
JERRY_UNUSED (resource_name_length);
|
||||
#endif /* JERRY_DEBUGGER && JERRY_PARSER */
|
||||
|
||||
#if JERRY_PARSER
|
||||
jerry_assert_api_available ();
|
||||
|
||||
ecma_value_t resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
uint32_t allowed_parse_options = (JERRY_PARSE_STRICT_MODE
|
||||
| JERRY_PARSE_MODULE
|
||||
| JERRY_PARSE_HAS_RESOURCE
|
||||
| JERRY_PARSE_HAS_START);
|
||||
|
||||
#if JERRY_RESOURCE_NAME
|
||||
if (resource_name_length > 0)
|
||||
if (options_p != NULL && (options_p->options & ~allowed_parse_options) != 0)
|
||||
{
|
||||
resource_name = ecma_find_or_create_literal_string (resource_name_p, (lit_utf8_size_t) resource_name_length);
|
||||
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (wrong_args_msg_p)));
|
||||
}
|
||||
#endif /* JERRY_PARSER */
|
||||
|
||||
#if JERRY_DEBUGGER && JERRY_PARSER
|
||||
if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
|
||||
&& options_p != NULL
|
||||
&& (options_p->options & JERRY_PARSE_HAS_RESOURCE)
|
||||
&& options_p->resource_name_length > 0)
|
||||
{
|
||||
jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE_NAME,
|
||||
JERRY_DEBUGGER_NO_SUBTYPE,
|
||||
options_p->resource_name_p,
|
||||
options_p->resource_name_length);
|
||||
}
|
||||
#endif /* JERRY_DEBUGGER && JERRY_PARSER */
|
||||
|
||||
#if JERRY_PARSER
|
||||
uint32_t parse_opts = 0;
|
||||
|
||||
if (options_p != NULL)
|
||||
{
|
||||
parse_opts |= options_p->options & (JERRY_PARSE_STRICT_MODE | JERRY_PARSE_MODULE);
|
||||
}
|
||||
#endif /* JERRY_RESOURCE_NAME */
|
||||
|
||||
if ((parse_opts & JERRY_PARSE_MODULE) != 0)
|
||||
{
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
ecma_module_initialize_context (ecma_get_string_from_value (resource_name));
|
||||
ecma_module_initialize_context ((const ecma_parse_options_t *) options_p);
|
||||
#else /* !JERRY_MODULE_SYSTEM */
|
||||
return jerry_throw (ecma_raise_syntax_error (ECMA_ERR_MSG ("Module system has been disabled")));
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
@@ -518,8 +534,8 @@ jerry_parse (const jerry_char_t *resource_name_p, /**< resource name (usually a
|
||||
0,
|
||||
source_p,
|
||||
source_size,
|
||||
resource_name,
|
||||
parse_opts);
|
||||
parse_opts,
|
||||
(const ecma_parse_options_t *) options_p);
|
||||
|
||||
if (JERRY_UNLIKELY (bytecode_data_p == NULL))
|
||||
{
|
||||
@@ -570,7 +586,7 @@ jerry_parse (const jerry_char_t *resource_name_p, /**< resource name (usually a
|
||||
#else /* !JERRY_PARSER */
|
||||
JERRY_UNUSED (source_p);
|
||||
JERRY_UNUSED (source_size);
|
||||
JERRY_UNUSED (parse_opts);
|
||||
JERRY_UNUSED (options_p);
|
||||
|
||||
return jerry_throw (ecma_raise_syntax_error (ECMA_ERR_MSG (error_parser_not_supported_p)));
|
||||
#endif /* JERRY_PARSER */
|
||||
@@ -584,38 +600,45 @@ jerry_parse (const jerry_char_t *resource_name_p, /**< resource name (usually a
|
||||
* thrown error - otherwise
|
||||
*/
|
||||
jerry_value_t
|
||||
jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (usually a file name) */
|
||||
size_t resource_name_length, /**< length of resource name */
|
||||
const jerry_char_t *arg_list_p, /**< script source */
|
||||
jerry_parse_function (const jerry_char_t *arg_list_p, /**< script source */
|
||||
size_t arg_list_size, /**< script source size */
|
||||
const jerry_char_t *source_p, /**< script source */
|
||||
size_t source_size, /**< script source size */
|
||||
uint32_t parse_opts) /**< jerry_parse_opts_t option bits */
|
||||
const jerry_parse_options_t *options_p) /**< parsing options, can be NULL if not used */
|
||||
{
|
||||
#if JERRY_DEBUGGER && JERRY_PARSER
|
||||
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
|
||||
{
|
||||
jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE_NAME,
|
||||
JERRY_DEBUGGER_NO_SUBTYPE,
|
||||
resource_name_p,
|
||||
resource_name_length);
|
||||
}
|
||||
#else /* !(JERRY_DEBUGGER && JERRY_PARSER) */
|
||||
JERRY_UNUSED (resource_name_p);
|
||||
JERRY_UNUSED (resource_name_length);
|
||||
#endif /* JERRY_DEBUGGER && JERRY_PARSER */
|
||||
|
||||
#if JERRY_PARSER
|
||||
jerry_assert_api_available ();
|
||||
|
||||
ecma_value_t resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
uint32_t allowed_parse_options = (JERRY_PARSE_STRICT_MODE
|
||||
| JERRY_PARSE_HAS_RESOURCE
|
||||
| JERRY_PARSE_HAS_START);
|
||||
|
||||
#if JERRY_RESOURCE_NAME
|
||||
if (resource_name_length > 0)
|
||||
if (options_p != NULL && (options_p->options & ~allowed_parse_options) != 0)
|
||||
{
|
||||
resource_name = ecma_find_or_create_literal_string (resource_name_p, (lit_utf8_size_t) resource_name_length);
|
||||
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (wrong_args_msg_p)));
|
||||
}
|
||||
#endif /* JERRY_PARSER */
|
||||
|
||||
#if JERRY_DEBUGGER && JERRY_PARSER
|
||||
if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
|
||||
&& options_p != NULL
|
||||
&& (options_p->options & JERRY_PARSE_HAS_RESOURCE)
|
||||
&& options_p->resource_name_length > 0)
|
||||
{
|
||||
jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE_NAME,
|
||||
JERRY_DEBUGGER_NO_SUBTYPE,
|
||||
options_p->resource_name_p,
|
||||
options_p->resource_name_length);
|
||||
}
|
||||
#endif /* JERRY_DEBUGGER && JERRY_PARSER */
|
||||
|
||||
#if JERRY_PARSER
|
||||
uint32_t parse_opts = 0;
|
||||
|
||||
if (options_p != NULL)
|
||||
{
|
||||
parse_opts |= options_p->options & JERRY_PARSE_STRICT_MODE;
|
||||
}
|
||||
#endif /* JERRY_RESOURCE_NAME */
|
||||
|
||||
if (arg_list_p == NULL)
|
||||
{
|
||||
@@ -627,8 +650,8 @@ jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (u
|
||||
arg_list_size,
|
||||
source_p,
|
||||
source_size,
|
||||
resource_name,
|
||||
parse_opts);
|
||||
parse_opts,
|
||||
(const ecma_parse_options_t *) options_p);
|
||||
|
||||
if (JERRY_UNLIKELY (bytecode_p == NULL))
|
||||
{
|
||||
@@ -651,7 +674,7 @@ jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (u
|
||||
JERRY_UNUSED (arg_list_size);
|
||||
JERRY_UNUSED (source_p);
|
||||
JERRY_UNUSED (source_size);
|
||||
JERRY_UNUSED (parse_opts);
|
||||
JERRY_UNUSED (options_p);
|
||||
|
||||
return jerry_throw (ecma_raise_syntax_error (ECMA_ERR_MSG (error_parser_not_supported_p)));
|
||||
#endif /* JERRY_PARSER */
|
||||
@@ -731,6 +754,13 @@ jerry_eval (const jerry_char_t *source_p, /**< source code */
|
||||
{
|
||||
jerry_assert_api_available ();
|
||||
|
||||
uint32_t allowed_parse_options = JERRY_PARSE_STRICT_MODE;
|
||||
|
||||
if ((parse_opts & ~allowed_parse_options) != 0)
|
||||
{
|
||||
return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (wrong_args_msg_p)));
|
||||
}
|
||||
|
||||
return jerry_return (ecma_op_eval_chars_buffer ((const lit_utf8_byte_t *) source_p,
|
||||
source_size,
|
||||
parse_opts));
|
||||
|
||||
@@ -331,6 +331,32 @@ typedef struct ecma_native_pointer_t
|
||||
struct ecma_native_pointer_t *next_p; /**< points to the next ecma_native_pointer_t element */
|
||||
} ecma_native_pointer_t;
|
||||
|
||||
/**
|
||||
* Option bits for ecma_parse_options_t.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/* bit 0: ECMA_PARSE_STRICT_MODE */
|
||||
/* bit 1: ECMA_PARSE_MODULE */
|
||||
ECMA_PARSE_HAS_RESOURCE = (1 << 2), /**< resource_name_p and resource_name_length fields are valid */
|
||||
ECMA_PARSE_HAS_START = (1 << 3), /**< start_line and start_column fields are valid */
|
||||
} ecma_parse_option_feature_t;
|
||||
|
||||
/**
|
||||
* Variable configuration options for parsing functions such as ecma_parse or ecma_parse_function.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t options; /**< combination of ecma_parse_option_feature_t values
|
||||
* which enables parsing features */
|
||||
const lit_utf8_byte_t *resource_name_p; /**< resource name (usually a file name)
|
||||
* if ECMA_PARSE_HAS_RESOURCE is set in options */
|
||||
size_t resource_name_length; /**< length of resource name
|
||||
* if ECMA_PARSE_HAS_RESOURCE is set in options */
|
||||
uint32_t start_line; /**< start line of the source code if ECMA_PARSE_HAS_START is set in options */
|
||||
uint32_t start_column; /**< start column of the source code if ECMA_PARSE_HAS_START is set in options */
|
||||
} ecma_parse_options_t;
|
||||
|
||||
#if JERRY_ESNEXT
|
||||
|
||||
/**
|
||||
|
||||
@@ -198,28 +198,27 @@ ecma_module_find_native_module (ecma_string_t *const path_p)
|
||||
* Initialize context variables for the root module.
|
||||
*/
|
||||
void
|
||||
ecma_module_initialize_context (ecma_string_t *root_path_p) /**< root module */
|
||||
ecma_module_initialize_context (const ecma_parse_options_t *options_p) /**< configuration options */
|
||||
{
|
||||
JERRY_ASSERT (JERRY_CONTEXT (module_current_p) == NULL);
|
||||
JERRY_ASSERT (JERRY_CONTEXT (module_list_p) == NULL);
|
||||
|
||||
lit_utf8_size_t path_str_size;
|
||||
uint8_t flags = ECMA_STRING_FLAG_EMPTY;
|
||||
ecma_string_t *path_p = ecma_get_magic_string (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
|
||||
const lit_utf8_byte_t *path_str_chars_p = ecma_string_get_chars (root_path_p,
|
||||
&path_str_size,
|
||||
NULL,
|
||||
NULL,
|
||||
&flags);
|
||||
|
||||
ecma_string_t *path_p = ecma_module_create_normalized_path (path_str_chars_p,
|
||||
path_str_size,
|
||||
NULL);
|
||||
|
||||
if (path_p == NULL)
|
||||
if (options_p != NULL
|
||||
&& (options_p->options & JERRY_PARSE_HAS_RESOURCE)
|
||||
&& options_p->resource_name_length > 0)
|
||||
{
|
||||
ecma_ref_ecma_string (root_path_p);
|
||||
path_p = root_path_p;
|
||||
const lit_utf8_byte_t *path_str_chars_p = options_p->resource_name_p;
|
||||
lit_utf8_size_t path_str_size = (lit_utf8_size_t) options_p->resource_name_length;
|
||||
|
||||
path_p = ecma_module_create_normalized_path (path_str_chars_p,
|
||||
path_str_size,
|
||||
NULL);
|
||||
if (path_p == NULL)
|
||||
{
|
||||
path_p = ecma_new_ecma_string_from_utf8_converted_to_cesu8 (path_str_chars_p, path_str_size);
|
||||
}
|
||||
}
|
||||
|
||||
ecma_module_t *module_p = (ecma_module_t *) jmem_heap_alloc_block (sizeof (ecma_module_t));
|
||||
@@ -1000,10 +999,10 @@ ecma_module_parse (ecma_module_t *module_p) /**< module */
|
||||
|
||||
size_t source_size = 0;
|
||||
uint8_t *source_p = jerry_port_read_source ((const char *) module_path_p, &source_size);
|
||||
jmem_heap_free_block (module_path_p, module_path_size + 1);
|
||||
|
||||
if (source_p == NULL)
|
||||
{
|
||||
jmem_heap_free_block (module_path_p, module_path_size + 1);
|
||||
return ecma_raise_syntax_error (ECMA_ERR_MSG ("File not found"));
|
||||
}
|
||||
|
||||
@@ -1020,14 +1019,21 @@ ecma_module_parse (ecma_module_t *module_p) /**< module */
|
||||
}
|
||||
#endif /* JERRY_DEBUGGER && JERRY_PARSER */
|
||||
|
||||
/* TODO: Improve this code in the future. */
|
||||
ecma_parse_options_t parse_options;
|
||||
parse_options.options = ECMA_PARSE_STRICT_MODE | ECMA_PARSE_MODULE | ECMA_PARSE_HAS_RESOURCE;
|
||||
parse_options.resource_name_p = module_path_p;
|
||||
parse_options.resource_name_length = module_path_size;
|
||||
|
||||
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);
|
||||
ECMA_PARSE_STRICT_MODE | ECMA_PARSE_MODULE,
|
||||
&parse_options);
|
||||
|
||||
JERRY_CONTEXT (module_current_p) = prev_module_p;
|
||||
jmem_heap_free_block (module_path_p, module_path_size + 1);
|
||||
jerry_port_release_source (source_p);
|
||||
|
||||
if (JERRY_UNLIKELY (bytecode_p == NULL))
|
||||
|
||||
@@ -126,7 +126,7 @@ ecma_module_t *ecma_module_find_native_module (ecma_string_t *const path_p);
|
||||
ecma_value_t ecma_module_parse_referenced_modules (void);
|
||||
ecma_value_t ecma_module_initialize (ecma_module_t *module_p);
|
||||
|
||||
void ecma_module_initialize_context (ecma_string_t *root_path_p);
|
||||
void ecma_module_initialize_context (const ecma_parse_options_t *options_p);
|
||||
void ecma_module_cleanup_context (void);
|
||||
|
||||
void ecma_module_release_module_nodes (ecma_module_node_t *module_node_p);
|
||||
|
||||
@@ -95,13 +95,12 @@ ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, /**< code characters b
|
||||
ECMA_CLEAR_LOCAL_PARSE_OPTS ();
|
||||
#endif /* JERRY_ESNEXT */
|
||||
|
||||
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);
|
||||
parse_opts,
|
||||
NULL);
|
||||
|
||||
if (JERRY_UNLIKELY (bytecode_p == NULL))
|
||||
{
|
||||
|
||||
@@ -457,13 +457,12 @@ 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);
|
||||
|
||||
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);
|
||||
parse_opts,
|
||||
NULL);
|
||||
|
||||
ECMA_FINALIZE_UTF8_STRING (function_body_buffer_p, function_body_buffer_size);
|
||||
ECMA_FINALIZE_UTF8_STRING (arguments_buffer_p, arguments_buffer_size);
|
||||
|
||||
@@ -113,16 +113,6 @@ typedef enum
|
||||
JERRY_FEATURE__COUNT /**< number of features. NOTE: must be at the end of the list */
|
||||
} jerry_feature_t;
|
||||
|
||||
/**
|
||||
* Option flags for jerry_parse and jerry_parse_function functions.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
JERRY_PARSE_NO_OPTS = 0, /**< no options passed */
|
||||
JERRY_PARSE_STRICT_MODE = (1 << 0), /**< enable strict mode */
|
||||
JERRY_PARSE_MODULE = (1 << 1) /**< parse source as an ECMAScript module */
|
||||
} jerry_parse_opts_t;
|
||||
|
||||
/**
|
||||
* GC operational modes.
|
||||
*/
|
||||
@@ -168,7 +158,33 @@ typedef uint32_t jerry_length_t;
|
||||
typedef uint32_t jerry_value_t;
|
||||
|
||||
/**
|
||||
* Flags of ECMA property descriptor.
|
||||
* Option bits for jerry_parse_options_t.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
JERRY_PARSE_NO_OPTS = 0, /**< no options passed */
|
||||
JERRY_PARSE_STRICT_MODE = (1 << 0), /**< enable strict mode */
|
||||
JERRY_PARSE_MODULE = (1 << 1), /**< parse source as an ECMAScript module */
|
||||
JERRY_PARSE_HAS_RESOURCE = (1 << 2), /**< resource_name_p and resource_name_length fields are valid */
|
||||
JERRY_PARSE_HAS_START = (1 << 3), /**< start_line and start_column fields are valid */
|
||||
} jerry_parse_option_enable_feature_t;
|
||||
|
||||
/**
|
||||
* Various configuration options for parsing functions such as jerry_parse or jerry_parse_function.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t options; /**< combination of jerry_parse_option_enable_feature_t values */
|
||||
const jerry_char_t *resource_name_p; /**< resource name (usually a file name)
|
||||
* if JERRY_PARSE_HAS_RESOURCE is set in options */
|
||||
size_t resource_name_length; /**< length of resource name
|
||||
* if JERRY_PARSE_HAS_RESOURCE is set in options */
|
||||
uint32_t start_line; /**< start line of the source code if JERRY_PARSE_HAS_START is set in options */
|
||||
uint32_t start_column; /**< start column of the source code if JERRY_PARSE_HAS_START is set in options */
|
||||
} jerry_parse_options_t;
|
||||
|
||||
/**
|
||||
* Description of ECMA property descriptor.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
@@ -411,11 +427,11 @@ bool jerry_get_memory_stats (jerry_heap_stats_t *out_stats_p);
|
||||
* Parser and executor functions.
|
||||
*/
|
||||
bool jerry_run_simple (const jerry_char_t *script_source_p, size_t script_source_size, jerry_init_flag_t flags);
|
||||
jerry_value_t jerry_parse (const jerry_char_t *resource_name_p, size_t resource_name_length,
|
||||
const jerry_char_t *source_p, size_t source_size, uint32_t parse_opts);
|
||||
jerry_value_t jerry_parse_function (const jerry_char_t *resource_name_p, size_t resource_name_length,
|
||||
const jerry_char_t *arg_list_p, size_t arg_list_size,
|
||||
const jerry_char_t *source_p, size_t source_size, uint32_t parse_opts);
|
||||
jerry_value_t jerry_parse (const jerry_char_t *source_p, size_t source_size,
|
||||
const jerry_parse_options_t *options_p);
|
||||
jerry_value_t jerry_parse_function (const jerry_char_t *arg_list_p, size_t arg_list_size,
|
||||
const jerry_char_t *source_p, size_t source_size,
|
||||
const jerry_parse_options_t *options_p);
|
||||
jerry_value_t jerry_run (const jerry_value_t func_val);
|
||||
jerry_value_t jerry_eval (const jerry_char_t *source_p, size_t source_size, uint32_t parse_opts);
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ extern "C"
|
||||
typedef enum
|
||||
{
|
||||
JERRY_SNAPSHOT_SAVE_STATIC = (1u << 0), /**< static snapshot */
|
||||
JERRY_SNAPSHOT_SAVE_STRICT = (1u << 1), /**< strict mode code */
|
||||
} jerry_generate_snapshot_opts_t;
|
||||
|
||||
/**
|
||||
@@ -53,14 +52,14 @@ typedef enum
|
||||
/**
|
||||
* Snapshot functions.
|
||||
*/
|
||||
jerry_value_t jerry_generate_snapshot (const jerry_char_t *resource_name_p, size_t resource_name_length,
|
||||
const jerry_char_t *source_p, size_t source_size,
|
||||
uint32_t generate_snapshot_opts, uint32_t *buffer_p, size_t buffer_size);
|
||||
jerry_value_t jerry_generate_function_snapshot (const jerry_char_t *resource_name_p, size_t resource_name_length,
|
||||
const jerry_char_t *source_p, size_t source_size,
|
||||
jerry_value_t jerry_generate_snapshot (const jerry_char_t *source_p, size_t source_size,
|
||||
const jerry_parse_options_t *options_p, uint32_t generate_snapshot_opts,
|
||||
uint32_t *buffer_p, size_t buffer_size);
|
||||
jerry_value_t jerry_generate_function_snapshot (const jerry_char_t *source_p, size_t source_size,
|
||||
const jerry_char_t *args_p, size_t args_size,
|
||||
uint32_t generate_snapshot_opts, uint32_t *buffer_p,
|
||||
size_t buffer_size);
|
||||
const jerry_parse_options_t *options_p,
|
||||
uint32_t generate_snapshot_opts,
|
||||
uint32_t *buffer_p, size_t buffer_size);
|
||||
|
||||
jerry_value_t jerry_exec_snapshot (const uint32_t *snapshot_p, size_t snapshot_size,
|
||||
size_t func_index, uint32_t exec_snapshot_opts);
|
||||
|
||||
@@ -313,7 +313,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 JERRY_PARSER
|
||||
#if JERRY_PARSER && JERRY_RESOURCE_NAME
|
||||
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_RESOURCE_EVAL, "<eval>")
|
||||
#endif
|
||||
#if JERRY_BUILTIN_BIGINT
|
||||
@@ -1070,7 +1070,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 JERRY_PARSER
|
||||
#if JERRY_PARSER && JERRY_RESOURCE_NAME
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (6, LIT_MAGIC_STRING_RESOURCE_EVAL)
|
||||
#elif JERRY_BUILTIN_BIGINT
|
||||
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (6, LIT_MAGIC_STRING_BIGINT_UL)
|
||||
|
||||
@@ -3694,6 +3694,24 @@ lexer_compare_literal_to_string (parser_context_t *context_p, /**< context */
|
||||
&& memcmp (context_p->token.lit_location.char_p, string_p, string_length) == 0);
|
||||
} /* lexer_compare_literal_to_string */
|
||||
|
||||
/**
|
||||
* Initialize line info to its default value
|
||||
*/
|
||||
void
|
||||
lexer_init_line_info (parser_context_t *context_p) /**< context */
|
||||
{
|
||||
context_p->line = 1;
|
||||
context_p->column = 1;
|
||||
|
||||
const ecma_parse_options_t *options_p = context_p->options_p;
|
||||
|
||||
if (options_p != NULL && (options_p->options & ECMA_PARSE_HAS_START))
|
||||
{
|
||||
context_p->line = (options_p->start_line > 0) ? options_p->start_line : 1;
|
||||
context_p->column = (options_p->start_column > 0) ? options_p->start_column : 1;
|
||||
}
|
||||
} /* lexer_init_line_info */
|
||||
|
||||
/**
|
||||
* Convert binary lvalue token to binary token
|
||||
* e.g. += -> +
|
||||
|
||||
@@ -546,6 +546,7 @@ typedef struct
|
||||
uint32_t global_status_flags; /**< global status flags */
|
||||
uint16_t stack_depth; /**< current stack depth */
|
||||
uint16_t stack_limit; /**< maximum stack depth */
|
||||
const ecma_parse_options_t *options_p; /**< parse options */
|
||||
parser_saved_context_t *last_context_p; /**< last saved context */
|
||||
parser_stack_iterator_t last_statement; /**< last statement position */
|
||||
|
||||
@@ -781,6 +782,7 @@ bool lexer_token_is_let (parser_context_t *context_p);
|
||||
bool lexer_token_is_async (parser_context_t *context_p);
|
||||
#endif /* JERRY_ESNEXT */
|
||||
bool lexer_compare_literal_to_string (parser_context_t *context_p, const char *string_p, size_t string_length);
|
||||
void lexer_init_line_info (parser_context_t *context_p);
|
||||
uint8_t lexer_convert_binary_lvalue_token_to_binary (uint8_t token);
|
||||
|
||||
/**
|
||||
|
||||
@@ -1794,20 +1794,13 @@ 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 */
|
||||
const ecma_parse_options_t *options_p) /**< additional configuration options */
|
||||
{
|
||||
parser_context_t context;
|
||||
ecma_compiled_code_t *compiled_code_p;
|
||||
|
||||
context.error = PARSER_ERR_NO_ERROR;
|
||||
|
||||
if (error_location_p != NULL)
|
||||
{
|
||||
error_location_p->error = PARSER_ERR_NO_ERROR;
|
||||
}
|
||||
|
||||
context.status_flags = parse_opts & PARSER_STRICT_MODE_MASK;
|
||||
context.global_status_flags = parse_opts;
|
||||
|
||||
@@ -1842,16 +1835,29 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
|
||||
|
||||
context.stack_depth = 0;
|
||||
context.stack_limit = 0;
|
||||
context.options_p = options_p;
|
||||
context.last_context_p = NULL;
|
||||
context.last_statement.current_p = NULL;
|
||||
|
||||
context.token.flags = 0;
|
||||
context.line = 1;
|
||||
context.column = 1;
|
||||
lexer_init_line_info (&context);
|
||||
|
||||
#if JERRY_RESOURCE_NAME
|
||||
ecma_value_t resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_ANON);
|
||||
|
||||
if (context.global_status_flags & ECMA_PARSE_EVAL)
|
||||
{
|
||||
resource_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_RESOURCE_EVAL);
|
||||
}
|
||||
|
||||
if (context.options_p != NULL
|
||||
&& (context.options_p->options & JERRY_PARSE_HAS_RESOURCE)
|
||||
&& context.options_p->resource_name_length > 0)
|
||||
{
|
||||
resource_name = ecma_find_or_create_literal_string (context.options_p->resource_name_p,
|
||||
(lit_utf8_size_t) context.options_p->resource_name_length);
|
||||
}
|
||||
|
||||
context.resource_name = resource_name;
|
||||
#else /* !JERRY_RESOURCE_NAME */
|
||||
JERRY_UNUSED (resource_name);
|
||||
#endif /* !JERRY_RESOURCE_NAME */
|
||||
|
||||
scanner_info_t scanner_info_end;
|
||||
@@ -1912,12 +1918,9 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
|
||||
{
|
||||
JERRY_ASSERT (context.error == PARSER_ERR_OUT_OF_MEMORY);
|
||||
|
||||
if (error_location_p != NULL)
|
||||
{
|
||||
error_location_p->error = context.error;
|
||||
error_location_p->line = context.token.line;
|
||||
error_location_p->column = context.token.column;
|
||||
}
|
||||
/* 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 NULL;
|
||||
}
|
||||
|
||||
@@ -1933,9 +1936,8 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
|
||||
}
|
||||
|
||||
context.u.allocated_buffer_p = NULL;
|
||||
context.line = 1;
|
||||
context.column = 1;
|
||||
context.token.flags = 0;
|
||||
lexer_init_line_info (&context);
|
||||
|
||||
parser_stack_init (&context);
|
||||
|
||||
@@ -1970,8 +1972,7 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
|
||||
|
||||
context.source_p = source_p;
|
||||
context.source_end_p = source_p + source_size;
|
||||
context.line = 1;
|
||||
context.column = 1;
|
||||
lexer_init_line_info (&context);
|
||||
|
||||
lexer_next_token (&context);
|
||||
}
|
||||
@@ -2056,13 +2057,6 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
|
||||
}
|
||||
#endif
|
||||
|
||||
if (error_location_p != NULL)
|
||||
{
|
||||
error_location_p->error = context.error;
|
||||
error_location_p->line = context.token.line;
|
||||
error_location_p->column = context.token.column;
|
||||
}
|
||||
|
||||
compiled_code_p = NULL;
|
||||
parser_free_literals (&context.literal_pool);
|
||||
parser_cbc_stream_free (&context.byte_code);
|
||||
@@ -2085,7 +2079,69 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
|
||||
|
||||
parser_stack_free (&context);
|
||||
|
||||
return compiled_code_p;
|
||||
if (compiled_code_p != NULL)
|
||||
{
|
||||
return compiled_code_p;
|
||||
}
|
||||
|
||||
#if JERRY_DEBUGGER
|
||||
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
|
||||
{
|
||||
jerry_debugger_send_type (JERRY_DEBUGGER_PARSE_ERROR);
|
||||
}
|
||||
#endif /* JERRY_DEBUGGER */
|
||||
|
||||
if (context.error == PARSER_ERR_OUT_OF_MEMORY)
|
||||
{
|
||||
/* 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 NULL;
|
||||
}
|
||||
|
||||
#if JERRY_ERROR_MESSAGES
|
||||
ecma_string_t *err_str_p;
|
||||
|
||||
if (context.error == PARSER_ERR_INVALID_REGEXP)
|
||||
{
|
||||
ecma_value_t error = jcontext_take_exception ();
|
||||
ecma_property_t *prop_p = ecma_find_named_property (ecma_get_object_from_value (error),
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_MESSAGE));
|
||||
ecma_free_value (error);
|
||||
JERRY_ASSERT (prop_p);
|
||||
err_str_p = ecma_get_string_from_value (ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
|
||||
ecma_ref_ecma_string (err_str_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
const lit_utf8_byte_t *err_bytes_p = (const lit_utf8_byte_t *) parser_error_to_string (context.error);
|
||||
lit_utf8_size_t err_bytes_size = lit_zt_utf8_string_size (err_bytes_p);
|
||||
err_str_p = ecma_new_ecma_string_from_utf8 (err_bytes_p, err_bytes_size);
|
||||
}
|
||||
ecma_value_t err_str_val = ecma_make_string_value (err_str_p);
|
||||
ecma_value_t line_str_val = ecma_make_uint32_value (context.token.line);
|
||||
ecma_value_t col_str_val = ecma_make_uint32_value (context.token.column);
|
||||
|
||||
ecma_raise_standard_error_with_format (ECMA_ERROR_SYNTAX,
|
||||
"% [%:%:%]",
|
||||
err_str_val,
|
||||
context.resource_name,
|
||||
line_str_val,
|
||||
col_str_val);
|
||||
|
||||
ecma_free_value (col_str_val);
|
||||
ecma_free_value (line_str_val);
|
||||
ecma_deref_ecma_string (err_str_p);
|
||||
#else /* !JERRY_ERROR_MESSAGES */
|
||||
if (context.error == PARSER_ERR_INVALID_REGEXP)
|
||||
{
|
||||
jcontext_release_exception ();
|
||||
}
|
||||
|
||||
ecma_raise_syntax_error ("");
|
||||
#endif /* JERRY_ERROR_MESSAGES */
|
||||
|
||||
return NULL;
|
||||
} /* parser_parse_source */
|
||||
|
||||
/**
|
||||
@@ -2788,11 +2844,10 @@ 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 */
|
||||
ecma_value_t resource_name, /**< resource name */
|
||||
uint32_t parse_opts) /**< ecma_parse_opts_t option bits */
|
||||
uint32_t parse_opts, /**< ecma_parse_opts_t option bits */
|
||||
const ecma_parse_options_t *options_p) /**< additional configuration options */
|
||||
{
|
||||
#if JERRY_PARSER
|
||||
parser_error_location_t parser_error;
|
||||
|
||||
#if JERRY_DEBUGGER
|
||||
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
|
||||
@@ -2808,69 +2863,12 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */
|
||||
arg_list_size,
|
||||
source_p,
|
||||
source_size,
|
||||
resource_name,
|
||||
parse_opts,
|
||||
&parser_error);
|
||||
options_p);
|
||||
|
||||
if (JERRY_UNLIKELY (bytecode_p == NULL))
|
||||
{
|
||||
#if JERRY_DEBUGGER
|
||||
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
|
||||
{
|
||||
jerry_debugger_send_type (JERRY_DEBUGGER_PARSE_ERROR);
|
||||
}
|
||||
#endif /* JERRY_DEBUGGER */
|
||||
|
||||
if (parser_error.error == PARSER_ERR_OUT_OF_MEMORY)
|
||||
{
|
||||
/* 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 NULL;
|
||||
}
|
||||
|
||||
#if JERRY_ERROR_MESSAGES
|
||||
ecma_string_t *err_str_p;
|
||||
|
||||
if (parser_error.error == PARSER_ERR_INVALID_REGEXP)
|
||||
{
|
||||
ecma_value_t error = jcontext_take_exception ();
|
||||
ecma_property_t *prop_p = ecma_find_named_property (ecma_get_object_from_value (error),
|
||||
ecma_get_magic_string (LIT_MAGIC_STRING_MESSAGE));
|
||||
ecma_free_value (error);
|
||||
JERRY_ASSERT (prop_p);
|
||||
err_str_p = ecma_get_string_from_value (ECMA_PROPERTY_VALUE_PTR (prop_p)->value);
|
||||
ecma_ref_ecma_string (err_str_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
const lit_utf8_byte_t *err_bytes_p = (const lit_utf8_byte_t *) parser_error_to_string (parser_error.error);
|
||||
lit_utf8_size_t err_bytes_size = lit_zt_utf8_string_size (err_bytes_p);
|
||||
err_str_p = ecma_new_ecma_string_from_utf8 (err_bytes_p, err_bytes_size);
|
||||
}
|
||||
ecma_value_t err_str_val = ecma_make_string_value (err_str_p);
|
||||
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_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_deref_ecma_string (err_str_p);
|
||||
#else /* !JERRY_ERROR_MESSAGES */
|
||||
if (parser_error.error == PARSER_ERR_INVALID_REGEXP)
|
||||
{
|
||||
jcontext_release_exception ();
|
||||
}
|
||||
|
||||
ecma_raise_syntax_error ("");
|
||||
#endif /* JERRY_ERROR_MESSAGES */
|
||||
|
||||
/* Exception has already thrown. */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -191,24 +191,11 @@ typedef enum
|
||||
*/
|
||||
typedef uint32_t parser_line_counter_t;
|
||||
|
||||
/**
|
||||
* Error code location.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
parser_error_t error; /**< error code */
|
||||
parser_line_counter_t line; /**< line where the error occured */
|
||||
parser_line_counter_t column; /**< column where the error occured */
|
||||
} parser_error_location_t;
|
||||
|
||||
/* Note: source must be a valid UTF-8 string */
|
||||
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);
|
||||
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, const ecma_parse_options_t *options_p);
|
||||
|
||||
#if JERRY_ERROR_MESSAGES
|
||||
const char *parser_error_to_string (parser_error_t);
|
||||
|
||||
@@ -2472,9 +2472,6 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
|
||||
|
||||
PARSER_TRY (context_p->try_buffer)
|
||||
{
|
||||
context_p->line = 1;
|
||||
context_p->column = 1;
|
||||
|
||||
if (arg_list_p == NULL)
|
||||
{
|
||||
context_p->source_p = source_p;
|
||||
@@ -3085,8 +3082,7 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
|
||||
context_p->next_scanner_info_p = scanner_info_p;
|
||||
context_p->source_p = source_p;
|
||||
context_p->source_end_p = source_end_p;
|
||||
context_p->line = 1;
|
||||
context_p->column = 1;
|
||||
lexer_init_line_info (context_p);
|
||||
|
||||
#if JERRY_ESNEXT
|
||||
scanner_filter_arguments (context_p, &scanner_context);
|
||||
|
||||
Reference in New Issue
Block a user