Implement ES2015 class feature (part I.) (#2404)

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

Currently supported:
 - Class statement
 - Class expression
 - Static methods

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2018-07-12 18:20:08 +02:00
committed by yichoi
parent 62cdb3965f
commit 43aae199ce
18 changed files with 779 additions and 15 deletions
+52
View File
@@ -1763,6 +1763,13 @@ parser_post_processing (parser_context_t *context_p) /**< context */
}
#endif /* !CONFIG_DISABLE_ES2015_ARROW_FUNCTION */
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (context_p->status_flags & PARSER_CLASS_CONSTRUCTOR)
{
compiled_code_p->status_flags |= CBC_CODE_FLAGS_CONSTRUCTOR;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
literal_pool_p = (ecma_value_t *) byte_code_p;
literal_pool_p -= context_p->register_count;
byte_code_p += literal_length;
@@ -2479,6 +2486,38 @@ 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
*
@@ -2498,7 +2537,14 @@ parser_parse_function (parser_context_t *context_p, /**< context */
#ifdef PARSER_DUMP_BYTE_CODE
if (context_p->is_show_opcodes)
{
#ifndef CONFIG_DISABLE_ES2015_CLASS
bool is_constructor = context_p->status_flags & PARSER_CLASS_CONSTRUCTOR;
JERRY_DEBUG_MSG (is_constructor ? "\n--- Class constructor parsing start ---\n\n"
: "\n--- Function parsing start ---\n\n");
#else
JERRY_DEBUG_MSG ("\n--- Function parsing start ---\n\n");
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
}
#endif /* PARSER_DUMP_BYTE_CODE */
@@ -2596,7 +2642,13 @@ parser_parse_function (parser_context_t *context_p, /**< context */
#ifdef PARSER_DUMP_BYTE_CODE
if (context_p->is_show_opcodes)
{
#ifndef CONFIG_DISABLE_ES2015_CLASS
bool is_constructor = context_p->status_flags & PARSER_CLASS_CONSTRUCTOR;
JERRY_DEBUG_MSG (is_constructor ? "\n--- Class constructor parsing end ---\n\n"
: "\n--- Function parsing end ---\n\n");
#else
JERRY_DEBUG_MSG ("\n--- Function parsing end ---\n\n");
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
}
#endif /* PARSER_DUMP_BYTE_CODE */