Fix direct call to eval from strict mode code.

JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
Ruben Ayrapetyan
2015-06-28 22:26:50 +03:00
committed by Evgeny Gavrin
parent 6573ffd632
commit 984e269db6
4 changed files with 28 additions and 5 deletions
+4 -1
View File
@@ -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;
+13 -3
View File
@@ -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 */
/**
+1 -1
View File
@@ -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 */
+10
View File
@@ -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);