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
+21 -4
View File
@@ -34,9 +34,11 @@
* @return configuration flags
*/
static inline uint32_t JERRY_ATTR_ALWAYS_INLINE
snapshot_get_global_flags (bool has_regex) /**< regex literal is present */
snapshot_get_global_flags (bool has_regex, /**< regex literal is present */
bool has_class) /**< class literal is present */
{
JERRY_UNUSED (has_regex);
JERRY_UNUSED (has_class);
uint32_t flags = 0;
@@ -45,7 +47,10 @@ snapshot_get_global_flags (bool has_regex) /**< regex literal is present */
#endif /* JERRY_CPOINTER_32_BIT */
#ifndef CONFIG_DISABLE_REGEXP_BUILTIN
flags |= (has_regex ? JERRY_SNAPSHOT_HAS_REGEX_LITERAL : 0);
#endif /* CONFIG_DISABLE_REGEXP_BUILTIN */
#endif /* !CONFIG_DISABLE_REGEXP_BUILTIN */
#ifndef CONFIG_DISABLE_ES2015_CLASS
flags |= (has_class ? JERRY_SNAPSHOT_HAS_CLASS_LITERAL : 0);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
return flags;
} /* snapshot_get_global_flags */
@@ -61,8 +66,11 @@ snapshot_check_global_flags (uint32_t global_flags) /**< global flags */
#ifndef CONFIG_DISABLE_REGEXP_BUILTIN
global_flags &= (uint32_t) ~JERRY_SNAPSHOT_HAS_REGEX_LITERAL;
#endif /* !CONFIG_DISABLE_REGEXP_BUILTIN */
#ifndef CONFIG_DISABLE_ES2015_CLASS
global_flags &= (uint32_t) ~JERRY_SNAPSHOT_HAS_CLASS_LITERAL;
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
return global_flags == snapshot_get_global_flags (false);
return global_flags == snapshot_get_global_flags (false, false);
} /* snapshot_check_global_flags */
#endif /* JERRY_ENABLE_SNAPSHOT_SAVE || JERRY_ENABLE_SNAPSHOT_EXEC */
@@ -77,6 +85,7 @@ typedef struct
size_t snapshot_buffer_write_offset;
ecma_value_t snapshot_error;
bool regex_found;
bool class_found;
} snapshot_globals_t;
/** \addtogroup jerrysnapshot Jerry snapshot operations
@@ -154,6 +163,13 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< compiled
uint8_t *copied_code_start_p = snapshot_buffer_p + globals_p->snapshot_buffer_write_offset;
ecma_compiled_code_t *copied_code_p = (ecma_compiled_code_t *) copied_code_start_p;
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_CONSTRUCTOR)
{
globals_p->class_found = true;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
#ifndef CONFIG_DISABLE_REGEXP_BUILTIN
if (!(compiled_code_p->status_flags & CBC_CODE_FLAGS_FUNCTION))
{
@@ -739,6 +755,7 @@ jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< scr
globals.snapshot_buffer_write_offset = aligned_header_size;
globals.snapshot_error = ECMA_VALUE_EMPTY;
globals.regex_found = false;
globals.class_found = false;
parse_status = parser_parse_script (args_p,
args_size,
@@ -769,7 +786,7 @@ jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< scr
jerry_snapshot_header_t header;
header.magic = JERRY_SNAPSHOT_MAGIC;
header.version = JERRY_SNAPSHOT_VERSION;
header.global_flags = snapshot_get_global_flags (globals.regex_found);
header.global_flags = snapshot_get_global_flags (globals.regex_found, globals.class_found);
header.lit_table_offset = (uint32_t) globals.snapshot_buffer_write_offset;
header.number_of_funcs = 1;
header.func_offsets[0] = aligned_header_size;
+2 -1
View File
@@ -41,7 +41,7 @@ typedef struct
/**
* Jerry snapshot format version.
*/
#define JERRY_SNAPSHOT_VERSION (14u)
#define JERRY_SNAPSHOT_VERSION (15u)
/**
* Snapshot configuration flags.
@@ -50,6 +50,7 @@ typedef enum
{
/* 8 bits are reserved for dynamic features */
JERRY_SNAPSHOT_HAS_REGEX_LITERAL = (1u << 0), /**< byte code has regex literal */
JERRY_SNAPSHOT_HAS_CLASS_LITERAL = (1u << 1), /**< byte code has class literal */
/* 24 bits are reserved for compile time features */
JERRY_SNAPSHOT_FOUR_BYTE_CPOINTER = (1u << 8) /**< compressed pointers are four byte long */
} jerry_snapshot_global_flags_t;
+1
View File
@@ -37,6 +37,7 @@
*/
#ifdef CONFIG_DISABLE_ES2015
# define CONFIG_DISABLE_ES2015_ARROW_FUNCTION
# define CONFIG_DISABLE_ES2015_CLASS
# define CONFIG_DISABLE_ES2015_BUILTIN
# define CONFIG_DISABLE_ES2015_PROMISE_BUILTIN
# define CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS
@@ -402,6 +402,14 @@ ecma_op_function_has_instance (ecma_object_t *func_obj_p, /**< Function object *
return ecma_make_boolean_value (result);
} /* ecma_op_function_has_instance */
#ifndef CONFIG_DISABLE_ES2015_CLASS
/**
* Indicates whether the class has been invoked with 'new'.
*/
#define ECMA_CLASS_CONSTRUCT_FLAG ((uintptr_t) 0x01u)
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
/**
* Sets the construct flag in the arguments list pointer.
*
@@ -413,8 +421,10 @@ ecma_op_function_set_construct_flag (const ecma_value_t *arguments_list_p) /**<
/* Any ecma value list must be aligned to 4 byte. */
JERRY_ASSERT ((((uintptr_t) arguments_list_p) & 0x3) == 0);
/* Currently it returns with the same pointer. When classes
* will be enabled, it will set the lowest bit. */
#ifndef CONFIG_DISABLE_ES2015_CLASS
arguments_list_p = (const ecma_value_t *)(((uintptr_t) arguments_list_p) | ECMA_CLASS_CONSTRUCT_FLAG);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
return arguments_list_p;
} /* ecma_op_function_set_construct_flag */
@@ -426,8 +436,10 @@ ecma_op_function_set_construct_flag (const ecma_value_t *arguments_list_p) /**<
static inline const ecma_value_t * JERRY_ATTR_ALWAYS_INLINE
ecma_op_function_clear_construct_flag (const ecma_value_t *arguments_list_p) /**< modified arguments list pointer */
{
/* Currently it returns with the same pointer. When classes
* will be enabled, the lowest bit will be cleared. */
#ifndef CONFIG_DISABLE_ES2015_CLASS
arguments_list_p = (const ecma_value_t *)(((uintptr_t) arguments_list_p) & ~ECMA_CLASS_CONSTRUCT_FLAG);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
return arguments_list_p;
} /* ecma_op_function_clear_construct_flag */
@@ -439,8 +451,12 @@ ecma_op_function_clear_construct_flag (const ecma_value_t *arguments_list_p) /**
static inline bool JERRY_ATTR_ALWAYS_INLINE
ecma_op_function_has_construct_flag (const ecma_value_t *arguments_list_p) /**< modified arguments list pointer */
{
#ifndef CONFIG_DISABLE_ES2015_CLASS
return (((uintptr_t) arguments_list_p) & ECMA_CLASS_CONSTRUCT_FLAG);
#else
JERRY_UNUSED (arguments_list_p);
return false;
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
} /* ecma_op_function_has_construct_flag */
/**
@@ -496,6 +512,14 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
const ecma_compiled_code_t *bytecode_data_p = ecma_op_function_get_compiled_code (ext_func_p);
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (bytecode_data_p->status_flags & CBC_CODE_FLAGS_CONSTRUCTOR &&
!ecma_op_function_has_construct_flag (arguments_list_p))
{
return ecma_raise_type_error (ECMA_ERR_MSG ("Class constructor cannot be invoked without 'new'."));
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
is_strict = (bytecode_data_p->status_flags & CBC_CODE_FLAGS_STRICT_MODE) ? true : false;
is_no_lex_env = (bytecode_data_p->status_flags & CBC_CODE_FLAGS_LEXICAL_ENV_NOT_NEEDED) ? true : false;
+7
View File
@@ -551,6 +551,12 @@
VM_OC_RESOURCE_NAME) \
CBC_OPCODE (CBC_EXT_LINE, CBC_NO_FLAG, 0, \
VM_OC_LINE) \
CBC_OPCODE (CBC_EXT_SET_STATIC_PROPERTY, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
VM_OC_SET_PROPERTY | VM_OC_GET_LITERAL_LITERAL) \
CBC_OPCODE (CBC_EXT_SET_STATIC_SETTER, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
VM_OC_SET_SETTER | VM_OC_GET_LITERAL_LITERAL) \
CBC_OPCODE (CBC_EXT_SET_STATIC_GETTER, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
VM_OC_SET_GETTER | VM_OC_GET_LITERAL_LITERAL) \
\
/* Binary compound assignment opcodes with pushing the result. */ \
CBC_EXT_BINARY_LVALUE_OPERATION (CBC_EXT_ASSIGN_ADD, \
@@ -667,6 +673,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;
#define CBC_OPCODE(arg1, arg2, arg3, arg4) arg1,
+62
View File
@@ -277,6 +277,23 @@ lexer_skip_spaces (parser_context_t *context_p) /**< context */
}
} /* lexer_skip_spaces */
#ifndef CONFIG_DISABLE_ES2015_CLASS
/**
* Skip all the continuous empty statements.
*/
void
lexer_skip_empty_statements (parser_context_t *context_p) /**< context */
{
lexer_skip_spaces (context_p);
while (*context_p->source_p == LIT_CHAR_SEMICOLON)
{
lexer_next_token (context_p);
lexer_skip_spaces (context_p);
}
} /* lexer_skip_empty_statements */
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
/**
* Keyword data.
*/
@@ -1308,6 +1325,25 @@ lexer_check_colon (parser_context_t *context_p) /**< context */
&& 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 */
#ifndef CONFIG_DISABLE_ES2015_ARROW_FUNCTION
/**
@@ -2231,6 +2267,10 @@ lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */
{
lexer_skip_spaces (context_p);
#ifndef CONFIG_DISABLE_ES2015_CLASS
bool is_static_method = (context_p->token.type == LEXER_KEYW_STATIC);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
context_p->token.line = context_p->line;
context_p->token.column = context_p->column;
@@ -2262,6 +2302,17 @@ lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */
}
}
}
#ifndef CONFIG_DISABLE_ES2015_CLASS
if ((context_p->status_flags & PARSER_IS_CLASS)
&& !must_be_identifier
&& !is_static_method
&& context_p->token.lit_location.length == 6
&& lexer_compare_raw_identifier_to_current (context_p, "static", 6))
{
context_p->token.type = LEXER_KEYW_STATIC;
return;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
create_literal_object = true;
}
@@ -2297,6 +2348,17 @@ lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */
}
}
#ifndef CONFIG_DISABLE_ES2015_CLASS
if ((context_p->status_flags & PARSER_IS_CLASS)
&& !must_be_identifier
&& !is_static_method
&& lexer_compare_raw_identifier_to_current (context_p, "constructor", 11))
{
context_p->token.type = LEXER_CLASS_CONSTRUCTOR;
return;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
if (create_literal_object)
{
lexer_construct_literal_object (context_p,
+1
View File
@@ -149,6 +149,7 @@ typedef enum
LEXER_PROPERTY_SETTER, /**< property setter function */
LEXER_COMMA_SEP_LIST, /**< comma separated bracketed expression list */
LEXER_SCAN_SWITCH, /**< special value for switch pre-scan */
LEXER_CLASS_CONSTRUCTOR, /**< special value for class constructor method */
/* Future reserved words: these keywords
* must form a group after all other keywords. */
+252
View File
@@ -21,6 +21,10 @@
#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) */
/** \addtogroup parser Parser
* @{
*
@@ -353,6 +357,247 @@ parser_append_object_literal_item (parser_context_t *context_p, /**< context */
}
} /* parser_append_object_literal_item */
#ifndef CONFIG_DISABLE_ES2015_CLASS
/**
* 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 */
{
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;
while (true)
{
if (!is_static)
{
lexer_skip_empty_statements (context_p);
}
lexer_expect_object_literal_id (context_p, false);
if (context_p->token.type == LEXER_RIGHT_BRACE)
{
break;
}
if (context_p->token.type == LEXER_PROPERTY_GETTER || context_p->token.type == LEXER_PROPERTY_SETTER)
{
uint32_t status_flags;
cbc_ext_opcode_t opcode;
uint16_t literal_index, function_literal_index;
if (context_p->token.type == LEXER_PROPERTY_GETTER)
{
status_flags = PARSER_IS_FUNCTION | PARSER_IS_CLOSURE | PARSER_IS_PROPERTY_GETTER;
opcode = is_static ? CBC_EXT_SET_STATIC_GETTER : CBC_EXT_SET_GETTER;
}
else
{
status_flags = PARSER_IS_FUNCTION | PARSER_IS_CLOSURE | PARSER_IS_PROPERTY_SETTER;
opcode = is_static ? CBC_EXT_SET_STATIC_SETTER : CBC_EXT_SET_SETTER;
}
lexer_expect_object_literal_id (context_p, true);
literal_index = context_p->lit_object.index;
if (!is_static && 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);
parser_emit_cbc_literal (context_p,
CBC_PUSH_LITERAL,
literal_index);
JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_LITERAL);
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (opcode);
context_p->last_cbc.value = function_literal_index;
is_static = false;
}
else if (!is_static && context_p->token.type == LEXER_CLASS_CONSTRUCTOR)
{
if (constructor_literal_p->type == LEXER_FUNCTION_LITERAL)
{
/* 14.5.1 */
parser_raise_error (context_p, PARSER_ERR_MULTIPLE_CLASS_CONSTRUCTOR);
}
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;
}
else if (!is_static && context_p->token.type == LEXER_KEYW_STATIC)
{
is_static = true;
}
else
{
if (is_static && lexer_compare_raw_identifier_to_current (context_p, "prototype", 9))
{
parser_raise_error (context_p, PARSER_ERR_CLASS_STATIC_PROPERTY_NAME_PROTOTYPE);
}
if (!lexer_check_left_paren (context_p))
{
lexer_next_token (context_p);
parser_raise_error (context_p, PARSER_ERR_LEFT_PAREN_EXPECTED);
}
parser_flush_cbc (context_p);
uint16_t literal_index = context_p->lit_object.index;
uint32_t status_flags = PARSER_IS_FUNCTION | PARSER_IS_FUNC_EXPRESSION | PARSER_IS_CLOSURE;
uint16_t function_literal_index = lexer_construct_function_object (context_p, status_flags);
parser_emit_cbc_literal (context_p,
CBC_PUSH_LITERAL,
function_literal_index);
JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_LITERAL);
context_p->last_cbc.value = literal_index;
if (is_static)
{
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SET_STATIC_PROPERTY);
is_static = false;
}
else
{
context_p->last_cbc_opcode = CBC_SET_LITERAL_PROPERTY;
}
}
}
if (constructor_literal_p->type == LEXER_UNUSED_LITERAL)
{
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;
}
JERRY_ASSERT (constructor_literal_p->type == LEXER_FUNCTION_LITERAL);
} /* 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.
*/
void
parser_parse_class (parser_context_t *context_p, /**< context */
bool is_statement) /**< true - if class is parsed as a statement
* false - otherwise (as an expression) */
{
JERRY_ASSERT (context_p->token.type == LEXER_KEYW_CLASS);
uint16_t class_ident_index = PARSER_MAXIMUM_NUMBER_OF_LITERALS;
if (is_statement)
{
/* Class statement must contain an identifier. */
lexer_expect_identifier (context_p, LEXER_IDENT_LITERAL);
JERRY_ASSERT (context_p->token.type == LEXER_LITERAL
&& context_p->token.lit_location.type == LEXER_IDENT_LITERAL);
class_ident_index = context_p->lit_object.index;
context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_VAR;
lexer_next_token (context_p);
}
else
{
lexer_next_token (context_p);
/* Class expression may contain an identifier. */
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_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)
{
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++;
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 | PARSER_IS_CLASS;
/* 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 */
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 (is_statement)
{
parser_emit_cbc_literal (context_p, CBC_ASSIGN_SET_IDENT, class_ident_index);
}
parser_flush_cbc (context_p);
context_p->status_flags &= (uint32_t) ~PARSER_IS_CLASS;
if (!is_strict)
{
/* Restore flag */
context_p->status_flags &= (uint32_t) ~PARSER_IS_STRICT;
}
lexer_next_token (context_p);
} /* parser_parse_class */
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
/**
* Parse object literal.
*/
@@ -857,6 +1102,13 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
PARSER_IS_FUNCTION | PARSER_IS_FUNC_EXPRESSION | PARSER_IS_CLOSURE);
break;
}
#ifndef CONFIG_DISABLE_ES2015_CLASS
case LEXER_KEYW_CLASS:
{
parser_parse_class (context_p, false);
return;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
case LEXER_LEFT_BRACE:
{
parser_parse_object_literal (context_p);
+14
View File
@@ -67,6 +67,10 @@ typedef enum
PARSER_IS_ARROW_FUNCTION = (1u << 18), /**< an arrow function is parsed */
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_IS_CLASS = (1u << 20), /**< statements parsed inside class body */
PARSER_CLASS_CONSTRUCTOR = (1u << 21), /**< a class constructor is parsed */
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
} parser_general_flags_t;
/**
@@ -426,6 +430,10 @@ void parser_set_continues_to_current_position (parser_context_t *context_p, pars
void lexer_next_token (parser_context_t *context_p);
bool lexer_check_colon (parser_context_t *context_p);
#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
lexer_token_type_t lexer_check_arrow (parser_context_t *context_p);
#endif /* !CONFIG_DISABLE_ES2015_ARROW_FUNCTION */
@@ -472,6 +480,9 @@ void parser_scan_until (parser_context_t *context_p, lexer_range_t *range_p, lex
*/
void parser_parse_statements (parser_context_t *context_p);
#ifndef CONFIG_DISABLE_ES2015_CLASS
void parser_parse_class (parser_context_t *context_p, bool is_statement);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
void parser_free_jumps (parser_stack_iterator_t iterator);
/**
@@ -485,6 +496,9 @@ 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. */
+93 -2
View File
@@ -41,6 +41,10 @@ typedef enum
#ifndef CONFIG_DISABLE_ES2015_ARROW_FUNCTION
SCAN_MODE_ARROW_FUNCTION, /**< arrow function might follows */
#endif /* !CONFIG_DISABLE_ES2015_ARROW_FUNCTION */
#ifndef CONFIG_DISABLE_ES2015_CLASS
SCAN_MODE_CLASS_DECLARATION, /**< scanning class declaration */
SCAN_MODE_CLASS_METHOD, /**< scanning class method */
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
SCAN_MODE_POST_PRIMARY_EXPRESSION, /**< scanning post primary expression */
SCAN_MODE_PRIMARY_EXPRESSION_END, /**< scanning primary expression end */
SCAN_MODE_STATEMENT, /**< scanning statement */
@@ -55,9 +59,9 @@ typedef enum
{
SCAN_STACK_HEAD, /**< head */
SCAN_STACK_PAREN_EXPRESSION, /**< parent expression group */
SCAN_STACK_PAREN_STATEMENT, /**< parent stetement group */
SCAN_STACK_PAREN_STATEMENT, /**< parent statement group */
SCAN_STACK_COLON_EXPRESSION, /**< colon expression group */
SCAN_STACK_COLON_STATEMENT, /**< colon statement group*/
SCAN_STACK_COLON_STATEMENT, /**< colon statement group */
SCAN_STACK_SQUARE_BRACKETED_EXPRESSION, /**< square bracketed expression group */
SCAN_STACK_OBJECT_LITERAL, /**< object literal group */
SCAN_STACK_BLOCK_STATEMENT, /**< block statement group */
@@ -66,6 +70,9 @@ typedef enum
#ifndef CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS
SCAN_STACK_TEMPLATE_STRING, /**< template string */
#endif /* !CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS */
#ifndef CONFIG_DISABLE_ES2015_CLASS
SCAN_STACK_CLASS, /**< class language element */
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
} scan_stack_modes_t;
/**
@@ -99,6 +106,14 @@ parser_scan_primary_expression (parser_context_t *context_p, /**< context */
*mode = SCAN_MODE_FUNCTION_ARGUMENTS;
break;
}
#ifndef CONFIG_DISABLE_ES2015_CLASS
case LEXER_KEYW_CLASS:
{
parser_stack_push_uint8 (context_p, SCAN_STACK_BLOCK_EXPRESSION);
*mode = SCAN_MODE_CLASS_DECLARATION;
break;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
case LEXER_LEFT_PAREN:
{
parser_stack_push_uint8 (context_p, SCAN_STACK_PAREN_EXPRESSION);
@@ -360,6 +375,9 @@ parser_scan_primary_expression_end (parser_context_t *context_p, /**< context */
/* Check whether we can enter to statement mode. */
if (stack_top != SCAN_STACK_BLOCK_STATEMENT
&& stack_top != SCAN_STACK_BLOCK_EXPRESSION
#ifndef CONFIG_DISABLE_ES2015_CLASS
&& stack_top != SCAN_STACK_CLASS
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
&& !(stack_top == SCAN_STACK_HEAD && end_type == LEXER_SCAN_SWITCH))
{
parser_raise_error (context_p, PARSER_ERR_INVALID_EXPRESSION);
@@ -482,6 +500,9 @@ parser_scan_statement (parser_context_t *context_p, /**< context */
{
if (stack_top == SCAN_STACK_BLOCK_STATEMENT
|| stack_top == SCAN_STACK_BLOCK_EXPRESSION
#ifndef CONFIG_DISABLE_ES2015_CLASS
|| stack_top == SCAN_STACK_CLASS
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
|| stack_top == SCAN_STACK_BLOCK_PROPERTY)
{
parser_stack_pop_uint8 (context_p);
@@ -490,6 +511,12 @@ parser_scan_statement (parser_context_t *context_p, /**< context */
{
*mode = SCAN_MODE_POST_PRIMARY_EXPRESSION;
}
#ifndef CONFIG_DISABLE_ES2015_CLASS
if (stack_top == SCAN_STACK_CLASS)
{
*mode = SCAN_MODE_CLASS_METHOD;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
else if (stack_top == SCAN_STACK_BLOCK_PROPERTY)
{
*mode = SCAN_MODE_POST_PRIMARY_EXPRESSION;
@@ -516,6 +543,14 @@ parser_scan_statement (parser_context_t *context_p, /**< context */
*mode = SCAN_MODE_FUNCTION_ARGUMENTS;
return false;
}
#ifndef CONFIG_DISABLE_ES2015_CLASS
case LEXER_KEYW_CLASS:
{
parser_stack_push_uint8 (context_p, SCAN_STACK_BLOCK_STATEMENT);
*mode = SCAN_MODE_CLASS_DECLARATION;
return false;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
default:
{
break;
@@ -620,6 +655,55 @@ parser_scan_until (parser_context_t *context_p, /**< context */
}
break;
}
#ifndef CONFIG_DISABLE_ES2015_CLASS
case SCAN_MODE_CLASS_DECLARATION:
{
if (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL)
{
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)
{
parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_EXPECTED);
}
mode = SCAN_MODE_CLASS_METHOD;
break;
}
case SCAN_MODE_CLASS_METHOD:
{
if (type == LEXER_SEMICOLON)
{
break;
}
if (type == LEXER_RIGHT_BRACE
&& (stack_top == SCAN_STACK_BLOCK_STATEMENT
|| stack_top == SCAN_STACK_BLOCK_EXPRESSION))
{
mode = (stack_top == SCAN_STACK_BLOCK_EXPRESSION) ? SCAN_MODE_PRIMARY_EXPRESSION_END : SCAN_MODE_STATEMENT;
parser_stack_pop_uint8 (context_p);
break;
}
if (lexer_compare_raw_identifier_to_current (context_p, "static", 6))
{
lexer_next_token (context_p);
}
if (lexer_compare_raw_identifier_to_current (context_p, "get", 3)
|| lexer_compare_raw_identifier_to_current (context_p, "set", 3))
{
lexer_next_token (context_p);
}
parser_stack_push_uint8 (context_p, SCAN_STACK_CLASS);
mode = SCAN_MODE_FUNCTION_ARGUMENTS;
continue;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
#ifndef CONFIG_DISABLE_ES2015_ARROW_FUNCTION
case SCAN_MODE_ARROW_FUNCTION:
{
@@ -678,9 +762,16 @@ parser_scan_until (parser_context_t *context_p, /**< context */
}
case SCAN_MODE_FUNCTION_ARGUMENTS:
{
#ifndef CONFIG_DISABLE_ES2015_CLASS
JERRY_ASSERT (stack_top == SCAN_STACK_BLOCK_STATEMENT
|| stack_top == SCAN_STACK_BLOCK_EXPRESSION
|| stack_top == SCAN_STACK_CLASS
|| stack_top == SCAN_STACK_BLOCK_PROPERTY);
#else
JERRY_ASSERT (stack_top == SCAN_STACK_BLOCK_STATEMENT
|| stack_top == SCAN_STACK_BLOCK_EXPRESSION
|| stack_top == SCAN_STACK_BLOCK_PROPERTY);
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
if (context_p->token.type == LEXER_LITERAL
&& (context_p->token.lit_location.type == LEXER_IDENT_LITERAL
+8
View File
@@ -1837,6 +1837,14 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
break;
}
#ifndef CONFIG_DISABLE_ES2015_CLASS
case LEXER_KEYW_CLASS:
{
parser_parse_class (context_p, true);
continue;
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
case LEXER_KEYW_FUNCTION:
{
parser_parse_function_statement (context_p);
+14
View File
@@ -920,6 +920,20 @@ parser_error_to_string (parser_error_t error) /**< error code */
return "Expected '}' token.";
}
#endif /* !CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS */
#ifndef CONFIG_DISABLE_ES2015_CLASS
case PARSER_ERR_MULTIPLE_CLASS_CONSTRUCTOR:
{
return "Multiple constructors are not allowed.";
}
case PARSER_ERR_CLASS_CONSTRUCTOR_AS_ACCESSOR:
{
return "Class constructor may not be an accessor.";
}
case PARSER_ERR_CLASS_STATIC_PROPERTY_NAME_PROTOTYPE:
{
return "Classes may not have a static property called 'prototype'.";
}
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
case PARSER_ERR_COLON_EXPECTED:
{
return "Expected ':' token.";
+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 */
+5
View File
@@ -87,6 +87,11 @@ typedef enum
#ifndef CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS
PARSER_ERR_RIGHT_BRACE_EXPECTED, /**< right brace expected */
#endif /* !CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS */
#ifndef CONFIG_DISABLE_ES2015_CLASS
PARSER_ERR_MULTIPLE_CLASS_CONSTRUCTOR, /**< multiple class constructor */
PARSER_ERR_CLASS_CONSTRUCTOR_AS_ACCESSOR, /**< class constructor cannot be an accessor */
PARSER_ERR_CLASS_STATIC_PROPERTY_NAME_PROTOTYPE, /**< static method name 'prototype' is not allowed */
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
PARSER_ERR_COLON_EXPECTED, /**< colon expected */
PARSER_ERR_COLON_FOR_CONDITIONAL_EXPECTED, /**< colon expected for conditional expression */
PARSER_ERR_SEMICOLON_EXPECTED, /**< semicolon expected */
+4 -1
View File
@@ -31,6 +31,7 @@ Alternatively, if you want to use a custom profile at
```
# Turn off every ES2015 feature EXCEPT the arrow functions
CONFIG_DISABLE_ES2015_BUILTIN
CONFIG_DISABLE_ES2015_CLASS
CONFIG_DISABLE_ES2015_PROMISE_BUILTIN
CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS
CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN
@@ -84,6 +85,8 @@ In JerryScript all of the features are enabled by default, so an empty profile f
Disable the [arrow functions](http://www.ecma-international.org/ecma-262/6.0/#sec-arrow-function-definitions).
* `CONFIG_DISABLE_ES2015_BUILTIN`:
Disable the built-in updates of the 5.1 standard. There are some differences in those built-ins which available in both [5.1](http://www.ecma-international.org/ecma-262/5.1/) and [2015](http://www.ecma-international.org/ecma-262/6.0/) versions of the standard. JerryScript uses the latest definition by default.
* `CONFIG_DISABLE_ES2015_CLASS`:
Disable the [class](https://www.ecma-international.org/ecma-262/6.0/#sec-class-definitions) language element.
* `CONFIG_DISABLE_ES2015_PROMISE_BUILTIN`:
Disable the [Promise](http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects) built-in.
* `CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS`:
@@ -91,4 +94,4 @@ In JerryScript all of the features are enabled by default, so an empty profile f
* `CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN`:
Disable the [ArrayBuffer](http://www.ecma-international.org/ecma-262/6.0/#sec-arraybuffer-objects) and [TypedArray](http://www.ecma-international.org/ecma-262/6.0/#sec-typedarray-objects) built-ins.
* `CONFIG_DISABLE_ES2015`: Disable all of the implemented [ECMAScript2015 features](http://www.ecma-international.org/ecma-262/6.0/).
(equivalent to `CONFIG_DISABLE_ES2015_ARROW_FUNCTION`, `CONFIG_DISABLE_ES2015_BUILTIN`, `CONFIG_DISABLE_ES2015_PROMISE_BUILTIN`, `CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS`, and `CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN`).
(equivalent to `CONFIG_DISABLE_ES2015_ARROW_FUNCTION`, `CONFIG_DISABLE_ES2015_BUILTIN`, `CONFIG_DISABLE_ES2015_CLASS`, `CONFIG_DISABLE_ES2015_PROMISE_BUILTIN`, `CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS`, and `CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN`).
+15 -2
View File
@@ -1047,7 +1047,13 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
}
case VM_OC_SET_PROPERTY:
{
ecma_object_t *object_p = ecma_get_object_from_value (stack_top_p[-1]);
#ifndef CONFIG_DISABLE_ES2015_CLASS
const int index = (byte_code_start_p[0] == CBC_EXT_OPCODE) ? -2 : -1;
#else
const int index = -1;
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
ecma_object_t *object_p = ecma_get_object_from_value (stack_top_p[index]);
ecma_string_t *prop_name_p;
ecma_property_t *property_p;
@@ -1102,8 +1108,15 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
case VM_OC_SET_GETTER:
case VM_OC_SET_SETTER:
{
JERRY_ASSERT (byte_code_start_p[0] == CBC_EXT_OPCODE);
#ifndef CONFIG_DISABLE_ES2015_CLASS
const int index = (byte_code_start_p[1] > CBC_EXT_SET_SETTER) ? -2 : -1;
#else
const int index = -1;
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
opfunc_set_accessor (VM_OC_GROUP_GET_INDEX (opcode_data) == VM_OC_SET_GETTER,
stack_top_p[-1],
stack_top_p[index],
left_value,
right_value);
+199
View File
@@ -0,0 +1,199 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function must_throw(str) {
try {
eval("switch (1) { default: " + str + "}");
assert(false);
} catch (e) {
}
try {
eval(str);
assert(false);
}
catch (e) {
}
must_throw_strict(str);
}
function must_throw_strict(str) {
try {
eval ("'use strict'; switch (1) { default: " + str + "}");
assert (false);
} catch (e) {
}
try {
eval("'use strict'; " + str);
assert(false);
} catch (e) {
}
}
must_throw("class {}");
must_throw("class class {}");
must_throw("class A { constructor() {} this.a = 5 }");
must_throw("class A { constructor() {} constructor() {} }");
must_throw("class A { static prototype() {} }");
must_throw("class A { get constructor() {} }");
must_throw("class A { set constructor() {} }");
must_throw("class A {}; A()");
must_throw("class X {}; var o = {}; Object.defineProperty(o, 'p', { get: X, set: X }); o.p;");
must_throw("var a = new A; class A {};");
must_throw("class A { g\\u0065t e() {} }");
must_throw('class A { "static" e() {} }');
assert(eval("class A {}") === undefined);
assert(eval("var a = class A {}") === undefined);
assert(eval("var a = class {}") === undefined);
assert(eval("class A { ; ; ; ;;;;;;;;;;;; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;; }") === undefined);
assert(eval('class A {"constructor"() {} }') === undefined);
assert(isNaN (eval('switch(1) { default: (class A{} % 1) }')));
class B {
}
var b = new B;
assert(typeof B === "function");
assert(typeof b === "object");
class C {
c1() {
return 5;
}
c2() {
return this._c;
}
3() {
return 3;
}
}
var c = new C;
assert (c.c1() === 5);
assert (c.c2() === undefined);
assert (c["3"]() === 3);
class D {
constructor(d) {
this._d = d;
}
d1() {
return this._d;
}
}
var d = new D(5);
assert(d.d1() === 5);
class E {
constructor(e) {
this._e = e;
}
get e() {
return this._e;
}
set e(e) {
this._e = e;
}
}
var e = new E (5);
assert (e.e === 5);
e.e = 10;
assert (e.e === 10);
var F = class ClassF {
constructor(f) {
this._f = f;
}
static f1() {
return this;
}
static f2() {
return this._f;
}
static f3(a, b) {
return a + b;
}
static constructor(a) {
return a;
}
static static(a) {
return a;
}
static 2 (a) {
return 2 * a;
}
}
var f = new F(5);
assert (f.f1 === undefined);
assert (f.f2 === undefined);
assert (F.f1() === F);
assert (F.f2() === undefined);
assert (F.f3(1, 1) === 2);
assert (F.constructor(5) === 5);
assert (F.static(5) === 5);
assert (F["2"](5) === 10);
var G = class {
static set a(a) {
this._a = a;
}
static get a() {
return this._a;
}
static set 1(a) {
this._a = a;
}
static get 1() {
return this._a;
}
static set constructor(a) {
this._a = a;
}
static get constructor() {
return this._a;
}
static g1() {
return 5;
}
static g1() {
return 10;
}
}
G.a = 10;
assert (G.a === 10);
assert (G.g1() === 10);
G["1"] = 20;
assert (G["1"] === 20);
G.constructor = 30;
assert (G.constructor === 30);
+1 -1
View File
@@ -216,7 +216,7 @@ main (void)
/* Check the snapshot data. Unused bytes should be filled with zeroes */
const uint8_t expected_data[] =
{
0x4A, 0x52, 0x52, 0x59, 0x0E, 0x00, 0x00, 0x00,
0x4A, 0x52, 0x52, 0x59, 0x0F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,