Support parsing of scripts / functions stored in string values (#4728)
Function arguments must be passed as string values. Snapshots are generated from compiled code rather than source code. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -115,12 +115,20 @@ typedef enum
|
||||
ECMA_PARSE_ALLOW_NEW_TARGET = (1u << 8), /**< allow new.target access */
|
||||
ECMA_PARSE_FUNCTION_CONTEXT = (1u << 9), /**< function context is present (ECMA_PARSE_DIRECT_EVAL must be set) */
|
||||
|
||||
ECMA_PARSE_GENERATOR_FUNCTION = (1u << 10), /**< generator function is parsed */
|
||||
ECMA_PARSE_ASYNC_FUNCTION = (1u << 11), /**< async function is parsed */
|
||||
ECMA_PARSE_HAS_SOURCE_VALUE = (1u << 10), /**< source_p points to a value list
|
||||
* and the first value is the source code */
|
||||
ECMA_PARSE_HAS_ARGUMENT_LIST_VALUE = (1u << 11), /**< source_p points to a value list
|
||||
* and the second value is the argument list */
|
||||
#if JERRY_ESNEXT
|
||||
ECMA_PARSE_GENERATOR_FUNCTION = (1u << 12), /**< generator function is parsed */
|
||||
ECMA_PARSE_ASYNC_FUNCTION = (1u << 13), /**< async function is parsed */
|
||||
#endif /* JERRY_ESNEXT */
|
||||
|
||||
/* These flags are internally used by the parser. */
|
||||
ECMA_PARSE_INTERNAL_FREE_SOURCE = (1u << 14), /**< free source_p data */
|
||||
ECMA_PARSE_INTERNAL_FREE_ARG_LIST = (1u << 15), /**< free arg_list_p data */
|
||||
#if JERRY_ESNEXT
|
||||
ECMA_PARSE_INTERNAL_PRE_SCANNING = (1u << 12),
|
||||
ECMA_PARSE_INTERNAL_PRE_SCANNING = (1u << 16), /**< the parser is in pre-scanning mode */
|
||||
#endif /* JERRY_ESNEXT */
|
||||
#ifndef JERRY_NDEBUG
|
||||
/**
|
||||
|
||||
@@ -714,7 +714,7 @@ ecma_snapshot_get_literal (const uint8_t *literal_base_p, /**< literal start */
|
||||
* @return pointer to the beginning of the serializable ecma-values
|
||||
*/
|
||||
ecma_value_t *
|
||||
ecma_snapshot_resolve_serializable_values (ecma_compiled_code_t *compiled_code_p, /**< compiled code */
|
||||
ecma_snapshot_resolve_serializable_values (const ecma_compiled_code_t *compiled_code_p, /**< compiled code */
|
||||
uint8_t *bytecode_end_p) /**< end of the bytecode */
|
||||
{
|
||||
ecma_value_t *base_p = (ecma_value_t *) bytecode_end_p;
|
||||
|
||||
@@ -59,7 +59,7 @@ bool ecma_save_literals_for_snapshot (ecma_collection_t *lit_pool_p, uint32_t *b
|
||||
ecma_value_t
|
||||
ecma_snapshot_get_literal (const uint8_t *literal_base_p, ecma_value_t literal_value);
|
||||
ecma_value_t *
|
||||
ecma_snapshot_resolve_serializable_values (ecma_compiled_code_t *compiled_code_p, uint8_t *byte_code_end_p);
|
||||
ecma_snapshot_resolve_serializable_values (const ecma_compiled_code_t *compiled_code_p, uint8_t *byte_code_end_p);
|
||||
#endif /* JERRY_SNAPSHOT_EXEC || JERRY_SNAPSHOT_SAVE */
|
||||
|
||||
/**
|
||||
|
||||
@@ -107,7 +107,7 @@ ecma_builtin_global_object_eval (ecma_value_t x) /**< routine's first argument *
|
||||
#endif /* JERRY_ESNEXT */
|
||||
|
||||
/* steps 2 to 8 */
|
||||
return ecma_op_eval (ecma_get_string_from_value (x), parse_opts);
|
||||
return ecma_op_eval (x, parse_opts);
|
||||
} /* ecma_builtin_global_object_eval */
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,28 +41,18 @@
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_eval (ecma_string_t *code_p, /**< code string */
|
||||
ecma_op_eval (ecma_value_t source_code, /**< source code */
|
||||
uint32_t parse_opts) /**< ecma_parse_opts_t option bits */
|
||||
{
|
||||
ecma_value_t ret_value;
|
||||
JERRY_ASSERT (ecma_is_value_string (source_code));
|
||||
|
||||
lit_utf8_size_t chars_num = ecma_string_get_size (code_p);
|
||||
if (chars_num == 0)
|
||||
if (ecma_is_value_magic_string (source_code, LIT_MAGIC_STRING__EMPTY))
|
||||
{
|
||||
ret_value = ECMA_VALUE_UNDEFINED;
|
||||
}
|
||||
else
|
||||
{
|
||||
ECMA_STRING_TO_UTF8_STRING (code_p, code_utf8_buffer_p, code_utf8_buffer_size);
|
||||
|
||||
ret_value = ecma_op_eval_chars_buffer (code_utf8_buffer_p,
|
||||
chars_num,
|
||||
parse_opts);
|
||||
|
||||
ECMA_FINALIZE_UTF8_STRING (code_utf8_buffer_p, code_utf8_buffer_size);
|
||||
return ECMA_VALUE_UNDEFINED;
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
return ecma_op_eval_chars_buffer ((void *) &source_code,
|
||||
parse_opts | ECMA_PARSE_HAS_SOURCE_VALUE);
|
||||
} /* ecma_op_eval */
|
||||
|
||||
/**
|
||||
@@ -75,12 +65,11 @@ ecma_op_eval (ecma_string_t *code_p, /**< code string */
|
||||
* @return ecma value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, /**< code characters buffer */
|
||||
size_t code_buffer_size, /**< size of the buffer */
|
||||
ecma_op_eval_chars_buffer (void *source_p, /**< source code */
|
||||
uint32_t parse_opts) /**< ecma_parse_opts_t option bits */
|
||||
{
|
||||
#if JERRY_PARSER
|
||||
JERRY_ASSERT (code_p != NULL);
|
||||
JERRY_ASSERT (source_p != NULL);
|
||||
|
||||
uint32_t is_strict_call = ECMA_PARSE_STRICT_MODE | ECMA_PARSE_DIRECT_EVAL;
|
||||
|
||||
@@ -95,12 +84,7 @@ ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, /**< code characters b
|
||||
ECMA_CLEAR_LOCAL_PARSE_OPTS ();
|
||||
#endif /* JERRY_ESNEXT */
|
||||
|
||||
ecma_compiled_code_t *bytecode_p = parser_parse_script (NULL,
|
||||
0,
|
||||
code_p,
|
||||
code_buffer_size,
|
||||
parse_opts,
|
||||
NULL);
|
||||
ecma_compiled_code_t *bytecode_p = parser_parse_script (source_p, parse_opts, NULL);
|
||||
|
||||
if (JERRY_UNLIKELY (bytecode_p == NULL))
|
||||
{
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
*/
|
||||
|
||||
ecma_value_t
|
||||
ecma_op_eval (ecma_string_t *code_p, uint32_t parse_opts);
|
||||
ecma_op_eval (ecma_value_t source_code, uint32_t parse_opts);
|
||||
|
||||
ecma_value_t
|
||||
ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, size_t code_buffer_size, uint32_t parse_opts);
|
||||
ecma_op_eval_chars_buffer (void *source_p, uint32_t parse_opts);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -454,18 +454,14 @@ ecma_op_create_dynamic_function (const ecma_value_t *arguments_list_p, /**< argu
|
||||
function_body_str_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
|
||||
}
|
||||
|
||||
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 source[2];
|
||||
source[0] = ecma_make_string_value (function_body_str_p);
|
||||
source[1] = ecma_make_string_value (arguments_str_p);
|
||||
|
||||
ecma_compiled_code_t *bytecode_p = parser_parse_script (arguments_buffer_p,
|
||||
arguments_buffer_size,
|
||||
function_body_buffer_p,
|
||||
function_body_buffer_size,
|
||||
parse_opts,
|
||||
NULL);
|
||||
parse_opts |= ECMA_PARSE_HAS_SOURCE_VALUE | ECMA_PARSE_HAS_ARGUMENT_LIST_VALUE;
|
||||
|
||||
ecma_compiled_code_t *bytecode_p = parser_parse_script ((void *) source, 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);
|
||||
ecma_deref_ecma_string (arguments_str_p);
|
||||
ecma_deref_ecma_string (function_body_str_p);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user