Simplify source evaluation options. (#2431)

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2018-07-20 08:50:39 +02:00
committed by László Langó
parent 76ff084dc7
commit 77d9314b1d
26 changed files with 88 additions and 79 deletions
+11
View File
@@ -80,6 +80,17 @@ typedef enum
ECMA_TYPE___MAX = ECMA_TYPE_ERROR /** highest value for ecma types */
} ecma_type_t;
/**
* Option flags for script parsing.
*/
typedef enum
{
ECMA_PARSE_NO_OPTS = 0, /**< no options passed */
ECMA_PARSE_STRICT_MODE = (1 << 0), /**< enable strict mode */
ECMA_PARSE_DIRECT_EVAL = (1 << 1) /**< is eval called directly (ECMA-262 v5, 15.1.2.1.1) */
} ecma_parse_opts_t;
/**
* Description of an ecma value
*
@@ -169,7 +169,7 @@ ecma_builtin_function_dispatch_construct (const ecma_value_t *arguments_list_p,
arguments_buffer_size,
function_body_buffer_p,
function_body_buffer_size,
false,
ECMA_PARSE_NO_OPTS,
&bytecode_data_p);
if (!ECMA_IS_VALUE_ERROR (ret_value))
@@ -63,17 +63,13 @@ ecma_builtin_global_object_eval (ecma_value_t this_arg, /**< this argument */
JERRY_UNUSED (this_arg);
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
bool is_direct_eval = vm_is_direct_eval_form_call ();
uint32_t parse_opts = vm_is_direct_eval_form_call () ? ECMA_PARSE_DIRECT_EVAL : ECMA_PARSE_NO_OPTS;
/* See also: ECMA-262 v5, 10.1.1 */
bool is_called_from_strict_mode_code;
if (is_direct_eval)
if (parse_opts && vm_is_strict_mode ())
{
is_called_from_strict_mode_code = vm_is_strict_mode ();
}
else
{
is_called_from_strict_mode_code = false;
JERRY_ASSERT (parse_opts & ECMA_PARSE_DIRECT_EVAL);
parse_opts |= ECMA_PARSE_STRICT_MODE;
}
if (!ecma_is_value_string (x))
@@ -85,8 +81,7 @@ ecma_builtin_global_object_eval (ecma_value_t this_arg, /**< this argument */
{
/* steps 2 to 8 */
ret_value = ecma_op_eval (ecma_get_string_from_value (x),
is_direct_eval,
is_called_from_strict_mode_code);
parse_opts);
}
return ret_value;
+12 -11
View File
@@ -45,8 +45,7 @@
*/
ecma_value_t
ecma_op_eval (ecma_string_t *code_p, /**< code string */
bool is_direct, /**< is eval called directly (ECMA-262 v5, 15.1.2.1.1) */
bool is_called_from_strict_mode_code) /**< is eval is called from strict mode code */
uint32_t parse_opts) /**< ecma_parse_opts_t option bits */
{
ecma_value_t ret_value;
@@ -61,8 +60,7 @@ ecma_op_eval (ecma_string_t *code_p, /**< code string */
ret_value = ecma_op_eval_chars_buffer (code_utf8_buffer_p,
chars_num,
is_direct,
is_called_from_strict_mode_code);
parse_opts);
ECMA_FINALIZE_UTF8_STRING (code_utf8_buffer_p, code_utf8_buffer_size);
}
@@ -82,15 +80,19 @@ ecma_op_eval (ecma_string_t *code_p, /**< code string */
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 */
bool is_direct, /**< is eval called directly (ECMA-262 v5, 15.1.2.1.1) */
bool is_called_from_strict_mode_code) /**< is eval is called from strict mode code */
uint32_t parse_opts) /**< ecma_parse_opts_t option bits */
{
#ifndef JERRY_DISABLE_JS_PARSER
JERRY_ASSERT (code_p != NULL);
ecma_compiled_code_t *bytecode_data_p;
bool is_strict_call = (is_direct && is_called_from_strict_mode_code);
uint32_t is_strict_call = ECMA_PARSE_STRICT_MODE | ECMA_PARSE_DIRECT_EVAL;
if ((parse_opts & is_strict_call) != is_strict_call)
{
parse_opts &= (uint32_t) ~ECMA_PARSE_STRICT_MODE;
}
#ifdef JERRY_ENABLE_LINE_INFO
JERRY_CONTEXT (resource_name) = ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY);
@@ -100,7 +102,7 @@ ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, /**< code characters b
0,
code_p,
code_buffer_size,
is_strict_call,
parse_opts,
&bytecode_data_p);
if (ECMA_IS_VALUE_ERROR (parse_status))
@@ -108,12 +110,11 @@ ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, /**< code characters b
return parse_status;
}
return vm_run_eval (bytecode_data_p, is_direct);
return vm_run_eval (bytecode_data_p, parse_opts);
#else /* JERRY_DISABLE_JS_PARSER */
JERRY_UNUSED (code_p);
JERRY_UNUSED (code_buffer_size);
JERRY_UNUSED (is_direct);
JERRY_UNUSED (is_called_from_strict_mode_code);
JERRY_UNUSED (parse_opts);
return ecma_raise_syntax_error (ECMA_ERR_MSG ("The parser has been disabled."));
#endif /* !JERRY_DISABLE_JS_PARSER */
+2 -3
View File
@@ -26,11 +26,10 @@
*/
ecma_value_t
ecma_op_eval (ecma_string_t *code_p, bool is_direct, bool is_called_from_strict_mode_code);
ecma_op_eval (ecma_string_t *code_p, uint32_t parse_opts);
ecma_value_t
ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, size_t code_buffer_size, bool is_direct,
bool is_called_from_strict_mode_code);
ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, size_t code_buffer_size, uint32_t parse_opts);
/**
* @}
@@ -566,7 +566,7 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
ecma_value_t ret_value = vm_run (bytecode_data_p,
this_binding,
local_env_p,
false,
ECMA_PARSE_NO_OPTS,
arguments_list_p,
arguments_list_len);
@@ -629,7 +629,7 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
ecma_value_t ret_value = vm_run (bytecode_data_p,
arrow_func_p->this_binding,
local_env_p,
false,
ECMA_PARSE_NO_OPTS,
arguments_list_p,
arguments_list_len);