Rework the core of class parsing/runtime semantic (#3598)
Changes:
- Use the pre-scanner to provide information for the parser about the existence of the class constructor
- The allocation of the super declarative environment is no longer needed
- The VM frame context holds the information about the this binding status
- Reduce the number of class related VM/CBC instructions
- Improve ecma_op_function_{construct, call} to properly set new.target
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
@@ -194,12 +194,10 @@
|
||||
#define PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION 4
|
||||
/* PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION must be <= 3 */
|
||||
#define PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION 3
|
||||
/* PARSER_BLOCK_CONTEXT_STACK_ALLOCATION must be <= 3 */
|
||||
#define PARSER_WITH_CONTEXT_STACK_ALLOCATION 1
|
||||
/* PARSER_SUPER_CLASS_CONTEXT_STACK_ALLOCATION must be <= 4 */
|
||||
#define PARSER_BLOCK_CONTEXT_STACK_ALLOCATION 1
|
||||
/* PARSER_WITH_CONTEXT_STACK_ALLOCATION must be <= 4 */
|
||||
#define PARSER_SUPER_CLASS_CONTEXT_STACK_ALLOCATION 1
|
||||
#define PARSER_WITH_CONTEXT_STACK_ALLOCATION 1
|
||||
/* PARSER_BLOCK_CONTEXT_STACK_ALLOCATION must be <= 3 */
|
||||
#define PARSER_BLOCK_CONTEXT_STACK_ALLOCATION 1
|
||||
|
||||
/**
|
||||
* Opcode definitions.
|
||||
@@ -540,10 +538,6 @@
|
||||
VM_OC_RESOLVE_BASE_FOR_CALL) \
|
||||
CBC_FORWARD_BRANCH (CBC_EXT_FINALLY, 0, \
|
||||
VM_OC_FINALLY) \
|
||||
CBC_OPCODE (CBC_EXT_CLASS_EXPR_CONTEXT_END, CBC_NO_FLAG, 0, \
|
||||
VM_OC_CLASS_EXPR_CONTEXT_END) \
|
||||
CBC_FORWARD_BRANCH (CBC_EXT_SUPER_CLASS_CREATE_CONTEXT, \
|
||||
-1 + PARSER_SUPER_CLASS_CONTEXT_STACK_ALLOCATION, VM_OC_CLASS_HERITAGE) \
|
||||
CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_PROP, CBC_NO_FLAG, 0, \
|
||||
VM_OC_INITIALIZER_PUSH_PROP | VM_OC_GET_STACK) \
|
||||
CBC_FORWARD_BRANCH (CBC_EXT_DEFAULT_INITIALIZER, -1, \
|
||||
@@ -602,16 +596,36 @@
|
||||
VM_OC_SET_SETTER | VM_OC_GET_STACK_LITERAL) \
|
||||
\
|
||||
/* Class related opcodes. */ \
|
||||
CBC_OPCODE (CBC_EXT_INHERIT_AND_SET_CONSTRUCTOR, CBC_NO_FLAG, 0, \
|
||||
VM_OC_CLASS_INHERITANCE) \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_CLASS_CONSTRUCTOR_AND_PROTOTYPE, CBC_NO_FLAG, 2, \
|
||||
VM_OC_PUSH_CLASS_CONSTRUCTOR_AND_PROTOTYPE | VM_OC_PUT_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_IMPLICIT_CONSTRUCTOR_CALL, CBC_NO_FLAG, 0, \
|
||||
VM_OC_PUSH_IMPL_CONSTRUCTOR) \
|
||||
CBC_OPCODE (CBC_EXT_SET_CLASS_LITERAL, CBC_HAS_LITERAL_ARG, 0, \
|
||||
VM_OC_SET_CLASS_CONSTRUCTOR | VM_OC_GET_LITERAL) \
|
||||
CBC_OPCODE (CBC_EXT_CLASS_EVAL, CBC_HAS_BYTE_ARG, 0, \
|
||||
VM_OC_CLASS_EVAL) \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_NAMED_CLASS_ENV, CBC_HAS_LITERAL_ARG, 1, \
|
||||
VM_OC_PUSH_CLASS_ENVIRONMENT | VM_OC_GET_LITERAL) \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_ANONYMOUS_CLASS_ENV, CBC_NO_FLAG, 1, \
|
||||
VM_OC_PUSH_CLASS_ENVIRONMENT) \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR, CBC_NO_FLAG, 1, \
|
||||
VM_OC_PUSH_IMPLICIT_CTOR | VM_OC_PUT_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR_HERITAGE, CBC_NO_FLAG, 1, \
|
||||
VM_OC_PUSH_IMPLICIT_CTOR | VM_OC_PUT_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_INIT_CLASS, CBC_NO_FLAG, 0, \
|
||||
VM_OC_INIT_CLASS | VM_OC_PUT_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_FINALIZE_NAMED_CLASS, CBC_HAS_LITERAL_ARG, -2, \
|
||||
VM_OC_FINALIZE_CLASS | VM_OC_GET_LITERAL) \
|
||||
CBC_OPCODE (CBC_EXT_FINALIZE_ANONYMOUS_CLASS, CBC_NO_FLAG, -2, \
|
||||
VM_OC_FINALIZE_CLASS) \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_SUPER, CBC_NO_FLAG, 1, \
|
||||
VM_OC_NONE) \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_SUPER_CONSTRUCTOR, CBC_NO_FLAG, 1, \
|
||||
VM_OC_PUSH_SUPER_CONSTRUCTOR) \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_SUPER_PROP, CBC_NO_FLAG, 0, \
|
||||
VM_OC_SUPER_REFERENCE | VM_OC_GET_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_SUPER_PROP_CALL_REFERENCE, CBC_NO_FLAG, 2, \
|
||||
VM_OC_SUPER_REFERENCE | VM_OC_GET_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_SUPER_PROP_LITERAL, CBC_HAS_LITERAL_ARG, 1, \
|
||||
VM_OC_SUPER_REFERENCE | VM_OC_GET_LITERAL) \
|
||||
CBC_OPCODE (CBC_EXT_SUPER_PROP_LITERAL_CALL_REFERENCE, CBC_HAS_LITERAL_ARG, 3, \
|
||||
VM_OC_SUPER_REFERENCE | VM_OC_GET_LITERAL) \
|
||||
CBC_OPCODE (CBC_EXT_RESOLVE_LEXICAL_THIS, CBC_NO_FLAG, 1, \
|
||||
VM_OC_RESOLVE_LEXICAL_THIS | VM_OC_PUT_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_LOCAL_EVAL, CBC_HAS_BYTE_ARG, 0, \
|
||||
VM_OC_LOCAL_EVAL) \
|
||||
CBC_OPCODE (CBC_EXT_SUPER_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, \
|
||||
VM_OC_SUPER_CALL) \
|
||||
CBC_OPCODE (CBC_EXT_SUPER_CALL_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, 0, \
|
||||
@@ -624,6 +638,8 @@
|
||||
VM_OC_SUPER_CALL | VM_OC_PUT_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_SPREAD_SUPER_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, \
|
||||
VM_OC_SUPER_CALL | VM_OC_PUT_BLOCK) \
|
||||
\
|
||||
/* Spread / rest operation related opcodes. */ \
|
||||
CBC_OPCODE (CBC_EXT_SPREAD_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, \
|
||||
VM_OC_SPREAD_ARGUMENTS) \
|
||||
CBC_OPCODE (CBC_EXT_SPREAD_CALL_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, 0, \
|
||||
@@ -636,24 +652,6 @@
|
||||
VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_SPREAD_CALL_PROP_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -3, \
|
||||
VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_BLOCK) \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_CONSTRUCTOR_SUPER, CBC_NO_FLAG, 1, \
|
||||
VM_OC_PUSH_CONSTRUCTOR_SUPER | VM_OC_PUT_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_CONSTRUCTOR_SUPER_PROP, CBC_NO_FLAG, 1, \
|
||||
VM_OC_PUSH_CONSTRUCTOR_SUPER | VM_OC_PUT_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_SUPER, CBC_NO_FLAG, 1, \
|
||||
VM_OC_PUSH_SUPER | VM_OC_PUT_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_STATIC_SUPER, CBC_NO_FLAG, 1, \
|
||||
VM_OC_PUSH_SUPER | VM_OC_PUT_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_CONSTRUCTOR_THIS, CBC_NO_FLAG, 1, \
|
||||
VM_OC_PUSH_CONSTRUCTOR_THIS | VM_OC_PUT_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_SUPER_PROP_CALL, CBC_NO_FLAG, 0, \
|
||||
VM_OC_SUPER_PROP_REFERENCE) \
|
||||
CBC_OPCODE (CBC_EXT_SUPER_PROP_ASSIGN, CBC_NO_FLAG, 0, \
|
||||
VM_OC_SUPER_PROP_REFERENCE) \
|
||||
CBC_OPCODE (CBC_EXT_CONSTRUCTOR_RETURN, CBC_NO_FLAG, -1, \
|
||||
VM_OC_CONSTRUCTOR_RET | VM_OC_GET_STACK) \
|
||||
\
|
||||
/* Spread / rest operation related opcodes. */ \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_SPREAD_ELEMENT, CBC_NO_FLAG, 1, \
|
||||
VM_OC_PUSH_SPREAD_ELEMENT) \
|
||||
CBC_OPCODE (CBC_EXT_SPREAD_ARRAY_APPEND, CBC_HAS_POP_STACK_BYTE_ARG, 0, \
|
||||
@@ -782,7 +780,7 @@ typedef enum
|
||||
CBC_CODE_FLAGS_ARROW_FUNCTION = (1u << 7), /**< this function is an arrow function */
|
||||
CBC_CODE_FLAGS_STATIC_FUNCTION = (1u << 8), /**< this function is a static snapshot function */
|
||||
CBC_CODE_FLAGS_DEBUGGER_IGNORE = (1u << 9), /**< this function should be ignored by debugger */
|
||||
CBC_CODE_FLAGS_CONSTRUCTOR = (1u << 10), /**< this function is a constructor */
|
||||
CBC_CODE_FLAGS_CLASS_CONSTRUCTOR = (1u << 10), /**< this function is a class constructor */
|
||||
CBC_CODE_FLAGS_GENERATOR = (1u << 11), /**< this function is a generator */
|
||||
CBC_CODE_FLAGS_REST_PARAMETER = (1u << 12), /**< this function has rest parameter */
|
||||
CBC_CODE_FLAG_HAS_TAGGED_LITERALS = (1u << 13), /**< this function has tagged template literal list */
|
||||
|
||||
@@ -2762,9 +2762,8 @@ lexer_expect_identifier (parser_context_t *context_p, /**< context */
|
||||
* In this case we use a synthetic name for them. */
|
||||
context_p->token.type = LEXER_LITERAL;
|
||||
context_p->token.keyword_type = LEXER_EOS;
|
||||
context_p->token.lit_location.type = LEXER_IDENT_LITERAL;
|
||||
context_p->token.lit_location.has_escape = false;
|
||||
lexer_construct_literal_object (context_p, &lexer_default_literal, literal_type);
|
||||
context_p->token.lit_location = lexer_default_literal;
|
||||
lexer_construct_literal_object (context_p, &context_p->token.lit_location, literal_type);
|
||||
context_p->status_flags &= (uint32_t) ~(PARSER_MODULE_DEFAULT_CLASS_OR_FUNC);
|
||||
return;
|
||||
}
|
||||
@@ -2917,6 +2916,7 @@ lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */
|
||||
if (is_class_method && lexer_compare_literal_to_string (context_p, "constructor", 11))
|
||||
{
|
||||
context_p->token.type = LEXER_CLASS_CONSTRUCTOR;
|
||||
context_p->token.flags &= (uint8_t) ~LEXER_NO_SKIP_SPACES;
|
||||
return;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
@@ -428,20 +428,56 @@ static const lexer_lit_location_t lexer_set_literal =
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse class as an object literal.
|
||||
* Class literal parsing options.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
PARSER_CLASS_LITERAL_NO_OPTS = 0, /**< no options are provided */
|
||||
PARSER_CLASS_LITERAL_CTOR_PRESENT = (1 << 0), /**< class constructor is present */
|
||||
PARSER_CLASS_LITERAL_HERTIAGE_PRESENT = (1 << 1), /**< class heritage is present */
|
||||
} parser_class_literal_opts_t;
|
||||
|
||||
/**
|
||||
* Parse class literal.
|
||||
*/
|
||||
static void
|
||||
parser_parse_class_literal (parser_context_t *context_p) /**< context */
|
||||
parser_parse_class_literal (parser_context_t *context_p, /**< context */
|
||||
parser_class_literal_opts_t opts) /**< class literal parsing options */
|
||||
{
|
||||
JERRY_ASSERT (context_p->token.type == LEXER_LEFT_BRACE);
|
||||
|
||||
bool super_called = false;
|
||||
uint32_t status_flags = PARSER_FUNCTION_CLOSURE;
|
||||
status_flags |= context_p->status_flags & (PARSER_CLASS_HAS_SUPER | PARSER_CLASS_IMPLICIT_SUPER);
|
||||
uint32_t status_flags = PARSER_FUNCTION_CLOSURE | PARSER_ALLOW_SUPER;
|
||||
|
||||
lexer_literal_t *ctor_literal_p = NULL;
|
||||
|
||||
if (opts & PARSER_CLASS_LITERAL_CTOR_PRESENT)
|
||||
{
|
||||
if (context_p->literal_count >= PARSER_MAXIMUM_NUMBER_OF_LITERALS)
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_LITERAL_LIMIT_REACHED);
|
||||
}
|
||||
|
||||
ctor_literal_p = (lexer_literal_t *) parser_list_append (context_p, &context_p->literal_pool);
|
||||
ctor_literal_p->type = LEXER_UNUSED_LITERAL;
|
||||
ctor_literal_p->status_flags = 0;
|
||||
parser_emit_cbc_literal (context_p, CBC_PUSH_LITERAL, (uint16_t) (context_p->literal_count++));
|
||||
}
|
||||
else if (opts & PARSER_CLASS_LITERAL_HERTIAGE_PRESENT)
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR_HERITAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR);
|
||||
}
|
||||
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_INIT_CLASS);
|
||||
|
||||
bool is_static = false;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (!(status_flags & PARSER_CLASS_STATIC_FUNCTION))
|
||||
if (!is_static)
|
||||
{
|
||||
lexer_skip_empty_statements (context_p);
|
||||
}
|
||||
@@ -469,7 +505,7 @@ parser_parse_class_literal (parser_context_t *context_p) /**< context */
|
||||
goto parse_class_method;
|
||||
}
|
||||
|
||||
uint32_t accessor_status_flags = PARSER_FUNCTION_CLOSURE;
|
||||
uint32_t accessor_status_flags = status_flags;
|
||||
accessor_status_flags |= (is_getter ? PARSER_IS_PROPERTY_GETTER : PARSER_IS_PROPERTY_SETTER);
|
||||
|
||||
lexer_expect_object_literal_id (context_p, LEXER_OBJ_IDENT_CLASS_METHOD | LEXER_OBJ_IDENT_ONLY_IDENTIFIERS);
|
||||
@@ -479,7 +515,7 @@ parser_parse_class_literal (parser_context_t *context_p) /**< context */
|
||||
{
|
||||
is_computed = true;
|
||||
}
|
||||
else if (!(status_flags & PARSER_CLASS_STATIC_FUNCTION)
|
||||
else if (!is_static
|
||||
&& LEXER_IS_IDENT_OR_STRING (context_p->token.lit_location.type)
|
||||
&& lexer_compare_literal_to_string (context_p, "constructor", 11))
|
||||
{
|
||||
@@ -495,7 +531,6 @@ parser_parse_class_literal (parser_context_t *context_p) /**< context */
|
||||
JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_LITERAL);
|
||||
|
||||
cbc_ext_opcode_t opcode;
|
||||
bool is_static = (status_flags & PARSER_CLASS_STATIC_FUNCTION) != 0;
|
||||
|
||||
if (is_computed)
|
||||
{
|
||||
@@ -525,51 +560,42 @@ parser_parse_class_literal (parser_context_t *context_p) /**< context */
|
||||
}
|
||||
|
||||
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (opcode);
|
||||
status_flags &= (uint32_t) ~PARSER_CLASS_STATIC_FUNCTION;
|
||||
is_static = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(status_flags & PARSER_CLASS_STATIC_FUNCTION))
|
||||
if (!is_static)
|
||||
{
|
||||
if (context_p->token.type == LEXER_KEYW_STATIC)
|
||||
{
|
||||
status_flags |= PARSER_CLASS_STATIC_FUNCTION;
|
||||
is_static = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (context_p->token.type == LEXER_CLASS_CONSTRUCTOR)
|
||||
{
|
||||
if (super_called)
|
||||
JERRY_ASSERT (opts & PARSER_CLASS_LITERAL_CTOR_PRESENT);
|
||||
JERRY_ASSERT (ctor_literal_p != NULL);
|
||||
|
||||
if (ctor_literal_p->type == LEXER_FUNCTION_LITERAL)
|
||||
{
|
||||
/* 14.5.1 */
|
||||
parser_raise_error (context_p, PARSER_ERR_MULTIPLE_CLASS_CONSTRUCTORS);
|
||||
}
|
||||
else
|
||||
|
||||
uint32_t constructor_status_flags = (status_flags
|
||||
| PARSER_CLASS_CONSTRUCTOR
|
||||
| PARSER_LEXICAL_ENV_NEEDED);
|
||||
|
||||
if (opts & PARSER_CLASS_LITERAL_HERTIAGE_PRESENT)
|
||||
{
|
||||
super_called = true;
|
||||
constructor_status_flags |= PARSER_ALLOW_SUPER_CALL;
|
||||
}
|
||||
|
||||
parser_flush_cbc (context_p);
|
||||
uint32_t constructor_status_flags = status_flags | PARSER_CLASS_CONSTRUCTOR;
|
||||
|
||||
if (context_p->status_flags & PARSER_CLASS_HAS_SUPER)
|
||||
{
|
||||
constructor_status_flags |= PARSER_LEXICAL_ENV_NEEDED;
|
||||
}
|
||||
|
||||
if (context_p->literal_count >= PARSER_MAXIMUM_NUMBER_OF_LITERALS)
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_LITERAL_LIMIT_REACHED);
|
||||
}
|
||||
|
||||
uint16_t result_index = context_p->literal_count;
|
||||
lexer_literal_t *literal_p = (lexer_literal_t *) parser_list_append (context_p, &context_p->literal_pool);
|
||||
literal_p->type = LEXER_UNUSED_LITERAL;
|
||||
literal_p->status_flags = 0;
|
||||
literal_p->u.bytecode_p = parser_parse_function (context_p, constructor_status_flags);
|
||||
literal_p->type = LEXER_FUNCTION_LITERAL;
|
||||
parser_emit_cbc_literal (context_p, PARSER_TO_EXT_OPCODE (CBC_EXT_SET_CLASS_LITERAL), result_index);
|
||||
context_p->literal_count++;
|
||||
ecma_compiled_code_t *compiled_code_p = parser_parse_function (context_p, constructor_status_flags);
|
||||
ctor_literal_p->u.bytecode_p = compiled_code_p;
|
||||
ctor_literal_p->type = LEXER_FUNCTION_LITERAL;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -598,7 +624,7 @@ parser_parse_class_literal (parser_context_t *context_p) /**< context */
|
||||
}
|
||||
else if (LEXER_IS_IDENT_OR_STRING (context_p->token.lit_location.type))
|
||||
{
|
||||
if (status_flags & PARSER_CLASS_STATIC_FUNCTION)
|
||||
if (is_static)
|
||||
{
|
||||
if (lexer_compare_literal_to_string (context_p, "prototype", 9))
|
||||
{
|
||||
@@ -625,11 +651,11 @@ parse_class_method:
|
||||
|
||||
context_p->last_cbc.value = literal_index;
|
||||
|
||||
if ((status_flags & PARSER_CLASS_STATIC_FUNCTION))
|
||||
if (is_static)
|
||||
{
|
||||
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (is_computed ? CBC_EXT_SET_STATIC_COMPUTED_PROPERTY_LITERAL
|
||||
: CBC_EXT_SET_STATIC_PROPERTY_LITERAL);
|
||||
status_flags &= (uint32_t) ~PARSER_CLASS_STATIC_FUNCTION;
|
||||
is_static = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -637,26 +663,8 @@ parse_class_method:
|
||||
: CBC_SET_LITERAL_PROPERTY);
|
||||
}
|
||||
}
|
||||
|
||||
if (!super_called && (context_p->status_flags & PARSER_CLASS_HAS_SUPER))
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_IMPLICIT_CONSTRUCTOR_CALL);
|
||||
}
|
||||
|
||||
if (context_p->status_flags & PARSER_CLASS_HAS_SUPER)
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_INHERIT_AND_SET_CONSTRUCTOR);
|
||||
}
|
||||
} /* parser_parse_class_literal */
|
||||
|
||||
/**
|
||||
* Description of "prototype" literal string.
|
||||
*/
|
||||
static const lexer_lit_location_t lexer_prototype_literal =
|
||||
{
|
||||
(const uint8_t *) "prototype", 9, LEXER_STRING_LITERAL, false
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse class statement or expression.
|
||||
*/
|
||||
@@ -668,6 +676,15 @@ parser_parse_class (parser_context_t *context_p, /**< context */
|
||||
JERRY_ASSERT (context_p->token.type == LEXER_KEYW_CLASS);
|
||||
|
||||
uint16_t class_ident_index = PARSER_MAXIMUM_NUMBER_OF_LITERALS;
|
||||
uint16_t class_name_index = PARSER_MAXIMUM_NUMBER_OF_LITERALS;
|
||||
parser_class_literal_opts_t opts = PARSER_CLASS_LITERAL_NO_OPTS;
|
||||
|
||||
if (context_p->next_scanner_info_p->source_p == context_p->source_p)
|
||||
{
|
||||
JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_CLASS_CONSTRUCTOR);
|
||||
scanner_release_next (context_p, sizeof (scanner_info_t));
|
||||
opts |= PARSER_CLASS_LITERAL_CTOR_PRESENT;
|
||||
}
|
||||
|
||||
if (is_statement)
|
||||
{
|
||||
@@ -681,9 +698,11 @@ parser_parse_class (parser_context_t *context_p, /**< context */
|
||||
JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED);
|
||||
parser_raise_error (context_p, PARSER_ERR_VARIABLE_REDECLARED);
|
||||
}
|
||||
|
||||
class_ident_index = context_p->lit_object.index;
|
||||
|
||||
lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_STRING_LITERAL);
|
||||
class_name_index = context_p->lit_object.index;
|
||||
|
||||
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
parser_module_append_export_name (context_p);
|
||||
context_p->status_flags &= (uint32_t) ~(PARSER_MODULE_STORE_IDENT);
|
||||
@@ -699,16 +718,31 @@ parser_parse_class (parser_context_t *context_p, /**< context */
|
||||
if (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL)
|
||||
{
|
||||
/* NOTE: If 'Function.name' will be supported, the current literal object must be set to 'name' property. */
|
||||
lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_STRING_LITERAL);
|
||||
class_name_index = context_p->lit_object.index;
|
||||
lexer_next_token (context_p);
|
||||
}
|
||||
}
|
||||
|
||||
bool create_class_env = (context_p->token.type == LEXER_KEYW_EXTENDS
|
||||
|| (context_p->status_flags & PARSER_CLASS_HAS_SUPER));
|
||||
|
||||
if (create_class_env)
|
||||
if (class_name_index != PARSER_MAXIMUM_NUMBER_OF_LITERALS)
|
||||
{
|
||||
parser_parse_super_class_context_start (context_p);
|
||||
parser_emit_cbc_ext_literal (context_p, CBC_EXT_PUSH_NAMED_CLASS_ENV, class_name_index);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_ANONYMOUS_CLASS_ENV);
|
||||
}
|
||||
|
||||
if (context_p->token.type == LEXER_KEYW_EXTENDS)
|
||||
{
|
||||
lexer_next_token (context_p);
|
||||
parser_parse_expression (context_p, PARSE_EXPR | PARSE_EXPR_LEFT_HAND_SIDE);
|
||||
opts |= PARSER_CLASS_LITERAL_HERTIAGE_PRESENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Elisions represents that the classHeritage is not present */
|
||||
parser_emit_cbc (context_p, CBC_PUSH_ELISION);
|
||||
}
|
||||
|
||||
if (context_p->token.type != LEXER_LEFT_BRACE)
|
||||
@@ -716,28 +750,21 @@ parser_parse_class (parser_context_t *context_p, /**< context */
|
||||
parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_EXPECTED);
|
||||
}
|
||||
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_CLASS_CONSTRUCTOR_AND_PROTOTYPE);
|
||||
|
||||
bool is_strict = context_p->status_flags & PARSER_IS_STRICT;
|
||||
|
||||
/* 14.5. A ClassBody is always strict code. */
|
||||
context_p->status_flags |= PARSER_IS_STRICT;
|
||||
|
||||
/* ClassDeclaration is parsed. Continue with class body. */
|
||||
parser_parse_class_literal (context_p);
|
||||
parser_parse_class_literal (context_p, opts);
|
||||
|
||||
JERRY_ASSERT (context_p->token.type == LEXER_RIGHT_BRACE);
|
||||
|
||||
lexer_construct_literal_object (context_p,
|
||||
(lexer_lit_location_t *) &lexer_prototype_literal,
|
||||
lexer_prototype_literal.type);
|
||||
|
||||
parser_emit_cbc_literal (context_p, CBC_SET_PROPERTY, context_p->lit_object.index);
|
||||
|
||||
if (create_class_env)
|
||||
if (class_name_index != PARSER_MAXIMUM_NUMBER_OF_LITERALS)
|
||||
{
|
||||
parser_parse_super_class_context_end (context_p);
|
||||
context_p->status_flags &= (uint32_t) ~(PARSER_CLASS_HAS_SUPER | PARSER_CLASS_IMPLICIT_SUPER);
|
||||
parser_emit_cbc_ext_literal (context_p, CBC_EXT_FINALIZE_NAMED_CLASS, class_name_index);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_FINALIZE_ANONYMOUS_CLASS);
|
||||
}
|
||||
|
||||
if (is_statement)
|
||||
@@ -754,6 +781,7 @@ parser_parse_class (parser_context_t *context_p, /**< context */
|
||||
/* Restore flag */
|
||||
context_p->status_flags &= (uint32_t) ~PARSER_IS_STRICT;
|
||||
}
|
||||
context_p->status_flags &= (uint32_t) ~PARSER_ALLOW_SUPER;
|
||||
|
||||
lexer_next_token (context_p);
|
||||
} /* parser_parse_class */
|
||||
@@ -1412,7 +1440,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
|
||||
/* Check if "new.target" is written here. */
|
||||
if (scanner_try_scan_new_target (context_p))
|
||||
{
|
||||
if (!(context_p->status_flags & PARSER_IS_FUNCTION)
|
||||
if (!(context_p->status_flags & PARSER_ALLOW_NEW_TARGET)
|
||||
&& !(context_p->global_status_flags & ECMA_PARSE_CALLED_FROM_FUNCTION))
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_NEW_TARGET_NOT_ALLOWED);
|
||||
@@ -1478,8 +1506,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
|
||||
}
|
||||
|
||||
parser_check_assignment_expr (context_p);
|
||||
parser_parse_function_expression (context_p,
|
||||
PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION);
|
||||
parser_parse_function_expression (context_p, PARSER_IS_ARROW_FUNCTION);
|
||||
return parser_abort_parsing_after_arrow (context_p);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
@@ -1618,16 +1645,9 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
|
||||
case LEXER_KEYW_THIS:
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (PARSER_IS_CLASS_CONSTRUCTOR_SUPER (context_p->status_flags))
|
||||
if (context_p->status_flags & PARSER_ALLOW_SUPER_CALL)
|
||||
{
|
||||
if (context_p->status_flags & PARSER_CLASS_IMPLICIT_SUPER)
|
||||
{
|
||||
parser_emit_cbc (context_p, CBC_PUSH_THIS);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_CONSTRUCTOR_THIS);
|
||||
}
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_RESOLVE_LEXICAL_THIS);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1661,40 +1681,25 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
|
||||
}
|
||||
case LEXER_KEYW_SUPER:
|
||||
{
|
||||
if (lexer_check_next_characters (context_p, LIT_CHAR_DOT, LIT_CHAR_LEFT_SQUARE)
|
||||
&& context_p->status_flags & (PARSER_CLASS_HAS_SUPER))
|
||||
if (context_p->status_flags & PARSER_ALLOW_SUPER)
|
||||
{
|
||||
if (!LEXER_IS_BINARY_LVALUE_TOKEN (context_p->stack_top_uint8))
|
||||
if (lexer_check_next_characters (context_p, LIT_CHAR_DOT, LIT_CHAR_LEFT_SQUARE)
|
||||
&& ((context_p->status_flags & PARSER_ALLOW_NEW_TARGET)
|
||||
|| (context_p->global_status_flags & ECMA_PARSE_CALLED_FROM_FUNCTION)))
|
||||
{
|
||||
context_p->status_flags |= PARSER_CLASS_SUPER_PROP_REFERENCE;
|
||||
}
|
||||
|
||||
if (context_p->status_flags & PARSER_CLASS_CONSTRUCTOR)
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_CONSTRUCTOR_SUPER_PROP);
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_SUPER);
|
||||
break;
|
||||
}
|
||||
|
||||
if (context_p->status_flags & PARSER_CLASS_IMPLICIT_SUPER)
|
||||
if (lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN)
|
||||
&& (context_p->status_flags & PARSER_ALLOW_SUPER_CALL))
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_STATIC_SUPER);
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_SUPER_CONSTRUCTOR);
|
||||
break;
|
||||
}
|
||||
|
||||
bool is_static = (context_p->status_flags & PARSER_CLASS_STATIC_FUNCTION) != 0;
|
||||
parser_emit_cbc_ext (context_p, is_static ? CBC_EXT_PUSH_STATIC_SUPER : CBC_EXT_PUSH_SUPER);
|
||||
break;
|
||||
}
|
||||
|
||||
if (lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN)
|
||||
&& ((context_p->status_flags & PARSER_CLASS_CONSTRUCTOR_SUPER) == PARSER_CLASS_CONSTRUCTOR_SUPER)
|
||||
&& !(context_p->status_flags & PARSER_CLASS_IMPLICIT_SUPER))
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_CONSTRUCTOR_SUPER);
|
||||
break;
|
||||
}
|
||||
|
||||
parser_raise_error (context_p, PARSER_ERR_UNEXPECTED_SUPER_REFERENCE);
|
||||
parser_raise_error (context_p, PARSER_ERR_UNEXPECTED_SUPER_KEYWORD);
|
||||
}
|
||||
case LEXER_LEFT_PAREN:
|
||||
{
|
||||
@@ -1704,7 +1709,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
|
||||
parser_check_assignment_expr (context_p);
|
||||
|
||||
context_p->token.type = LEXER_ARROW_LEFT_PAREN;
|
||||
parser_parse_function_expression (context_p, PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION);
|
||||
parser_parse_function_expression (context_p, PARSER_IS_ARROW_FUNCTION);
|
||||
return parser_abort_parsing_after_arrow (context_p);
|
||||
}
|
||||
case LEXER_KEYW_YIELD:
|
||||
@@ -1758,31 +1763,9 @@ static void
|
||||
parser_process_unary_expression (parser_context_t *context_p, /**< context */
|
||||
size_t grouping_level) /**< grouping level */
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
/* Track to see if a property was accessed or not */
|
||||
bool property_accessed = false;
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/* Parse postfix part of a primary expression. */
|
||||
while (true)
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (context_p->token.type == LEXER_DOT || context_p->token.type == LEXER_LEFT_SQUARE)
|
||||
{
|
||||
if (property_accessed)
|
||||
{
|
||||
/**
|
||||
* In the case of "super.prop1.prop2(...)" the second property access should not
|
||||
* generate a super prop call thus the 'PARSER_CLASS_SUPER_PROP_REFERENCE' flags should be removed.
|
||||
*
|
||||
* Similar case: "super[propname].prop2(...)"
|
||||
*/
|
||||
context_p->status_flags &= (uint32_t) ~PARSER_CLASS_SUPER_PROP_REFERENCE;
|
||||
}
|
||||
property_accessed = true;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/* Since break would only break the switch, we use
|
||||
* continue to continue this loop. Without continue,
|
||||
* the code abandons the loop. */
|
||||
@@ -1809,6 +1792,13 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
|
||||
context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE;
|
||||
parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_PROP_THIS_LITERAL);
|
||||
}
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
else if (context_p->last_cbc_opcode == 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.literal_index = context_p->lit_object.index;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
else
|
||||
{
|
||||
parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_PROP_LITERAL);
|
||||
@@ -1821,6 +1811,15 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
|
||||
{
|
||||
parser_push_result (context_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
uint16_t last_cbc_opcode = context_p->last_cbc_opcode;
|
||||
|
||||
if (last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER))
|
||||
{
|
||||
context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
lexer_next_token (context_p);
|
||||
parser_parse_expression (context_p, PARSE_EXPR);
|
||||
if (context_p->token.type != LEXER_RIGHT_SQUARE)
|
||||
@@ -1829,6 +1828,14 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
|
||||
}
|
||||
lexer_next_token (context_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER))
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_SUPER_PROP);
|
||||
continue;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
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);
|
||||
@@ -1871,10 +1878,20 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
|
||||
context_p->last_cbc_opcode = PARSER_PUSH_PROP_TO_PUSH_PROP_REFERENCE (context_p->last_cbc_opcode);
|
||||
}
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_CONSTRUCTOR_SUPER))
|
||||
else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_CONSTRUCTOR))
|
||||
{
|
||||
opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_CALL);
|
||||
}
|
||||
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_CALL_REFERENCE);
|
||||
opcode = CBC_CALL_PROP;
|
||||
}
|
||||
else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP))
|
||||
{
|
||||
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_PROP_CALL_REFERENCE);
|
||||
opcode = CBC_CALL_PROP;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
else if (JERRY_UNLIKELY (context_p->status_flags & PARSER_INSIDE_WITH)
|
||||
&& PARSER_IS_PUSH_LITERAL (context_p->last_cbc_opcode)
|
||||
@@ -1961,11 +1978,11 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
|
||||
if (is_eval)
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (context_p->status_flags & PARSER_CLASS_HAS_SUPER)
|
||||
if (context_p->status_flags & (PARSER_ALLOW_SUPER_CALL | PARSER_ALLOW_SUPER))
|
||||
{
|
||||
parser_flush_cbc (context_p);
|
||||
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_CLASS_EVAL);
|
||||
context_p->last_cbc.value = PARSER_GET_CLASS_ECMA_PARSE_OPTS (context_p->status_flags);
|
||||
parser_emit_cbc_ext_call (context_p,
|
||||
CBC_EXT_LOCAL_EVAL,
|
||||
PARSER_SAVE_STATUS_FLAGS (context_p->status_flags));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1977,12 +1994,6 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if ((context_p->status_flags & PARSER_CLASS_SUPER_PROP_REFERENCE) && opcode == CBC_CALL_PROP)
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_SUPER_PROP_CALL);
|
||||
context_p->status_flags &= (uint32_t) ~PARSER_CLASS_SUPER_PROP_REFERENCE;
|
||||
}
|
||||
|
||||
if (has_spread_element)
|
||||
{
|
||||
uint16_t spread_opcode;
|
||||
@@ -2149,6 +2160,13 @@ parser_append_binary_single_assignment_token (parser_context_t *context_p, /**<
|
||||
* assignment, since it has multiple forms depending on the
|
||||
* previous instruction. */
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER_PROP_LITERAL))
|
||||
{
|
||||
context_p->last_cbc_opcode = CBC_PUSH_PROP_THIS_LITERAL;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
if (PARSER_IS_PUSH_LITERAL (context_p->last_cbc_opcode)
|
||||
&& context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL)
|
||||
{
|
||||
@@ -2199,14 +2217,6 @@ parser_append_binary_single_assignment_token (parser_context_t *context_p, /**<
|
||||
parser_stack_push_uint16 (context_p, context_p->last_cbc.literal_index);
|
||||
parser_stack_push_uint8 (context_p, CBC_ASSIGN_PROP_LITERAL);
|
||||
context_p->last_cbc_opcode = PARSER_CBC_UNAVAILABLE;
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (context_p->status_flags & PARSER_CLASS_SUPER_PROP_REFERENCE)
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_SUPER_PROP_ASSIGN);
|
||||
parser_flush_cbc (context_p);
|
||||
}
|
||||
context_p->status_flags &= (uint32_t) ~PARSER_CLASS_SUPER_PROP_REFERENCE;
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2708,8 +2718,7 @@ parser_pattern_process_assignment (parser_context_t *context_p, /**< context */
|
||||
|
||||
if (!PARSER_IS_PUSH_LITERAL (context_p->last_cbc_opcode))
|
||||
{
|
||||
if (!PARSER_IS_PUSH_PROP (context_p->last_cbc_opcode)
|
||||
&& context_p->last_cbc_opcode != CBC_EXT_PUSH_CONSTRUCTOR_SUPER_PROP)
|
||||
if (!PARSER_IS_PUSH_PROP (context_p->last_cbc_opcode))
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_INVALID_DESTRUCTURING_PATTERN);
|
||||
}
|
||||
@@ -3065,16 +3074,6 @@ parser_parse_expression (parser_context_t *context_p, /**< context */
|
||||
|
||||
parser_stack_push_uint8 (context_p, LEXER_EXPRESSION_START);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
/* Parsing a new expression:
|
||||
* So save, remove, and at the end restore the super prop reference indicator.
|
||||
*
|
||||
* If this is not done, it is possible to carry the flag over to the next expression.
|
||||
*/
|
||||
bool has_super_ref = (context_p->status_flags & PARSER_CLASS_SUPER_PROP_REFERENCE) != 0;
|
||||
context_p->status_flags &= (uint32_t) ~PARSER_CLASS_SUPER_PROP_REFERENCE;
|
||||
#endif
|
||||
|
||||
if (options & PARSE_EXPR_HAS_LITERAL)
|
||||
{
|
||||
JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_LITERAL);
|
||||
@@ -3164,14 +3163,6 @@ process_unary_expression:
|
||||
{
|
||||
parser_push_result (context_p);
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
/* Restore the super prop ref flag. */
|
||||
if (has_super_ref)
|
||||
{
|
||||
context_p->status_flags |= (uint32_t) PARSER_CLASS_SUPER_PROP_REFERENCE;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
} /* parser_parse_expression */
|
||||
|
||||
/**
|
||||
|
||||
@@ -65,23 +65,26 @@ typedef enum
|
||||
PARSER_DISALLOW_YIELD = (1u << 16), /**< throw SyntaxError for yield expression */
|
||||
PARSER_FUNCTION_HAS_NON_SIMPLE_PARAM = (1u << 17), /**< function has a non simple parameter */
|
||||
PARSER_FUNCTION_HAS_REST_PARAM = (1u << 18), /**< function has rest parameter */
|
||||
/* These four status flags must be in this order. See PARSER_CLASS_PARSE_OPTS_OFFSET. */
|
||||
PARSER_CLASS_CONSTRUCTOR = (1u << 19), /**< a class constructor is parsed (this value must be kept in
|
||||
* in sync with ECMA_PARSE_CLASS_CONSTRUCTOR) */
|
||||
PARSER_CLASS_HAS_SUPER = (1u << 20), /**< class has super reference */
|
||||
PARSER_CLASS_IMPLICIT_SUPER = (1u << 21), /**< class has implicit parent class */
|
||||
PARSER_CLASS_STATIC_FUNCTION = (1u << 22), /**< this function is a static class method */
|
||||
PARSER_CLASS_SUPER_PROP_REFERENCE = (1u << 23), /**< super property call or assignment */
|
||||
/* These three status flags must be in this order. See PARSER_SAVED_FLAGS_OFFSET. */
|
||||
PARSER_CLASS_CONSTRUCTOR = (1u << 19), /**< a class constructor is parsed
|
||||
* Note: PARSER_ALLOW_SUPER must be present */
|
||||
PARSER_ALLOW_SUPER = (1u << 20), /**< allow super property access */
|
||||
PARSER_ALLOW_SUPER_CALL = (1u << 21), /**< allow super constructor call
|
||||
* Note: PARSER_CLASS_CONSTRUCTOR must be present */
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
PARSER_MODULE_DEFAULT_CLASS_OR_FUNC = (1u << 24), /**< parsing a function or class default export */
|
||||
PARSER_MODULE_STORE_IDENT = (1u << 25), /**< store identifier of the current export statement */
|
||||
PARSER_MODULE_DEFAULT_CLASS_OR_FUNC = (1u << 22), /**< parsing a function or class default export */
|
||||
PARSER_MODULE_STORE_IDENT = (1u << 23), /**< store identifier of the current export statement */
|
||||
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
PARSER_HAS_LATE_LIT_INIT = (1u << 30), /**< there are identifier or string literals which construction
|
||||
* is postponed after the local parser data is freed */
|
||||
#ifndef JERRY_NDEBUG
|
||||
PARSER_SCANNING_SUCCESSFUL = PARSER_HAS_LATE_LIT_INIT, /**< scanning process was successful */
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
PARSER_ALLOW_NEW_TARGET = PARSER_IS_FUNCTION, /**< allow new.target parsing in the current context */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
} parser_general_flags_t;
|
||||
|
||||
/**
|
||||
@@ -127,43 +130,32 @@ typedef enum
|
||||
/**
|
||||
* Offset between PARSER_CLASS_CONSTRUCTOR and ECMA_PARSE_CLASS_CONSTRUCTOR
|
||||
*/
|
||||
#define PARSER_CLASS_PARSE_OPTS_OFFSET \
|
||||
#define PARSER_SAVED_FLAGS_OFFSET \
|
||||
(JERRY_LOG2 (PARSER_CLASS_CONSTRUCTOR) - JERRY_LOG2 (ECMA_PARSE_CLASS_CONSTRUCTOR))
|
||||
|
||||
/**
|
||||
* Count of ecma_parse_opts_t class parsing options related bits
|
||||
*/
|
||||
#define PARSER_CLASS_PARSE_OPTS_COUNT \
|
||||
(JERRY_LOG2 (ECMA_PARSE_HAS_STATIC_SUPER) - JERRY_LOG2 (ECMA_PARSE_CLASS_CONSTRUCTOR))
|
||||
#define PARSER_SAVED_FLAGS_COUNT \
|
||||
(JERRY_LOG2 (ECMA_PARSE_ALLOW_SUPER_CALL) - JERRY_LOG2 (ECMA_PARSE_CLASS_CONSTRUCTOR) + 1)
|
||||
|
||||
/**
|
||||
* Mask for get class option bits from ecma_parse_opts_t
|
||||
*/
|
||||
#define PARSER_CLASS_ECMA_PARSE_OPTS_TO_PARSER_OPTS_MASK \
|
||||
(((1 << PARSER_CLASS_PARSE_OPTS_COUNT) - 1) << JERRY_LOG2 (ECMA_PARSE_CLASS_CONSTRUCTOR))
|
||||
(((1 << PARSER_SAVED_FLAGS_COUNT) - 1) << JERRY_LOG2 (ECMA_PARSE_CLASS_CONSTRUCTOR))
|
||||
|
||||
/**
|
||||
* Get class option bits from ecma_parse_opts_t
|
||||
*/
|
||||
#define PARSER_GET_CLASS_PARSER_OPTS(opts) \
|
||||
(((opts) & PARSER_CLASS_ECMA_PARSE_OPTS_TO_PARSER_OPTS_MASK) << PARSER_CLASS_PARSE_OPTS_OFFSET)
|
||||
#define PARSER_GET_SAVED_FLAGS(opts) \
|
||||
(((opts) & PARSER_CLASS_ECMA_PARSE_OPTS_TO_PARSER_OPTS_MASK) << PARSER_SAVED_FLAGS_OFFSET)
|
||||
|
||||
/**
|
||||
* Get class option bits from parser_general_flags_t
|
||||
*/
|
||||
#define PARSER_GET_CLASS_ECMA_PARSE_OPTS(opts) \
|
||||
((uint16_t) (((opts) >> PARSER_CLASS_PARSE_OPTS_OFFSET) & PARSER_CLASS_ECMA_PARSE_OPTS_TO_PARSER_OPTS_MASK))
|
||||
|
||||
/**
|
||||
* Class constructor with heritage context representing bits
|
||||
*/
|
||||
#define PARSER_CLASS_CONSTRUCTOR_SUPER (PARSER_CLASS_CONSTRUCTOR | PARSER_CLASS_HAS_SUPER)
|
||||
|
||||
/**
|
||||
* Check the scope is a class constructor with heritage context
|
||||
*/
|
||||
#define PARSER_IS_CLASS_CONSTRUCTOR_SUPER(flag) \
|
||||
(((flag) & PARSER_CLASS_CONSTRUCTOR_SUPER) == PARSER_CLASS_CONSTRUCTOR_SUPER)
|
||||
#define PARSER_SAVE_STATUS_FLAGS(opts) \
|
||||
((uint16_t) (((opts) >> PARSER_SAVED_FLAGS_OFFSET) & PARSER_CLASS_ECMA_PARSE_OPTS_TO_PARSER_OPTS_MASK))
|
||||
|
||||
/* All flags that affect exotic arguments object creation. */
|
||||
#define PARSER_ARGUMENTS_RELATED_FLAGS \
|
||||
@@ -697,8 +689,6 @@ void parser_parse_expression_statement (parser_context_t *context_p, int options
|
||||
void parser_parse_expression (parser_context_t *context_p, int options);
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
void parser_parse_class (parser_context_t *context_p, bool is_statement);
|
||||
void parser_parse_super_class_context_start (parser_context_t *context_p);
|
||||
void parser_parse_super_class_context_end (parser_context_t *context_p);
|
||||
void parser_parse_initializer (parser_context_t *context_p, parser_pattern_flags_t flags);
|
||||
void parser_parse_initializer_by_next_char (parser_context_t *context_p, parser_pattern_flags_t flags);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
@@ -901,64 +901,6 @@ parser_parse_with_statement_end (parser_context_t *context_p) /**< context */
|
||||
parser_set_branch_to_current_position (context_p, &with_statement.branch);
|
||||
} /* parser_parse_with_statement_end */
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
/**
|
||||
* Parse super class context like a with statement (starting part).
|
||||
*/
|
||||
void
|
||||
parser_parse_super_class_context_start (parser_context_t *context_p) /**< context */
|
||||
{
|
||||
JERRY_ASSERT (context_p->token.type == LEXER_KEYW_EXTENDS
|
||||
|| (context_p->status_flags & PARSER_CLASS_HAS_SUPER));
|
||||
parser_with_statement_t with_statement;
|
||||
|
||||
if (context_p->token.type == LEXER_KEYW_EXTENDS)
|
||||
{
|
||||
lexer_next_token (context_p);
|
||||
|
||||
parser_parse_expression (context_p, PARSE_EXPR | PARSE_EXPR_LEFT_HAND_SIDE);
|
||||
}
|
||||
else
|
||||
{
|
||||
JERRY_ASSERT (context_p->status_flags & PARSER_CLASS_HAS_SUPER);
|
||||
parser_emit_cbc (context_p, CBC_PUSH_NULL);
|
||||
context_p->status_flags |= PARSER_CLASS_IMPLICIT_SUPER;
|
||||
}
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
PARSER_PLUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_SUPER_CLASS_CONTEXT_STACK_ALLOCATION);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
context_p->status_flags |= PARSER_CLASS_HAS_SUPER;
|
||||
parser_emit_cbc_ext_forward_branch (context_p,
|
||||
CBC_EXT_SUPER_CLASS_CREATE_CONTEXT,
|
||||
&with_statement.branch);
|
||||
|
||||
parser_stack_push (context_p, &with_statement, sizeof (parser_with_statement_t));
|
||||
parser_stack_push_uint8 (context_p, PARSER_STATEMENT_WITH);
|
||||
} /* parser_parse_super_class_context_start */
|
||||
|
||||
/**
|
||||
* Parse super class context like a with statement (ending part).
|
||||
*/
|
||||
void
|
||||
parser_parse_super_class_context_end (parser_context_t *context_p) /**< context */
|
||||
{
|
||||
parser_with_statement_t with_statement;
|
||||
parser_stack_pop_uint8 (context_p);
|
||||
parser_stack_pop (context_p, &with_statement, sizeof (parser_with_statement_t));
|
||||
|
||||
parser_flush_cbc (context_p);
|
||||
PARSER_MINUS_EQUAL_U16 (context_p->stack_depth, PARSER_SUPER_CLASS_CONTEXT_STACK_ALLOCATION);
|
||||
#ifndef JERRY_NDEBUG
|
||||
PARSER_MINUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_SUPER_CLASS_CONTEXT_STACK_ALLOCATION);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_CLASS_EXPR_CONTEXT_END);
|
||||
parser_set_branch_to_current_position (context_p, &with_statement.branch);
|
||||
} /* parser_parse_super_class_context_end */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/**
|
||||
* Parse do-while statement (ending part).
|
||||
*/
|
||||
@@ -2958,7 +2900,12 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
|
||||
|
||||
case LEXER_KEYW_RETURN:
|
||||
{
|
||||
if (!(context_p->status_flags & PARSER_IS_FUNCTION))
|
||||
uint32_t status_flag = PARSER_IS_FUNCTION;
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
status_flag |= PARSER_IS_ARROW_FUNCTION;
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
if (!(context_p->status_flags & status_flag))
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_INVALID_RETURN);
|
||||
}
|
||||
@@ -2971,20 +2918,6 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
|
||||
|| context_p->token.type == LEXER_RIGHT_BRACE)
|
||||
{
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (JERRY_UNLIKELY (PARSER_IS_CLASS_CONSTRUCTOR_SUPER (context_p->status_flags)))
|
||||
{
|
||||
if (context_p->status_flags & PARSER_CLASS_IMPLICIT_SUPER)
|
||||
{
|
||||
parser_emit_cbc (context_p, CBC_PUSH_THIS);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_CONSTRUCTOR_THIS);
|
||||
}
|
||||
parser_emit_cbc (context_p, CBC_RETURN);
|
||||
break;
|
||||
}
|
||||
|
||||
if (context_p->status_flags & PARSER_IS_ASYNC_FUNCTION)
|
||||
{
|
||||
parser_emit_cbc (context_p, CBC_PUSH_UNDEFINED);
|
||||
@@ -3000,12 +2933,6 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
|
||||
parser_parse_expression (context_p, PARSE_EXPR);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (JERRY_UNLIKELY (PARSER_IS_CLASS_CONSTRUCTOR_SUPER (context_p->status_flags)))
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_CONSTRUCTOR_RETURN);
|
||||
break;
|
||||
}
|
||||
|
||||
if (context_p->status_flags & PARSER_IS_ASYNC_FUNCTION)
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_RETURN_PROMISE);
|
||||
@@ -3174,22 +3101,6 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
/* There is no lexer_next_token here, since the
|
||||
* next token belongs to the parent context. */
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (JERRY_UNLIKELY (PARSER_IS_CLASS_CONSTRUCTOR_SUPER (context_p->status_flags)))
|
||||
{
|
||||
if (context_p->status_flags & PARSER_CLASS_IMPLICIT_SUPER)
|
||||
{
|
||||
parser_emit_cbc (context_p, CBC_PUSH_THIS);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_CONSTRUCTOR_THIS);
|
||||
}
|
||||
parser_emit_cbc (context_p, CBC_RETURN);
|
||||
parser_flush_cbc (context_p);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
return;
|
||||
}
|
||||
parser_raise_error (context_p, PARSER_ERR_INVALID_RIGHT_SQUARE);
|
||||
|
||||
@@ -153,6 +153,8 @@ parser_flush_cbc (parser_context_t *context_p) /**< context */
|
||||
return;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (last_opcode != PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_SUPER));
|
||||
|
||||
context_p->status_flags |= PARSER_NO_END_LABEL;
|
||||
|
||||
if (PARSER_IS_BASIC_OPCODE (last_opcode))
|
||||
@@ -1154,7 +1156,7 @@ parser_error_to_string (parser_error_t error) /**< error code */
|
||||
{
|
||||
return "Classes may not have a static property called 'prototype'.";
|
||||
}
|
||||
case PARSER_ERR_UNEXPECTED_SUPER_REFERENCE:
|
||||
case PARSER_ERR_UNEXPECTED_SUPER_KEYWORD:
|
||||
{
|
||||
return "Super is not allowed to be used here.";
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ JERRY_STATIC_ASSERT ((int) ECMA_PARSE_STRICT_MODE == (int) PARSER_IS_STRICT,
|
||||
ecma_parse_strict_mode_must_be_equal_to_parser_is_strict);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
JERRY_STATIC_ASSERT ((ECMA_PARSE_CLASS_CONSTRUCTOR << PARSER_CLASS_PARSE_OPTS_OFFSET) == PARSER_CLASS_CONSTRUCTOR,
|
||||
ecma_class_parse_options_must_be_able_to_be_shifted_to_ecma_general_flags);
|
||||
JERRY_STATIC_ASSERT ((ECMA_PARSE_CLASS_CONSTRUCTOR << PARSER_SAVED_FLAGS_OFFSET) == PARSER_CLASS_CONSTRUCTOR,
|
||||
ecma_saved_parse_options_must_be_transformed_to_ecma_general_flags);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/** \addtogroup parser Parser
|
||||
@@ -675,7 +675,7 @@ parse_print_final_cbc (ecma_compiled_code_t *compiled_code_p, /**< compiled code
|
||||
JERRY_DEBUG_MSG (",arrow");
|
||||
}
|
||||
|
||||
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_CONSTRUCTOR)
|
||||
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_CLASS_CONSTRUCTOR)
|
||||
{
|
||||
JERRY_DEBUG_MSG (",constructor");
|
||||
}
|
||||
@@ -994,8 +994,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
|
||||
length++;
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (ext_opcode == CBC_EXT_CONSTRUCTOR_RETURN
|
||||
|| ext_opcode == CBC_EXT_RETURN_PROMISE)
|
||||
if (ext_opcode == CBC_EXT_RETURN_PROMISE)
|
||||
{
|
||||
last_opcode = CBC_RETURN;
|
||||
}
|
||||
@@ -1294,7 +1293,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
|
||||
|
||||
if (context_p->status_flags & PARSER_CLASS_CONSTRUCTOR)
|
||||
{
|
||||
compiled_code_p->status_flags |= CBC_CODE_FLAGS_CONSTRUCTOR;
|
||||
compiled_code_p->status_flags |= CBC_CODE_FLAGS_CLASS_CONSTRUCTOR;
|
||||
}
|
||||
|
||||
if (context_p->status_flags & PARSER_IS_GENERATOR_FUNCTION)
|
||||
@@ -1936,7 +1935,7 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
context.status_flags |= PARSER_GET_CLASS_PARSER_OPTS (parse_opts);
|
||||
context.status_flags |= PARSER_GET_SAVED_FLAGS (parse_opts);
|
||||
context.tagged_template_literal_cp = JMEM_CP_NULL;
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
@@ -2374,13 +2373,6 @@ parser_parse_function (parser_context_t *context_p, /**< context */
|
||||
}
|
||||
|
||||
lexer_next_token (context_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if ((context_p->status_flags & PARSER_CLASS_CONSTRUCTOR_SUPER) == PARSER_CLASS_CONSTRUCTOR_SUPER)
|
||||
{
|
||||
context_p->status_flags |= PARSER_LEXICAL_ENV_NEEDED;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
parser_parse_statements (context_p);
|
||||
compiled_code_p = parser_post_processing (context_p);
|
||||
|
||||
@@ -2416,12 +2408,14 @@ parser_parse_arrow_function (parser_context_t *context_p, /**< context */
|
||||
parser_saved_context_t saved_context;
|
||||
ecma_compiled_code_t *compiled_code_p;
|
||||
|
||||
JERRY_ASSERT ((status_flags & PARSER_IS_FUNCTION)
|
||||
JERRY_ASSERT (!(status_flags & PARSER_IS_FUNCTION)
|
||||
&& (status_flags & PARSER_IS_ARROW_FUNCTION));
|
||||
parser_save_context (context_p, &saved_context);
|
||||
context_p->status_flags |= status_flags;
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
context_p->status_flags |= saved_context.status_flags & PARSER_CLASS_HAS_SUPER;
|
||||
context_p->status_flags |= saved_context.status_flags & (PARSER_IS_FUNCTION
|
||||
| PARSER_ALLOW_SUPER
|
||||
| PARSER_ALLOW_SUPER_CALL);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
#if ENABLED (JERRY_PARSER_DUMP_BYTE_CODE)
|
||||
|
||||
@@ -133,7 +133,7 @@ typedef enum
|
||||
PARSER_ERR_CLASS_CONSTRUCTOR_AS_ACCESSOR, /**< class constructor cannot be an accessor */
|
||||
PARSER_ERR_CLASS_CONSTRUCTOR_AS_GENERATOR, /**< class constructor cannot be a generator */
|
||||
PARSER_ERR_CLASS_STATIC_PROTOTYPE, /**< static method name 'prototype' is not allowed */
|
||||
PARSER_ERR_UNEXPECTED_SUPER_REFERENCE, /**< unexpected super keyword */
|
||||
PARSER_ERR_UNEXPECTED_SUPER_KEYWORD, /**< unexpected super keyword */
|
||||
|
||||
PARSER_ERR_RIGHT_BRACE_EXPECTED, /**< right brace expected */
|
||||
PARSER_ERR_OF_EXPECTED, /**< of keyword expected */
|
||||
|
||||
@@ -104,6 +104,8 @@ typedef enum
|
||||
SCAN_STACK_FOR_BLOCK_END, /**< end of "for" statement with let/const declaration */
|
||||
SCAN_STACK_ARROW_ARGUMENTS, /**< might be arguments of an arrow function */
|
||||
SCAN_STACK_ARROW_EXPRESSION, /**< expression body of an arrow function */
|
||||
SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR, /**< explicit class constructor */
|
||||
SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR, /**< implicit class constructor */
|
||||
SCAN_STACK_CLASS_STATEMENT, /**< class statement */
|
||||
SCAN_STACK_CLASS_EXPRESSION, /**< class expression */
|
||||
SCAN_STACK_CLASS_EXTENDS, /**< class extends expression */
|
||||
@@ -346,6 +348,8 @@ void scanner_detect_invalid_let (parser_context_t *context_p, lexer_lit_location
|
||||
void scanner_detect_eval_call (parser_context_t *context_p, scanner_context_t *scanner_context_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
void scanner_push_class_declaration (parser_context_t *context_p, scanner_context_t *scanner_context_p,
|
||||
uint8_t stack_mode);
|
||||
void scanner_push_destructuring_pattern (parser_context_t *context_p, scanner_context_t *scanner_context_p,
|
||||
uint8_t binding_type, bool is_nested);
|
||||
void scanner_pop_binding_list (scanner_context_t *scanner_context_p);
|
||||
|
||||
@@ -1327,6 +1327,27 @@ scanner_detect_invalid_let (parser_context_t *context_p, /**< context */
|
||||
}
|
||||
} /* scanner_detect_invalid_let */
|
||||
|
||||
/**
|
||||
* Push the values required for class declaration parsing.
|
||||
*/
|
||||
void
|
||||
scanner_push_class_declaration (parser_context_t *context_p, /**< context */
|
||||
scanner_context_t *scanner_context_p, /* scanner context */
|
||||
uint8_t stack_mode) /**< stack mode */
|
||||
{
|
||||
JERRY_ASSERT (context_p->token.type == LEXER_KEYW_CLASS);
|
||||
|
||||
parser_stack_push_uint8 (context_p, stack_mode);
|
||||
scanner_source_start_t source_start;
|
||||
source_start.source_p = context_p->source_p;
|
||||
|
||||
parser_stack_push (context_p, &source_start, sizeof (scanner_source_start_t));
|
||||
parser_stack_push_uint8 (context_p, SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR);
|
||||
scanner_context_p->mode = SCAN_MODE_CLASS_DECLARATION;
|
||||
|
||||
lexer_next_token (context_p);
|
||||
} /* scanner_push_class_declaration */
|
||||
|
||||
/**
|
||||
* Push the values required for destructuring assignment or binding parsing.
|
||||
*/
|
||||
@@ -1512,6 +1533,7 @@ scanner_cleanup (parser_context_t *context_p) /**< context */
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
JERRY_ASSERT (scanner_info_p->type == SCANNER_TYPE_END_ARGUMENTS
|
||||
|| scanner_info_p->type == SCANNER_TYPE_LET_EXPRESSION
|
||||
|| scanner_info_p->type == SCANNER_TYPE_CLASS_CONSTRUCTOR
|
||||
|| scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED);
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
JERRY_ASSERT (scanner_info_p->type == SCANNER_TYPE_END_ARGUMENTS);
|
||||
|
||||
@@ -196,10 +196,7 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
case LEXER_KEYW_CLASS:
|
||||
{
|
||||
parser_stack_push_uint8 (context_p, SCAN_STACK_CLASS_EXPRESSION);
|
||||
scanner_context_p->mode = SCAN_MODE_CLASS_DECLARATION;
|
||||
|
||||
lexer_next_token (context_p);
|
||||
scanner_push_class_declaration (context_p, scanner_context_p, SCAN_STACK_CLASS_EXPRESSION);
|
||||
|
||||
if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL)
|
||||
{
|
||||
@@ -1028,8 +1025,10 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context *
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
scanner_context_p->mode = SCAN_MODE_CLASS_METHOD;
|
||||
parser_stack_pop_uint8 (context_p);
|
||||
|
||||
return SCAN_KEEP_TOKEN;
|
||||
}
|
||||
case SCAN_STACK_FUNCTION_PARAMETERS:
|
||||
@@ -1407,7 +1406,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
case LEXER_KEYW_CLASS:
|
||||
{
|
||||
lexer_next_token (context_p);
|
||||
scanner_push_class_declaration (context_p, scanner_context_p, SCAN_STACK_CLASS_STATEMENT);
|
||||
|
||||
if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL)
|
||||
{
|
||||
@@ -1427,8 +1426,6 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
|
||||
scanner_context_p->mode = SCAN_MODE_CLASS_DECLARATION;
|
||||
parser_stack_push_uint8 (context_p, SCAN_STACK_CLASS_STATEMENT);
|
||||
return SCAN_NEXT_TOKEN;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
@@ -1659,10 +1656,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (context_p->token.type == LEXER_KEYW_CLASS)
|
||||
{
|
||||
scanner_context_p->mode = SCAN_MODE_CLASS_DECLARATION;
|
||||
parser_stack_push_uint8 (context_p, SCAN_STACK_CLASS_STATEMENT);
|
||||
|
||||
lexer_next_token (context_p);
|
||||
scanner_push_class_declaration (context_p, scanner_context_p, SCAN_STACK_CLASS_STATEMENT);
|
||||
|
||||
if (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL)
|
||||
{
|
||||
@@ -1976,8 +1970,8 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */
|
||||
parser_stack_pop_uint8 (context_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (context_p->stack_top_uint8 == SCAN_STACK_CLASS_STATEMENT
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_CLASS_EXPRESSION)
|
||||
if (context_p->stack_top_uint8 == SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR)
|
||||
{
|
||||
scanner_context_p->mode = SCAN_MODE_CLASS_METHOD;
|
||||
return SCAN_KEEP_TOKEN;
|
||||
@@ -2342,13 +2336,28 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
|
||||
}
|
||||
case SCAN_MODE_CLASS_METHOD:
|
||||
{
|
||||
JERRY_ASSERT (stack_top == SCAN_STACK_CLASS_STATEMENT || stack_top == SCAN_STACK_CLASS_EXPRESSION);
|
||||
JERRY_ASSERT (stack_top == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR
|
||||
|| stack_top == SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR);
|
||||
|
||||
lexer_skip_empty_statements (context_p);
|
||||
|
||||
lexer_scan_identifier (context_p);
|
||||
|
||||
if (context_p->token.type == LEXER_RIGHT_BRACE)
|
||||
{
|
||||
scanner_source_start_t source_start;
|
||||
|
||||
parser_stack_pop_uint8 (context_p);
|
||||
|
||||
if (stack_top == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR)
|
||||
{
|
||||
parser_stack_pop (context_p, &source_start, sizeof (scanner_source_start_t));
|
||||
}
|
||||
|
||||
stack_top = context_p->stack_top_uint8;
|
||||
|
||||
JERRY_ASSERT (stack_top == SCAN_STACK_CLASS_STATEMENT || stack_top == SCAN_STACK_CLASS_EXPRESSION);
|
||||
|
||||
if (stack_top == SCAN_STACK_CLASS_STATEMENT)
|
||||
{
|
||||
/* The token is kept to disallow consuming a semicolon after it. */
|
||||
@@ -2361,6 +2370,22 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
|
||||
break;
|
||||
}
|
||||
|
||||
if (context_p->token.type == LEXER_LITERAL
|
||||
&& LEXER_IS_IDENT_OR_STRING (context_p->token.lit_location.type)
|
||||
&& lexer_compare_literal_to_string (context_p, "constructor", 11))
|
||||
{
|
||||
if (stack_top == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR)
|
||||
{
|
||||
scanner_source_start_t source_start;
|
||||
parser_stack_pop_uint8 (context_p);
|
||||
parser_stack_pop (context_p, &source_start, sizeof (scanner_source_start_t));
|
||||
|
||||
scanner_info_t *info_p = scanner_insert_info (context_p, source_start.source_p, sizeof (scanner_info_t));
|
||||
info_p->type = SCANNER_TYPE_CLASS_CONSTRUCTOR;
|
||||
parser_stack_push_uint8 (context_p, SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR);
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer_token_is_identifier (context_p, "static", 6))
|
||||
{
|
||||
lexer_scan_identifier (context_p);
|
||||
@@ -3328,6 +3353,13 @@ scan_completed:
|
||||
print_location = true;
|
||||
break;
|
||||
}
|
||||
case SCANNER_TYPE_CLASS_CONSTRUCTOR:
|
||||
{
|
||||
JERRY_DEBUG_MSG (" CLASS-CONSTRUCTOR: source:%d\n",
|
||||
(int) (info_p->source_p - source_start_p));
|
||||
print_location = false;
|
||||
break;
|
||||
}
|
||||
case SCANNER_TYPE_LET_EXPRESSION:
|
||||
{
|
||||
JERRY_DEBUG_MSG (" LET_EXPRESSION: source:%d\n",
|
||||
|
||||
@@ -46,6 +46,7 @@ typedef enum
|
||||
SCANNER_TYPE_CASE, /**< case statement */
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
SCANNER_TYPE_INITIALIZER, /**< destructuring binding or assignment pattern with initializer */
|
||||
SCANNER_TYPE_CLASS_CONSTRUCTOR, /**< class constructor */
|
||||
SCANNER_TYPE_LET_EXPRESSION, /**< let expression */
|
||||
SCANNER_TYPE_ERR_REDECLARED, /**< syntax error: a variable is redeclared */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
Reference in New Issue
Block a user