Fabric: Lock-free events 4/n: Added an assert in EventTarget
Summary: See the diff for more details. Reviewed By: sahrens Differential Revision: D13642593 fbshipit-source-id: 8bdcc91bcc2ea1e4093bcac03d87167b8901cbb4
This commit is contained in:
parent
97f9e4082c
commit
cdb983d339
|
@ -46,7 +46,6 @@ class EventEmitter {
|
||||||
virtual ~EventEmitter() = default;
|
virtual ~EventEmitter() = default;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* `DispatchMutex` must be acquired before calling.
|
|
||||||
* Enables/disables event emitter.
|
* Enables/disables event emitter.
|
||||||
* Enabled event emitter retains a pointer to `eventTarget` strongly (as
|
* Enabled event emitter retains a pointer to `eventTarget` strongly (as
|
||||||
* `std::shared_ptr`) whereas disabled one don't.
|
* `std::shared_ptr`) whereas disabled one don't.
|
||||||
|
@ -54,6 +53,7 @@ class EventEmitter {
|
||||||
* a possibility to extract JSI value from it.
|
* a possibility to extract JSI value from it.
|
||||||
* The enable state is additive; a number of `enable` calls should be equal to
|
* The enable state is additive; a number of `enable` calls should be equal to
|
||||||
* a number of `disable` calls to release the event target.
|
* a number of `disable` calls to release the event target.
|
||||||
|
* `DispatchMutex` must be acquired before calling.
|
||||||
*/
|
*/
|
||||||
void setEnabled(bool enabled) const;
|
void setEnabled(bool enabled) const;
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,15 @@ void EventTarget::retain(jsi::Runtime &runtime) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
strongInstanceHandle_ = weakInstanceHandle_.lock(runtime);
|
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 {
|
jsi::Value EventTarget::release(jsi::Runtime &runtime) const {
|
||||||
|
|
Loading…
Reference in New Issue