@@ -636,6 +636,30 @@ parser_parse_class (parser_context_t *context_p, /**< context */
636
636
} /* parser_parse_class */
637
637
#endif /* !CONFIG_DISABLE_ES2015_CLASS */
638
638
639
+ #ifndef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
640
+ /**
641
+ * Parse object initializer method definition.
642
+ *
643
+ * See also: ES2015 14.3
644
+ */
645
+ static void
646
+ parser_parse_object_method (parser_context_t * context_p ) /**< context */
647
+ {
648
+ parser_flush_cbc (context_p );
649
+
650
+ context_p -> source_p -- ;
651
+ context_p -> column -- ;
652
+ uint16_t function_literal_index = lexer_construct_function_object (context_p ,
653
+ PARSER_IS_FUNCTION | PARSER_IS_CLOSURE );
654
+
655
+ parser_emit_cbc_literal (context_p ,
656
+ CBC_PUSH_LITERAL ,
657
+ function_literal_index );
658
+
659
+ lexer_next_token (context_p );
660
+ } /* parser_parse_object_method */
661
+ #endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
662
+
639
663
/**
640
664
* Parse object literal.
641
665
*/
@@ -654,122 +678,151 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
654
678
{
655
679
lexer_expect_object_literal_id (context_p , LEXER_OBJ_IDENT_NO_OPTS );
656
680
657
- if (context_p -> token .type == LEXER_RIGHT_BRACE )
658
- {
659
- break ;
660
- }
661
-
662
- if (context_p -> token .type == LEXER_PROPERTY_GETTER
663
- || context_p -> token .type == LEXER_PROPERTY_SETTER )
681
+ switch (context_p -> token .type )
664
682
{
665
- uint32_t status_flags ;
666
- cbc_ext_opcode_t opcode ;
667
- uint16_t literal_index , function_literal_index ;
683
+ case LEXER_RIGHT_BRACE :
684
+ {
685
+ break ;
686
+ }
687
+ case LEXER_PROPERTY_GETTER :
688
+ case LEXER_PROPERTY_SETTER :
689
+ {
690
+ uint32_t status_flags ;
691
+ cbc_ext_opcode_t opcode ;
692
+ uint16_t literal_index , function_literal_index ;
668
693
#ifdef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
669
- parser_object_literal_item_types_t item_type ;
694
+ parser_object_literal_item_types_t item_type ;
670
695
#endif /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
671
696
672
- if (context_p -> token .type == LEXER_PROPERTY_GETTER )
673
- {
674
- status_flags = PARSER_IS_FUNCTION | PARSER_IS_CLOSURE | PARSER_IS_PROPERTY_GETTER ;
675
- opcode = CBC_EXT_SET_GETTER ;
697
+ if (context_p -> token .type == LEXER_PROPERTY_GETTER )
698
+ {
699
+ status_flags = PARSER_IS_FUNCTION | PARSER_IS_CLOSURE | PARSER_IS_PROPERTY_GETTER ;
700
+ opcode = CBC_EXT_SET_GETTER ;
676
701
#ifdef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
677
- item_type = PARSER_OBJECT_PROPERTY_GETTER ;
702
+ item_type = PARSER_OBJECT_PROPERTY_GETTER ;
678
703
#endif /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
679
- }
680
- else
681
- {
682
- status_flags = PARSER_IS_FUNCTION | PARSER_IS_CLOSURE | PARSER_IS_PROPERTY_SETTER ;
683
- opcode = CBC_EXT_SET_SETTER ;
704
+ }
705
+ else
706
+ {
707
+ status_flags = PARSER_IS_FUNCTION | PARSER_IS_CLOSURE | PARSER_IS_PROPERTY_SETTER ;
708
+ opcode = CBC_EXT_SET_SETTER ;
684
709
#ifdef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
685
- item_type = PARSER_OBJECT_PROPERTY_SETTER ;
710
+ item_type = PARSER_OBJECT_PROPERTY_SETTER ;
686
711
#endif /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
687
- }
712
+ }
688
713
689
- lexer_expect_object_literal_id (context_p , LEXER_OBJ_IDENT_ONLY_IDENTIFIERS );
714
+ lexer_expect_object_literal_id (context_p , LEXER_OBJ_IDENT_ONLY_IDENTIFIERS );
690
715
691
- /* This assignment is a nop for computed getters/setters. */
692
- literal_index = context_p -> lit_object .index ;
716
+ /* This assignment is a nop for computed getters/setters. */
717
+ literal_index = context_p -> lit_object .index ;
693
718
694
719
#ifndef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
695
- if (context_p -> token .type == LEXER_RIGHT_SQUARE )
696
- {
697
- opcode = ((opcode == CBC_EXT_SET_GETTER ) ? CBC_EXT_SET_COMPUTED_GETTER
698
- : CBC_EXT_SET_COMPUTED_SETTER );
699
- }
720
+ if (context_p -> token .type == LEXER_RIGHT_SQUARE )
721
+ {
722
+ opcode = ((opcode == CBC_EXT_SET_GETTER ) ? CBC_EXT_SET_COMPUTED_GETTER
723
+ : CBC_EXT_SET_COMPUTED_SETTER );
724
+ }
700
725
#else /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
701
- parser_append_object_literal_item (context_p , literal_index , item_type );
726
+ parser_append_object_literal_item (context_p , literal_index , item_type );
702
727
#endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
703
728
704
- parser_flush_cbc (context_p );
705
- function_literal_index = lexer_construct_function_object (context_p , status_flags );
729
+ parser_flush_cbc (context_p );
730
+ function_literal_index = lexer_construct_function_object (context_p , status_flags );
706
731
707
732
#ifndef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
708
- if (opcode >= CBC_EXT_SET_COMPUTED_GETTER )
709
- {
710
- literal_index = function_literal_index ;
711
- }
733
+ if (opcode >= CBC_EXT_SET_COMPUTED_GETTER )
734
+ {
735
+ literal_index = function_literal_index ;
736
+ }
712
737
#endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
713
738
714
- parser_emit_cbc_literal (context_p ,
715
- CBC_PUSH_LITERAL ,
716
- literal_index );
739
+ parser_emit_cbc_literal (context_p ,
740
+ CBC_PUSH_LITERAL ,
741
+ literal_index );
717
742
718
- JERRY_ASSERT (context_p -> last_cbc_opcode == CBC_PUSH_LITERAL );
719
- context_p -> last_cbc_opcode = PARSER_TO_EXT_OPCODE (opcode );
720
- context_p -> last_cbc .value = function_literal_index ;
743
+ JERRY_ASSERT (context_p -> last_cbc_opcode == CBC_PUSH_LITERAL );
744
+ context_p -> last_cbc_opcode = PARSER_TO_EXT_OPCODE (opcode );
745
+ context_p -> last_cbc .value = function_literal_index ;
721
746
722
- lexer_next_token (context_p );
723
- }
747
+ lexer_next_token (context_p );
748
+ break ;
749
+ }
724
750
#ifndef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
725
- else if (context_p -> token .type == LEXER_RIGHT_SQUARE )
726
- {
727
- lexer_next_token (context_p );
728
- if (context_p -> token .type != LEXER_COLON )
751
+ case LEXER_RIGHT_SQUARE :
729
752
{
730
- parser_raise_error (context_p , PARSER_ERR_COLON_EXPECTED );
731
- }
753
+ lexer_next_token (context_p );
732
754
733
- lexer_next_token (context_p );
734
- parser_parse_expression (context_p , PARSE_EXPR_NO_COMMA );
755
+ if (context_p -> token .type == LEXER_LEFT_PAREN )
756
+ {
757
+ parser_parse_object_method (context_p );
735
758
736
- if (context_p -> last_cbc_opcode == CBC_PUSH_LITERAL )
737
- {
738
- context_p -> last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SET_COMPUTED_PROPERTY_LITERAL );
739
- }
740
- else
741
- {
742
- parser_emit_cbc_ext (context_p , CBC_EXT_SET_COMPUTED_PROPERTY );
759
+ JERRY_ASSERT (context_p -> last_cbc_opcode == CBC_PUSH_LITERAL );
760
+ context_p -> last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SET_COMPUTED_PROPERTY_LITERAL );
761
+ break ;
762
+ }
763
+
764
+ if (context_p -> token .type != LEXER_COLON )
765
+ {
766
+ parser_raise_error (context_p , PARSER_ERR_COLON_EXPECTED );
767
+ }
768
+
769
+ lexer_next_token (context_p );
770
+ parser_parse_expression (context_p , PARSE_EXPR_NO_COMMA );
771
+
772
+ if (context_p -> last_cbc_opcode == CBC_PUSH_LITERAL )
773
+ {
774
+ context_p -> last_cbc_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_SET_COMPUTED_PROPERTY_LITERAL );
775
+ }
776
+ else
777
+ {
778
+ parser_emit_cbc_ext (context_p , CBC_EXT_SET_COMPUTED_PROPERTY );
779
+ }
780
+ break ;
743
781
}
744
- }
745
782
#endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
746
- else
747
- {
748
- uint16_t literal_index = context_p -> lit_object .index ;
783
+ default :
784
+ {
785
+ uint16_t literal_index = context_p -> lit_object .index ;
749
786
750
787
#ifdef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
751
- parser_append_object_literal_item (context_p ,
752
- literal_index ,
753
- PARSER_OBJECT_PROPERTY_VALUE );
788
+ parser_append_object_literal_item (context_p ,
789
+ literal_index ,
790
+ PARSER_OBJECT_PROPERTY_VALUE );
754
791
#endif /* CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
755
792
756
- lexer_next_token (context_p );
757
- if (context_p -> token .type != LEXER_COLON )
758
- {
759
- parser_raise_error (context_p , PARSER_ERR_COLON_EXPECTED );
760
- }
793
+ lexer_next_token (context_p );
761
794
762
- lexer_next_token (context_p );
763
- parser_parse_expression (context_p , PARSE_EXPR_NO_COMMA );
795
+ #ifndef CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER
796
+ if (context_p -> token .type == LEXER_LEFT_PAREN )
797
+ {
798
+ parser_parse_object_method (context_p );
764
799
765
- if (context_p -> last_cbc_opcode == CBC_PUSH_LITERAL )
766
- {
767
- context_p -> last_cbc_opcode = CBC_SET_LITERAL_PROPERTY ;
768
- context_p -> last_cbc .value = literal_index ;
769
- }
770
- else
771
- {
772
- parser_emit_cbc_literal (context_p , CBC_SET_PROPERTY , literal_index );
800
+ JERRY_ASSERT (context_p -> last_cbc_opcode == CBC_PUSH_LITERAL );
801
+ context_p -> last_cbc_opcode = CBC_SET_LITERAL_PROPERTY ;
802
+ context_p -> last_cbc .value = literal_index ;
803
+ break ;
804
+ }
805
+ #endif /* !CONFIG_DISABLE_ES2015_OBJECT_INITIALIZER */
806
+
807
+ if (context_p -> token .type != LEXER_COLON )
808
+ {
809
+ parser_raise_error (context_p , PARSER_ERR_COLON_EXPECTED );
810
+ }
811
+
812
+ lexer_next_token (context_p );
813
+ parser_parse_expression (context_p , PARSE_EXPR_NO_COMMA );
814
+
815
+ if (context_p -> last_cbc_opcode == CBC_PUSH_LITERAL )
816
+ {
817
+ context_p -> last_cbc_opcode = CBC_SET_LITERAL_PROPERTY ;
818
+ context_p -> last_cbc .value = literal_index ;
819
+ }
820
+ else
821
+ {
822
+ parser_emit_cbc_literal (context_p , CBC_SET_PROPERTY , literal_index );
823
+ }
824
+
825
+ break ;
773
826
}
774
827
}
775
828
0 commit comments