diff --git a/jerry-core/ecma/operations/ecma-eval.c b/jerry-core/ecma/operations/ecma-eval.c index c1c5c600d..6febae8cd 100644 --- a/jerry-core/ecma/operations/ecma-eval.c +++ b/jerry-core/ecma/operations/ecma-eval.c @@ -100,8 +100,9 @@ ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, /**< code characters b #if ENABLED (JERRY_ES2015) ECMA_CLEAR_SUPER_EVAL_PARSER_OPTS (); - /* If an eval is used inside the function the info should be propagated. */ - if (JERRY_CONTEXT (current_new_target) != JERRY_CONTEXT_INVALID_NEW_TARGET) + /* 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 + && (JERRY_CONTEXT (status_flags) & ECMA_STATUS_DIRECT_EVAL)) { parse_opts |= ECMA_PARSE_FUNCTION; } diff --git a/jerry-core/ecma/operations/ecma-function-object.c b/jerry-core/ecma/operations/ecma-function-object.c index 77ea4be41..d36c6a708 100644 --- a/jerry-core/ecma/operations/ecma-function-object.c +++ b/jerry-core/ecma/operations/ecma-function-object.c @@ -1138,7 +1138,8 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */ { #if ENABLED (JERRY_ES2015) 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; } diff --git a/tests/jerry/es2015/new-target.js b/tests/jerry/es2015/new-target.js index 4e1759377..cc6e87675 100644 --- a/tests/jerry/es2015/new-target.js +++ b/tests/jerry/es2015/new-target.js @@ -91,6 +91,30 @@ function 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" */ function expect_syntax_error (src)