@@ -260,7 +260,6 @@ parser_parse_array_literal (parser_context_t *context_p) /**< context */
260
260
}
261
261
} /* parser_parse_array_literal */
262
262
263
- #ifdef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
264
263
/**
265
264
* Object literal item types.
266
265
*/
@@ -357,7 +356,6 @@ parser_append_object_literal_item (parser_context_t *context_p, /**< context */
357
356
context_p -> stack_top_uint8 = PARSER_OBJECT_PROPERTY_BOTH_ACCESSORS ;
358
357
}
359
358
} /* parser_append_object_literal_item */
360
- #endif /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
361
359
362
360
#ifndef CONFIG_DISABLE_ES2015_CLASS
363
361
@@ -649,41 +647,58 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
649
647
650
648
while (true)
651
649
{
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 */
652
653
lexer_expect_object_literal_id (context_p , LEXER_OBJ_IDENT_NO_OPTS );
654
+ #endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
653
655
654
656
if (context_p -> token .type == LEXER_RIGHT_BRACE )
655
657
{
656
658
break ;
657
659
}
658
660
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 )
661
669
{
662
670
uint32_t status_flags ;
663
- cbc_ext_opcode_t opcode ;
671
+ uint16_t opcode ;
664
672
uint16_t literal_index , function_literal_index ;
665
- #ifdef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
666
673
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 ;
668
675
669
- if (context_p -> token . type == LEXER_PROPERTY_GETTER )
676
+ if (token_type == LEXER_PROPERTY_GETTER )
670
677
{
671
678
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 );
674
680
item_type = PARSER_OBJECT_PROPERTY_GETTER ;
675
- #endif /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
676
681
}
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 */
678
691
{
679
692
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 );
682
694
item_type = PARSER_OBJECT_PROPERTY_SETTER ;
683
- #endif /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
684
695
}
685
696
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 */
686
700
lexer_expect_object_literal_id (context_p , LEXER_OBJ_IDENT_ONLY_IDENTIFIERS );
701
+ #endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
687
702
688
703
/* This assignment is a nop for computed getters/setters. */
689
704
literal_index = context_p -> lit_object .index ;
@@ -694,6 +709,11 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
694
709
opcode = ((opcode == CBC_EXT_SET_GETTER ) ? CBC_EXT_SET_COMPUTED_GETTER
695
710
: CBC_EXT_SET_COMPUTED_SETTER );
696
711
}
712
+
713
+ if (opcode == CBC_SET_LITERAL_PROPERTY )
714
+ {
715
+ parser_append_object_literal_item (context_p , literal_index , item_type );
716
+ }
697
717
#else /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
698
718
parser_append_object_literal_item (context_p , literal_index , item_type );
699
719
#endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
@@ -706,14 +726,21 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
706
726
{
707
727
literal_index = function_literal_index ;
708
728
}
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
+ }
709
736
#endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
710
737
711
738
parser_emit_cbc_literal (context_p ,
712
739
CBC_PUSH_LITERAL ,
713
740
literal_index );
714
741
715
742
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 ;
717
744
context_p -> last_cbc .value = function_literal_index ;
718
745
719
746
lexer_next_token (context_p );
@@ -751,13 +778,35 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
751
778
#endif /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
752
779
753
780
lexer_next_token (context_p );
754
- if (context_p -> token .type != LEXER_COLON )
781
+
782
+ if (context_p -> token .type == LEXER_COLON )
755
783
{
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 );
757
786
}
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 ;
758
793
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
+ }
761
810
762
811
if (context_p -> last_cbc_opcode == CBC_PUSH_LITERAL )
763
812
{
0 commit comments