Environment
Environment:
OS: macOS High Sierra 10.13.2
Node: 9.11.1
Yarn: Not Found
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 3.0 AI-171.4443003
Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: 0.55.2 => 0.55.2
Description
RCTEventEmitter has a check implemented in class initializer to check that the Implementation being created implements 'supportedEvents' method. this is achieved here
But the RCTClassOverridesInstanceMethod method defined here uses class_copyMethodList obj-C Runtime method to get instance methods and iterate over them to see if required method is implemented.
as per Apple Docs class_copyMethodList does NOT return instance methods implemented by super classes.
This causes the app to crash in Dev mode (because of RCTAssert?) if the app has its own hierarchy of RCTEventEmitters, in which case the supportedEvents is implemented by an intermediate superclass between the current class and RCTEventEmitter.
IMO, the implementation should walk the inheritance hierarchy till RCTEventEmitter to make the correct assertion.
Reproducible Demo
Create a Native Module with One BaseEmitter which extends from RCTEventEmitter implement all the required functionalities also the supportedEvents method. Now create another class MainEmitter which extends from BaseEmitter, do not implement the supportedEvents method in MyEmitter to re-use implementation from BaseEmitter
App will crash on first use of MainEmitter
Environment
Environment:
OS: macOS High Sierra 10.13.2
Node: 9.11.1
Yarn: Not Found
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 3.0 AI-171.4443003
Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: 0.55.2 => 0.55.2
Description
RCTEventEmitter has a check implemented in class initializer to check that the Implementation being created implements 'supportedEvents' method. this is achieved here
But the
RCTClassOverridesInstanceMethodmethod defined here usesclass_copyMethodListobj-C Runtime method to get instance methods and iterate over them to see if required method is implemented.as per Apple Docs
class_copyMethodListdoes NOT return instance methods implemented by super classes.This causes the app to crash in Dev mode (because of RCTAssert?) if the app has its own hierarchy of
RCTEventEmitters, in which case thesupportedEventsis implemented by an intermediate superclass between the current class andRCTEventEmitter.IMO, the implementation should walk the inheritance hierarchy till
RCTEventEmitterto make the correct assertion.Reproducible Demo
Create a Native Module with One
BaseEmitterwhich extends fromRCTEventEmitterimplement all the required functionalities also thesupportedEventsmethod. Now create another classMainEmitterwhich extends fromBaseEmitter, do not implement thesupportedEventsmethod inMyEmitterto re-use implementation fromBaseEmitterApp will crash on first use of
MainEmitter