@@ -260,7 +260,6 @@ parser_parse_array_literal (parser_context_t *context_p) /**< context */
260260 }
261261} /* parser_parse_array_literal */
262262
263- #ifdef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
264263/**
265264 * Object literal item types.
266265 */
@@ -357,7 +356,6 @@ parser_append_object_literal_item (parser_context_t *context_p, /**< context */
357356 context_p -> stack_top_uint8 = PARSER_OBJECT_PROPERTY_BOTH_ACCESSORS ;
358357 }
359358} /* parser_append_object_literal_item */
360- #endif /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
361359
362360#ifndef CONFIG_DISABLE_ES2015_CLASS
363361
@@ -649,41 +647,58 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
649647
650648 while (true)
651649 {
650+ #ifndef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
651+ lexer_expect_object_literal_id (context_p , LEXER_OBJ_IDENT_OBJ_METHOD );
652+ #else /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
652653 lexer_expect_object_literal_id (context_p , LEXER_OBJ_IDENT_NO_OPTS );
654+ #endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
653655
654656 if (context_p -> token .type == LEXER_RIGHT_BRACE )
655657 {
656658 break ;
657659 }
658660
659- if (context_p -> token .type == LEXER_PROPERTY_GETTER
660- || context_p -> token .type == LEXER_PROPERTY_SETTER )
661+ bool token_type_is_method = (context_p -> token .type == LEXER_PROPERTY_GETTER
662+ || context_p -> token .type == LEXER_PROPERTY_SETTER );
663+
664+ #ifndef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
665+ token_type_is_method = token_type_is_method || context_p -> token .type == LEXER_PROPERTY_METHOD ;
666+ #endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
667+
668+ if (token_type_is_method )
661669 {
662670 uint32_t status_flags ;
663- cbc_ext_opcode_t opcode ;
671+ uint16_t opcode ;
664672 uint16_t literal_index , function_literal_index ;
665- #ifdef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
666673 parser_object_literal_item_types_t item_type ;
667- #endif /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
674+ lexer_token_type_t token_type = context_p -> token . type ;
668675
669- if (context_p -> token . type == LEXER_PROPERTY_GETTER )
676+ if (token_type == LEXER_PROPERTY_GETTER )
670677 {
671678 status_flags = PARSER_IS_FUNCTION | PARSER_IS_CLOSURE | PARSER_IS_PROPERTY_GETTER ;
672- opcode = CBC_EXT_SET_GETTER ;
673- #ifdef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
679+ opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SET_GETTER );
674680 item_type = PARSER_OBJECT_PROPERTY_GETTER ;
675- #endif /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
676681 }
677- else
682+ #ifndef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
683+ else if (token_type == LEXER_PROPERTY_METHOD )
684+ {
685+ status_flags = PARSER_IS_FUNCTION | PARSER_IS_CLOSURE | PARSER_IS_FUNC_EXPRESSION ;
686+ opcode = CBC_SET_LITERAL_PROPERTY ;
687+ item_type = PARSER_OBJECT_PROPERTY_VALUE ;
688+ }
689+ #endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
690+ else /* token_type == LEXER_PROPERTY_SETTER */
678691 {
679692 status_flags = PARSER_IS_FUNCTION | PARSER_IS_CLOSURE | PARSER_IS_PROPERTY_SETTER ;
680- opcode = CBC_EXT_SET_SETTER ;
681- #ifdef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
693+ opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SET_SETTER );
682694 item_type = PARSER_OBJECT_PROPERTY_SETTER ;
683- #endif /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
684695 }
685696
697+ #ifndef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
698+ lexer_expect_object_literal_id (context_p , LEXER_OBJ_IDENT_ONLY_IDENTIFIERS | LEXER_OBJ_IDENT_OBJ_METHOD );
699+ #else /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
686700 lexer_expect_object_literal_id (context_p , LEXER_OBJ_IDENT_ONLY_IDENTIFIERS );
701+ #endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
687702
688703 /* This assignment is a nop for computed getters/setters. */
689704 literal_index = context_p -> lit_object .index ;
@@ -694,6 +709,11 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
694709 opcode = ((opcode == CBC_EXT_SET_GETTER ) ? CBC_EXT_SET_COMPUTED_GETTER
695710 : CBC_EXT_SET_COMPUTED_SETTER );
696711 }
712+
713+ if (opcode == CBC_SET_LITERAL_PROPERTY )
714+ {
715+ parser_append_object_literal_item (context_p , literal_index , item_type );
716+ }
697717#else /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
698718 parser_append_object_literal_item (context_p , literal_index , item_type );
699719#endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
@@ -706,14 +726,21 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
706726 {
707727 literal_index = function_literal_index ;
708728 }
729+ /* Property methods aren't extended opcodes, so swap the values here. */
730+ else if (opcode == CBC_SET_LITERAL_PROPERTY )
731+ {
732+ literal_index ^= function_literal_index ;
733+ function_literal_index ^= literal_index ;
734+ literal_index ^= function_literal_index ;
735+ }
709736#endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
710737
711738 parser_emit_cbc_literal (context_p ,
712739 CBC_PUSH_LITERAL ,
713740 literal_index );
714741
715742 JERRY_ASSERT (context_p -> last_cbc_opcode == CBC_PUSH_LITERAL );
716- context_p -> last_cbc_opcode = PARSER_TO_EXT_OPCODE ( opcode ) ;
743+ context_p -> last_cbc_opcode = opcode ;
717744 context_p -> last_cbc .value = function_literal_index ;
718745
719746 lexer_next_token (context_p );
@@ -751,13 +778,35 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
751778#endif /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
752779
753780 lexer_next_token (context_p );
754- if (context_p -> token .type != LEXER_COLON )
781+
782+ if (context_p -> token .type == LEXER_COLON )
755783 {
756- parser_raise_error (context_p , PARSER_ERR_COLON_EXPECTED );
784+ lexer_next_token (context_p );
785+ parser_parse_expression (context_p , PARSE_EXPR_NO_COMMA );
757786 }
787+ #ifndef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
788+ else if (context_p -> token .type == LEXER_COMMA
789+ || context_p -> token .type == LEXER_RIGHT_BRACE )
790+ {
791+ // TODO somehow clean this up -- is it possible to parse and check for keywords by this step?
792+ lexer_lit_location_t prop_name_literal = context_p -> token .lit_location ;
758793
759- lexer_next_token (context_p );
760- parser_parse_expression (context_p , PARSE_EXPR_NO_COMMA );
794+ if (prop_name_literal .type != LEXER_IDENT_LITERAL || lexer_is_identifier_keyword (context_p ))
795+ {
796+ parser_raise_error (context_p , PARSER_ERR_COLON_EXPECTED );
797+ }
798+
799+ lexer_construct_literal_object (context_p ,
800+ & context_p -> token .lit_location ,
801+ context_p -> token .lit_location .type );
802+ parser_emit_cbc_literal_from_token (context_p , CBC_PUSH_LITERAL );
803+ JERRY_ASSERT (context_p -> last_cbc_opcode == CBC_PUSH_LITERAL );
804+ }
805+ #endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
806+ else
807+ {
808+ parser_raise_error (context_p , PARSER_ERR_COLON_EXPECTED );
809+ }
761810
762811 if (context_p -> last_cbc_opcode == CBC_PUSH_LITERAL )
763812 {
0 commit comments