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));
|
||||
|
||||
Reference in New Issue
Block a user