Remove JERRY_CONTEXT_INVALID_NEW_TARGET (#3643)

Until now JERRY_CONTEXT_INVALID_NEW_TARGET was used to represent whether the eval called from the script directly.
This information can be retrieved from the parser, so it simplifies the runtime handling of the new.target.

This patch fixes #3630, fixes #3640 and fixes #3641.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2020-03-27 11:21:50 +01:00
committed by GitHub
parent 14bcc98089
commit 76b8555210
15 changed files with 96 additions and 52 deletions
+5 -8
View File
@@ -1439,8 +1439,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
/* Check if "new.target" is written here. */
if (scanner_try_scan_new_target (context_p))
{
if (!(context_p->status_flags & PARSER_ALLOW_NEW_TARGET)
&& !(context_p->global_status_flags & ECMA_PARSE_CALLED_FROM_FUNCTION))
if (!(context_p->status_flags & PARSER_ALLOW_NEW_TARGET))
{
parser_raise_error (context_p, PARSER_ERR_NEW_TARGET_NOT_ALLOWED);
}
@@ -1505,7 +1504,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
}
parser_check_assignment_expr (context_p);
parser_parse_function_expression (context_p, PARSER_IS_ARROW_FUNCTION);
parser_parse_function_expression (context_p, PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION);
return parser_abort_parsing_after_arrow (context_p);
}
#endif /* ENABLED (JERRY_ES2015) */
@@ -1682,9 +1681,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
{
if (context_p->status_flags & PARSER_ALLOW_SUPER)
{
if (lexer_check_next_characters (context_p, LIT_CHAR_DOT, LIT_CHAR_LEFT_SQUARE)
&& ((context_p->status_flags & PARSER_ALLOW_NEW_TARGET)
|| (context_p->global_status_flags & ECMA_PARSE_CALLED_FROM_FUNCTION)))
if (lexer_check_next_characters (context_p, LIT_CHAR_DOT, LIT_CHAR_LEFT_SQUARE))
{
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_SUPER);
break;
@@ -1708,7 +1705,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
parser_check_assignment_expr (context_p);
context_p->token.type = LEXER_ARROW_LEFT_PAREN;
parser_parse_function_expression (context_p, PARSER_IS_ARROW_FUNCTION);
parser_parse_function_expression (context_p, PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION);
return parser_abort_parsing_after_arrow (context_p);
}
case LEXER_KEYW_YIELD:
@@ -1977,7 +1974,7 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
if (is_eval)
{
#if ENABLED (JERRY_ES2015)
if (context_p->status_flags & (PARSER_ALLOW_SUPER_CALL | PARSER_ALLOW_SUPER))
if (context_p->status_flags & (PARSER_ALLOW_SUPER_CALL | PARSER_ALLOW_SUPER | PARSER_ALLOW_NEW_TARGET))
{
parser_emit_cbc_ext_call (context_p,
CBC_EXT_LOCAL_EVAL,
+5 -7
View File
@@ -65,26 +65,24 @@ typedef enum
PARSER_DISALLOW_YIELD = (1u << 16), /**< throw SyntaxError for yield expression */
PARSER_FUNCTION_HAS_NON_SIMPLE_PARAM = (1u << 17), /**< function has a non simple parameter */
PARSER_FUNCTION_HAS_REST_PARAM = (1u << 18), /**< function has rest parameter */
/* These three status flags must be in this order. See PARSER_SAVED_FLAGS_OFFSET. */
/* These 4 status flags must be in this order. See PARSER_SAVED_FLAGS_OFFSET. */
PARSER_CLASS_CONSTRUCTOR = (1u << 19), /**< a class constructor is parsed
* Note: PARSER_ALLOW_SUPER must be present */
PARSER_ALLOW_SUPER = (1u << 20), /**< allow super property access */
PARSER_ALLOW_SUPER_CALL = (1u << 21), /**< allow super constructor call
* Note: PARSER_CLASS_CONSTRUCTOR must be present */
PARSER_ALLOW_NEW_TARGET = (1u << 22), /**< allow new.target parsing in the current context */
#endif /* ENABLED (JERRY_ES2015) */
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
PARSER_MODULE_DEFAULT_CLASS_OR_FUNC = (1u << 22), /**< parsing a function or class default export */
PARSER_MODULE_STORE_IDENT = (1u << 23), /**< store identifier of the current export statement */
PARSER_MODULE_DEFAULT_CLASS_OR_FUNC = (1u << 23), /**< parsing a function or class default export */
PARSER_MODULE_STORE_IDENT = (1u << 24), /**< store identifier of the current export statement */
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
PARSER_HAS_LATE_LIT_INIT = (1u << 30), /**< there are identifier or string literals which construction
* is postponed after the local parser data is freed */
#ifndef JERRY_NDEBUG
PARSER_SCANNING_SUCCESSFUL = PARSER_HAS_LATE_LIT_INIT, /**< scanning process was successful */
#endif /* !JERRY_NDEBUG */
#if ENABLED (JERRY_ES2015)
PARSER_ALLOW_NEW_TARGET = PARSER_IS_FUNCTION, /**< allow new.target parsing in the current context */
#endif /* ENABLED (JERRY_ES2015) */
} parser_general_flags_t;
/**
@@ -137,7 +135,7 @@ typedef enum
* Count of ecma_parse_opts_t class parsing options related bits
*/
#define PARSER_SAVED_FLAGS_COUNT \
(JERRY_LOG2 (ECMA_PARSE_ALLOW_SUPER_CALL) - JERRY_LOG2 (ECMA_PARSE_CLASS_CONSTRUCTOR) + 1)
(JERRY_LOG2 (ECMA_PARSE_ALLOW_NEW_TARGET) - JERRY_LOG2 (ECMA_PARSE_CLASS_CONSTRUCTOR) + 1)
/**
* Mask for get class option bits from ecma_parse_opts_t
+1 -6
View File
@@ -2901,12 +2901,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
case LEXER_KEYW_RETURN:
{
uint32_t status_flag = PARSER_IS_FUNCTION;
#if ENABLED (JERRY_ES2015)
status_flag |= PARSER_IS_ARROW_FUNCTION;
#endif /* ENABLED (JERRY_ES2015) */
if (!(context_p->status_flags & status_flag))
if (!(context_p->status_flags & PARSER_IS_FUNCTION))
{
parser_raise_error (context_p, PARSER_ERR_INVALID_RETURN);
}
+6 -3
View File
@@ -2314,6 +2314,9 @@ parser_parse_function (parser_context_t *context_p, /**< context */
JERRY_ASSERT (status_flags & PARSER_IS_FUNCTION);
parser_save_context (context_p, &saved_context);
context_p->status_flags |= status_flags;
#if ENABLED (JERRY_ES2015)
context_p->status_flags |= PARSER_ALLOW_NEW_TARGET;
#endif /* ENABLED (JERRY_ES2015) */
#if ENABLED (JERRY_PARSER_DUMP_BYTE_CODE)
if (context_p->is_show_opcodes)
@@ -2408,12 +2411,12 @@ parser_parse_arrow_function (parser_context_t *context_p, /**< context */
parser_saved_context_t saved_context;
ecma_compiled_code_t *compiled_code_p;
JERRY_ASSERT (!(status_flags & PARSER_IS_FUNCTION)
&& (status_flags & PARSER_IS_ARROW_FUNCTION));
JERRY_ASSERT (status_flags & PARSER_IS_FUNCTION);
JERRY_ASSERT (status_flags & PARSER_IS_ARROW_FUNCTION);
parser_save_context (context_p, &saved_context);
context_p->status_flags |= status_flags;
#if ENABLED (JERRY_ES2015)
context_p->status_flags |= saved_context.status_flags & (PARSER_IS_FUNCTION
context_p->status_flags |= saved_context.status_flags & (PARSER_ALLOW_NEW_TARGET
| PARSER_ALLOW_SUPER
| PARSER_ALLOW_SUPER_CALL);
#endif /* ENABLED (JERRY_ES2015) */