Skip to content

Commit 242134f

Browse files
author
Robert Fancsik
committed
Implement optional chaining
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 53b61c1 commit 242134f

File tree

13 files changed

+1027
-417
lines changed

13 files changed

+1027
-417
lines changed

jerry-core/parser/js/byte-code.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ JERRY_STATIC_ASSERT (offsetof (cbc_uint8_arguments_t, script_value) == offsetof
2828
* whenever new bytecodes are introduced or existing ones have been deleted.
2929
*/
3030
JERRY_STATIC_ASSERT (CBC_END == 238, number_of_cbc_opcodes_changed);
31-
JERRY_STATIC_ASSERT (CBC_EXT_END == 167, number_of_cbc_ext_opcodes_changed);
31+
JERRY_STATIC_ASSERT (CBC_EXT_END == 170, number_of_cbc_ext_opcodes_changed);
3232

3333
#if JERRY_PARSER || JERRY_PARSER_DUMP_BYTE_CODE
3434

jerry-core/parser/js/byte-code.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,9 @@
504504
CBC_FORWARD_BRANCH (CBC_EXT_DEFAULT_INITIALIZER, -1, VM_OC_DEFAULT_INITIALIZER) \
505505
CBC_OPCODE (CBC_EXT_ERROR, CBC_NO_FLAG, 0, VM_OC_ERROR) \
506506
CBC_FORWARD_BRANCH (CBC_EXT_BRANCH_IF_NULLISH, -1, VM_OC_BRANCH_IF_NULLISH) \
507-
\
508-
/* Basic opcodes. */ \
509507
CBC_OPCODE (CBC_EXT_POP_REFERENCE, CBC_NO_FLAG, -2, VM_OC_POP_REFERENCE) \
508+
CBC_FORWARD_BRANCH (CBC_EXT_BRANCH_OPTIONAL_CHAIN, 0, VM_OC_BRANCH_OPTIONAL_CHAIN) \
509+
/* Basic opcodes. */ \
510510
CBC_OPCODE (CBC_EXT_CREATE_ARGUMENTS, CBC_HAS_LITERAL_ARG, 0, VM_OC_CREATE_ARGUMENTS) \
511511
CBC_OPCODE (CBC_EXT_CREATE_VAR_EVAL, CBC_HAS_LITERAL_ARG, 0, VM_OC_EXT_VAR_EVAL) \
512512
CBC_OPCODE (CBC_EXT_CREATE_VAR_FUNC_EVAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, VM_OC_EXT_VAR_EVAL) \

jerry-core/parser/js/js-lexer.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,29 @@ lexer_skip_spaces (parser_context_t *context_p) /**< context */
390390

391391
#if JERRY_ESNEXT
392392

393+
/**
394+
* Checks the next token start character.
395+
*
396+
* @return LIT_INVALID_CP - if there is no more characters to read
397+
* next byte - otherwise
398+
*/
399+
lit_code_point_t
400+
lexer_peek_next_character (parser_context_t *context_p) /**< context */
401+
{
402+
if (!(context_p->token.flags & LEXER_NO_SKIP_SPACES))
403+
{
404+
lexer_skip_spaces (context_p);
405+
context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES);
406+
}
407+
408+
if (context_p->source_p < context_p->source_end_p)
409+
{
410+
return context_p->source_p[0];
411+
}
412+
413+
return LIT_INVALID_CP;
414+
} /* lexer_check_next_character */
415+
393416
/**
394417
* Skip all the continuous empty statements.
395418
*/
@@ -1845,6 +1868,15 @@ lexer_next_token (parser_context_t *context_p) /**< context */
18451868
length = 2;
18461869
break;
18471870
}
1871+
if (context_p->source_p[1] == (uint8_t) LIT_CHAR_DOT)
1872+
{
1873+
if (length < 3 || !lit_char_is_decimal_digit (context_p->source_p[2]))
1874+
{
1875+
context_p->token.type = LEXER_QUESTION_MARK_DOT;
1876+
length = 2;
1877+
break;
1878+
}
1879+
}
18481880
}
18491881
#endif /* JERRY_ESNEXT */
18501882
context_p->token.type = LEXER_QUESTION_MARK;

jerry-core/parser/js/js-lexer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ typedef enum
171171
LEXER_RIGHT_PAREN, /**< ")" */
172172
LEXER_RIGHT_SQUARE, /**< "]" */
173173
LEXER_DOT, /**< "." */
174+
LEXER_QUESTION_MARK_DOT, /**< "?." */
174175
LEXER_SEMICOLON, /**< ";" */
175176
LEXER_COLON, /**< ":" */
176177
LEXER_COMMA, /**< "," */

0 commit comments

Comments
 (0)