diff --git a/ReactCommon/fabric/events/EventEmitter.h b/ReactCommon/fabric/events/EventEmitter.h index 8e3045170a5..3e06c81e456 100644 --- a/ReactCommon/fabric/events/EventEmitter.h +++ b/ReactCommon/fabric/events/EventEmitter.h @@ -46,7 +46,6 @@ class EventEmitter { virtual ~EventEmitter() = default; /* - * `DispatchMutex` must be acquired before calling. * Enables/disables event emitter. * Enabled event emitter retains a pointer to `eventTarget` strongly (as * `std::shared_ptr`) whereas disabled one don't. @@ -54,6 +53,7 @@ class EventEmitter { * a possibility to extract JSI value from it. * The enable state is additive; a number of `enable` calls should be equal to * a number of `disable` calls to release the event target. + * `DispatchMutex` must be acquired before calling. */ void setEnabled(bool enabled) const; diff --git a/ReactCommon/fabric/events/EventTarget.cpp b/ReactCommon/fabric/events/EventTarget.cpp index ee893d631c7..64dc2549056 100644 --- a/ReactCommon/fabric/events/EventTarget.cpp +++ b/ReactCommon/fabric/events/EventTarget.cpp @@ -31,6 +31,15 @@ void EventTarget::retain(jsi::Runtime &runtime) const { } strongInstanceHandle_ = weakInstanceHandle_.lock(runtime); + + // Having a `null` or `undefined` object here indicates that + // `weakInstanceHandle_` was already deallocated. This should *not* happen by + // design, and if it happens it's a severe problem. This basically means that + // particular implementation of JSI was able to detect this inconsistency and + // dealt with it, but some JSI implementation may not support this feature and + // that case will lead to a crash in those environments. + assert(!strongInstanceHandle_.isNull()); + assert(!strongInstanceHandle_.isUndefined()); } jsi::Value EventTarget::release(jsi::Runtime &runtime) const {