Skip to content

Commit ba4ede9

Browse files
Fix direct call to eval from strict mode code.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan [email protected]
1 parent 507411f commit ba4ede9

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

jerry-core/ecma/operations/ecma-eval.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ ecma_op_eval_chars_buffer (const ecma_char_t *code_p, /**< code characters buffe
8989
const opcode_t *opcodes_p;
9090
bool is_syntax_correct;
9191

92+
bool is_strict_call = (is_direct && is_called_from_strict_mode_code);
93+
9294
is_syntax_correct = parser_parse_eval ((const char *) code_p,
9395
code_buffer_size,
96+
is_strict_call,
9497
&opcodes_p);
9598

9699
if (!is_syntax_correct)
@@ -108,7 +111,7 @@ ecma_op_eval_chars_buffer (const ecma_char_t *code_p, /**< code characters buffe
108111
is_strict_prologue = true;
109112
}
110113

111-
bool is_strict = (is_strict_prologue || (is_direct && is_called_from_strict_mode_code));
114+
bool is_strict = (is_strict_call || is_strict_prologue);
112115

113116
ecma_value_t this_binding;
114117
ecma_object_t *lex_env_p;

jerry-core/parser/js/parser.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,6 +3063,8 @@ parser_parse_program (const char *source_p, /**< source code buffer */
30633063
size_t source_size, /**< source code size in bytes */
30643064
bool in_function, /**< flag indicating if we are parsing body of a function */
30653065
bool in_eval, /**< flag indicating if we are parsing body of eval code */
3066+
bool is_strict, /**< flag, indicating whether current code
3067+
* inherited strict mode from code of an outer scope */
30663068
const opcode_t **out_opcodes_p) /**< out: generated byte-code array
30673069
* (in case there were no syntax errors) */
30683070
{
@@ -3089,6 +3091,7 @@ parser_parse_program (const char *source_p, /**< source code buffer */
30893091
STACK_INIT (scopes);
30903092
STACK_PUSH (scopes, scopes_tree_init (NULL));
30913093
serializer_set_scope (STACK_TOP (scopes));
3094+
scopes_tree_set_strict_mode (STACK_TOP (scopes), is_strict);
30923095
lexer_set_strict_mode (scopes_tree_strict_mode (STACK_TOP (scopes)));
30933096

30943097
jmp_buf *syntax_error_label_p = syntax_get_syntax_error_longjmp_label ();
@@ -3166,7 +3169,7 @@ parser_parse_script (const char *source, /**< source script */
31663169
const opcode_t **opcodes_p) /**< out: generated byte-code array
31673170
* (in case there were no syntax errors) */
31683171
{
3169-
return parser_parse_program (source, source_size, false, false, opcodes_p);
3172+
return parser_parse_program (source, source_size, false, false, false, opcodes_p);
31703173
} /* parser_parse_script */
31713174

31723175
/**
@@ -3178,10 +3181,12 @@ parser_parse_script (const char *source, /**< source script */
31783181
bool
31793182
parser_parse_eval (const char *source, /**< string passed to eval() */
31803183
size_t source_size, /**< string size in bytes */
3184+
bool is_strict, /**< flag, indicating whether eval is called
3185+
* from strict code in direct mode */
31813186
const opcode_t **opcodes_p) /**< out: generated byte-code array
31823187
* (in case there were no syntax errors) */
31833188
{
3184-
return parser_parse_program (source, source_size, false, true, opcodes_p);
3189+
return parser_parse_program (source, source_size, false, true, is_strict, opcodes_p);
31853190
} /* parser_parse_eval */
31863191

31873192
/**
@@ -3207,7 +3212,12 @@ parser_parse_new_function (const char **params, /**< array of arguments of new F
32073212
FIXME ("check parameter's name for syntax errors");
32083213
lit_find_or_create_literal_from_charset ((ecma_char_t *) params[i], (ecma_length_t) strlen (params[i]));
32093214
}
3210-
return parser_parse_program (params[params_count - 1], strlen (params[params_count - 1]), true, false, out_opcodes_p);
3215+
return parser_parse_program (params[params_count - 1],
3216+
strlen (params[params_count - 1]),
3217+
true,
3218+
false,
3219+
false,
3220+
out_opcodes_p);
32113221
} /* parser_parse_new_function */
32123222

32133223
/**

jerry-core/parser/js/parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
void parser_set_show_opcodes (bool);
2222
bool parser_parse_script (const char *, size_t, const opcode_t **);
23-
bool parser_parse_eval (const char *, size_t, const opcode_t **);
23+
bool parser_parse_eval (const char *, size_t, bool, const opcode_t **);
2424
bool parser_parse_new_function (const char **, size_t, const opcode_t **);
2525

2626
#endif /* PARSER_H */

tests/jerry/eval.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ function f2 (global)
5151
assert (v2 === 'local value');
5252
assert (typeof (global.v2) === 'undefined');
5353
assert (r === undefined);
54+
55+
try
56+
{
57+
eval ('arguments = 1;');
58+
assert (false);
59+
}
60+
catch (e)
61+
{
62+
assert (e instanceof SyntaxError);
63+
}
5464
}
5565

5666
f2 (this);

0 commit comments

Comments
 (0)