diff --git a/jerry-core/ecma/operations/ecma-eval.cpp b/jerry-core/ecma/operations/ecma-eval.cpp index 5db2dfbdd6..de73639867 100644 --- a/jerry-core/ecma/operations/ecma-eval.cpp +++ b/jerry-core/ecma/operations/ecma-eval.cpp @@ -89,8 +89,11 @@ ecma_op_eval_chars_buffer (const ecma_char_t *code_p, /**< code characters buffe const opcode_t *opcodes_p; bool is_syntax_correct; + bool is_strict_call = (is_direct && is_called_from_strict_mode_code); + is_syntax_correct = parser_parse_eval ((const char *) code_p, code_buffer_size, + is_strict_call, &opcodes_p); if (!is_syntax_correct) @@ -108,7 +111,7 @@ ecma_op_eval_chars_buffer (const ecma_char_t *code_p, /**< code characters buffe is_strict_prologue = true; } - bool is_strict = (is_strict_prologue || (is_direct && is_called_from_strict_mode_code)); + bool is_strict = (is_strict_call || is_strict_prologue); ecma_value_t this_binding; ecma_object_t *lex_env_p; diff --git a/jerry-core/parser/js/parser.cpp b/jerry-core/parser/js/parser.cpp index 5704afd8b7..576422504a 100644 --- a/jerry-core/parser/js/parser.cpp +++ b/jerry-core/parser/js/parser.cpp @@ -3062,6 +3062,8 @@ parser_parse_program (const char *source_p, /**< source code buffer */ size_t source_size, /**< source code size in bytes */ bool in_function, /**< flag indicating if we are parsing body of a function */ bool in_eval, /**< flag indicating if we are parsing body of eval code */ + bool is_strict, /**< flag, indicating whether current code + * inherited strict mode from code of an outer scope */ const opcode_t **out_opcodes_p) /**< out: generated byte-code array * (in case there were no syntax errors) */ { @@ -3088,6 +3090,7 @@ parser_parse_program (const char *source_p, /**< source code buffer */ STACK_INIT (scopes); STACK_PUSH (scopes, scopes_tree_init (NULL)); serializer_set_scope (STACK_TOP (scopes)); + scopes_tree_set_strict_mode (STACK_TOP (scopes), is_strict); lexer_set_strict_mode (scopes_tree_strict_mode (STACK_TOP (scopes))); jmp_buf *syntax_error_label_p = syntax_get_syntax_error_longjmp_label (); @@ -3165,7 +3168,7 @@ parser_parse_script (const char *source, /**< source script */ const opcode_t **opcodes_p) /**< out: generated byte-code array * (in case there were no syntax errors) */ { - return parser_parse_program (source, source_size, false, false, opcodes_p); + return parser_parse_program (source, source_size, false, false, false, opcodes_p); } /* parser_parse_script */ /** @@ -3177,10 +3180,12 @@ parser_parse_script (const char *source, /**< source script */ bool parser_parse_eval (const char *source, /**< string passed to eval() */ size_t source_size, /**< string size in bytes */ + bool is_strict, /**< flag, indicating whether eval is called + * from strict code in direct mode */ const opcode_t **opcodes_p) /**< out: generated byte-code array * (in case there were no syntax errors) */ { - return parser_parse_program (source, source_size, false, true, opcodes_p); + return parser_parse_program (source, source_size, false, true, is_strict, opcodes_p); } /* parser_parse_eval */ /** @@ -3206,7 +3211,12 @@ parser_parse_new_function (const char **params, /**< array of arguments of new F FIXME ("check parameter's name for syntax errors"); lit_find_or_create_literal_from_charset ((ecma_char_t *) params[i], (ecma_length_t) strlen (params[i])); } - return parser_parse_program (params[params_count - 1], strlen (params[params_count - 1]), true, false, out_opcodes_p); + return parser_parse_program (params[params_count - 1], + strlen (params[params_count - 1]), + true, + false, + false, + out_opcodes_p); } /* parser_parse_new_function */ /** diff --git a/jerry-core/parser/js/parser.h b/jerry-core/parser/js/parser.h index 6bbfe6ae8c..228d539b5b 100644 --- a/jerry-core/parser/js/parser.h +++ b/jerry-core/parser/js/parser.h @@ -20,7 +20,7 @@ void parser_set_show_opcodes (bool); bool parser_parse_script (const char *, size_t, const opcode_t **); -bool parser_parse_eval (const char *, size_t, const opcode_t **); +bool parser_parse_eval (const char *, size_t, bool, const opcode_t **); bool parser_parse_new_function (const char **, size_t, const opcode_t **); #endif /* PARSER_H */ diff --git a/tests/jerry/eval.js b/tests/jerry/eval.js index f3e6bfb514..84b5557a8c 100644 --- a/tests/jerry/eval.js +++ b/tests/jerry/eval.js @@ -51,6 +51,16 @@ function f2 (global) assert (v2 === 'local value'); assert (typeof (global.v2) === 'undefined'); assert (r === undefined); + + try + { + eval ('arguments = 1;'); + assert (false); + } + catch (e) + { + assert (e instanceof SyntaxError); + } } f2 (this);