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
+4 -5
View File
@@ -391,7 +391,7 @@ jerry_parse (const jerry_char_t *resource_name_p, /**< resource name (usually a
0,
source_p,
source_size,
(parse_opts & JERRY_PARSE_STRICT_MODE) != 0,
parse_opts,
&bytecode_data_p);
if (ECMA_IS_VALUE_ERROR (parse_status))
@@ -466,7 +466,7 @@ jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (u
arg_list_size,
source_p,
source_size,
(parse_opts & JERRY_PARSE_STRICT_MODE) != 0,
parse_opts,
&bytecode_data_p);
if (ECMA_IS_VALUE_ERROR (parse_status))
@@ -544,14 +544,13 @@ jerry_run (const jerry_value_t func_val) /**< function to run */
jerry_value_t
jerry_eval (const jerry_char_t *source_p, /**< source code */
size_t source_size, /**< length of source code */
bool is_strict) /**< source must conform with strict mode */
uint32_t parse_opts) /**< jerry_parse_opts_t option bits */
{
jerry_assert_api_available ();
return jerry_return (ecma_op_eval_chars_buffer ((const lit_utf8_byte_t *) source_p,
source_size,
false,
is_strict));
parse_opts));
} /* jerry_eval */
/**
+1 -1
View File
@@ -192,7 +192,7 @@ jerry_debugger_send_eval (const lit_utf8_byte_t *eval_string_p, /**< evaluated s
JERRY_ASSERT (!(JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_VM_IGNORE));
JERRY_DEBUGGER_SET_FLAGS (JERRY_DEBUGGER_VM_IGNORE);
ecma_value_t result = ecma_op_eval_chars_buffer (eval_string_p + 1, eval_string_size - 1, true, false);
ecma_value_t result = ecma_op_eval_chars_buffer (eval_string_p + 1, eval_string_size - 1, ECMA_PARSE_DIRECT_EVAL);
JERRY_DEBUGGER_CLEAR_FLAGS (JERRY_DEBUGGER_VM_IGNORE);
if (!ECMA_IS_VALUE_ERROR (result))
+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);
+1 -1
View File
@@ -329,7 +329,7 @@ jerry_value_t jerry_parse_function (const jerry_char_t *resource_name_p, size_t
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_run (const jerry_value_t func_val);
jerry_value_t jerry_eval (const jerry_char_t *source_p, size_t source_size, bool is_strict);
jerry_value_t jerry_eval (const jerry_char_t *source_p, size_t source_size, uint32_t parse_opts);
jerry_value_t jerry_run_all_enqueued_jobs (void);
+5 -5
View File
@@ -2224,7 +2224,7 @@ 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 */
int strict_mode, /**< strict mode */
uint32_t parse_opts, /**< ecma_parse_opts_t option bits */
parser_error_location_t *error_location_p) /**< error location */
{
parser_context_t context;
@@ -2264,7 +2264,7 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
context.last_context_p = NULL;
context.last_statement.current_p = NULL;
if (strict_mode)
if (parse_opts & ECMA_PARSE_STRICT_MODE)
{
context.status_flags |= PARSER_IS_STRICT;
}
@@ -2867,7 +2867,7 @@ 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 */
bool is_strict, /**< strict mode */
uint32_t parse_opts, /**< ecma_parse_opts_t option bits */
ecma_compiled_code_t **bytecode_data_p) /**< [out] JS bytecode */
{
#ifndef JERRY_DISABLE_JS_PARSER
@@ -2887,7 +2887,7 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */
arg_list_size,
source_p,
source_size,
is_strict,
parse_opts,
&parser_error);
if (!*bytecode_data_p)
@@ -2959,7 +2959,7 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */
JERRY_UNUSED (arg_list_size);
JERRY_UNUSED (source_p);
JERRY_UNUSED (source_size);
JERRY_UNUSED (is_strict);
JERRY_UNUSED (parse_opts);
JERRY_UNUSED (bytecode_data_p);
return ecma_raise_syntax_error (ECMA_ERR_MSG ("The parser has been disabled."));
+1 -1
View File
@@ -138,7 +138,7 @@ typedef struct
/* Note: source must be a valid UTF-8 string */
ecma_value_t parser_parse_script (const uint8_t *arg_list_p, size_t arg_list_size,
const uint8_t *source_p, size_t source_size,
bool is_strict, ecma_compiled_code_t **bytecode_data_p);
uint32_t parse_opts, ecma_compiled_code_t **bytecode_data_p);
#ifdef JERRY_ENABLE_ERROR_MESSAGES
const char *parser_error_to_string (parser_error_t);
+5 -5
View File
@@ -240,13 +240,13 @@ vm_run_global (const ecma_compiled_code_t *bytecode_p) /**< pointer to bytecode
*/
ecma_value_t
vm_run_eval (ecma_compiled_code_t *bytecode_data_p, /**< byte-code data */
bool is_direct) /**< is eval called in direct mode? */
uint32_t parse_opts) /**< ecma_parse_opts_t option bits */
{
ecma_value_t this_binding;
ecma_object_t *lex_env_p;
/* ECMA-262 v5, 10.4.2 */
if (is_direct)
if (parse_opts & ECMA_PARSE_DIRECT_EVAL)
{
this_binding = ecma_copy_value (JERRY_CONTEXT (vm_top_context_p)->this_binding);
lex_env_p = JERRY_CONTEXT (vm_top_context_p)->lex_env_p;
@@ -270,7 +270,7 @@ vm_run_eval (ecma_compiled_code_t *bytecode_data_p, /**< byte-code data */
ecma_value_t completion_value = vm_run (bytecode_data_p,
this_binding,
lex_env_p,
true,
parse_opts,
NULL,
0);
@@ -3040,7 +3040,7 @@ ecma_value_t
vm_run (const ecma_compiled_code_t *bytecode_header_p, /**< byte-code data header */
ecma_value_t this_binding_value, /**< value of 'ThisBinding' */
ecma_object_t *lex_env_p, /**< lexical environment to use */
bool is_eval_code, /**< is the code is eval code (ECMA-262 v5, 10.1) */
uint32_t parse_opts, /**< ecma_parse_opts_t option bits */
const ecma_value_t *arg_list_p, /**< arguments list */
ecma_length_t arg_list_len) /**< length of arguments list */
{
@@ -3080,7 +3080,7 @@ vm_run (const ecma_compiled_code_t *bytecode_header_p, /**< byte-code data heade
frame_ctx.current_line = 0;
#endif /* JERRY_ENABLE_LINE_INFO */
frame_ctx.context_depth = 0;
frame_ctx.is_eval_code = is_eval_code;
frame_ctx.is_eval_code = parse_opts & ECMA_PARSE_DIRECT_EVAL;
frame_ctx.call_operation = VM_NO_EXEC_OP;
/* Use JERRY_MAX() to avoid array declaration with size 0. */
+2 -2
View File
@@ -282,10 +282,10 @@ typedef enum
} vm_call_operation;
ecma_value_t vm_run_global (const ecma_compiled_code_t *bytecode_p);
ecma_value_t vm_run_eval (ecma_compiled_code_t *bytecode_data_p, bool is_direct);
ecma_value_t vm_run_eval (ecma_compiled_code_t *bytecode_data_p, uint32_t parse_opts);
ecma_value_t vm_run (const ecma_compiled_code_t *bytecode_header_p, ecma_value_t this_binding_value,
ecma_object_t *lex_env_p, bool is_eval_code, const ecma_value_t *arg_list_p,
ecma_object_t *lex_env_p, uint32_t parse_opts, const ecma_value_t *arg_list_p,
ecma_length_t arg_list_len);
bool vm_is_strict_mode (void);