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:
Zoltan Herczeg
2021-08-11 17:37:12 +02:00
committed by GitHub
parent b7dead7b05
commit 3ed93cfb51
24 changed files with 601 additions and 696 deletions
+9 -25
View File
@@ -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))
{
+2 -2
View File
@@ -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);