Skip to content

Commit 0fd1ed6

Browse files
galpeterrerobika
authored andcommitted
Add support for new.target (#3469)
Notable changes: * Extracted the pure JS/builtin and external C method invocations into two new methods (`ecma_op_function_call_{simple, external}`). * Updated parser/scanner to handle "new.target" correctly. * Added JS test case. JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
1 parent be8ae3a commit 0fd1ed6

22 files changed

Lines changed: 836 additions & 119 deletions

jerry-core/ecma/base/ecma-globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ typedef enum
107107
ECMA_PARSE_HAS_STATIC_SUPER = (1u << 5), /**< the current context is a static class method */
108108
ECMA_PARSE_EVAL = (1u << 6), /**< eval is called */
109109
ECMA_PARSE_MODULE = (1u << 7), /**< module is parsed */
110+
ECMA_PARSE_FUNCTION = (1u << 8), /**< a function body is parsed or the code is inside a function */
110111
} ecma_parse_opts_t;
111112

112113
/**

jerry-core/ecma/base/ecma-init-finalize.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ ecma_init (void)
5454
#if ENABLED (JERRY_ES2015_BUILTIN_PROMISE)
5555
ecma_job_queue_init ();
5656
#endif /* ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */
57+
58+
#if ENABLED (JERRY_ES2015)
59+
JERRY_CONTEXT (current_new_target) = JERRY_CONTEXT_INVALID_NEW_TARGET;
60+
#endif /* ENABLED (JERRY_ES2015) */
5761
} /* ecma_init */
5862

5963
/**
@@ -62,6 +66,10 @@ ecma_init (void)
6266
void
6367
ecma_finalize (void)
6468
{
69+
#if ENABLED (JERRY_ES2015)
70+
JERRY_ASSERT (JERRY_CONTEXT (current_new_target) == JERRY_CONTEXT_INVALID_NEW_TARGET);
71+
#endif /* ENABLED (JERRY_ES2015) */
72+
6573
ecma_finalize_global_lex_env ();
6674
ecma_finalize_builtins ();
6775
ecma_gc_run ();

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, /**< code characters b
9999

100100
#if ENABLED (JERRY_ES2015)
101101
ECMA_CLEAR_SUPER_EVAL_PARSER_OPTS ();
102+
103+
/* If an eval is used inside the function the info should be propagated. */
104+
if (JERRY_CONTEXT (current_new_target) != JERRY_CONTEXT_INVALID_NEW_TARGET)
105+
{
106+
parse_opts |= ECMA_PARSE_FUNCTION;
107+
}
102108
#endif /* ENABLED (JERRY_ES2015) */
103109

104110
ecma_value_t parse_status = parser_parse_script (NULL,

0 commit comments

Comments
 (0)