Update parser early return type in ESNEXT (#3742)
This patch updates the early return types in the parser to SyntaxError instead of ReferenceError in ESNEXT This patch also includes a lot of tests for LeftHandSideExpression validation when using the = operator JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
@@ -267,9 +267,10 @@ parser_emit_unary_lvalue_opcode (parser_context_t *context_p, /**< context */
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
parser_check_invalid_new_target (context_p, opcode);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
parser_raise_error (context_p, PARSER_ERR_INVALID_LHS_POSTFIX_OP);
|
||||
#else /* ENABLED (JERRY_ESNEXT) */
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_THROW_REFERENCE_ERROR);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
}
|
||||
|
||||
parser_emit_cbc (context_p, (uint16_t) opcode);
|
||||
@@ -2637,12 +2638,13 @@ parser_append_binary_single_assignment_token (parser_context_t *context_p, /**<
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
else
|
||||
{
|
||||
/* Invalid LeftHandSide expression. */
|
||||
/* Invalid LeftHandSide expression. */ //3820, 3815
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
parser_check_invalid_new_target (context_p, CBC_ASSIGN);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
parser_raise_error (context_p, PARSER_ERR_INVALID_LHS_ASSIGNMENT);
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_THROW_REFERENCE_ERROR);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
}
|
||||
|
||||
parser_stack_push_uint8 (context_p, assign_opcode);
|
||||
@@ -2692,9 +2694,11 @@ parser_append_binary_token (parser_context_t *context_p) /**< context */
|
||||
/* Invalid LeftHandSide expression. */
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
parser_check_invalid_new_target (context_p, CBC_ASSIGN);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
parser_raise_error (context_p, PARSER_ERR_INVALID_LHS_ASSIGNMENT);
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_THROW_REFERENCE_ERROR);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
parser_emit_cbc (context_p, CBC_PUSH_PROP_REFERENCE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1169,7 +1169,12 @@ parser_check_left_hand_side_expression (parser_context_t *context_p, /**< contex
|
||||
else
|
||||
{
|
||||
/* Invalid LeftHandSide expression. */
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
parser_raise_error (context_p, PARSER_ERR_INVALID_LHS_FOR_LOOP);
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_THROW_REFERENCE_ERROR);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
return CBC_ASSIGN;
|
||||
}
|
||||
|
||||
|
||||
@@ -968,6 +968,18 @@ parser_error_to_string (parser_error_t error) /**< error code */
|
||||
{
|
||||
return "Duplicate __proto__ fields are not allowed in object literals.";
|
||||
}
|
||||
case PARSER_ERR_INVALID_LHS_ASSIGNMENT:
|
||||
{
|
||||
return "Invalid left-hand side in assignment.";
|
||||
}
|
||||
case PARSER_ERR_INVALID_LHS_POSTFIX_OP:
|
||||
{
|
||||
return "Invalid left-hand side expression in postfix operation.";
|
||||
}
|
||||
case PARSER_ERR_INVALID_LHS_FOR_LOOP:
|
||||
{
|
||||
return "Invalid left-hand-side in for-loop.";
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
case PARSER_ERR_DELETE_IDENT_NOT_ALLOWED:
|
||||
{
|
||||
|
||||
@@ -85,6 +85,9 @@ typedef enum
|
||||
PARSER_ERR_FOR_AWAIT_NO_ASYNC, /**< for-await-of is only allowed inside async functions */
|
||||
PARSER_ERR_FOR_AWAIT_NO_OF, /**< only 'of' form is allowed for for-await loops */
|
||||
PARSER_ERR_DUPLICATED_PROTO, /**< duplicated __proto__ fields are not allowed */
|
||||
PARSER_ERR_INVALID_LHS_ASSIGNMENT, /**< invalid LeftHandSide in assignment */
|
||||
PARSER_ERR_INVALID_LHS_POSTFIX_OP, /**< invalid LeftHandSide expression in postfix operation */
|
||||
PARSER_ERR_INVALID_LHS_FOR_LOOP, /**< invalid LeftHandSide in for-loop */
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
PARSER_ERR_DELETE_IDENT_NOT_ALLOWED, /**< identifier delete is not allowed in strict mode */
|
||||
PARSER_ERR_EVAL_CANNOT_ASSIGNED, /**< eval cannot be assigned in strict mode */
|
||||
|
||||
Reference in New Issue
Block a user