Implement ES2015 class feature (part II.) (#2439)

This patch is the second milestone of the implementation of this new language element.

Supported:
 - Single class inheritance
 - Functionality of 'super' keyword
 - Implicit constructor in class heritage
 - Specific behaviour while extending with the built-in 'Array' or '%TypedArray%' object
 - Abstract subclasses (Mix-ins)

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2018-10-25 16:00:48 +02:00
committed by Akos Kiss
parent e0e6363f85
commit d1860d0e34
54 changed files with 2543 additions and 199 deletions
+60 -5
View File
@@ -64,13 +64,29 @@
#define CBC_HAS_POP_STACK_BYTE_ARG (CBC_HAS_BYTE_ARG | CBC_POP_STACK_BYTE_ARG)
#ifndef CONFIG_DISABLE_ES2015_CLASS
/**
* Checks whether the current opcode is a super constructor call
*/
#define CBC_SUPER_CALL_OPERATION(opcode) \
((opcode) >= PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_CALL) \
&& (opcode) <= PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_CALL_BLOCK))
#else /* CONFIG_DISABLE_ES2015_CLASS */
/**
* Checks whether the current opcode is a super constructor call
*/
#define CBC_SUPER_CALL_OPERATION(opcode) false
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
/* Debug macro. */
#define CBC_ARGS_EQ(op, types) \
((cbc_flags[op] & CBC_ARG_TYPES) == (types))
/* Debug macro. */
#define CBC_SAME_ARGS(op1, op2) \
((cbc_flags[op1] & CBC_ARG_TYPES) == (cbc_flags[op2] & CBC_ARG_TYPES))
(CBC_SUPER_CALL_OPERATION (op1) ? ((cbc_ext_flags[PARSER_GET_EXT_OPCODE (op1)] & CBC_ARG_TYPES) \
== (cbc_ext_flags[PARSER_GET_EXT_OPCODE (op2)] & CBC_ARG_TYPES)) \
: ((cbc_flags[op1] & CBC_ARG_TYPES) == (cbc_flags[op2] & CBC_ARG_TYPES)))
#define CBC_UNARY_OPERATION(name, group) \
CBC_OPCODE (name, CBC_NO_FLAG, 0, \
@@ -143,15 +159,14 @@
* Hence CBC_NO_RESULT_OPERATION (context_p->last_cbc_opcode)
* cannot be true for an opcode which has a result
*/
#define CBC_NO_RESULT_OPERATION(opcode) \
((opcode) >= CBC_PRE_INCR && (opcode) < CBC_END)
(((opcode) >= CBC_PRE_INCR && (opcode) < CBC_END) || CBC_SUPER_CALL_OPERATION ((opcode)))
#define CBC_NO_RESULT_BLOCK(opcode) \
((opcode) >= CBC_PRE_INCR && (opcode) < CBC_ASSIGN_ADD)
(((opcode) >= CBC_PRE_INCR && (opcode) < CBC_ASSIGN_ADD) || CBC_SUPER_CALL_OPERATION ((opcode)))
#define CBC_NO_RESULT_COMPOUND_ASSIGMENT(opcode) \
((opcode) >= CBC_ASSIGN_ADD && (opcode) < CBC_END)
((opcode) >= CBC_ASSIGN_ADD && (opcode) < CBC_END && !CBC_SUPER_CALL_OPERATION ((opcode)))
/**
* Branch instructions are organized in group of 8 opcodes.
@@ -203,6 +218,8 @@
#define PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION 4
/* PARSER_WITH_CONTEXT_STACK_ALLOCATION must be <= 4 */
#define PARSER_WITH_CONTEXT_STACK_ALLOCATION 1
/* PARSER_SUPER_CLASS_CONTEXT_STACK_ALLOCATION must be <= 4 */
#define PARSER_SUPER_CLASS_CONTEXT_STACK_ALLOCATION 1
/* PARSER_TRY_CONTEXT_STACK_ALLOCATION must be <= 3 */
#define PARSER_TRY_CONTEXT_STACK_ALLOCATION 2
@@ -537,6 +554,10 @@
VM_OC_PUSH_UNDEFINED_BASE | VM_OC_PUT_STACK) \
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) \
\
/* Basic opcodes. */ \
CBC_OPCODE (CBC_EXT_PUSH_LITERAL_PUSH_NUMBER_0, CBC_HAS_LITERAL_ARG, 2, \
@@ -570,6 +591,40 @@
CBC_OPCODE (CBC_EXT_SET_STATIC_COMPUTED_SETTER, CBC_HAS_LITERAL_ARG, -1, \
VM_OC_SET_SETTER | VM_OC_GET_STACK_LITERAL) \
\
/* Class opcodes */ \
CBC_OPCODE (CBC_EXT_INHERIT_AND_SET_CONSTRUCTOR, CBC_NO_FLAG, 0, \
VM_OC_CLASS_INHERITANCE) \
CBC_OPCODE (CBC_EXT_PUSH_CLASS_CONSTRUCTOR, CBC_NO_FLAG, 1, \
VM_OC_PUSH_CLASS_CONSTRUCTOR | 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_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, \
VM_OC_SUPER_CALL | VM_OC_PUT_STACK) \
CBC_OPCODE (CBC_EXT_SUPER_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, \
VM_OC_SUPER_CALL | 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) \
\
/* Binary compound assignment opcodes with pushing the result. */ \
CBC_EXT_BINARY_LVALUE_OPERATION (CBC_EXT_ASSIGN_ADD, \
ADD) \
+19 -25
View File
@@ -352,11 +352,23 @@ static const keyword_string_t keyword_length_4[9] =
LEXER_KEYWORD_END ()
};
#ifndef CONFIG_DISABLE_ES2015
/**
* Number of keywords with 5 characters.
*/
#define KEYWORD_LENGTH_COUNT 11
#else /* CONFIG_DISABLE_ES2015 */
#define KEYWORD_LENGTH_COUNT 10
#endif /* !CONFIG_DISABLE_ES2015 */
/**
* Keywords with 5 characters.
*/
static const keyword_string_t keyword_length_5[10] =
static const keyword_string_t keyword_length_5[KEYWORD_LENGTH_COUNT] =
{
#ifndef CONFIG_DISABLE_ES2015
LEXER_KEYWORD ("await", LEXER_KEYW_AWAIT),
#endif /* !CONFIG_DISABLE_ES2015 */
LEXER_KEYWORD ("break", LEXER_KEYW_BREAK),
LEXER_KEYWORD ("catch", LEXER_KEYW_CATCH),
LEXER_KEYWORD ("class", LEXER_KEYW_CLASS),
@@ -1310,40 +1322,22 @@ lexer_next_token (parser_context_t *context_p) /**< context */
#undef LEXER_TYPE_D_TOKEN
/**
* Checks whether the next token is a colon.
* Checks whether the next token is the specified character.
*
* @return true - if the next token is a colon
* @return true - if the next is the specified character
* false - otherwise
*/
bool
lexer_check_colon (parser_context_t *context_p) /**< context */
lexer_check_next_character (parser_context_t *context_p, /**< context */
lit_utf8_byte_t character) /**< specified character */
{
lexer_skip_spaces (context_p);
context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES);
return (context_p->source_p < context_p->source_end_p
&& context_p->source_p[0] == (uint8_t) LIT_CHAR_COLON);
} /* lexer_check_colon */
#ifndef CONFIG_DISABLE_ES2015_CLASS
/**
* Checks whether the next token is a left parenthesis.
*
* @return true - if the next token is a left parenthesis
* false - otherwise
*/
bool
lexer_check_left_paren (parser_context_t *context_p) /**< context */
{
lexer_skip_spaces (context_p);
context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES);
return (context_p->source_p < context_p->source_end_p
&& context_p->source_p[0] == (uint8_t) LIT_CHAR_LEFT_PAREN);
} /* lexer_check_left_paren */
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
&& context_p->source_p[0] == (uint8_t) character);
} /* lexer_check_next_character */
#ifndef CONFIG_DISABLE_ES2015_ARROW_FUNCTION
+33 -3
View File
@@ -151,29 +151,59 @@ typedef enum
LEXER_SCAN_SWITCH, /**< special value for switch pre-scan */
LEXER_CLASS_CONSTRUCTOR, /**< special value for class constructor method */
#ifdef CONFIG_DISABLE_ES2015
/* Future reserved words: these keywords
* must form a group after all other keywords. */
#define LEXER_FIRST_FUTURE_RESERVED_WORD LEXER_KEYW_CLASS
#endif /* CONFIG_DISABLE_ES2015 */
LEXER_KEYW_CLASS, /**< class */
LEXER_KEYW_ENUM, /**< enum */
LEXER_KEYW_EXTENDS, /**< extends */
LEXER_KEYW_SUPER, /**< super */
LEXER_KEYW_CONST, /**< const */
LEXER_KEYW_EXPORT, /**< export */
LEXER_KEYW_IMPORT, /**< import */
#ifndef CONFIG_DISABLE_ES2015
/* Future reserved words: these keywords
* must form a group after all other keywords.
* Note:
* Tokens from LEXER_KEYW_CLASS to LEXER_KEYW_IMPORT
* are no longer future reserved words in ES2015. */
#define LEXER_FIRST_FUTURE_RESERVED_WORD LEXER_KEYW_ENUM
#endif /* !CONFIG_DISABLE_ES2015 */
LEXER_KEYW_ENUM, /**< enum */
#ifndef CONFIG_DISABLE_ES2015
LEXER_KEYW_AWAIT, /**< await */
#endif /* !CONFIG_DISABLE_ES2015 */
/* Future strict reserved words: these keywords
* must form a group after future reserved words. */
#define LEXER_FIRST_FUTURE_STRICT_RESERVED_WORD LEXER_KEYW_IMPLEMENTS
LEXER_KEYW_IMPLEMENTS, /**< implements */
LEXER_KEYW_LET, /**< let */
LEXER_KEYW_PRIVATE, /**< private */
LEXER_KEYW_PUBLIC, /**< public */
LEXER_KEYW_YIELD, /**< yield */
LEXER_KEYW_INTERFACE, /**< interface */
LEXER_KEYW_PACKAGE, /**< package */
LEXER_KEYW_PROTECTED, /**< protected */
#ifndef CONFIG_DISABLE_ES2015
/* Context dependent strict reserved words:
* See also: ECMA-262 v6, 11.6.2.1 */
#define LEXER_FIRST_CONTEXT_DEPENDENT_RESERVED_WORD LEXER_KEYW_STATIC
LEXER_KEYW_STATIC, /**< static */
#else /* CONFIG_DISABLE_ES2015 */
/* Context dependent strict reserved words:
* See also: ECMA-262 v6, 11.6.2.1 */
#define LEXER_FIRST_CONTEXT_DEPENDENT_RESERVED_WORD
#endif /* !CONFIG_DISABLE_ES2015 */
/* Context dependent future strict reserved words:
* See also: ECMA-262 v6, 11.6.2.1 */
#define LEXER_FIRST_CONTEXT_DEPENDENT_FUTURE_RESERVED_WORD LEXER_KEYW_LET
LEXER_KEYW_LET, /**< let */
LEXER_KEYW_YIELD, /**< yield */
#ifdef CONFIG_DISABLE_ES2015
LEXER_KEYW_STATIC, /**< static */
#endif /* CONFIG_DISABLE_ES2015 */
} lexer_token_type_t;
#define LEXER_NEWLINE_LS_PS_BYTE_1 0xe2
+142 -61
View File
@@ -15,15 +15,9 @@
#include "js-parser-internal.h"
#ifndef CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS
#include "lit-char-helpers.h"
#endif /* !CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS */
#ifndef JERRY_DISABLE_JS_PARSER
#if !defined (CONFIG_DISABLE_ES2015_CLASS) && (defined (JERRY_DEBUGGER) || defined (JERRY_ENABLE_LINE_INFO))
#include "jcontext.h"
#endif /* !CONFIG_DISABLE_ES2015_CLASS && (JERRY_DEBUGGER || JERRY_ENABLE_LINE_INFO) */
#include "lit-char-helpers.h"
/** \addtogroup parser Parser
* @{
@@ -369,19 +363,17 @@ parser_append_object_literal_item (parser_context_t *context_p, /**< context */
* Parse class as an object literal.
*/
static void
parser_parse_class_literal (parser_context_t *context_p, /**< context */
lexer_literal_t *constructor_literal_p) /**< constructor literal */
parser_parse_class_literal (parser_context_t *context_p) /**< context */
{
JERRY_ASSERT (context_p->token.type == LEXER_LEFT_BRACE);
JERRY_ASSERT (constructor_literal_p->type == LEXER_UNUSED_LITERAL);
parser_emit_cbc (context_p, CBC_CREATE_OBJECT);
bool is_static = false;
bool super_called = false;
uint32_t status_flags = PARSER_IS_FUNCTION | PARSER_IS_CLOSURE | (context_p->status_flags & PARSER_CLASS_HAS_SUPER);
while (true)
{
if (!is_static)
if (!(status_flags & PARSER_CLASS_STATIC_FUNCTION))
{
lexer_skip_empty_statements (context_p);
}
@@ -398,8 +390,8 @@ parser_parse_class_literal (parser_context_t *context_p, /**< context */
uint16_t literal_index, function_literal_index;
bool is_getter = (context_p->token.type == LEXER_PROPERTY_GETTER);
uint32_t status_flags = PARSER_IS_FUNCTION | PARSER_IS_CLOSURE;
status_flags |= (is_getter ? PARSER_IS_PROPERTY_GETTER : PARSER_IS_PROPERTY_SETTER);
uint32_t accessor_status_flags = PARSER_IS_FUNCTION | PARSER_IS_CLOSURE;
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);
literal_index = context_p->lit_object.index;
@@ -410,13 +402,14 @@ parser_parse_class_literal (parser_context_t *context_p, /**< context */
{
is_computed = true;
}
else if (!is_static && lexer_compare_raw_identifier_to_current (context_p, "constructor", 11))
else if (!(status_flags & PARSER_CLASS_STATIC_FUNCTION)
&& lexer_compare_raw_identifier_to_current (context_p, "constructor", 11))
{
parser_raise_error (context_p, PARSER_ERR_CLASS_CONSTRUCTOR_AS_ACCESSOR);
}
parser_flush_cbc (context_p);
function_literal_index = lexer_construct_function_object (context_p, status_flags);
function_literal_index = lexer_construct_function_object (context_p, accessor_status_flags);
parser_emit_cbc_literal (context_p,
CBC_PUSH_LITERAL,
@@ -425,6 +418,7 @@ 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);
if (is_computed)
{
@@ -454,28 +448,48 @@ parser_parse_class_literal (parser_context_t *context_p, /**< context */
}
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (opcode);
is_static = false;
status_flags &= (uint32_t) ~PARSER_CLASS_STATIC_FUNCTION;
continue;
}
if (!is_static && context_p->token.type == LEXER_CLASS_CONSTRUCTOR)
if (!(status_flags & PARSER_CLASS_STATIC_FUNCTION) && context_p->token.type == LEXER_CLASS_CONSTRUCTOR)
{
if (constructor_literal_p->type == LEXER_FUNCTION_LITERAL)
if (super_called)
{
/* 14.5.1 */
parser_raise_error (context_p, PARSER_ERR_MULTIPLE_CLASS_CONSTRUCTORS);
}
else
{
super_called = true;
}
parser_flush_cbc (context_p);
uint32_t status_flags = PARSER_IS_FUNCTION | PARSER_IS_CLOSURE | PARSER_CLASS_CONSTRUCTOR;
constructor_literal_p->u.bytecode_p = parser_parse_function (context_p, status_flags);
constructor_literal_p->type = LEXER_FUNCTION_LITERAL;
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);
}
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), context_p->literal_count);
context_p->literal_count++;
continue;
}
if (!is_static && context_p->token.type == LEXER_KEYW_STATIC)
if (!(status_flags & PARSER_CLASS_STATIC_FUNCTION) && context_p->token.type == LEXER_KEYW_STATIC)
{
is_static = true;
status_flags |= PARSER_CLASS_STATIC_FUNCTION;
continue;
}
@@ -485,7 +499,8 @@ parser_parse_class_literal (parser_context_t *context_p, /**< context */
{
is_computed = true;
}
else if (is_static && lexer_compare_raw_identifier_to_current (context_p, "prototype", 9))
else if ((status_flags & PARSER_CLASS_STATIC_FUNCTION)
&& lexer_compare_raw_identifier_to_current (context_p, "prototype", 9))
{
parser_raise_error (context_p, PARSER_ERR_CLASS_STATIC_PROTOTYPE);
}
@@ -493,7 +508,6 @@ parser_parse_class_literal (parser_context_t *context_p, /**< context */
parser_flush_cbc (context_p);
uint16_t literal_index = context_p->lit_object.index;
uint32_t status_flags = PARSER_IS_FUNCTION | PARSER_IS_CLOSURE;
uint16_t function_literal_index = lexer_construct_function_object (context_p, status_flags);
parser_emit_cbc_literal (context_p,
@@ -504,11 +518,11 @@ parser_parse_class_literal (parser_context_t *context_p, /**< context */
context_p->last_cbc.value = literal_index;
if (is_static)
if ((status_flags & PARSER_CLASS_STATIC_FUNCTION))
{
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (is_computed ? CBC_EXT_SET_STATIC_COMPUTED_PROPERTY_LITERAL
: CBC_EXT_SET_STATIC_PROPERTY_LITERAL);
is_static = false;
status_flags &= (uint32_t) ~PARSER_CLASS_STATIC_FUNCTION;
}
else
{
@@ -517,14 +531,15 @@ parser_parse_class_literal (parser_context_t *context_p, /**< context */
}
}
if (constructor_literal_p->type == LEXER_UNUSED_LITERAL)
if (!super_called && (context_p->status_flags & PARSER_CLASS_HAS_SUPER))
{
parser_flush_cbc (context_p);
constructor_literal_p->u.bytecode_p = parser_create_class_implicit_constructor (context_p);
constructor_literal_p->type = LEXER_FUNCTION_LITERAL;
parser_emit_cbc_ext (context_p, CBC_EXT_IMPLICIT_CONSTRUCTOR_CALL);
}
JERRY_ASSERT (constructor_literal_p->type == LEXER_FUNCTION_LITERAL);
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 */
/**
@@ -570,25 +585,17 @@ parser_parse_class (parser_context_t *context_p, /**< context */
}
}
/* Currently heritage is not supported so the next token must be left brace. */
if (context_p->token.type == LEXER_KEYW_EXTENDS)
{
parser_parse_super_class_context_start (context_p);
}
if (context_p->token.type != LEXER_LEFT_BRACE)
{
parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_EXPECTED);
}
/* Create an empty literal for class constructor. */
if (context_p->literal_count >= PARSER_MAXIMUM_NUMBER_OF_LITERALS)
{
parser_raise_error (context_p, PARSER_ERR_LITERAL_LIMIT_REACHED);
}
lexer_literal_t *constructor_literal_p = (lexer_literal_t *) parser_list_append (context_p, &context_p->literal_pool);
constructor_literal_p->type = LEXER_UNUSED_LITERAL;
constructor_literal_p->status_flags = 0;
parser_emit_cbc_literal (context_p, CBC_PUSH_LITERAL, context_p->literal_count);
context_p->literal_count++;
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_CLASS_CONSTRUCTOR);
bool is_strict = context_p->status_flags & PARSER_IS_STRICT;
@@ -596,17 +603,7 @@ parser_parse_class (parser_context_t *context_p, /**< context */
context_p->status_flags |= PARSER_IS_STRICT;
/* ClassDeclaration is parsed. Continue with class body. */
parser_parse_class_literal (context_p, constructor_literal_p);
#ifdef JERRY_DEBUGGER
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
{
jerry_debugger_send_string (JERRY_DEBUGGER_FUNCTION_NAME,
JERRY_DEBUGGER_NO_SUBTYPE,
constructor_literal_p->u.char_p,
constructor_literal_p->prop.length);
}
#endif /* JERRY_DEBUGGER */
parser_parse_class_literal (context_p);
JERRY_ASSERT (context_p->token.type == LEXER_RIGHT_BRACE);
@@ -621,6 +618,12 @@ parser_parse_class (parser_context_t *context_p, /**< context */
parser_emit_cbc_literal (context_p, CBC_ASSIGN_SET_IDENT, class_ident_index);
}
if (context_p->status_flags & PARSER_CLASS_HAS_SUPER)
{
parser_parse_super_class_context_end (context_p, is_statement);
context_p->status_flags &= (uint32_t) ~PARSER_CLASS_HAS_SUPER;
}
parser_flush_cbc (context_p);
if (!is_strict)
@@ -1226,7 +1229,18 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
}
case LEXER_KEYW_THIS:
{
parser_emit_cbc (context_p, CBC_PUSH_THIS);
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (PARSER_IS_CLASS_CONSTRUCTOR_SUPER (context_p->status_flags))
{
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_CONSTRUCTOR_THIS);
}
else
{
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
parser_emit_cbc (context_p, CBC_PUSH_THIS);
#ifndef CONFIG_DISABLE_ES2015_CLASS
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
break;
}
case LEXER_LIT_TRUE:
@@ -1250,6 +1264,38 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
parser_parse_class (context_p, false);
return;
}
case LEXER_KEYW_SUPER:
{
if ((lexer_check_next_character (context_p, LIT_CHAR_DOT)
|| lexer_check_next_character (context_p, LIT_CHAR_LEFT_SQUARE))
&& context_p->status_flags & (PARSER_CLASS_HAS_SUPER | PARSER_IS_ARROW_FUNCTION))
{
if (!LEXER_IS_BINARY_OP_TOKEN (context_p->stack_top_uint8))
{
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);
break;
}
bool is_static = context_p->status_flags & PARSER_CLASS_STATIC_FUNCTION;
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_HAS_SUPER)
&& (context_p->status_flags & (PARSER_IS_ARROW_FUNCTION | PARSER_CLASS_CONSTRUCTOR)))
{
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_CONSTRUCTOR_SUPER);
break;
}
parser_raise_error (context_p, PARSER_ERR_UNEXPECTED_SUPER_REFERENCE);
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
#ifndef CONFIG_DISABLE_ES2015_ARROW_FUNCTION
case LEXER_RIGHT_PAREN:
@@ -1393,6 +1439,12 @@ parser_process_unary_expression (parser_context_t *context_p) /**< context */
context_p->last_cbc_opcode = CBC_PUSH_PROP_THIS_LITERAL_REFERENCE;
opcode = CBC_CALL_PROP;
}
#ifndef CONFIG_DISABLE_ES2015_CLASS
else if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_CONSTRUCTOR_SUPER))
{
opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_CALL);
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
else if ((context_p->status_flags & (PARSER_INSIDE_WITH | PARSER_RESOLVE_BASE_FOR_CALLS))
&& PARSER_IS_PUSH_LITERAL (context_p->last_cbc_opcode)
&& context_p->last_cbc.literal_type == LEXER_IDENT_LITERAL)
@@ -1452,9 +1504,30 @@ parser_process_unary_expression (parser_context_t *context_p) /**< context */
if (is_eval)
{
parser_emit_cbc (context_p, CBC_EVAL);
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (context_p->status_flags & PARSER_CLASS_HAS_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);
}
else
{
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
parser_emit_cbc (context_p, CBC_EVAL);
#ifndef CONFIG_DISABLE_ES2015_CLASS
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
}
#ifndef CONFIG_DISABLE_ES2015_CLASS
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;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
if (call_arguments == 0)
{
if (opcode == CBC_CALL)
@@ -1687,6 +1760,14 @@ parser_append_binary_token (parser_context_t *context_p) /**< context */
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;
#ifndef CONFIG_DISABLE_ES2015_CLASS
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 /* !CONFIG_DISABLE_ES2015_CLASS */
}
else
{
+57 -6
View File
@@ -68,7 +68,12 @@ typedef enum
PARSER_ARROW_PARSE_ARGS = (1u << 19), /**< parse the argument list of an arrow function */
#endif /* !CONFIG_DISABLE_ES2015_ARROW_FUNCTION */
#ifndef CONFIG_DISABLE_ES2015_CLASS
PARSER_CLASS_CONSTRUCTOR = (1u << 20), /**< a class constructor is parsed */
/* These three status flags must be in this order. See PARSER_CLASS_PARSE_OPTS_OFFSET. */
PARSER_CLASS_CONSTRUCTOR = (1u << 20), /**< a class constructor is parsed (this value must be kept in
* in sync with ECMA_PARSE_CLASS_CONSTRUCTOR) */
PARSER_CLASS_HAS_SUPER = (1u << 21), /**< class has super reference */
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 */
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
} parser_general_flags_t;
@@ -85,6 +90,54 @@ typedef enum
* CBC_PUSH_LITERAL instruction */
} parser_expression_flags_t;
/**
* Mask for strict mode code
*/
#define PARSER_STRICT_MODE_MASK 0x1
#ifndef CONFIG_DISABLE_ES2015_CLASS
/**
* Offset between PARSER_CLASS_CONSTRUCTOR and ECMA_PARSE_CLASS_CONSTRUCTOR
*/
#define PARSER_CLASS_PARSE_OPTS_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))
/**
* 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))
/**
* 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)
/**
* 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)
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
/* The maximum of PARSER_CBC_STREAM_PAGE_SIZE is 127. */
#define PARSER_CBC_STREAM_PAGE_SIZE \
((uint32_t) (64 - sizeof (void *)))
@@ -434,9 +487,8 @@ void parser_set_continues_to_current_position (parser_context_t *context_p, pars
/* Lexer functions */
void lexer_next_token (parser_context_t *context_p);
bool lexer_check_colon (parser_context_t *context_p);
bool lexer_check_next_character (parser_context_t *context_p, lit_utf8_byte_t character);
#ifndef CONFIG_DISABLE_ES2015_CLASS
bool lexer_check_left_paren (parser_context_t *context_p);
void lexer_skip_empty_statements (parser_context_t *context_p);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
#ifndef CONFIG_DISABLE_ES2015_ARROW_FUNCTION
@@ -469,6 +521,8 @@ bool lexer_compare_raw_identifier_to_current (parser_context_t *context_p, const
void parser_parse_expression (parser_context_t *context_p, int options);
#ifndef CONFIG_DISABLE_ES2015_CLASS
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, bool is_statement);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
/**
@@ -501,9 +555,6 @@ ecma_compiled_code_t *parser_parse_function (parser_context_t *context_p, uint32
#ifndef CONFIG_DISABLE_ES2015_ARROW_FUNCTION
ecma_compiled_code_t *parser_parse_arrow_function (parser_context_t *context_p, uint32_t status_flags);
#endif /* !CONFIG_DISABLE_ES2015_ARROW_FUNCTION */
#ifndef CONFIG_DISABLE_ES2015_CLASS
ecma_compiled_code_t *parser_create_class_implicit_constructor (parser_context_t *context_p);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
/* Error management. */
+17 -5
View File
@@ -14,10 +14,7 @@
*/
#include "js-parser-internal.h"
#ifndef CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS
#include "lit-char-helpers.h"
#endif /* !CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS */
#ifndef JERRY_DISABLE_JS_PARSER
@@ -75,6 +72,7 @@ typedef enum
#endif /* !CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS */
#ifndef CONFIG_DISABLE_ES2015_CLASS
SCAN_STACK_CLASS, /**< class language element */
SCAN_STACK_CLASS_EXTENDS, /**< class extends expression */
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
} scan_stack_modes_t;
@@ -335,6 +333,9 @@ parser_scan_primary_expression_end (parser_context_t *context_p, /**< context */
if ((type == LEXER_RIGHT_SQUARE && stack_top == SCAN_STACK_SQUARE_BRACKETED_EXPRESSION)
|| (type == LEXER_RIGHT_PAREN && stack_top == SCAN_STACK_PAREN_EXPRESSION)
#ifndef CONFIG_DISABLE_ES2015_CLASS
|| (type == LEXER_LEFT_BRACE && stack_top == SCAN_STACK_CLASS_EXTENDS)
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
|| (type == LEXER_RIGHT_BRACE && stack_top == SCAN_STACK_OBJECT_LITERAL))
{
parser_stack_pop_uint8 (context_p);
@@ -345,6 +346,12 @@ parser_scan_primary_expression_end (parser_context_t *context_p, /**< context */
*mode = SCAN_MODE_ARROW_FUNCTION;
}
#endif /* !CONFIG_DISABLE_ES2015_ARROW_FUNCTION */
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (stack_top == SCAN_STACK_CLASS_EXTENDS)
{
*mode = SCAN_MODE_CLASS_METHOD;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
return false;
}
@@ -699,8 +706,13 @@ parser_scan_until (parser_context_t *context_p, /**< context */
lexer_next_token (context_p);
}
/* Currently heritage is not supported so the next token must be left brace. */
if (context_p->token.type != LEXER_LEFT_BRACE)
if (context_p->token.type == LEXER_KEYW_EXTENDS)
{
parser_stack_push_uint8 (context_p, SCAN_STACK_CLASS_EXTENDS);
mode = SCAN_MODE_PRIMARY_EXPRESSION;
break;
}
else if (context_p->token.type != LEXER_LEFT_BRACE)
{
parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_EXPECTED);
}
+106 -8
View File
@@ -16,10 +16,8 @@
#include "js-parser-internal.h"
#ifndef JERRY_DISABLE_JS_PARSER
#if defined (JERRY_DEBUGGER) || defined (JERRY_ENABLE_LINE_INFO)
#include "jcontext.h"
#endif /* JERRY_DEBUGGER || JERRY_ENABLE_LINE_INFO */
#include "lit-char-helpers.h"
/** \addtogroup parser Parser
* @{
@@ -617,6 +615,68 @@ parser_parse_with_statement_end (parser_context_t *context_p) /**< context */
}
} /* parser_parse_with_statement_end */
#ifndef CONFIG_DISABLE_ES2015_CLASS
/**
* 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);
parser_with_statement_t with_statement;
lexer_next_token (context_p);
/* NOTE: Currently there is no proper way to check whether the currently parsed expression
is a valid lefthand-side expression or not, so we do not throw syntax error and parse
the class extending value as an expression. */
parser_parse_expression (context_p, PARSE_EXPR | PARSE_EXPR_NO_COMMA);
#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 */
bool is_statement) /**< true - if class is parsed as a statement
* false - otherwise (as an expression) */
{
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 */
if (is_statement)
{
parser_emit_cbc (context_p, CBC_CONTEXT_END);
}
else
{
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 /* !CONFIG_DISABLE_ES2015_CLASS */
/**
* Parse do-while statement (ending part).
*/
@@ -1970,22 +2030,52 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
}
lexer_next_token (context_p);
if ((context_p->token.flags & LEXER_WAS_NEWLINE)
|| context_p->token.type == LEXER_SEMICOLON
|| context_p->token.type == LEXER_RIGHT_BRACE)
{
parser_emit_cbc (context_p, CBC_RETURN_WITH_BLOCK);
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (JERRY_UNLIKELY (PARSER_IS_CLASS_CONSTRUCTOR_SUPER (context_p->status_flags)))
{
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_CONSTRUCTOR_THIS);
parser_emit_cbc (context_p, CBC_RETURN);
}
else
{
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
parser_emit_cbc (context_p, CBC_RETURN_WITH_BLOCK);
#ifndef CONFIG_DISABLE_ES2015_CLASS
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
break;
}
parser_parse_expression (context_p, PARSE_EXPR);
if (context_p->last_cbc_opcode == CBC_PUSH_LITERAL)
bool return_with_literal = (context_p->last_cbc_opcode == CBC_PUSH_LITERAL);
#ifndef CONFIG_DISABLE_ES2015_CLASS
return_with_literal &= !PARSER_IS_CLASS_CONSTRUCTOR_SUPER (context_p->status_flags);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
if (return_with_literal)
{
context_p->last_cbc_opcode = CBC_RETURN_WITH_LITERAL;
}
else
{
parser_emit_cbc (context_p, CBC_RETURN);
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (JERRY_UNLIKELY (PARSER_IS_CLASS_CONSTRUCTOR_SUPER (context_p->status_flags)))
{
parser_emit_cbc_ext (context_p, CBC_EXT_CONSTRUCTOR_RETURN);
}
else
{
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
parser_emit_cbc (context_p, CBC_RETURN);
#ifndef CONFIG_DISABLE_ES2015_CLASS
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
}
break;
}
@@ -2003,11 +2093,10 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
lexer_next_token (context_p);
break;
}
case LEXER_LITERAL:
{
if (context_p->token.lit_location.type == LEXER_IDENT_LITERAL
&& lexer_check_colon (context_p))
&& lexer_check_next_character (context_p, LIT_CHAR_COLON))
{
parser_parse_label (context_p);
lexer_next_token (context_p);
@@ -2087,6 +2176,15 @@ 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. */
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (JERRY_UNLIKELY (PARSER_IS_CLASS_CONSTRUCTOR_SUPER (context_p->status_flags)))
{
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_CONSTRUCTOR_THIS);
parser_emit_cbc (context_p, CBC_RETURN);
parser_flush_cbc (context_p);
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
return;
}
parser_raise_error (context_p, PARSER_ERR_INVALID_RIGHT_SQUARE);
+4
View File
@@ -911,6 +911,10 @@ 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:
{
return "Super is not allowed to be used here.";
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
case PARSER_ERR_LEFT_PAREN_EXPECTED:
{
+36 -36
View File
@@ -22,6 +22,14 @@
#ifndef JERRY_DISABLE_JS_PARSER
JERRY_STATIC_ASSERT ((int) ECMA_PARSE_STRICT_MODE == (int) PARSER_IS_STRICT,
ecma_parse_strict_mode_must_be_equal_to_parser_is_strict);
#ifndef CONFIG_DISABLE_ES2015_CLASS
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);
#endif /* !CONFIG_DISABLE_ES2015 */
/** \addtogroup parser Parser
* @{
*
@@ -1210,6 +1218,13 @@ parse_print_final_cbc (ecma_compiled_code_t *compiled_code_p, /**< compiled code
}
#endif /* !CONFIG_DISABLE_ES2015_ARROW_FUNCTION */
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_CONSTRUCTOR)
{
JERRY_DEBUG_MSG (",constructor");
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
JERRY_DEBUG_MSG ("]\n");
JERRY_DEBUG_MSG (" Argument range end: %d\n", (int) argument_end);
@@ -1546,6 +1561,13 @@ parser_post_processing (parser_context_t *context_p) /**< context */
PARSER_NEXT_BYTE (page_p, offset);
length++;
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (ext_opcode == CBC_EXT_CONSTRUCTOR_RETURN)
{
last_opcode = CBC_RETURN;
}
#endif /* !CONFIG_DISABLE_ES2015 */
#ifdef JERRY_ENABLE_LINE_INFO
if (ext_opcode == CBC_EXT_LINE)
{
@@ -2302,11 +2324,11 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
context.stack_limit = 0;
context.last_context_p = NULL;
context.last_statement.current_p = NULL;
context.status_flags |= parse_opts & PARSER_STRICT_MODE_MASK;
if (parse_opts & ECMA_PARSE_STRICT_MODE)
{
context.status_flags |= PARSER_IS_STRICT;
}
#ifndef CONFIG_DISABLE_ES2015_CLASS
context.status_flags |= PARSER_GET_CLASS_PARSER_OPTS (parse_opts);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
context.token.flags = 0;
context.line = 1;
@@ -2525,38 +2547,6 @@ parser_restore_context (parser_context_t *context_p, /**< context */
#endif /* !JERRY_NDEBUG */
} /* parser_restore_context */
#ifndef CONFIG_DISABLE_ES2015_CLASS
/**
* Parse default constructor code
*
* @return compiled code
*/
ecma_compiled_code_t *
parser_create_class_implicit_constructor (parser_context_t *context_p) /**< context */
{
parser_saved_context_t saved_context;
parser_save_context (context_p, &saved_context);
#ifdef JERRY_DEBUGGER
if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
&& jerry_debugger_send_parse_function (context_p->token.line, context_p->token.column))
{
/* This option has a high memory and performance costs,
* but it is necessary for executing eval operations by the debugger. */
context_p->status_flags |= PARSER_LEXICAL_ENV_NEEDED | PARSER_NO_REG_STORE;
}
#endif /* JERRY_DEBUGGER */
context_p->status_flags |= PARSER_CLASS_CONSTRUCTOR;
ecma_compiled_code_t *compiled_code_p = parser_post_processing (context_p);
parser_restore_context (context_p, &saved_context);
return compiled_code_p;
} /* parser_create_class_implicit_constructor */
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
/**
* Parse function code
*
@@ -2674,6 +2664,13 @@ parser_parse_function (parser_context_t *context_p, /**< context */
}
lexer_next_token (context_p);
#ifndef CONFIG_DISABLE_ES2015_CLASS
if ((context_p->status_flags & PARSER_CLASS_CONSTRUCTOR_SUPER) == PARSER_CLASS_CONSTRUCTOR_SUPER)
{
context_p->status_flags |= PARSER_LEXICAL_ENV_NEEDED;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
parser_parse_statements (context_p);
compiled_code_p = parser_post_processing (context_p);
@@ -2713,6 +2710,9 @@ parser_parse_arrow_function (parser_context_t *context_p, /**< context */
&& (status_flags & PARSER_IS_ARROW_FUNCTION));
parser_save_context (context_p, &saved_context);
context_p->status_flags |= status_flags | PARSER_ARGUMENTS_NOT_NEEDED;
#ifndef CONFIG_DISABLE_ES2015_CLASS
context_p->status_flags |= saved_context.status_flags & PARSER_CLASS_HAS_SUPER;
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
#ifdef PARSER_DUMP_BYTE_CODE
if (context_p->is_show_opcodes)
+1
View File
@@ -83,6 +83,7 @@ typedef enum
PARSER_ERR_MULTIPLE_CLASS_CONSTRUCTORS, /**< multiple class constructor */
PARSER_ERR_CLASS_CONSTRUCTOR_AS_ACCESSOR, /**< class constructor cannot be an accessor */
PARSER_ERR_CLASS_STATIC_PROTOTYPE, /**< static method name 'prototype' is not allowed */
PARSER_ERR_UNEXPECTED_SUPER_REFERENCE, /**< unexpected super keyword */
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
PARSER_ERR_LEFT_PAREN_EXPECTED, /**< left paren expected */