@@ -46,6 +46,18 @@ static const V& getProperFunctionFromContainer(const std::vector<V>& container,
46
46
return *callee;
47
47
}
48
48
49
+ inline UInt8 encodeVersion (UInt8 majorVersion, UInt8 minorVersion) {
50
+ return (majorVersion << 3 ) | minorVersion;
51
+ }
52
+
53
+ inline UInt8 getMajorVersion (UInt8 encodedVersion) {
54
+ return encodedVersion >> 3 ;
55
+ }
56
+
57
+ inline UInt8 getMinorVersion (UInt8 encodedVersion) {
58
+ return encodedVersion & 0b111 ;
59
+ }
60
+
49
61
// Bit indices in flags section
50
62
enum MetaFlags {
51
63
HasName = 7 ,
@@ -126,6 +138,7 @@ enum BinaryTypeEncodingType : Byte {
126
138
template <typename T>
127
139
struct PtrTo ;
128
140
struct Meta ;
141
+ struct InterfaceMeta ;
129
142
struct ProtocolMeta ;
130
143
struct ModuleMeta ;
131
144
struct LibraryMeta ;
@@ -273,6 +286,18 @@ struct GlobalTable {
273
286
274
287
ArrayOfPtrTo<ArrayOfPtrTo<Meta>> buckets;
275
288
289
+ const InterfaceMeta* findInterfaceMeta (WTF::StringImpl* identifier) const ;
290
+
291
+ const InterfaceMeta* findInterfaceMeta (const char * identifierString) const ;
292
+
293
+ const InterfaceMeta* findInterfaceMeta (const char * identifierString, size_t length, unsigned hash) const ;
294
+
295
+ const ProtocolMeta* findProtocol (WTF::StringImpl* identifier) const ;
296
+
297
+ const ProtocolMeta* findProtocol (const char * identifierString) const ;
298
+
299
+ const ProtocolMeta* findProtocol (const char * identifierString, size_t length, unsigned hash) const ;
300
+
276
301
const Meta* findMeta (WTF::StringImpl* identifier, bool onlyIfAvailable = true ) const ;
277
302
278
303
const Meta* findMeta (const char * identifierString, bool onlyIfAvailable = true ) const ;
@@ -667,9 +692,16 @@ struct MethodMeta : MemberMeta {
667
692
const char * constructorTokens () const {
668
693
return this ->_constructorTokens .valuePtr ();
669
694
}
695
+
696
+ bool isImplementedInClass (Class klass, bool isStatic) const ;
697
+ bool isAvailableInClass (Class klass, bool isStatic) const {
698
+ return this ->isAvailable () && this ->isImplementedInClass (klass, isStatic);
699
+ }
670
700
};
671
701
672
- std::unordered_map<std::string, std::vector<const MemberMeta*>> getMetasByJSNames (std::vector<const MemberMeta*> methods);
702
+ typedef HashSet<const MemberMeta*> MembersCollection;
703
+
704
+ std::unordered_map<std::string, MembersCollection> getMetasByJSNames (MembersCollection methods);
673
705
674
706
struct PropertyMeta : MemberMeta {
675
707
PtrTo<MethodMeta> method1;
@@ -691,6 +723,16 @@ struct PropertyMeta : MemberMeta {
691
723
const MethodMeta* setter () const {
692
724
return (this ->hasSetter ()) ? (this ->hasGetter () ? method2.valuePtr () : method1.valuePtr ()) : nullptr ;
693
725
}
726
+
727
+ bool isImplementedInClass (Class klass, bool isStatic) const {
728
+ bool getterAvailable = this ->hasGetter () && this ->getter ()->isImplementedInClass (klass, isStatic);
729
+ bool setterAvailable = this ->hasSetter () && this ->setter ()->isImplementedInClass (klass, isStatic);
730
+ return getterAvailable || setterAvailable;
731
+ }
732
+
733
+ bool isAvailableInClass (Class klass, bool isStatic) const {
734
+ return this ->isAvailable () && this ->isImplementedInClass (klass, isStatic);
735
+ }
694
736
};
695
737
696
738
struct BaseClassMeta : Meta {
@@ -706,7 +748,7 @@ struct BaseClassMeta : Meta {
706
748
707
749
const MethodMeta* member (const char * identifier, size_t length, MemberType type, size_t paramsCount, bool includeProtocols = true , bool onlyIfAvailable = true ) const ;
708
750
709
- const std::vector< const MemberMeta*> members (const char * identifier, size_t length, MemberType type, bool includeProtocols = true , bool onlyIfAvailable = true ) const ;
751
+ const MembersCollection members (const char * identifier, size_t length, MemberType type, bool includeProtocols = true , bool onlyIfAvailable = true ) const ;
710
752
711
753
const MemberMeta* member (StringImpl* identifier, MemberType type, bool includeProtocols = true ) const {
712
754
const char * identif = reinterpret_cast <const char *>(identifier->characters8 ());
@@ -720,7 +762,7 @@ struct BaseClassMeta : Meta {
720
762
return this ->member (identif, length, type, paramsCount, includeProtocols);
721
763
}
722
764
723
- const std::vector< const MemberMeta*> members (StringImpl* identifier, MemberType type, bool includeProtocols = true ) const {
765
+ const MembersCollection members (StringImpl* identifier, MemberType type, bool includeProtocols = true ) const {
724
766
const char * identif = reinterpret_cast <const char *>(identifier->characters8 ());
725
767
size_t length = (size_t )identifier->length ();
726
768
return this ->members (identif, length, type, includeProtocols);
@@ -731,101 +773,110 @@ struct BaseClassMeta : Meta {
731
773
}
732
774
733
775
// / instance methods
734
- const MethodMeta* instanceMethod (const char * identifier, size_t paramsCount, bool includeProtocols = true ) const {
735
- return this ->member (identifier, strlen (identifier), MemberType::InstanceMethod, paramsCount, includeProtocols);
736
- }
737
776
738
- const MethodMeta* instanceMethod (StringImpl* identifier, size_t paramsCount, bool includeProtocols = true ) const {
739
- return this ->member (identifier, MemberType::InstanceMethod, paramsCount, includeProtocols);
777
+ // Remove all optional methods/properties which are not implemented in the class
778
+ template <typename TMemberMeta>
779
+ static void filterUnavailableMembers (MembersCollection& members, Class klass, bool isStatic) {
780
+ members.removeIf ([klass, isStatic](const MemberMeta* memberMeta) {
781
+ return !static_cast <const TMemberMeta*>(memberMeta)->isAvailableInClass (klass, isStatic);
782
+ });
740
783
}
741
784
742
- const std::vector<const MemberMeta*> getInstanceMethods (StringImpl* identifier, bool includeProtocols = true ) const {
743
- return this ->members (identifier, MemberType::InstanceMethod, includeProtocols);
785
+ const MembersCollection getInstanceMethods (StringImpl* identifier, Class klass, bool includeProtocols = true ) const {
786
+ MembersCollection methods = this ->members (identifier, MemberType::InstanceMethod, includeProtocols);
787
+
788
+ filterUnavailableMembers<MethodMeta>(methods, klass, false );
789
+
790
+ return methods;
744
791
}
745
792
746
793
// / static methods
747
- const MethodMeta* staticMethod (const char * identifier, size_t paramsCount, bool includeProtocols = true ) const {
748
- return this ->member (identifier, strlen (identifier), MemberType::StaticMethod, paramsCount, includeProtocols);
749
- }
794
+ const MembersCollection getStaticMethods (StringImpl* identifier, Class klass, bool includeProtocols = true ) const {
795
+ MembersCollection methods = this ->members (identifier, MemberType::StaticMethod, includeProtocols);
750
796
751
- const std::vector<const MemberMeta*> getStaticMethods (StringImpl* identifier, bool includeProtocols = true ) const {
752
- return this ->members (identifier, MemberType::StaticMethod, includeProtocols);
753
- }
797
+ filterUnavailableMembers<MethodMeta>(methods, klass, true );
754
798
755
- const MethodMeta* staticMethod (StringImpl* identifier, size_t paramsCount, bool includeProtocols = true ) const {
756
- return this ->member (identifier, MemberType::StaticMethod, paramsCount, includeProtocols);
799
+ return methods;
757
800
}
758
801
759
802
// / instance properties
760
- const PropertyMeta* instanceProperty (const char * identifier, bool includeProtocols = true ) const {
761
- return reinterpret_cast <const PropertyMeta*>(this ->member (identifier, MemberType::InstanceProperty, includeProtocols));
803
+ const PropertyMeta* instanceProperty (const char * identifier, Class klass, bool includeProtocols = true ) const {
804
+ auto propMeta = static_cast <const PropertyMeta*>(this ->member (identifier, MemberType::InstanceProperty, includeProtocols));
805
+ return propMeta && propMeta->isAvailableInClass (klass, /* isStatic*/ false ) ? propMeta : nullptr ;
762
806
}
763
807
764
- const PropertyMeta* instanceProperty (StringImpl* identifier, bool includeProtocols = true ) const {
765
- return reinterpret_cast <const PropertyMeta*>(this ->member (identifier, MemberType::InstanceProperty, includeProtocols));
808
+ const PropertyMeta* instanceProperty (StringImpl* identifier, Class klass, bool includeProtocols = true ) const {
809
+ auto propMeta = static_cast <const PropertyMeta*>(this ->member (identifier, MemberType::InstanceProperty, includeProtocols));
810
+ return propMeta && propMeta->isAvailableInClass (klass, /* isStatic*/ false ) ? propMeta : nullptr ;
766
811
}
767
812
768
813
// / static properties
769
- const PropertyMeta* staticProperty (const char * identifier, bool includeProtocols = true ) const {
770
- return reinterpret_cast <const PropertyMeta*>(this ->member (identifier, MemberType::StaticProperty, includeProtocols));
814
+ const PropertyMeta* staticProperty (const char * identifier, Class klass, bool includeProtocols = true ) const {
815
+ auto propMeta = static_cast <const PropertyMeta*>(this ->member (identifier, MemberType::StaticProperty, includeProtocols));
816
+ return propMeta && propMeta->isAvailableInClass (klass, /* isStatic*/ true ) ? propMeta : nullptr ;
771
817
}
772
818
773
- const PropertyMeta* staticProperty (StringImpl* identifier, bool includeProtocols = true ) const {
774
- return reinterpret_cast <const PropertyMeta*>(this ->member (identifier, MemberType::StaticProperty, includeProtocols));
819
+ const PropertyMeta* staticProperty (StringImpl* identifier, Class klass, bool includeProtocols = true ) const {
820
+ auto propMeta = static_cast <const PropertyMeta*>(this ->member (identifier, MemberType::StaticProperty, includeProtocols));
821
+ return propMeta && propMeta->isAvailableInClass (klass, /* isStatic*/ true ) ? propMeta : nullptr ;
775
822
}
776
823
777
824
// / vectors
778
- std::vector<const PropertyMeta*> instanceProperties () const {
825
+ std::vector<const PropertyMeta*> instanceProperties (Class klass ) const {
779
826
std::vector<const PropertyMeta*> properties;
780
- return this ->instanceProperties (properties);
827
+ return this ->instanceProperties (properties, klass );
781
828
}
782
829
783
- std::vector<const PropertyMeta*> instancePropertiesWithProtocols () const {
830
+ std::vector<const PropertyMeta*> instancePropertiesWithProtocols (Class klass ) const {
784
831
std::vector<const PropertyMeta*> properties;
785
- return this ->instancePropertiesWithProtocols (properties);
832
+ return this ->instancePropertiesWithProtocols (properties, klass );
786
833
}
787
834
788
- std::vector<const PropertyMeta*> instanceProperties (std::vector<const PropertyMeta*>& container) const {
835
+ std::vector<const PropertyMeta*> instanceProperties (std::vector<const PropertyMeta*>& container, Class klass ) const {
789
836
for (Array<PtrTo<PropertyMeta>>::iterator it = this ->instanceProps ->begin (); it != this ->instanceProps ->end (); it++) {
790
- container.push_back ((*it).valuePtr ());
837
+ if ((*it)->isAvailableInClass (klass, /* isStatic*/ false )) {
838
+ container.push_back ((*it).valuePtr ());
839
+ }
791
840
}
792
841
return container;
793
842
}
794
843
795
- std::vector<const PropertyMeta*> instancePropertiesWithProtocols (std::vector<const PropertyMeta*>& container) const ;
844
+ std::vector<const PropertyMeta*> instancePropertiesWithProtocols (std::vector<const PropertyMeta*>& container, Class klass ) const ;
796
845
797
- std::vector<const PropertyMeta*> staticProperties () const {
846
+ std::vector<const PropertyMeta*> staticProperties (Class klass ) const {
798
847
std::vector<const PropertyMeta*> properties;
799
- return this ->staticProperties (properties);
848
+ return this ->staticProperties (properties, klass );
800
849
}
801
850
802
- std::vector<const PropertyMeta*> staticPropertiesWithProtocols () const {
851
+ std::vector<const PropertyMeta*> staticPropertiesWithProtocols (Class klass ) const {
803
852
std::vector<const PropertyMeta*> properties;
804
- return this ->staticPropertiesWithProtocols (properties);
853
+ return this ->staticPropertiesWithProtocols (properties, klass );
805
854
}
806
855
807
- std::vector<const PropertyMeta*> staticProperties (std::vector<const PropertyMeta*>& container) const {
856
+ std::vector<const PropertyMeta*> staticProperties (std::vector<const PropertyMeta*>& container, Class klass ) const {
808
857
for (Array<PtrTo<PropertyMeta>>::iterator it = this ->staticProps ->begin (); it != this ->staticProps ->end (); it++) {
809
- container.push_back ((*it).valuePtr ());
858
+ if ((*it)->isAvailableInClass (klass, /* isStatic*/ true )) {
859
+ container.push_back ((*it).valuePtr ());
860
+ }
810
861
}
811
862
return container;
812
863
}
813
864
814
- std::vector<const PropertyMeta*> staticPropertiesWithProtocols (std::vector<const PropertyMeta*>& container) const ;
865
+ std::vector<const PropertyMeta*> staticPropertiesWithProtocols (std::vector<const PropertyMeta*>& container, Class klass ) const ;
815
866
816
- std::vector<const MethodMeta*> initializers () const {
867
+ std::vector<const MethodMeta*> initializers (Class klass ) const {
817
868
std::vector<const MethodMeta*> initializers;
818
- return this ->initializers (initializers);
869
+ return this ->initializers (initializers, klass );
819
870
}
820
871
821
- std::vector<const MethodMeta*> initializersWithProtcols ( ) const {
872
+ std::vector<const MethodMeta*> initializersWithProtocols (Class klass ) const {
822
873
std::vector<const MethodMeta*> initializers;
823
- return this ->initializersWithProtcols (initializers);
874
+ return this ->initializersWithProtocols (initializers, klass );
824
875
}
825
876
826
- std::vector<const MethodMeta*> initializers (std::vector<const MethodMeta*>& container) const ;
877
+ std::vector<const MethodMeta*> initializers (std::vector<const MethodMeta*>& container, Class klass ) const ;
827
878
828
- std::vector<const MethodMeta*> initializersWithProtcols (std::vector<const MethodMeta*>& container) const ;
879
+ std::vector<const MethodMeta*> initializersWithProtocols (std::vector<const MethodMeta*>& container, Class klass ) const ;
829
880
};
830
881
831
882
struct ProtocolMeta : BaseClassMeta {
@@ -843,9 +894,10 @@ struct InterfaceMeta : BaseClassMeta {
843
894
844
895
const InterfaceMeta* baseMeta () const {
845
896
if (this ->baseName () != nullptr ) {
846
- const Meta * baseMeta = MetaFile::instance ()->globalTable ()->findMeta (this ->baseName ());
847
- return baseMeta-> type () == MetaType::Interface ? reinterpret_cast < const InterfaceMeta*>(baseMeta) : nullptr ;
897
+ const InterfaceMeta * baseMeta = MetaFile::instance ()->globalTable ()->findInterfaceMeta (this ->baseName ());
898
+ return baseMeta;
848
899
}
900
+
849
901
return nullptr ;
850
902
}
851
903
};
0 commit comments