Implement optional chaining (#5164)
The work is based on PR #4843, only fixed some conflicts and cppcheck errors. Co-authored-by: Robert Fancsik robert.fancsik@h-lab.eu JerryScript-DCO-1.0-Signed-off-by: Gergo Csizi gergocs@inf.u-szeged.hu
This commit is contained in:
@@ -28,7 +28,7 @@ JERRY_STATIC_ASSERT (offsetof (cbc_uint8_arguments_t, script_value) == offsetof
|
|||||||
* whenever new bytecodes are introduced or existing ones have been deleted.
|
* whenever new bytecodes are introduced or existing ones have been deleted.
|
||||||
*/
|
*/
|
||||||
JERRY_STATIC_ASSERT (CBC_END == 238, number_of_cbc_opcodes_changed);
|
JERRY_STATIC_ASSERT (CBC_END == 238, number_of_cbc_opcodes_changed);
|
||||||
JERRY_STATIC_ASSERT (CBC_EXT_END == 167, number_of_cbc_ext_opcodes_changed);
|
JERRY_STATIC_ASSERT (CBC_EXT_END == 170, number_of_cbc_ext_opcodes_changed);
|
||||||
|
|
||||||
/** \addtogroup parser Parser
|
/** \addtogroup parser Parser
|
||||||
* @{
|
* @{
|
||||||
|
|||||||
@@ -497,9 +497,9 @@
|
|||||||
CBC_FORWARD_BRANCH (CBC_EXT_DEFAULT_INITIALIZER, -1, VM_OC_DEFAULT_INITIALIZER) \
|
CBC_FORWARD_BRANCH (CBC_EXT_DEFAULT_INITIALIZER, -1, VM_OC_DEFAULT_INITIALIZER) \
|
||||||
CBC_OPCODE (CBC_EXT_ERROR, CBC_NO_FLAG, 0, VM_OC_ERROR) \
|
CBC_OPCODE (CBC_EXT_ERROR, CBC_NO_FLAG, 0, VM_OC_ERROR) \
|
||||||
CBC_FORWARD_BRANCH (CBC_EXT_BRANCH_IF_NULLISH, -1, VM_OC_BRANCH_IF_NULLISH) \
|
CBC_FORWARD_BRANCH (CBC_EXT_BRANCH_IF_NULLISH, -1, VM_OC_BRANCH_IF_NULLISH) \
|
||||||
\
|
|
||||||
/* Basic opcodes. */ \
|
|
||||||
CBC_OPCODE (CBC_EXT_POP_REFERENCE, CBC_NO_FLAG, -2, VM_OC_POP_REFERENCE) \
|
CBC_OPCODE (CBC_EXT_POP_REFERENCE, CBC_NO_FLAG, -2, VM_OC_POP_REFERENCE) \
|
||||||
|
CBC_FORWARD_BRANCH (CBC_EXT_BRANCH_OPTIONAL_CHAIN, 0, VM_OC_BRANCH_OPTIONAL_CHAIN) \
|
||||||
|
/* Basic opcodes. */ \
|
||||||
CBC_OPCODE (CBC_EXT_CREATE_ARGUMENTS, CBC_HAS_LITERAL_ARG, 0, VM_OC_CREATE_ARGUMENTS) \
|
CBC_OPCODE (CBC_EXT_CREATE_ARGUMENTS, CBC_HAS_LITERAL_ARG, 0, VM_OC_CREATE_ARGUMENTS) \
|
||||||
CBC_OPCODE (CBC_EXT_CREATE_VAR_EVAL, CBC_HAS_LITERAL_ARG, 0, VM_OC_EXT_VAR_EVAL) \
|
CBC_OPCODE (CBC_EXT_CREATE_VAR_EVAL, CBC_HAS_LITERAL_ARG, 0, VM_OC_EXT_VAR_EVAL) \
|
||||||
CBC_OPCODE (CBC_EXT_CREATE_VAR_FUNC_EVAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, VM_OC_EXT_VAR_EVAL) \
|
CBC_OPCODE (CBC_EXT_CREATE_VAR_FUNC_EVAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, VM_OC_EXT_VAR_EVAL) \
|
||||||
|
|||||||
@@ -381,6 +381,29 @@ lexer_skip_spaces (parser_context_t *context_p) /**< context */
|
|||||||
}
|
}
|
||||||
} /* lexer_skip_spaces */
|
} /* lexer_skip_spaces */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the next token start character.
|
||||||
|
*
|
||||||
|
* @return LIT_INVALID_CP - if there is no more characters to read
|
||||||
|
* next byte - otherwise
|
||||||
|
*/
|
||||||
|
lit_code_point_t
|
||||||
|
lexer_peek_next_character (parser_context_t *context_p) /**< context */
|
||||||
|
{
|
||||||
|
if (!(context_p->token.flags & LEXER_NO_SKIP_SPACES))
|
||||||
|
{
|
||||||
|
lexer_skip_spaces (context_p);
|
||||||
|
context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context_p->source_p < context_p->source_end_p)
|
||||||
|
{
|
||||||
|
return context_p->source_p[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return LIT_INVALID_CP;
|
||||||
|
} /* lexer_check_next_character */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skip all the continuous empty statements.
|
* Skip all the continuous empty statements.
|
||||||
*/
|
*/
|
||||||
@@ -1738,6 +1761,13 @@ lexer_next_token (parser_context_t *context_p) /**< context */
|
|||||||
length = 2;
|
length = 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (context_p->source_p[1] == (uint8_t) LIT_CHAR_DOT
|
||||||
|
&& (length < 3 || !lit_char_is_decimal_digit (context_p->source_p[2])))
|
||||||
|
{
|
||||||
|
context_p->token.type = LEXER_QUESTION_MARK_DOT;
|
||||||
|
length = 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context_p->token.type = LEXER_QUESTION_MARK;
|
context_p->token.type = LEXER_QUESTION_MARK;
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ typedef enum
|
|||||||
LEXER_RIGHT_PAREN, /**< ")" */
|
LEXER_RIGHT_PAREN, /**< ")" */
|
||||||
LEXER_RIGHT_SQUARE, /**< "]" */
|
LEXER_RIGHT_SQUARE, /**< "]" */
|
||||||
LEXER_DOT, /**< "." */
|
LEXER_DOT, /**< "." */
|
||||||
|
LEXER_QUESTION_MARK_DOT, /**< "?." */
|
||||||
LEXER_SEMICOLON, /**< ";" */
|
LEXER_SEMICOLON, /**< ";" */
|
||||||
LEXER_COLON, /**< ":" */
|
LEXER_COLON, /**< ":" */
|
||||||
LEXER_COMMA, /**< "," */
|
LEXER_COMMA, /**< "," */
|
||||||
|
|||||||
@@ -106,6 +106,30 @@ static const uint8_t parser_binary_precedence_table[] = {
|
|||||||
JERRY_STATIC_ASSERT (sizeof (parser_binary_precedence_table) == 42,
|
JERRY_STATIC_ASSERT (sizeof (parser_binary_precedence_table) == 42,
|
||||||
parser_binary_precedence_table_should_have_39_values_in_es2015);
|
parser_binary_precedence_table_should_have_39_values_in_es2015);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call reference status flags
|
||||||
|
*/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
PARSER_CALL_REFERENCE_NONE = 0, /**< no options are present */
|
||||||
|
PARSER_CALL_REFERENCE_DIRECT_EVAL = (1 << 0), /**< direct eval call */
|
||||||
|
PARSER_CALL_REFERENCE_SPREAD = (1 << 1), /**< spread call */
|
||||||
|
} parser_call_reference_flags_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call reference
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
size_t call_arguments; /**< number of call arguments */
|
||||||
|
uint16_t status_flags; /**< any combination of parser_call_reference_flags_t */
|
||||||
|
uint16_t opcode; /**< call opcode */
|
||||||
|
} parser_call_reference_t;
|
||||||
|
|
||||||
|
static void parser_parse_postfix_expresion (parser_context_t *context_p, size_t *grouping_level_p);
|
||||||
|
static parser_call_reference_t parser_form_call_reference (parser_context_t *context_p);
|
||||||
|
static bool parser_process_group_expression (parser_context_t *context_p, size_t *grouping_level_p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate byte code for operators with lvalue.
|
* Generate byte code for operators with lvalue.
|
||||||
*/
|
*/
|
||||||
@@ -2354,27 +2378,11 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
|
|||||||
} /* parser_parse_unary_expression */
|
} /* parser_parse_unary_expression */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the postfix part of unary operators, and
|
* Parse expr.#property
|
||||||
* generate byte code for the whole expression.
|
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
parser_process_unary_expression (parser_context_t *context_p, /**< context */
|
parser_parse_private_property_access (parser_context_t *context_p) /**< context */
|
||||||
size_t grouping_level) /**< grouping level */
|
|
||||||
{
|
{
|
||||||
/* Parse postfix part of a primary expression. */
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
/* Since break would only break the switch, we use
|
|
||||||
* continue to continue this loop. Without continue,
|
|
||||||
* the code abandons the loop. */
|
|
||||||
switch (context_p->token.type)
|
|
||||||
{
|
|
||||||
case LEXER_DOT:
|
|
||||||
{
|
|
||||||
parser_push_result (context_p);
|
|
||||||
|
|
||||||
if (lexer_check_next_character (context_p, LIT_CHAR_HASHMARK))
|
|
||||||
{
|
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
|
|
||||||
if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER))
|
if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER))
|
||||||
@@ -2391,7 +2399,22 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
|
|||||||
|
|
||||||
parser_emit_cbc_ext_literal (context_p, CBC_EXT_PUSH_PRIVATE_PROP_LITERAL, context_p->lit_object.index);
|
parser_emit_cbc_ext_literal (context_p, CBC_EXT_PUSH_PRIVATE_PROP_LITERAL, context_p->lit_object.index);
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
continue;
|
} /* parser_parse_private_property_access */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse expr.property
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
parser_parse_property_access (parser_context_t *context_p) /**< context */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (context_p->token.type == LEXER_DOT || context_p->token.type == LEXER_QUESTION_MARK_DOT);
|
||||||
|
|
||||||
|
parser_push_result (context_p);
|
||||||
|
|
||||||
|
if (lexer_check_next_character (context_p, LIT_CHAR_HASHMARK))
|
||||||
|
{
|
||||||
|
parser_parse_private_property_access (context_p);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lexer_expect_identifier (context_p, LEXER_STRING_LITERAL);
|
lexer_expect_identifier (context_p, LEXER_STRING_LITERAL);
|
||||||
@@ -2400,55 +2423,87 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
|
|||||||
&& context_p->lit_object.literal_p->type == LEXER_STRING_LITERAL);
|
&& context_p->lit_object.literal_p->type == LEXER_STRING_LITERAL);
|
||||||
context_p->token.lit_location.type = LEXER_STRING_LITERAL;
|
context_p->token.lit_location.type = LEXER_STRING_LITERAL;
|
||||||
|
|
||||||
if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL)
|
switch (context_p->last_cbc_opcode)
|
||||||
|
{
|
||||||
|
case CBC_PUSH_LITERAL:
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (CBC_ARGS_EQ (CBC_PUSH_PROP_LITERAL_LITERAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2));
|
JERRY_ASSERT (CBC_ARGS_EQ (CBC_PUSH_PROP_LITERAL_LITERAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2));
|
||||||
context_p->last_cbc_opcode = CBC_PUSH_PROP_LITERAL_LITERAL;
|
context_p->last_cbc_opcode = CBC_PUSH_PROP_LITERAL_LITERAL;
|
||||||
context_p->last_cbc.value = context_p->lit_object.index;
|
context_p->last_cbc.value = context_p->lit_object.index;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (context_p->last_cbc_opcode == CBC_PUSH_THIS)
|
case CBC_PUSH_THIS:
|
||||||
{
|
{
|
||||||
context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE;
|
context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE;
|
||||||
parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_PROP_THIS_LITERAL);
|
parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_PROP_THIS_LITERAL);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER))
|
case PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER):
|
||||||
{
|
{
|
||||||
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP_LITERAL);
|
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP_LITERAL);
|
||||||
context_p->last_cbc.literal_index = context_p->lit_object.index;
|
context_p->last_cbc.literal_index = context_p->lit_object.index;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
default:
|
||||||
{
|
{
|
||||||
parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_PROP_LITERAL);
|
parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_PROP_LITERAL);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
continue;
|
} /* parser_parse_property_access */
|
||||||
}
|
|
||||||
|
|
||||||
case LEXER_LEFT_SQUARE:
|
/**
|
||||||
{
|
* Parse an expression enclosed with [] brackets ('[expr]')
|
||||||
parser_push_result (context_p);
|
*/
|
||||||
|
static void
|
||||||
uint16_t last_cbc_opcode = context_p->last_cbc_opcode;
|
parser_parse_square_bracketed_expression (parser_context_t *context_p) /**< context */
|
||||||
|
{
|
||||||
if (last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER))
|
JERRY_ASSERT (context_p->token.type == LEXER_LEFT_SQUARE);
|
||||||
{
|
|
||||||
context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
parser_parse_expression (context_p, PARSE_EXPR);
|
parser_parse_expression (context_p, PARSE_EXPR);
|
||||||
|
|
||||||
if (context_p->token.type != LEXER_RIGHT_SQUARE)
|
if (context_p->token.type != LEXER_RIGHT_SQUARE)
|
||||||
{
|
{
|
||||||
parser_raise_error (context_p, PARSER_ERR_RIGHT_SQUARE_EXPECTED);
|
parser_raise_error (context_p, PARSER_ERR_RIGHT_SQUARE_EXPECTED);
|
||||||
}
|
}
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
|
} /* parser_parser_square_bracketed_expression */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse super[expr]
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
parser_parse_super_element_access_expression (parser_context_t *context_p) /**< context */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER));
|
||||||
|
context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE;
|
||||||
|
|
||||||
|
parser_parse_square_bracketed_expression (context_p);
|
||||||
|
|
||||||
if (last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER))
|
|
||||||
{
|
|
||||||
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_SUPER_PROP);
|
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_SUPER_PROP);
|
||||||
continue;
|
} /* parser_parse_super_element_access_expression */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse expr[property]
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
parser_parse_element_access (parser_context_t *context_p) /**< context */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (context_p->token.type == LEXER_LEFT_SQUARE);
|
||||||
|
|
||||||
|
parser_push_result (context_p);
|
||||||
|
|
||||||
|
if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER))
|
||||||
|
{
|
||||||
|
parser_parse_super_element_access_expression (context_p);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parser_parse_square_bracketed_expression (context_p);
|
||||||
|
|
||||||
if (PARSER_IS_MUTABLE_PUSH_LITERAL (context_p->last_cbc_opcode))
|
if (PARSER_IS_MUTABLE_PUSH_LITERAL (context_p->last_cbc_opcode))
|
||||||
{
|
{
|
||||||
context_p->last_cbc_opcode = PARSER_PUSH_LITERAL_TO_PUSH_PROP_LITERAL (context_p->last_cbc_opcode);
|
context_p->last_cbc_opcode = PARSER_PUSH_LITERAL_TO_PUSH_PROP_LITERAL (context_p->last_cbc_opcode);
|
||||||
@@ -2457,76 +2512,125 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
|
|||||||
{
|
{
|
||||||
parser_emit_cbc (context_p, CBC_PUSH_PROP);
|
parser_emit_cbc (context_p, CBC_PUSH_PROP);
|
||||||
}
|
}
|
||||||
continue;
|
} /* parser_parse_element_access */
|
||||||
}
|
|
||||||
case LEXER_TEMPLATE_LITERAL:
|
|
||||||
case LEXER_LEFT_PAREN:
|
|
||||||
{
|
|
||||||
size_t call_arguments = 0;
|
|
||||||
uint16_t opcode = CBC_CALL;
|
|
||||||
bool is_eval = false;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form reference base for a call instruction
|
||||||
|
*/
|
||||||
|
static parser_call_reference_t
|
||||||
|
parser_form_call_reference (parser_context_t *context_p) /**< context */
|
||||||
|
{
|
||||||
parser_push_result (context_p);
|
parser_push_result (context_p);
|
||||||
|
|
||||||
|
parser_call_reference_t desc;
|
||||||
|
desc.status_flags = PARSER_CALL_REFERENCE_NONE;
|
||||||
|
desc.opcode = CBC_CALL;
|
||||||
|
desc.call_arguments = 0;
|
||||||
|
|
||||||
if (context_p->stack_top_uint8 == LEXER_KEYW_NEW)
|
if (context_p->stack_top_uint8 == LEXER_KEYW_NEW)
|
||||||
{
|
{
|
||||||
if (context_p->token.type == LEXER_LEFT_PAREN)
|
if (context_p->token.type == LEXER_LEFT_PAREN)
|
||||||
{
|
{
|
||||||
parser_stack_pop_uint8 (context_p);
|
parser_stack_pop_uint8 (context_p);
|
||||||
opcode = CBC_NEW;
|
desc.opcode = CBC_NEW;
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL
|
|
||||||
&& context_p->last_cbc.literal_keyword_type == LEXER_KEYW_EVAL
|
|
||||||
&& context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL)
|
|
||||||
{
|
|
||||||
is_eval = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PARSER_IS_PUSH_PROP (context_p->last_cbc_opcode))
|
return desc;
|
||||||
{
|
|
||||||
opcode = CBC_CALL_PROP;
|
|
||||||
context_p->last_cbc_opcode = PARSER_PUSH_PROP_TO_PUSH_PROP_REFERENCE (context_p->last_cbc_opcode);
|
|
||||||
}
|
}
|
||||||
else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_CONSTRUCTOR))
|
|
||||||
|
switch (context_p->last_cbc_opcode)
|
||||||
{
|
{
|
||||||
opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_CALL);
|
case CBC_PUSH_LITERAL:
|
||||||
}
|
|
||||||
else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP_LITERAL))
|
|
||||||
{
|
{
|
||||||
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_PROP_LITERAL_REFERENCE);
|
if (context_p->last_cbc.literal_keyword_type == LEXER_KEYW_EVAL
|
||||||
opcode = CBC_CALL_PROP;
|
&& context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL)
|
||||||
}
|
{
|
||||||
else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP))
|
desc.status_flags |= PARSER_CALL_REFERENCE_DIRECT_EVAL;
|
||||||
{
|
}
|
||||||
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_PROP_REFERENCE);
|
/* FALLTHRU */
|
||||||
opcode = CBC_CALL_PROP;
|
}
|
||||||
}
|
case CBC_PUSH_TWO_LITERALS:
|
||||||
else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_PRIVATE_PROP_LITERAL))
|
case CBC_PUSH_THIS_LITERAL:
|
||||||
{
|
case CBC_PUSH_THREE_LITERALS:
|
||||||
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_PRIVATE_PROP_LITERAL_REFERENCE);
|
{
|
||||||
opcode = CBC_CALL_PROP;
|
JERRY_ASSERT (PARSER_IS_PUSH_LITERALS_WITH_THIS (context_p->last_cbc_opcode));
|
||||||
}
|
|
||||||
else if (JERRY_UNLIKELY (context_p->status_flags & PARSER_INSIDE_WITH)
|
if (JERRY_UNLIKELY (context_p->status_flags & PARSER_INSIDE_WITH)
|
||||||
&& PARSER_IS_PUSH_LITERALS_WITH_THIS (context_p->last_cbc_opcode)
|
|
||||||
&& context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL)
|
&& context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL)
|
||||||
{
|
{
|
||||||
opcode = CBC_CALL_PROP;
|
|
||||||
parser_emit_ident_reference (context_p, CBC_PUSH_IDENT_REFERENCE);
|
parser_emit_ident_reference (context_p, CBC_PUSH_IDENT_REFERENCE);
|
||||||
parser_emit_cbc_ext (context_p, CBC_EXT_RESOLVE_BASE);
|
parser_emit_cbc_ext (context_p, CBC_EXT_RESOLVE_BASE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
case CBC_PUSH_PROP:
|
||||||
|
case CBC_PUSH_PROP_LITERAL:
|
||||||
|
case CBC_PUSH_PROP_LITERAL_LITERAL:
|
||||||
|
case CBC_PUSH_PROP_THIS_LITERAL:
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (PARSER_IS_PUSH_PROP (context_p->last_cbc_opcode));
|
||||||
|
context_p->last_cbc_opcode = PARSER_PUSH_PROP_TO_PUSH_PROP_REFERENCE (context_p->last_cbc_opcode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_CONSTRUCTOR):
|
||||||
|
{
|
||||||
|
desc.opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_CALL);
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
case PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP_LITERAL):
|
||||||
|
{
|
||||||
|
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_PROP_LITERAL_REFERENCE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP):
|
||||||
|
{
|
||||||
|
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_PROP_REFERENCE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_PRIVATE_PROP_LITERAL):
|
||||||
|
{
|
||||||
|
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_PRIVATE_PROP_LITERAL_REFERENCE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return desc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has_spread_element = false;
|
desc.opcode = CBC_CALL_PROP;
|
||||||
|
return desc;
|
||||||
|
} /* parser_form_call_reference */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expect the closing left parenthesis of a call expression
|
||||||
|
*/
|
||||||
|
static inline void
|
||||||
|
parser_expect_arguments_list_end (parser_context_t *context_p) /**< context */
|
||||||
|
{
|
||||||
|
if (context_p->token.type != LEXER_RIGHT_PAREN)
|
||||||
|
{
|
||||||
|
parser_raise_error (context_p, PARSER_ERR_RIGHT_PAREN_EXPECTED);
|
||||||
|
}
|
||||||
|
} /* parser_expect_arguments_list_end */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse arguments list of a call expression
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
parser_process_call_arguments (parser_context_t *context_p, /**< context */
|
||||||
|
parser_call_reference_t *call_ref_p) /**< call reference */
|
||||||
|
{
|
||||||
if (context_p->token.type == LEXER_TEMPLATE_LITERAL)
|
if (context_p->token.type == LEXER_TEMPLATE_LITERAL)
|
||||||
{
|
{
|
||||||
call_arguments = parser_parse_tagged_template_literal (context_p);
|
call_ref_p->call_arguments = (uint16_t) parser_parse_tagged_template_literal (context_p);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
uint32_t call_arguments = 0;
|
||||||
|
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
|
|
||||||
while (context_p->token.type != LEXER_RIGHT_PAREN)
|
while (context_p->token.type != LEXER_RIGHT_PAREN)
|
||||||
@@ -2538,7 +2642,7 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
|
|||||||
|
|
||||||
if (context_p->token.type == LEXER_THREE_DOTS)
|
if (context_p->token.type == LEXER_THREE_DOTS)
|
||||||
{
|
{
|
||||||
has_spread_element = true;
|
call_ref_p->status_flags |= PARSER_CALL_REFERENCE_SPREAD;
|
||||||
call_arguments++;
|
call_arguments++;
|
||||||
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_SPREAD_ELEMENT);
|
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_SPREAD_ELEMENT);
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
@@ -2552,19 +2656,20 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context_p->token.type != LEXER_RIGHT_PAREN)
|
parser_expect_arguments_list_end (context_p);
|
||||||
{
|
|
||||||
parser_raise_error (context_p, PARSER_ERR_RIGHT_PAREN_EXPECTED);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
lexer_next_token (context_p);
|
JERRY_ASSERT (context_p->token.type == LEXER_RIGHT_PAREN);
|
||||||
|
call_ref_p->call_arguments = call_arguments;
|
||||||
|
} /* parser_process_call_arguments */
|
||||||
|
|
||||||
if (is_eval)
|
/**
|
||||||
{
|
* Save local options flags for direct eval
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
parser_prepare_direct_eval_call (parser_context_t *context_p) /**< context */
|
||||||
|
{
|
||||||
context_p->status_flags |= PARSER_LEXICAL_ENV_NEEDED;
|
context_p->status_flags |= PARSER_LEXICAL_ENV_NEEDED;
|
||||||
|
|
||||||
uint16_t eval_flags = PARSER_SAVE_STATUS_FLAGS (context_p->status_flags);
|
uint16_t eval_flags = PARSER_SAVE_STATUS_FLAGS (context_p->status_flags);
|
||||||
@@ -2589,99 +2694,308 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
|
|||||||
{
|
{
|
||||||
parser_emit_cbc (context_p, CBC_EVAL);
|
parser_emit_cbc (context_p, CBC_EVAL);
|
||||||
}
|
}
|
||||||
|
} /* parser_prepare_direct_eval_call */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emit bytecode for spread call
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
parser_emit_spread_call (parser_context_t *context_p, /**< context */
|
||||||
|
parser_call_reference_t *call_ref_p) /**< call reference */
|
||||||
|
{
|
||||||
|
uint16_t call_opcode;
|
||||||
|
|
||||||
|
switch (call_ref_p->opcode)
|
||||||
|
{
|
||||||
|
case CBC_CALL:
|
||||||
|
{
|
||||||
|
call_opcode = CBC_EXT_SPREAD_CALL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CBC_CALL_PROP:
|
||||||
|
{
|
||||||
|
call_opcode = CBC_EXT_SPREAD_CALL_PROP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CBC_NEW:
|
||||||
|
{
|
||||||
|
call_opcode = CBC_EXT_SPREAD_NEW;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_CALL):
|
||||||
|
{
|
||||||
|
call_opcode = CBC_EXT_SPREAD_SUPER_CALL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
JERRY_UNREACHABLE ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_spread_element)
|
parser_emit_cbc_ext_call (context_p, call_opcode, call_ref_p->call_arguments);
|
||||||
{
|
} /* parser_emit_spread_call */
|
||||||
uint16_t spread_opcode;
|
|
||||||
|
|
||||||
if (opcode == CBC_CALL)
|
/**
|
||||||
{
|
* Emit call opcode with 0 or 1 argument
|
||||||
spread_opcode = CBC_EXT_SPREAD_CALL;
|
*/
|
||||||
}
|
static void
|
||||||
else if (opcode == CBC_CALL_PROP)
|
parser_emit_call_01 (parser_context_t *context_p, /**< context */
|
||||||
{
|
parser_call_reference_t *call_ref_p) /**< call reference */
|
||||||
spread_opcode = CBC_EXT_SPREAD_CALL_PROP;
|
{
|
||||||
}
|
JERRY_ASSERT (call_ref_p->call_arguments <= 1);
|
||||||
else if (opcode == CBC_NEW)
|
|
||||||
{
|
|
||||||
spread_opcode = CBC_EXT_SPREAD_NEW;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* opcode is unchanged */
|
|
||||||
JERRY_ASSERT (opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_CALL));
|
|
||||||
spread_opcode = CBC_EXT_SPREAD_SUPER_CALL;
|
|
||||||
}
|
|
||||||
|
|
||||||
parser_emit_cbc_ext_call (context_p, spread_opcode, call_arguments);
|
switch (call_ref_p->opcode)
|
||||||
continue;
|
{
|
||||||
|
case CBC_CALL:
|
||||||
|
{
|
||||||
|
parser_emit_cbc (context_p, (uint16_t) (CBC_CALL0 + (call_ref_p->call_arguments * 6)));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
case CBC_CALL_PROP:
|
||||||
|
{
|
||||||
|
parser_emit_cbc (context_p, (uint16_t) (CBC_CALL0_PROP + (call_ref_p->call_arguments * 6)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CBC_NEW:
|
||||||
|
{
|
||||||
|
parser_emit_cbc (context_p, (uint16_t) (CBC_NEW0 + call_ref_p->call_arguments));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
parser_emit_cbc_call (context_p, call_ref_p->opcode, call_ref_p->call_arguments);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} /* parser_emit_call_01 */
|
||||||
|
|
||||||
if (call_arguments <= 1)
|
/**
|
||||||
|
* Emit call opcode with 2 arguments
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
parser_emit_call_2 (parser_context_t *context_p, /**< context */
|
||||||
|
parser_call_reference_t *call_ref_p) /**< call reference */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (call_ref_p->call_arguments == 2);
|
||||||
|
|
||||||
|
switch (call_ref_p->opcode)
|
||||||
{
|
{
|
||||||
if (opcode == CBC_CALL)
|
case CBC_CALL:
|
||||||
{
|
|
||||||
parser_emit_cbc (context_p, (uint16_t) (CBC_CALL0 + (call_arguments * 6)));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (opcode == CBC_CALL_PROP)
|
|
||||||
{
|
|
||||||
parser_emit_cbc (context_p, (uint16_t) (CBC_CALL0_PROP + (call_arguments * 6)));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (opcode == CBC_NEW)
|
|
||||||
{
|
|
||||||
parser_emit_cbc (context_p, (uint16_t) (CBC_NEW0 + call_arguments));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (call_arguments == 2)
|
|
||||||
{
|
|
||||||
if (opcode == CBC_CALL)
|
|
||||||
{
|
{
|
||||||
parser_emit_cbc (context_p, CBC_CALL2);
|
parser_emit_cbc (context_p, CBC_CALL2);
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
if (opcode == CBC_CALL_PROP)
|
case CBC_CALL_PROP:
|
||||||
{
|
{
|
||||||
parser_flush_cbc (context_p);
|
parser_flush_cbc (context_p);
|
||||||
/* Manually adjusting stack usage. */
|
/* Manually adjusting stack usage. */
|
||||||
JERRY_ASSERT (context_p->stack_depth > 0);
|
JERRY_ASSERT (context_p->stack_depth > 0);
|
||||||
context_p->stack_depth--;
|
context_p->stack_depth--;
|
||||||
parser_emit_cbc (context_p, CBC_CALL2_PROP);
|
parser_emit_cbc (context_p, CBC_CALL2_PROP);
|
||||||
continue;
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
parser_emit_cbc_call (context_p, opcode, call_arguments);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
if (context_p->stack_top_uint8 == LEXER_KEYW_NEW)
|
parser_emit_cbc_call (context_p, call_ref_p->opcode, call_ref_p->call_arguments);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} /* parser_emit_call_2 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse expr(arguments) or expr`template literal`
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
parser_parse_call_expression (parser_context_t *context_p, /**< context */
|
||||||
|
parser_call_reference_t *call_ref_p) /**< call reference */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (context_p->token.type == LEXER_LEFT_PAREN || context_p->token.type == LEXER_TEMPLATE_LITERAL);
|
||||||
|
|
||||||
|
parser_process_call_arguments (context_p, call_ref_p);
|
||||||
|
|
||||||
|
lexer_next_token (context_p);
|
||||||
|
|
||||||
|
if (call_ref_p->status_flags & PARSER_CALL_REFERENCE_DIRECT_EVAL)
|
||||||
{
|
{
|
||||||
|
parser_prepare_direct_eval_call (context_p);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (call_ref_p->status_flags & PARSER_CALL_REFERENCE_SPREAD)
|
||||||
|
{
|
||||||
|
parser_emit_spread_call (context_p, call_ref_p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (call_ref_p->call_arguments <= 1)
|
||||||
|
{
|
||||||
|
parser_emit_call_01 (context_p, call_ref_p);
|
||||||
|
}
|
||||||
|
else if (call_ref_p->call_arguments == 2)
|
||||||
|
{
|
||||||
|
parser_emit_call_2 (context_p, call_ref_p);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parser_emit_cbc_call (context_p, call_ref_p->opcode, call_ref_p->call_arguments);
|
||||||
|
}
|
||||||
|
} /* parser_parse_call_expression */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process 'expr?.'
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
parser_parse_optional_chain (parser_context_t *context_p, /**< context */
|
||||||
|
size_t *grouping_level_p) /**< grouping level */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (context_p->token.type == LEXER_QUESTION_MARK_DOT);
|
||||||
|
|
||||||
|
parser_push_result (context_p);
|
||||||
|
|
||||||
|
parser_branch_t branch;
|
||||||
|
|
||||||
|
switch (lexer_peek_next_character (context_p))
|
||||||
|
{
|
||||||
|
case LIT_CHAR_GRAVE_ACCENT:
|
||||||
|
{
|
||||||
|
parser_raise_error (context_p, PARSER_ERR_INVALID_TAGGED_TEMPLATE_OPTIONAL_CHAIN);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LIT_CHAR_LEFT_PAREN:
|
||||||
|
{
|
||||||
|
lexer_next_token (context_p);
|
||||||
|
parser_call_reference_t call_ref = parser_form_call_reference (context_p);
|
||||||
|
|
||||||
|
parser_emit_cbc_ext_forward_branch (context_p, CBC_EXT_BRANCH_OPTIONAL_CHAIN, &branch);
|
||||||
|
|
||||||
|
if (call_ref.opcode == CBC_CALL_PROP)
|
||||||
|
{
|
||||||
|
parser_emit_cbc_ext (context_p, CBC_EXT_POP_REFERENCE);
|
||||||
|
parser_flush_cbc (context_p);
|
||||||
|
JERRY_ASSERT (context_p->stack_limit - context_p->stack_depth >= 2);
|
||||||
|
PARSER_PLUS_EQUAL_U16 (context_p->stack_depth, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
parser_parse_call_expression (context_p, &call_ref);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LIT_CHAR_LEFT_SQUARE:
|
||||||
|
{
|
||||||
|
parser_emit_cbc_ext_forward_branch (context_p, CBC_EXT_BRANCH_OPTIONAL_CHAIN, &branch);
|
||||||
|
|
||||||
|
lexer_next_token (context_p);
|
||||||
|
parser_parse_square_bracketed_expression (context_p);
|
||||||
|
parser_emit_cbc (context_p, CBC_PUSH_PROP);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
parser_emit_cbc_ext_forward_branch (context_p, CBC_EXT_BRANCH_OPTIONAL_CHAIN, &branch);
|
||||||
|
parser_parse_property_access (context_p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
switch (context_p->token.type)
|
||||||
|
{
|
||||||
|
case LEXER_TEMPLATE_LITERAL:
|
||||||
|
case LEXER_INCREASE:
|
||||||
|
case LEXER_DECREASE:
|
||||||
|
{
|
||||||
|
parser_raise_error (context_p, PARSER_ERR_INVALID_TAGGED_TEMPLATE_OPTIONAL_CHAIN);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LEXER_DOT:
|
||||||
|
case LEXER_LEFT_PAREN:
|
||||||
|
case LEXER_LEFT_SQUARE:
|
||||||
|
case LEXER_QUESTION_MARK_DOT:
|
||||||
|
{
|
||||||
|
size_t grouping_level = *grouping_level_p | PARSE_EXPR_LEFT_HAND_SIDE;
|
||||||
|
parser_parse_postfix_expresion (context_p, &grouping_level);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LEXER_RIGHT_PAREN:
|
||||||
|
{
|
||||||
|
if (parser_process_group_expression (context_p, grouping_level_p))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
parser_push_result (context_p);
|
||||||
|
|
||||||
|
parser_set_branch_to_current_position (context_p, &branch);
|
||||||
|
|
||||||
|
if (LEXER_IS_BINARY_LVALUE_OP_TOKEN (context_p->token.type))
|
||||||
|
{
|
||||||
|
parser_raise_error (context_p, PARSER_ERR_INVALID_LHS_ASSIGNMENT);
|
||||||
|
}
|
||||||
|
} /* parser_parse_optional_chain */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process 'new expr'
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
parser_process_new_expression (parser_context_t *context_p) /**< context */
|
||||||
|
{
|
||||||
|
JERRY_ASSERT (context_p->stack_top_uint8 == LEXER_KEYW_NEW);
|
||||||
|
|
||||||
parser_push_result (context_p);
|
parser_push_result (context_p);
|
||||||
parser_emit_cbc (context_p, CBC_NEW0);
|
parser_emit_cbc (context_p, CBC_NEW0);
|
||||||
parser_stack_pop_uint8 (context_p);
|
parser_stack_pop_uint8 (context_p);
|
||||||
continue;
|
} /* parser_process_new_expression */
|
||||||
}
|
|
||||||
|
|
||||||
if (!(context_p->token.flags & LEXER_WAS_NEWLINE)
|
/**
|
||||||
&& (context_p->token.type == LEXER_INCREASE || context_p->token.type == LEXER_DECREASE)
|
* Process postfix unary lvalue operators (++, --)
|
||||||
&& grouping_level != PARSE_EXPR_LEFT_HAND_SIDE)
|
*/
|
||||||
|
static void
|
||||||
|
parser_parse_postfix_lvalue (parser_context_t *context_p, /**< context */
|
||||||
|
size_t grouping_level) /**< grouping level */
|
||||||
|
{
|
||||||
|
if ((context_p->token.flags & LEXER_WAS_NEWLINE) || grouping_level == PARSE_EXPR_LEFT_HAND_SIDE)
|
||||||
{
|
{
|
||||||
cbc_opcode_t opcode = (context_p->token.type == LEXER_INCREASE) ? CBC_POST_INCR : CBC_POST_DECR;
|
return;
|
||||||
parser_push_result (context_p);
|
|
||||||
parser_emit_unary_lvalue_opcode (context_p, opcode);
|
|
||||||
lexer_next_token (context_p);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (context_p->token.type)
|
||||||
|
{
|
||||||
|
case LEXER_INCREASE:
|
||||||
|
{
|
||||||
|
parser_push_result (context_p);
|
||||||
|
parser_emit_unary_lvalue_opcode (context_p, CBC_POST_INCR);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LEXER_DECREASE:
|
||||||
|
{
|
||||||
|
parser_push_result (context_p);
|
||||||
|
parser_emit_unary_lvalue_opcode (context_p, CBC_POST_DECR);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lexer_next_token (context_p);
|
||||||
|
} /* parser_parse_postfix_lvalue */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emit bytecode for prefix unary tokes
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
parser_process_prefix_unary_opcodes (parser_context_t *context_p) /**< context */
|
||||||
|
{
|
||||||
uint8_t last_unary_token = LEXER_INCREASE;
|
uint8_t last_unary_token = LEXER_INCREASE;
|
||||||
|
|
||||||
/* Generate byte code for the unary operators. */
|
/* Generate byte code for the unary operators. */
|
||||||
@@ -2753,7 +3067,60 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} /* parser_process_unary_expression */
|
} /* parser_process_prefix_unary_opcodes */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the postfix part of the expression
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
parser_parse_postfix_expresion (parser_context_t *context_p, /**< context */
|
||||||
|
size_t *grouping_level_p) /**< grouping level */
|
||||||
|
{
|
||||||
|
/* Parse postfix part of a primary expression. */
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
/* Since break would only break the switch, we use
|
||||||
|
* continue to continue this loop. Without continue,
|
||||||
|
* the code abandons the loop. */
|
||||||
|
switch (context_p->token.type)
|
||||||
|
{
|
||||||
|
case LEXER_DOT:
|
||||||
|
{
|
||||||
|
parser_parse_property_access (context_p);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
case LEXER_LEFT_SQUARE:
|
||||||
|
{
|
||||||
|
parser_parse_element_access (context_p);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
case LEXER_QUESTION_MARK_DOT:
|
||||||
|
{
|
||||||
|
parser_parse_optional_chain (context_p, grouping_level_p);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
case LEXER_TEMPLATE_LITERAL:
|
||||||
|
case LEXER_LEFT_PAREN:
|
||||||
|
{
|
||||||
|
parser_call_reference_t call_ref = parser_form_call_reference (context_p);
|
||||||
|
parser_parse_call_expression (context_p, &call_ref);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
if (context_p->stack_top_uint8 == LEXER_KEYW_NEW)
|
||||||
|
{
|
||||||
|
parser_process_new_expression (context_p);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
parser_parse_postfix_lvalue (context_p, *grouping_level_p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} /* parser_parse_postfix_expresion */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a binary '=' token.
|
* Append a binary '=' token.
|
||||||
@@ -2947,8 +3314,8 @@ parser_check_invalid_logical_op (parser_context_t *context_p, /**< context */
|
|||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
parser_append_binary_lvalue_token (parser_context_t *context_p, /**< context */
|
parser_append_binary_lvalue_token (parser_context_t *context_p, /**< context */
|
||||||
bool is_logical_assignment) /**< true - if form logical assignment reference
|
bool is_logical_assignment) /**< true - if form logical assignment
|
||||||
* false - otherwise */
|
* reference false - otherwise */
|
||||||
{
|
{
|
||||||
if (PARSER_IS_PUSH_LITERALS_WITH_THIS (context_p->last_cbc_opcode)
|
if (PARSER_IS_PUSH_LITERALS_WITH_THIS (context_p->last_cbc_opcode)
|
||||||
&& context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL)
|
&& context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL)
|
||||||
@@ -3375,6 +3742,11 @@ parser_pattern_get_target (parser_context_t *context_p, /**< context */
|
|||||||
parser_pattern_flags_t flags) /**< flags */
|
parser_pattern_flags_t flags) /**< flags */
|
||||||
{
|
{
|
||||||
parser_pattern_end_marker_t end_marker;
|
parser_pattern_end_marker_t end_marker;
|
||||||
|
scanner_location_t location;
|
||||||
|
location.column = 0;
|
||||||
|
location.line = 0;
|
||||||
|
location.source_p = NULL;
|
||||||
|
end_marker.location = location;
|
||||||
end_marker.token.type = LEXER_INVALID_PATTERN;
|
end_marker.token.type = LEXER_INVALID_PATTERN;
|
||||||
parser_branch_t skip_init;
|
parser_branch_t skip_init;
|
||||||
|
|
||||||
@@ -4029,10 +4401,16 @@ parser_process_expression_sequence (parser_context_t *context_p) /**< context */
|
|||||||
/**
|
/**
|
||||||
* Process group expression.
|
* Process group expression.
|
||||||
*/
|
*/
|
||||||
static void
|
static bool
|
||||||
parser_process_group_expression (parser_context_t *context_p, /**< context */
|
parser_process_group_expression (parser_context_t *context_p, /**< context */
|
||||||
size_t *grouping_level_p) /**< grouping level */
|
size_t *grouping_level_p) /**< grouping level */
|
||||||
{
|
{
|
||||||
|
if (context_p->token.type != LEXER_RIGHT_PAREN
|
||||||
|
|| (context_p->stack_top_uint8 != LEXER_LEFT_PAREN && context_p->stack_top_uint8 != LEXER_COMMA_SEP_LIST))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
JERRY_ASSERT (*grouping_level_p >= PARSER_GROUPING_LEVEL_INCREASE);
|
JERRY_ASSERT (*grouping_level_p >= PARSER_GROUPING_LEVEL_INCREASE);
|
||||||
(*grouping_level_p) -= PARSER_GROUPING_LEVEL_INCREASE;
|
(*grouping_level_p) -= PARSER_GROUPING_LEVEL_INCREASE;
|
||||||
|
|
||||||
@@ -4056,6 +4434,7 @@ parser_process_group_expression (parser_context_t *context_p, /**< context */
|
|||||||
{
|
{
|
||||||
parser_stack_push_uint8 (context_p, LEXER_ASSIGN_GROUP_EXPR);
|
parser_stack_push_uint8 (context_p, LEXER_ASSIGN_GROUP_EXPR);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
} /* parser_process_group_expression */
|
} /* parser_process_group_expression */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -4124,7 +4503,8 @@ parser_parse_expression (parser_context_t *context_p, /**< context */
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
process_unary_expression:
|
process_unary_expression:
|
||||||
parser_process_unary_expression (context_p, grouping_level);
|
parser_parse_postfix_expresion (context_p, &grouping_level);
|
||||||
|
parser_process_prefix_unary_opcodes (context_p);
|
||||||
|
|
||||||
if (JERRY_LIKELY (grouping_level != PARSE_EXPR_LEFT_HAND_SIDE))
|
if (JERRY_LIKELY (grouping_level != PARSE_EXPR_LEFT_HAND_SIDE))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -736,6 +736,7 @@ bool lexer_check_next_character (parser_context_t *context_p, lit_utf8_byte_t ch
|
|||||||
bool lexer_check_next_characters (parser_context_t *context_p, lit_utf8_byte_t character1, lit_utf8_byte_t character2);
|
bool lexer_check_next_characters (parser_context_t *context_p, lit_utf8_byte_t character1, lit_utf8_byte_t character2);
|
||||||
uint8_t lexer_consume_next_character (parser_context_t *context_p);
|
uint8_t lexer_consume_next_character (parser_context_t *context_p);
|
||||||
bool lexer_check_post_primary_exp (parser_context_t *context_p);
|
bool lexer_check_post_primary_exp (parser_context_t *context_p);
|
||||||
|
lit_code_point_t lexer_peek_next_character (parser_context_t *context_p);
|
||||||
void lexer_skip_empty_statements (parser_context_t *context_p);
|
void lexer_skip_empty_statements (parser_context_t *context_p);
|
||||||
bool lexer_check_arrow (parser_context_t *context_p);
|
bool lexer_check_arrow (parser_context_t *context_p);
|
||||||
bool lexer_check_arrow_param (parser_context_t *context_p);
|
bool lexer_check_arrow_param (parser_context_t *context_p);
|
||||||
|
|||||||
@@ -354,6 +354,29 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
|
|||||||
return SCAN_NEXT_TOKEN;
|
return SCAN_NEXT_TOKEN;
|
||||||
} /* scanner_scan_primary_expression */
|
} /* scanner_scan_primary_expression */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Consume the ?. token
|
||||||
|
*
|
||||||
|
* @return token type to continue the post primary expression parsing
|
||||||
|
*/
|
||||||
|
static lexer_token_type_t
|
||||||
|
scanner_consume_optional_chain (parser_context_t *context_p) /**< context */
|
||||||
|
{
|
||||||
|
switch (lexer_peek_next_character (context_p))
|
||||||
|
{
|
||||||
|
case LIT_CHAR_LEFT_PAREN:
|
||||||
|
case LIT_CHAR_LEFT_SQUARE:
|
||||||
|
{
|
||||||
|
lexer_next_token (context_p);
|
||||||
|
return context_p->token.type;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return LEXER_DOT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} /* scanner_consume_optional_chain */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scan the tokens after the primary expression.
|
* Scan the tokens after the primary expression.
|
||||||
*
|
*
|
||||||
@@ -365,12 +388,18 @@ scanner_scan_post_primary_expression (parser_context_t *context_p, /**< context
|
|||||||
lexer_token_type_t type, /**< current token type */
|
lexer_token_type_t type, /**< current token type */
|
||||||
scan_stack_modes_t stack_top) /**< current stack top */
|
scan_stack_modes_t stack_top) /**< current stack top */
|
||||||
{
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
case LEXER_QUESTION_MARK_DOT:
|
||||||
|
{
|
||||||
|
type = scanner_consume_optional_chain (context_p);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
case LEXER_DOT:
|
case LEXER_DOT:
|
||||||
{
|
{
|
||||||
lexer_scan_identifier (context_p, LEXER_PARSE_NO_OPTS);
|
lexer_scan_identifier (context_p, LEXER_PARSE_NO_OPTS);
|
||||||
|
|
||||||
if (context_p->token.type == LEXER_HASHMARK)
|
if (context_p->token.type == LEXER_HASHMARK)
|
||||||
{
|
{
|
||||||
context_p->token.flags |= LEXER_NO_SKIP_SPACES;
|
context_p->token.flags |= LEXER_NO_SKIP_SPACES;
|
||||||
@@ -436,6 +465,9 @@ scanner_scan_post_primary_expression (parser_context_t *context_p, /**< context
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (LEXER_IS_BINARY_OP_TOKEN (type) && (type != LEXER_KEYW_IN || !SCANNER_IS_FOR_START (stack_top)))
|
if (LEXER_IS_BINARY_OP_TOKEN (type) && (type != LEXER_KEYW_IN || !SCANNER_IS_FOR_START (stack_top)))
|
||||||
{
|
{
|
||||||
scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION;
|
scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION;
|
||||||
|
|||||||
@@ -169,6 +169,7 @@ PARSER_ERROR_DEF (PARSER_ERR_IMPORT_META_REQUIRE_MODULE, "Cannot use 'import.met
|
|||||||
#if JERRY_PARSER
|
#if JERRY_PARSER
|
||||||
PARSER_ERROR_DEF (PARSER_ERR_INVALID_IDENTIFIER_PART, "Character cannot be part of an identifier")
|
PARSER_ERROR_DEF (PARSER_ERR_INVALID_IDENTIFIER_PART, "Character cannot be part of an identifier")
|
||||||
PARSER_ERROR_DEF (PARSER_ERR_EVAL_CANNOT_ASSIGNED, "Eval cannot be assigned to in strict mode")
|
PARSER_ERROR_DEF (PARSER_ERR_EVAL_CANNOT_ASSIGNED, "Eval cannot be assigned to in strict mode")
|
||||||
|
PARSER_ERROR_DEF (PARSER_ERR_INVALID_TAGGED_TEMPLATE_OPTIONAL_CHAIN, "Invalid tagged template on optional chain")
|
||||||
PARSER_ERROR_DEF (PARSER_ERR_WITH_NOT_ALLOWED, "With statement not allowed in strict mode")
|
PARSER_ERROR_DEF (PARSER_ERR_WITH_NOT_ALLOWED, "With statement not allowed in strict mode")
|
||||||
PARSER_ERROR_DEF (PARSER_ERR_NEW_TARGET_NOT_ALLOWED, "new.target expression is not allowed here")
|
PARSER_ERROR_DEF (PARSER_ERR_NEW_TARGET_NOT_ALLOWED, "new.target expression is not allowed here")
|
||||||
PARSER_ERROR_DEF (PARSER_ERR_INVALID_IDENTIFIER_START, "Character cannot be start of an identifier")
|
PARSER_ERROR_DEF (PARSER_ERR_INVALID_IDENTIFIER_START, "Character cannot be start of an identifier")
|
||||||
|
|||||||
@@ -140,3 +140,4 @@ PARSER_ERR_UNDECLARED_PRIVATE_FIELD = "Private field must be declared in an encl
|
|||||||
PARSER_ERR_DELETE_PRIVATE_FIELD = "Private fields can not be deleted"
|
PARSER_ERR_DELETE_PRIVATE_FIELD = "Private fields can not be deleted"
|
||||||
PARSER_ERR_UNEXPECTED_PRIVATE_FIELD = "Unexpected private field"
|
PARSER_ERR_UNEXPECTED_PRIVATE_FIELD = "Unexpected private field"
|
||||||
PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR = "Class constructor may not be a private method"
|
PARSER_ERR_CLASS_PRIVATE_CONSTRUCTOR = "Class constructor may not be a private method"
|
||||||
|
PARSER_ERR_INVALID_TAGGED_TEMPLATE_OPTIONAL_CHAIN = "Invalid tagged template on optional chain"
|
||||||
|
|||||||
+25
-3
@@ -3174,9 +3174,6 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
|||||||
case VM_OC_EVAL:
|
case VM_OC_EVAL:
|
||||||
{
|
{
|
||||||
JERRY_CONTEXT (status_flags) |= ECMA_STATUS_DIRECT_EVAL;
|
JERRY_CONTEXT (status_flags) |= ECMA_STATUS_DIRECT_EVAL;
|
||||||
JERRY_ASSERT ((*byte_code_p >= CBC_CALL && *byte_code_p <= CBC_CALL2_PROP_BLOCK)
|
|
||||||
|| (*byte_code_p == CBC_EXT_OPCODE && byte_code_p[1] >= CBC_EXT_SPREAD_CALL
|
|
||||||
&& byte_code_p[1] <= CBC_EXT_SPREAD_CALL_PROP_BLOCK));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case VM_OC_CALL:
|
case VM_OC_CALL:
|
||||||
@@ -3307,6 +3304,31 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
|||||||
ecma_fast_free_value (value);
|
ecma_fast_free_value (value);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
case VM_OC_BRANCH_OPTIONAL_CHAIN:
|
||||||
|
{
|
||||||
|
left_value = stack_top_p[-1];
|
||||||
|
|
||||||
|
bool pop_reference = byte_code_p[0] == CBC_EXT_OPCODE && byte_code_p[1] == CBC_EXT_POP_REFERENCE;
|
||||||
|
|
||||||
|
if (!(ecma_is_value_null (left_value) || ecma_is_value_undefined (left_value)))
|
||||||
|
{
|
||||||
|
if (pop_reference)
|
||||||
|
{
|
||||||
|
byte_code_p += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
stack_top_p[-1] = ECMA_VALUE_UNDEFINED;
|
||||||
|
byte_code_p = byte_code_start_p + branch_offset;
|
||||||
|
|
||||||
|
if (!pop_reference)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/* FALLTHRU */
|
||||||
|
}
|
||||||
case VM_OC_POP_REFERENCE:
|
case VM_OC_POP_REFERENCE:
|
||||||
{
|
{
|
||||||
ecma_free_value (stack_top_p[-2]);
|
ecma_free_value (stack_top_p[-2]);
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ typedef enum
|
|||||||
|
|
||||||
VM_OC_JUMP, /**< jump */
|
VM_OC_JUMP, /**< jump */
|
||||||
VM_OC_BRANCH_IF_NULLISH, /** branch if undefined or null */
|
VM_OC_BRANCH_IF_NULLISH, /** branch if undefined or null */
|
||||||
|
VM_OC_BRANCH_OPTIONAL_CHAIN, /** branch if undefined or null and adjust stack */
|
||||||
VM_OC_POP_REFERENCE, /** prop identifier or property reference from the stack */
|
VM_OC_POP_REFERENCE, /** prop identifier or property reference from the stack */
|
||||||
VM_OC_BRANCH_IF_STRICT_EQUAL, /**< branch if strict equal */
|
VM_OC_BRANCH_IF_STRICT_EQUAL, /**< branch if strict equal */
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,167 @@
|
|||||||
|
// Copyright JS Foundation and other contributors, http://js.foundation
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
function expectSyntaxError(str) {
|
||||||
|
try {
|
||||||
|
eval(str);
|
||||||
|
assert(false);
|
||||||
|
} catch (e) {
|
||||||
|
assert(e instanceof SyntaxError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function expectTypeError(cb) {
|
||||||
|
try {
|
||||||
|
cb();
|
||||||
|
assert(false);
|
||||||
|
} catch (e) {
|
||||||
|
assert(e instanceof TypeError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expectSyntaxError("this?.a``");
|
||||||
|
expectSyntaxError("this?.['a']``");
|
||||||
|
expectSyntaxError("this?.``");
|
||||||
|
expectSyntaxError("this.a?.``");
|
||||||
|
expectSyntaxError("this['a']?.``");
|
||||||
|
expectSyntaxError("this?.a = 9");
|
||||||
|
expectSyntaxError("this.a.a.a.a.a?.a = 9");
|
||||||
|
expectSyntaxError("this?.a.a.a.a.a.a = 9");
|
||||||
|
expectSyntaxError("this?.a++");
|
||||||
|
expectSyntaxError("this?.a.a.a.a.a.a++");
|
||||||
|
expectSyntaxError("this.a.a.a.a.?a.a++");
|
||||||
|
expectSyntaxError("this?.a--");
|
||||||
|
expectSyntaxError("this?.a.a.a.a.a.a--");
|
||||||
|
expectSyntaxError("this.a.a.a.a.?a.a--");
|
||||||
|
|
||||||
|
var o = {
|
||||||
|
a: 4.1,
|
||||||
|
b() {
|
||||||
|
return 4.2;
|
||||||
|
},
|
||||||
|
c: {
|
||||||
|
a: 4.3,
|
||||||
|
b() {
|
||||||
|
return 4.4
|
||||||
|
}
|
||||||
|
},
|
||||||
|
e(...args) {
|
||||||
|
return args.reduce((p, c) => p + c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
assert(o?.a === 4.1);
|
||||||
|
assert(o?.a2 === undefined);
|
||||||
|
assert(this.o?.a === 4.1);
|
||||||
|
assert(this.o?.a2 === undefined);
|
||||||
|
assert(this.o?.['a'] === 4.1);
|
||||||
|
assert(this.o?.['a2'] === undefined);
|
||||||
|
assert(typeof o?.a === 'number');
|
||||||
|
assert(typeof o?.a2 === 'undefined');
|
||||||
|
|
||||||
|
assert(o?.c?.a === 4.3);
|
||||||
|
assert(o?.c?.a2 === undefined);
|
||||||
|
assert(this.o?.c?.a === 4.3);
|
||||||
|
assert(this.o?.c?.a2 === undefined);
|
||||||
|
assert(this.o?.c?.['a'] === 4.3);
|
||||||
|
assert(this.o?.c?.['a2'] === undefined);
|
||||||
|
assert(typeof o?.c?.a === 'number');
|
||||||
|
assert(typeof o?.c?.a2 === 'undefined');
|
||||||
|
|
||||||
|
assert(o?.d === undefined);
|
||||||
|
assert(o?.d?.d === undefined);
|
||||||
|
assert(o?.d?.d?.['d'] === undefined);
|
||||||
|
|
||||||
|
assert(o?.b?.() === 4.2);
|
||||||
|
assert(o?.b2?.() === undefined);
|
||||||
|
|
||||||
|
assert(o?.c?.b?.() === 4.4);
|
||||||
|
assert(o?.c?.b2?.() === undefined);
|
||||||
|
|
||||||
|
assert(o?.e(...[1.25, 2.25, 3.25]) === 6.75);
|
||||||
|
assert(o?.e(...[1.25, 2.25, 3.25], ...[0.25]) === 7);
|
||||||
|
assert(o?.['e'](...[1.25, 2.25, 3.25]) === 6.75);
|
||||||
|
assert(o?.['e'](...[1.25, 2.25, 3.25], ...[0.25]) === 7);
|
||||||
|
|
||||||
|
assert(o?.e?.(...[1.25, 2.25, 3.25]) === 6.75);
|
||||||
|
assert(o?.e?.(...[1.25, 2.25, 3.25], ...[0.25]) === 7);
|
||||||
|
assert(o?.['e']?.(...[1.25, 2.25, 3.25]) === 6.75);
|
||||||
|
assert(o?.['e']?.(...[1.25, 2.25, 3.25], ...[0.25]) === 7);
|
||||||
|
|
||||||
|
// Test short circuit
|
||||||
|
let count = 0;
|
||||||
|
assert(undefined?.[count++] === undefined);
|
||||||
|
assert(undefined?.[count++]() === undefined);
|
||||||
|
assert(undefined?.[count++]()() === undefined);
|
||||||
|
assert(null?.[count++] === undefined);
|
||||||
|
assert(null?.[count++]() === undefined);
|
||||||
|
assert(null?.[count++]()() === undefined);
|
||||||
|
assert(count === 0);
|
||||||
|
|
||||||
|
// Test optional call
|
||||||
|
var g = undefined;
|
||||||
|
|
||||||
|
function f () {
|
||||||
|
return 4.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(g?.() === undefined);
|
||||||
|
assert(this?.g?.() === undefined);
|
||||||
|
assert(this.g?.() === undefined);
|
||||||
|
|
||||||
|
expectTypeError(_ => {
|
||||||
|
this.g();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert(f?.() === 4.5);
|
||||||
|
assert(this?.f?.() === 4.5);
|
||||||
|
assert(this.f?.() === 4.5);
|
||||||
|
assert(f() === 4.5);
|
||||||
|
|
||||||
|
// test direct eval
|
||||||
|
var a = 5.1;
|
||||||
|
eval('a = 5.2');
|
||||||
|
assert(a === 5.2);
|
||||||
|
eval?.('a = 5.3');
|
||||||
|
assert(a === 5.3);
|
||||||
|
eval?.(...['a = 5.4']);
|
||||||
|
assert(a === 5.4);
|
||||||
|
|
||||||
|
const saved_eval = eval;
|
||||||
|
eval = undefined;
|
||||||
|
|
||||||
|
eval?.('a = 5.5')
|
||||||
|
assert(a === 5.4);
|
||||||
|
eval?.(...['a = 5.5'])
|
||||||
|
assert(a === 5.4);
|
||||||
|
|
||||||
|
eval = saved_eval;
|
||||||
|
|
||||||
|
// test optional private property access
|
||||||
|
class A {
|
||||||
|
#a = 5.1;
|
||||||
|
|
||||||
|
test(o) {
|
||||||
|
return o?.#a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let instance = new A;
|
||||||
|
assert(instance.test(instance) === 5.1);
|
||||||
|
assert(instance.test(undefined) === undefined);
|
||||||
|
assert(instance.test(null) === undefined);
|
||||||
|
expectTypeError(_ => {
|
||||||
|
instance.test({});
|
||||||
|
});
|
||||||
@@ -2003,16 +2003,12 @@
|
|||||||
<test id="language/expressions/class/elements/async-gen-private-method/yield-promise-reject-next.js"><reason></reason></test>
|
<test id="language/expressions/class/elements/async-gen-private-method/yield-promise-reject-next.js"><reason></reason></test>
|
||||||
<test id="language/expressions/class/elements/class-name-static-initializer-anonymous.js"><reason></reason></test>
|
<test id="language/expressions/class/elements/class-name-static-initializer-anonymous.js"><reason></reason></test>
|
||||||
<test id="language/expressions/class/elements/class-name-static-initializer-default-export.js"><reason></reason></test>
|
<test id="language/expressions/class/elements/class-name-static-initializer-default-export.js"><reason></reason></test>
|
||||||
<test id="language/expressions/class/elements/grammar-private-field-optional-chaining.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/class/elements/private-field-after-optional-chain.js"><reason></reason></test>
|
|
||||||
<test id="language/statements/class/elements/async-gen-private-method-static/yield-promise-reject-next-catch.js"><reason></reason></test>
|
<test id="language/statements/class/elements/async-gen-private-method-static/yield-promise-reject-next-catch.js"><reason></reason></test>
|
||||||
<test id="language/statements/class/elements/async-gen-private-method-static/yield-promise-reject-next-for-await-of-async-iterator.js"><reason></reason></test>
|
<test id="language/statements/class/elements/async-gen-private-method-static/yield-promise-reject-next-for-await-of-async-iterator.js"><reason></reason></test>
|
||||||
<test id="language/statements/class/elements/async-gen-private-method-static/yield-promise-reject-next.js"><reason></reason></test>
|
<test id="language/statements/class/elements/async-gen-private-method-static/yield-promise-reject-next.js"><reason></reason></test>
|
||||||
<test id="language/statements/class/elements/async-gen-private-method/yield-promise-reject-next-catch.js"><reason></reason></test>
|
<test id="language/statements/class/elements/async-gen-private-method/yield-promise-reject-next-catch.js"><reason></reason></test>
|
||||||
<test id="language/statements/class/elements/async-gen-private-method/yield-promise-reject-next-for-await-of-async-iterator.js"><reason></reason></test>
|
<test id="language/statements/class/elements/async-gen-private-method/yield-promise-reject-next-for-await-of-async-iterator.js"><reason></reason></test>
|
||||||
<test id="language/statements/class/elements/async-gen-private-method/yield-promise-reject-next.js"><reason></reason></test>
|
<test id="language/statements/class/elements/async-gen-private-method/yield-promise-reject-next.js"><reason></reason></test>
|
||||||
<test id="language/statements/class/elements/grammar-private-field-optional-chaining.js"><reason></reason></test>
|
|
||||||
<test id="language/statements/class/elements/private-field-after-optional-chain.js"><reason></reason></test>
|
|
||||||
<!-- END - ESNext stage 3 proposals: class fields, private methods and static class features -->
|
<!-- END - ESNext stage 3 proposals: class fields, private methods and static class features -->
|
||||||
|
|
||||||
<!-- ESNext stage 3 proposal: top level await
|
<!-- ESNext stage 3 proposal: top level await
|
||||||
@@ -2512,37 +2508,6 @@
|
|||||||
<test id="language/statements/while/tco-body.js"><reason></reason></test>
|
<test id="language/statements/while/tco-body.js"><reason></reason></test>
|
||||||
<!-- END - ES2015: Proper Tail Call (PTC) Optimization -->
|
<!-- END - ES2015: Proper Tail Call (PTC) Optimization -->
|
||||||
|
|
||||||
<!-- ES2020: Optional Chaining
|
|
||||||
features: [optional-chaining]
|
|
||||||
https://github.com/tc39/proposal-optional-chaining
|
|
||||||
-->
|
|
||||||
<test id="language/expressions/optional-chaining/call-expression.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/eval-optional-call.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/iteration-statement-do.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/iteration-statement-for-await-of.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/iteration-statement-for-in.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/iteration-statement-for-of-type-error.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/iteration-statement-for.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/iteration-statement-while.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/member-expression-async-identifier.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/member-expression-async-literal.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/member-expression-async-this.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/member-expression.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/new-target-optional-call.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/optional-call-preserves-this.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/optional-chain-async-optional-chain-square-brackets.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/optional-chain-async-square-brackets.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/optional-chain-expression-optional-expression.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/optional-chain-prod-arguments.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/optional-chain-prod-expression.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/optional-chain-prod-identifiername.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/optional-chain.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/optional-expression.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/runtime-semantics-evaluation.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/short-circuiting.js"><reason></reason></test>
|
|
||||||
<test id="language/expressions/optional-chaining/super-property-optional-call.js"><reason></reason></test>
|
|
||||||
<!-- END - ES2020: Optional Chaining -->
|
|
||||||
|
|
||||||
<!-- ES2017: Shared Memory and Atomics
|
<!-- ES2017: Shared Memory and Atomics
|
||||||
features: [Atomics]
|
features: [Atomics]
|
||||||
https://github.com/tc39/ecmascript_sharedmem
|
https://github.com/tc39/ecmascript_sharedmem
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ shiftNegativeLHS:jerry-math/*.c
|
|||||||
shiftTooManyBits:jerry-core/*.c
|
shiftTooManyBits:jerry-core/*.c
|
||||||
shiftTooManyBitsSigned:jerry-math/*.c
|
shiftTooManyBitsSigned:jerry-math/*.c
|
||||||
signConversionCond:jerry-core/*.c
|
signConversionCond:jerry-core/*.c
|
||||||
uninitvar:jerry-core/parser/js/js-parser-expr.c:3423
|
|
||||||
uninitvar:tests/unit-core/test-api-objecttype.c:119
|
uninitvar:tests/unit-core/test-api-objecttype.c:119
|
||||||
unmatchedSuppression:jerry-core/*.inc.h
|
unmatchedSuppression:jerry-core/*.inc.h
|
||||||
unreadVariable:jerry-core/*.c
|
unreadVariable:jerry-core/*.c
|
||||||
|
|||||||
Reference in New Issue
Block a user