Improve new.target handling in case of eval calls (#3517)
Only direct eval calls propagate the "new.target" information. In any other eval cases the "new.target" invocation is a syntax error. Added test cases also. JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
This commit is contained in:
committed by
Robert Fancsik
parent
05b4bda927
commit
608bc9e5ff
@@ -100,8 +100,9 @@ ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, /**< code characters b
|
|||||||
#if ENABLED (JERRY_ES2015)
|
#if ENABLED (JERRY_ES2015)
|
||||||
ECMA_CLEAR_SUPER_EVAL_PARSER_OPTS ();
|
ECMA_CLEAR_SUPER_EVAL_PARSER_OPTS ();
|
||||||
|
|
||||||
/* If an eval is used inside the function the info should be propagated. */
|
/* If a direct eval is used inside the function the info should be propagated. */
|
||||||
if (JERRY_CONTEXT (current_new_target) != JERRY_CONTEXT_INVALID_NEW_TARGET)
|
if (JERRY_CONTEXT (current_new_target) != JERRY_CONTEXT_INVALID_NEW_TARGET
|
||||||
|
&& (JERRY_CONTEXT (status_flags) & ECMA_STATUS_DIRECT_EVAL))
|
||||||
{
|
{
|
||||||
parse_opts |= ECMA_PARSE_FUNCTION;
|
parse_opts |= ECMA_PARSE_FUNCTION;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1138,7 +1138,8 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
|
|||||||
{
|
{
|
||||||
#if ENABLED (JERRY_ES2015)
|
#if ENABLED (JERRY_ES2015)
|
||||||
ecma_object_t *old_new_target = JERRY_CONTEXT (current_new_target);
|
ecma_object_t *old_new_target = JERRY_CONTEXT (current_new_target);
|
||||||
if (JERRY_LIKELY (!ecma_get_object_is_builtin (func_obj_p)))
|
/* If the current function is not a direct eval call the "new.target" must be updated. */
|
||||||
|
if ((JERRY_CONTEXT (status_flags) & ECMA_STATUS_DIRECT_EVAL) == 0)
|
||||||
{
|
{
|
||||||
JERRY_CONTEXT (current_new_target) = NULL;
|
JERRY_CONTEXT (current_new_target) = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,30 @@ function eval_eval_test () {
|
|||||||
|
|
||||||
new eval_eval_test ();
|
new eval_eval_test ();
|
||||||
|
|
||||||
|
/* new.target is only valid in direct eval */
|
||||||
|
function eval_test_2 () {
|
||||||
|
var ev = eval;
|
||||||
|
try {
|
||||||
|
ev ("new.target");
|
||||||
|
assert (false);
|
||||||
|
} catch (ex) {
|
||||||
|
assert (ex instanceof SyntaxError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new eval_test_2 ();
|
||||||
|
|
||||||
|
function eval_test_3 () {
|
||||||
|
var ev = eval;
|
||||||
|
try {
|
||||||
|
eval ("ev ('new.target')");
|
||||||
|
assert (false);
|
||||||
|
} catch (ex) {
|
||||||
|
assert (ex instanceof SyntaxError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new eval_test_3 ();
|
||||||
|
|
||||||
/* test assignment of the "new.target" */
|
/* test assignment of the "new.target" */
|
||||||
function expect_syntax_error (src)
|
function expect_syntax_error (src)
|
||||||
|
|||||||
Reference in New Issue
Block a user