diff --git a/jerry-core/parser/js/byte-code.c b/jerry-core/parser/js/byte-code.c
index c188098b4..4ba63cd3d 100644
--- a/jerry-core/parser/js/byte-code.c
+++ b/jerry-core/parser/js/byte-code.c
@@ -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.
*/
JERRY_STATIC_ASSERT (CBC_END == 238, number_of_cbc_opcodes_changed);
-JERRY_STATIC_ASSERT (CBC_EXT_END == 166, number_of_cbc_ext_opcodes_changed);
+JERRY_STATIC_ASSERT (CBC_EXT_END == 167, number_of_cbc_ext_opcodes_changed);
#if JERRY_PARSER || JERRY_PARSER_DUMP_BYTE_CODE
diff --git a/jerry-core/parser/js/byte-code.h b/jerry-core/parser/js/byte-code.h
index 6eb6512fc..18d5325e9 100644
--- a/jerry-core/parser/js/byte-code.h
+++ b/jerry-core/parser/js/byte-code.h
@@ -581,6 +581,10 @@
VM_OC_PUSH_STATIC_FIELD_FUNC | VM_OC_GET_LITERAL) \
CBC_OPCODE (CBC_EXT_ADD_COMPUTED_FIELD, CBC_NO_FLAG, -1, VM_OC_ADD_COMPUTED_FIELD | VM_OC_GET_STACK) \
CBC_OPCODE (CBC_EXT_ADD_STATIC_COMPUTED_FIELD, CBC_NO_FLAG, -1, VM_OC_ADD_COMPUTED_FIELD | VM_OC_GET_STACK) \
+ CBC_OPCODE (CBC_EXT_CLASS_CALL_STATIC_BLOCK, \
+ CBC_HAS_LITERAL_ARG, \
+ 0, \
+ VM_OC_CLASS_CALL_STATIC_BLOCK | VM_OC_GET_LITERAL) \
/* Class private property related opcodes */ \
CBC_OPCODE (CBC_EXT_PUSH_PRIVATE_PROP_LITERAL_REFERENCE, \
CBC_HAS_LITERAL_ARG, \
diff --git a/jerry-core/parser/js/js-lexer.c b/jerry-core/parser/js/js-lexer.c
index 585bde84e..898303cfb 100644
--- a/jerry-core/parser/js/js-lexer.c
+++ b/jerry-core/parser/js/js-lexer.c
@@ -781,7 +781,7 @@ lexer_parse_identifier (parser_context_t *context_p, /**< context */
#if JERRY_ESNEXT
if (JERRY_UNLIKELY (keyword_p->type == LEXER_KEYW_AWAIT))
{
- if (!(context_p->status_flags & PARSER_IS_ASYNC_FUNCTION)
+ if (!(context_p->status_flags & (PARSER_IS_ASYNC_FUNCTION | PARSER_IS_CLASS_STATIC_BLOCK))
&& !(context_p->global_status_flags & ECMA_PARSE_MODULE))
{
break;
@@ -2833,6 +2833,33 @@ lexer_construct_function_object (parser_context_t *context_p, /**< context */
return result_index;
} /* lexer_construct_function_object */
+#if JERRY_ESNEXT
+/**
+ * Construct a class static block function literal object.
+ *
+ * @return function object literal index
+ */
+uint16_t
+lexer_construct_class_static_block_function (parser_context_t *context_p) /**< context */
+{
+ ecma_compiled_code_t *compiled_code_p;
+ lexer_literal_t *literal_p;
+ uint16_t result_index;
+
+ literal_p = lexer_construct_unused_literal (context_p);
+ result_index = context_p->literal_count;
+ context_p->literal_count++;
+
+ parser_flush_cbc (context_p);
+ compiled_code_p = parser_parse_class_static_block (context_p);
+
+ literal_p->u.bytecode_p = compiled_code_p;
+ literal_p->type = LEXER_FUNCTION_LITERAL;
+
+ return result_index;
+} /* lexer_construct_class_static_block_function */
+#endif /* JERRY_ESNEXT */
+
/**
* Construct a regular expression object.
*
@@ -3244,6 +3271,17 @@ lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */
break;
}
#endif /* JERRY_ESNEXT */
+ case LIT_CHAR_LEFT_BRACE:
+ {
+ if (ident_opts & (LEXER_OBJ_IDENT_CLASS_NO_STATIC | LEXER_OBJ_IDENT_CLASS_PRIVATE))
+ {
+ break;
+ }
+
+ context_p->token.type = LEXER_LEFT_BRACE;
+ lexer_consume_next_character (context_p);
+ return;
+ }
case LIT_CHAR_RIGHT_BRACE:
{
if (ident_opts & LEXER_OBJ_IDENT_ONLY_IDENTIFIERS)
diff --git a/jerry-core/parser/js/js-parser-expr.c b/jerry-core/parser/js/js-parser-expr.c
index c02205440..03309c128 100644
--- a/jerry-core/parser/js/js-parser-expr.c
+++ b/jerry-core/parser/js/js-parser-expr.c
@@ -847,11 +847,13 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
}
}
+ bool is_static_block = context_p->token.type == LEXER_LEFT_BRACE;
+
if (context_p->token.type == LEXER_RIGHT_SQUARE)
{
is_computed = true;
}
- else if (LEXER_IS_IDENT_OR_STRING (context_p->token.lit_location.type))
+ else if (!is_static_block && LEXER_IS_IDENT_OR_STRING (context_p->token.lit_location.type))
{
if (is_static && !is_private)
{
@@ -869,7 +871,7 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
if (!(status_flags & (PARSER_IS_ASYNC_FUNCTION | PARSER_IS_GENERATOR_FUNCTION)))
{
- if (!lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN))
+ if (is_static_block || !lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN))
{
/* Class field. */
if (fields_size == 0)
@@ -889,7 +891,7 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
parser_emit_cbc_ext_literal_from_token (context_p, field_opcode);
}
- if (is_static && parser_is_constructor_literal (context_p))
+ if (is_static && !is_static_block && parser_is_constructor_literal (context_p))
{
parser_raise_error (context_p, PARSER_ERR_ARGUMENT_LIST_EXPECTED);
}
@@ -925,7 +927,31 @@ parser_parse_class_body (parser_context_t *context_p, /**< context */
}
}
- if (lexer_consume_assign (context_p))
+ if (is_static_block)
+ {
+ class_field_type |= PARSER_CLASS_FIELD_STATIC_BLOCK;
+
+ if (context_p->next_scanner_info_p->type != SCANNER_TYPE_CLASS_STATIC_BLOCK_END)
+ {
+ parser_flush_cbc (context_p);
+ parser_parse_class_static_block (context_p);
+ }
+
+ JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_CLASS_STATIC_BLOCK_END);
+
+ scanner_set_location (context_p, &((scanner_location_info_t *) context_p->next_scanner_info_p)->location);
+ scanner_release_next (context_p, sizeof (scanner_location_info_t));
+ JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_FUNCTION);
+ range.start_location.source_p = context_p->next_scanner_info_p->source_p - 1;
+
+ scanner_seek (context_p);
+
+ parser_stack_push (context_p, &range.start_location, sizeof (scanner_location_t));
+ fields_size += sizeof (scanner_location_t);
+
+ lexer_consume_next_character (context_p);
+ }
+ else if (lexer_consume_assign (context_p))
{
class_field_type |= PARSER_CLASS_FIELD_INITIALIZED;
@@ -1738,8 +1764,17 @@ parser_parse_function_expression (parser_context_t *context_p, /**< context */
if (!lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN))
{
+#if JERRY_ESNEXT
+ /* The `await` keyword is interpreted as an IdentifierReference within function expressions */
+ context_p->status_flags &= (uint32_t) ~PARSER_IS_CLASS_STATIC_BLOCK;
+#endif /* JERRY_ESNEXT */
+
lexer_next_token (context_p);
+#if JERRY_ESNEXT
+ context_p->status_flags |= parent_status_flags & PARSER_IS_CLASS_STATIC_BLOCK;
+#endif /* JERRY_ESNEXT */
+
if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL)
{
parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED);
@@ -2168,7 +2203,8 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
#endif /* JERRY_FUNCTION_TO_STRING */
uint32_t arrow_status_flags =
- (PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION | (context_p->status_flags & PARSER_INSIDE_CLASS_FIELD));
+ (PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION
+ | (context_p->status_flags & (PARSER_INSIDE_CLASS_FIELD | PARSER_IS_CLASS_STATIC_BLOCK)));
if (context_p->next_scanner_info_p->u8_arg & SCANNER_FUNCTION_ASYNC)
{
@@ -2425,7 +2461,8 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
#endif /* JERRY_FUNCTION_TO_STRING */
uint32_t arrow_status_flags =
- (PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION | (context_p->status_flags & PARSER_INSIDE_CLASS_FIELD));
+ (PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION
+ | (context_p->status_flags & (PARSER_INSIDE_CLASS_FIELD | PARSER_IS_CLASS_STATIC_BLOCK)));
parser_parse_function_expression (context_p, arrow_status_flags);
return parser_abort_parsing_after_assignment_expression (context_p);
}
diff --git a/jerry-core/parser/js/js-parser-internal.h b/jerry-core/parser/js/js-parser-internal.h
index c61692f61..476b7996d 100644
--- a/jerry-core/parser/js/js-parser-internal.h
+++ b/jerry-core/parser/js/js-parser-internal.h
@@ -76,12 +76,13 @@ typedef enum
PARSER_INSIDE_CLASS_FIELD = (1u << 23), /**< a class field is being parsed */
PARSER_ALLOW_NEW_TARGET = (1u << 24), /**< allow new.target parsing in the current context */
PARSER_IS_METHOD = (1u << 25), /**< method is parsed */
+ PARSER_IS_CLASS_STATIC_BLOCK = (1u << 26), /**< a class static block is parsed */
PARSER_PRIVATE_FUNCTION_NAME = PARSER_IS_FUNC_EXPRESSION, /**< represents private method for
* parser_set_function_name*/
#endif /* JERRY_ESNEXT */
#if JERRY_MODULE_SYSTEM
- PARSER_MODULE_DEFAULT_CLASS_OR_FUNC = (1u << 26), /**< parsing a function or class default export */
- PARSER_MODULE_STORE_IDENT = (1u << 27), /**< store identifier of the current export statement */
+ PARSER_MODULE_DEFAULT_CLASS_OR_FUNC = (1u << 27), /**< parsing a function or class default export */
+ PARSER_MODULE_STORE_IDENT = (1u << 28), /**< store identifier of the current export statement */
#endif /* JERRY_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 */
@@ -144,6 +145,7 @@ typedef enum
PARSER_CLASS_FIELD_NORMAL = (1u << 1), /**< normal (non-computed) class field */
PARSER_CLASS_FIELD_INITIALIZED = (1u << 2), /**< class field is initialized */
PARSER_CLASS_FIELD_STATIC = (1u << 3), /**< static class field */
+ PARSER_CLASS_FIELD_STATIC_BLOCK = (1u << 4), /**< static class field */
} parser_class_field_type_t;
#endif /* JERRY_ESNEXT */
@@ -798,6 +800,9 @@ void lexer_construct_literal_object (parser_context_t *context_p,
bool lexer_construct_number_object (parser_context_t *context_p, bool is_expr, bool is_negative_number);
void lexer_convert_push_number_to_push_literal (parser_context_t *context_p);
uint16_t lexer_construct_function_object (parser_context_t *context_p, uint32_t extra_status_flags);
+#if JERRY_ESNEXT
+uint16_t lexer_construct_class_static_block_function (parser_context_t *context_p);
+#endif /* JERRY_ESNEXT */
void lexer_construct_regexp_object (parser_context_t *context_p, bool parse_only);
bool lexer_compare_identifier_to_string (const lexer_lit_location_t *left_p, const uint8_t *right_p, size_t size);
bool lexer_compare_identifiers (parser_context_t *context_p,
@@ -931,6 +936,7 @@ uint8_t *parser_line_info_generate (parser_context_t *context_p);
ecma_compiled_code_t *parser_parse_function (parser_context_t *context_p, uint32_t status_flags);
#if JERRY_ESNEXT
+ecma_compiled_code_t *parser_parse_class_static_block (parser_context_t *context_p);
ecma_compiled_code_t *parser_parse_arrow_function (parser_context_t *context_p, uint32_t status_flags);
ecma_compiled_code_t *parser_parse_class_fields (parser_context_t *context_p);
void parser_set_function_name (parser_context_t *context_p,
diff --git a/jerry-core/parser/js/js-parser-statm.c b/jerry-core/parser/js/js-parser-statm.c
index 6f20e499a..b6f5075d2 100644
--- a/jerry-core/parser/js/js-parser-statm.c
+++ b/jerry-core/parser/js/js-parser-statm.c
@@ -3090,6 +3090,12 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
{
parser_raise_error (context_p, PARSER_ERR_INVALID_RETURN);
}
+#if JERRY_ESNEXT
+ if (context_p->status_flags & PARSER_IS_CLASS_STATIC_BLOCK)
+ {
+ parser_raise_error (context_p, PARSER_ERR_INVALID_RETURN);
+ }
+#endif /* JERRY_ESNEXT */
lexer_next_token (context_p);
diff --git a/jerry-core/parser/js/js-parser.c b/jerry-core/parser/js/js-parser.c
index b9e7f127b..f1a139870 100644
--- a/jerry-core/parser/js/js-parser.c
+++ b/jerry-core/parser/js/js-parser.c
@@ -2793,6 +2793,46 @@ parser_parse_function (parser_context_t *context_p, /**< context */
#if JERRY_ESNEXT
+/**
+ * Parse static class block code
+ *
+ * @return compiled code
+ */
+ecma_compiled_code_t *
+parser_parse_class_static_block (parser_context_t *context_p) /**< context */
+{
+ parser_saved_context_t saved_context;
+ ecma_compiled_code_t *compiled_code_p;
+
+ parser_save_context (context_p, &saved_context);
+ context_p->status_flags |= (PARSER_IS_CLASS_STATIC_BLOCK | PARSER_FUNCTION_CLOSURE | PARSER_ALLOW_SUPER
+ | PARSER_INSIDE_CLASS_FIELD | PARSER_ALLOW_NEW_TARGET | PARSER_DISALLOW_AWAIT_YIELD);
+
+#if JERRY_PARSER_DUMP_BYTE_CODE
+ if (context_p->is_show_opcodes)
+ {
+ JERRY_DEBUG_MSG ("\n--- Static class block parsing start ---\n\n");
+ }
+#endif /* JERRY_PARSER_DUMP_BYTE_CODE */
+
+ scanner_create_variables (context_p, SCANNER_CREATE_VARS_NO_OPTS);
+ lexer_next_token (context_p);
+
+ parser_parse_statements (context_p);
+ compiled_code_p = parser_post_processing (context_p);
+
+#if JERRY_PARSER_DUMP_BYTE_CODE
+ if (context_p->is_show_opcodes)
+ {
+ JERRY_DEBUG_MSG ("\n--- Static class block parsing end ---\n\n");
+ }
+#endif /* JERRY_PARSER_DUMP_BYTE_CODE */
+
+ parser_restore_context (context_p, &saved_context);
+
+ return compiled_code_p;
+} /* parser_parse_class_static_block */
+
/**
* Parse arrow function code
*
@@ -2826,6 +2866,12 @@ parser_parse_arrow_function (parser_context_t *context_p, /**< context */
}
#endif /* JERRY_DEBUGGER */
+ /* The `await` keyword is disallowed in the IdentifierReference position */
+ if (status_flags & PARSER_IS_CLASS_STATIC_BLOCK)
+ {
+ context_p->status_flags |= PARSER_DISALLOW_AWAIT_YIELD;
+ }
+
if (context_p->token.type == LEXER_LEFT_PAREN)
{
lexer_next_token (context_p);
@@ -2837,6 +2883,12 @@ parser_parse_arrow_function (parser_context_t *context_p, /**< context */
parser_parse_function_arguments (context_p, LEXER_ARROW);
}
+ /* The `await` keyword is interpreted as an identifier within the body of arrow functions */
+ if (status_flags & PARSER_IS_CLASS_STATIC_BLOCK)
+ {
+ context_p->status_flags &= (uint32_t) ~(PARSER_DISALLOW_AWAIT_YIELD | PARSER_IS_CLASS_STATIC_BLOCK);
+ }
+
JERRY_ASSERT (context_p->token.type == LEXER_ARROW);
lexer_next_token (context_p);
@@ -2950,6 +3002,20 @@ parser_parse_class_fields (parser_context_t *context_p) /**< context */
if (class_field_type & PARSER_CLASS_FIELD_NORMAL)
{
scanner_set_location (context_p, &range.start_location);
+
+ if (class_field_type & PARSER_CLASS_FIELD_STATIC_BLOCK)
+ {
+ scanner_seek (context_p);
+ JERRY_ASSERT (context_p->source_p[1] == LIT_CHAR_LEFT_BRACE);
+ context_p->source_p += 2;
+ context_p->source_end_p = source_end_p;
+
+ uint16_t func_index = lexer_construct_class_static_block_function (context_p);
+
+ parser_emit_cbc_ext_literal (context_p, CBC_EXT_CLASS_CALL_STATIC_BLOCK, func_index);
+ continue;
+ }
+
uint32_t ident_opts = LEXER_OBJ_IDENT_ONLY_IDENTIFIERS;
is_private = context_p->source_p[-1] == LIT_CHAR_HASHMARK;
diff --git a/jerry-core/parser/js/js-scanner-internal.h b/jerry-core/parser/js/js-scanner-internal.h
index 369983272..169aa25f0 100644
--- a/jerry-core/parser/js/js-scanner-internal.h
+++ b/jerry-core/parser/js/js-scanner-internal.h
@@ -118,6 +118,7 @@ typedef enum
SCAN_STACK_FUNCTION_PARAMETERS, /**< function parameter initializer */
SCAN_STACK_FOR_START_PATTERN, /**< possible assignment pattern for "for" iterator */
SCAN_STACK_USE_ASYNC, /**< an "async" identifier is used */
+ SCAN_STACK_CLASS_STATIC_BLOCK, /**< class static block */
#endif /* JERRY_ESNEXT */
#if JERRY_MODULE_SYSTEM
SCAN_STACK_EXPORT_DEFAULT, /**< scan primary expression after export default */
diff --git a/jerry-core/parser/js/js-scanner-util.c b/jerry-core/parser/js/js-scanner-util.c
index a3ecfbf0c..4df3092ea 100644
--- a/jerry-core/parser/js/js-scanner-util.c
+++ b/jerry-core/parser/js/js-scanner-util.c
@@ -2083,6 +2083,7 @@ scanner_cleanup (parser_context_t *context_p) /**< context */
#if JERRY_ESNEXT
case SCANNER_TYPE_INITIALIZER:
case SCANNER_TYPE_CLASS_FIELD_INITIALIZER_END:
+ case SCANNER_TYPE_CLASS_STATIC_BLOCK_END:
#endif /* JERRY_ESNEXT */
{
size = sizeof (scanner_location_info_t);
diff --git a/jerry-core/parser/js/js-scanner.c b/jerry-core/parser/js/js-scanner.c
index 7007bb97a..75b2c2aee 100644
--- a/jerry-core/parser/js/js-scanner.c
+++ b/jerry-core/parser/js/js-scanner.c
@@ -2304,6 +2304,33 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */
continue;
}
#if JERRY_ESNEXT
+ case SCAN_STACK_CLASS_STATIC_BLOCK:
+ {
+ if (type != LEXER_RIGHT_BRACE)
+ {
+ break;
+ }
+
+ scanner_pop_literal_pool (context_p, scanner_context_p);
+ scanner_source_start_t start_range;
+ parser_stack_pop_uint8 (context_p);
+ parser_stack_pop (context_p, &start_range, sizeof (scanner_source_start_t));
+
+ scanner_context_p->mode = SCAN_MODE_CLASS_BODY_NO_SCAN;
+
+ scanner_location_info_t *location_info_p;
+ location_info_p = (scanner_location_info_t *) scanner_insert_info (context_p,
+ start_range.source_p,
+ sizeof (scanner_location_info_t));
+
+ location_info_p->info.type = SCANNER_TYPE_CLASS_STATIC_BLOCK_END;
+ location_info_p->location.source_p = context_p->source_p;
+ location_info_p->location.line = context_p->token.line;
+ location_info_p->location.column = context_p->token.column;
+
+ lexer_scan_identifier (context_p, LEXER_PARSE_CHECK_KEYWORDS | LEXER_PARSE_NO_STRICT_IDENT_ERROR);
+ return SCAN_KEEP_TOKEN;
+ }
case SCAN_STACK_PRIVATE_BLOCK_EARLY:
{
parser_list_iterator_t literal_iterator;
@@ -2681,9 +2708,28 @@ scanner_scan_all (parser_context_t *context_p) /**< context */
}
else if (lexer_token_is_identifier (context_p, "static", 6))
{
+ scanner_source_start_t static_start;
+ static_start.source_p = context_p->source_p - 1;
+
lexer_scan_identifier (context_p, LEXER_PARSE_NO_OPTS);
identifier_found = true;
private_field_flags |= SCANNER_PRIVATE_FIELD_STATIC;
+
+ if (!is_private && context_p->token.type == LEXER_LEFT_BRACE)
+ {
+ parser_stack_push (context_p, &static_start, sizeof (scanner_source_start_t));
+ parser_stack_push_uint8 (context_p, SCAN_STACK_CLASS_STATIC_BLOCK);
+
+ scanner_literal_pool_t *literal_pool_p =
+ scanner_push_literal_pool (context_p, &scanner_context, SCANNER_LITERAL_POOL_FUNCTION);
+ literal_pool_p->source_p = context_p->source_p - 1;
+
+ lexer_next_token (context_p);
+
+ scanner_context.mode = SCAN_MODE_STATEMENT_OR_TERMINATOR;
+
+ continue;
+ }
}
scanner_context.mode = SCAN_MODE_FUNCTION_ARGUMENTS;
@@ -3851,6 +3897,12 @@ scan_completed:
print_location = false;
break;
}
+ case SCANNER_TYPE_CLASS_STATIC_BLOCK_END:
+ {
+ name_p = "SCANNER_TYPE_CLASS_STATIC_BLOCK_END";
+ print_location = true;
+ break;
+ }
case SCANNER_TYPE_CLASS_FIELD_INITIALIZER_END:
{
name_p = "SCANNER_TYPE_CLASS_FIELD_INITIALIZER_END";
diff --git a/jerry-core/parser/js/js-scanner.h b/jerry-core/parser/js/js-scanner.h
index c9c2eda02..64b77e798 100644
--- a/jerry-core/parser/js/js-scanner.h
+++ b/jerry-core/parser/js/js-scanner.h
@@ -49,6 +49,7 @@ typedef enum
SCANNER_TYPE_LITERAL_FLAGS, /**< object or array literal with non-zero flags (stored in u8_arg) */
SCANNER_TYPE_CLASS_CONSTRUCTOR, /**< class constructor */
SCANNER_TYPE_CLASS_FIELD_INITIALIZER_END, /**< class field initializer end */
+ SCANNER_TYPE_CLASS_STATIC_BLOCK_END, /**< class static block end */
SCANNER_TYPE_LET_EXPRESSION, /**< let expression */
SCANNER_TYPE_ERR_REDECLARED, /**< syntax error: a variable is redeclared */
SCANNER_TYPE_ERR_ASYNC_FUNCTION, /**< an invalid async function follows */
diff --git a/jerry-core/vm/vm.c b/jerry-core/vm/vm.c
index 7c3eaafd4..33f1e0081 100644
--- a/jerry-core/vm/vm.c
+++ b/jerry-core/vm/vm.c
@@ -1806,6 +1806,16 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
}
goto free_left_value;
}
+ case VM_OC_CLASS_CALL_STATIC_BLOCK:
+ {
+ result = ecma_op_function_call (ecma_get_object_from_value (left_value), frame_ctx_p->this_binding, NULL, 0);
+
+ if (ECMA_IS_VALUE_ERROR (result))
+ {
+ goto error;
+ }
+ goto free_left_value;
+ }
case VM_OC_PUSH_STATIC_FIELD_FUNC:
{
JERRY_ASSERT (byte_code_start_p[0] == CBC_EXT_OPCODE
diff --git a/jerry-core/vm/vm.h b/jerry-core/vm/vm.h
index 7fa5a717b..3cb1bdb93 100644
--- a/jerry-core/vm/vm.h
+++ b/jerry-core/vm/vm.h
@@ -238,6 +238,7 @@ typedef enum
VM_OC_BREAKPOINT_DISABLED, /**< disabled breakpoint for debugger */
#endif /* JERRY_DEBUGGER */
#if JERRY_ESNEXT
+ VM_OC_CLASS_CALL_STATIC_BLOCK, /**< call the class static block */
VM_OC_DEFINE_FIELD, /**< define class field */
VM_OC_PRIVATE_PROP_REFERENCE, /**< reference to class private method */
VM_OC_ASSIGN_PRIVATE, /**< assign to private field */
@@ -333,6 +334,7 @@ typedef enum
VM_OC_BREAKPOINT_DISABLED = VM_OC_NONE, /**< disabled breakpoint for debugger is unused */
#endif /* !JERRY_DEBUGGER */
#if !JERRY_ESNEXT
+ VM_OC_CLASS_CALL_STATIC_BLOCK = VM_OC_NONE, /**< call the class static block */
VM_OC_DEFINE_FIELD = VM_OC_NONE, /**< define class field */
VM_OC_PRIVATE_PROP_REFERENCE = VM_OC_NONE, /* reference to class private method */
VM_OC_ASSIGN_PRIVATE = VM_OC_NONE, /**< assign to private field */
diff --git a/tests/jerry/es.next/class_static_block.js b/tests/jerry/es.next/class_static_block.js
new file mode 100644
index 000000000..440a8ae69
--- /dev/null
+++ b/tests/jerry/es.next/class_static_block.js
@@ -0,0 +1,147 @@
+// 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 check_syntax_error(code) {
+ try {
+ eval(code)
+ assert(false)
+ } catch (e) {
+ assert(e instanceof SyntaxError)
+ }
+}
+
+check_syntax_error("static {}");
+check_syntax_error("class C { #static {} }");
+check_syntax_error("function foo() { static {} }");
+check_syntax_error("class C { static { return; } }");
+check_syntax_error("class C { static { break; } }");
+check_syntax_error("class C { static { continue; } }");
+check_syntax_error("class C { static { await => 0; } }");
+check_syntax_error("class C { static { yield } }");
+check_syntax_error("class C { static { super(); } }");
+check_syntax_error("class C { static { let a; let a; } }");
+check_syntax_error("class C { static { label: label: 0 } }");
+check_syntax_error("class C { static { let #a; } }");
+check_syntax_error("class C { static { (class { [arguments]() { } }); } }");
+check_syntax_error("class C { static {x: while (false) {continue y; } } }");
+check_syntax_error("function* g() { class C { static { yield; } } }");
+
+try {
+ class C {
+ static {
+ function foo() {
+ return this.a
+ };
+
+ foo()
+ }
+ }
+ assert(false)
+} catch (e) {
+ assert(e instanceof TypeError)
+}
+
+class Parent {
+ static fieldP = 'fieldP'
+}
+
+class C1 extends Parent{
+ static a = 0;
+ static #privateField = 1;
+
+ static {
+ assert(this.a === 0)
+ assert(this.#privateField === 1)
+
+ this.a = 1
+ this.b = super.fieldP
+ this.c = new.target
+
+ assert(this.a === 1)
+ assert(this.b === 'fieldP')
+ assert(this.c === undefined)
+ assert(this.d === undefined)
+ }
+
+ static d = 2
+
+ static {
+ assert(this.b === 'fieldP')
+ assert(this.d === 2)
+ }
+
+ static {
+ function f() {
+ assert(this === undefined)
+ }
+
+ let a = 11
+ assert (this.a !== a)
+ }
+
+}
+
+class C2 {
+ getPrivateField;
+ static getPrivateField2;
+ static invalidAccess;
+}
+
+let getPrivateField;
+
+class C3 {
+ #privateField = 'invalid';
+ static #staticPrivateField = 'private';
+
+ constructor(p) {
+ this.#privateField = p;
+ }
+
+ static {
+ getPrivateField = (d) => d.#privateField;
+ C2.getPrivateField = () => this.#staticPrivateField;
+ C2.getPrivateField2 = () => this.#staticPrivateField;
+ C2.invalidAccess = () => this.#privateField;
+ }
+}
+
+assert(getPrivateField(new C3('private field')) == 'private field');
+assert(C2.getPrivateField() === 'private')
+assert(C2.getPrivateField2() === 'private')
+
+try {
+ C2.invalidAccess()
+ assert(false)
+} catch (e) {
+ assert(e instanceof TypeError)
+}
+
+let a = 'outter'
+let b, c
+
+class C5 {
+ static {
+ let a = 'first block'
+ b = a
+ }
+
+ static {
+ let a = "second block"
+ c = a
+ }
+}
+
+assert(a === "outter")
+assert(b === "first block")
+assert(c === "second block")
diff --git a/tests/test262-esnext-excludelist.xml b/tests/test262-esnext-excludelist.xml
index a6766b08d..801140306 100644
--- a/tests/test262-esnext-excludelist.xml
+++ b/tests/test262-esnext-excludelist.xml
@@ -79,19 +79,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -509,13 +496,6 @@
-
-
-
-
-
-
-
@@ -526,22 +506,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-