* fix(core): synchronize C++ `Promise<T>` state-inspection accessors
`resolve()`/`reject()` write `_state` under `_mutex`, but `isPending`/
`isResolved`/`isRejected`/`getResult`/`getError` read it lock-free.
`JSIConverter<shared_ptr<Promise<T>>>::toJSI` runs those reads on the JS thread
the instant a hybrid method returns, racing an off-JS-thread `resolve()`
(`Promise::async` / `Promise.parallel` / a main-thread resolve). Data race on the
`std::variant _state`, flagged by ThreadSanitizer.
Make `_mutex` mutable and acquire it in the inspection accessors. The lock-free
bodies move to private overloads that take a `unique_lock` (the caller proves it
holds the lock), so `getResult()`/`isPending()`-style call sites stay intact
without recursive self-locking. `resolve`/`reject` set the state and drain the
listeners under a single lock via `takeResolvedListeners(lock)`/
`takeRejectedListeners(lock)`, then fire them outside the lock; the `NITRO_DEBUG`
state assert runs just before the lock. Same treatment for `Promise<void>`.
* refactor(core): address review feedback on Promise synchronization
- Remove takeResolvedListenersAndClearAllListeners / takeRejectedListenersAndClearAllListeners helpers; inline as std::move + clearAllListeners
- Restore readable if/else structure in addOnXxxListener, using lock.unlock() before invoking the callback instead of nested RAII blocks with early returns
- Capture result pointer inside the lock in resolve() to avoid a second lock acquisition
* refactor(core): drop listeners outside lock by moving instead of clearing
* Update packages/react-native-nitro-modules/cpp/core/Promise.hpp
Co-authored-by: Marc Rousavy <me@mrousavy.com>
* refactor(core): remove redundant inline comments from listener methods
* fix(core): fix rebase artifact in resolve(const TResult&) — remove duplicate declaration and stale clearAllListeners
* refactor(core): remove remaining inline comment from addOnRejectedListener
* refactor(core): restore inline comments in addOnXxxListener per reviewer
---------
Co-authored-by: Miklós Fazekas <boga@MBPM5P.local>
Co-authored-by: Marc Rousavy <me@mrousavy.com>
* chore: Split `Object`, `Promise`, `Date` and `Error` under `CommonGlobals.hpp`
* feat: Use it everywhere
* fix: Implement them
* fix: `resolved` -> `resolve`
* feat: make toMap faster
* fix: lint
* fix: commits
* chore: Move C++ definitions into `JAnyMap`
we had too much stuff in header
---------
Co-authored-by: Marc Rousavy <me@mrousavy.com>
* feat: Create `ObjectUtils` for `Object.freeze`, `Object.defineProperty`, ...
* Use Object.create
* Fix missing obj
* fix: Better error
* Cache
* fix: Actually cache by preventing copy
* Object.create is part of RN 78
* Use `defineProperty(...)` for `Dispatcher` too
* Optimize Dispatcher install
* Create `getGlobalFunction`
* feat: Use `defineGlobal(...)` to define our global props
* fix: Move the globals
* fix: Don't protect/freeze the globals in JS
we already do it in native.
* chore: Add `NON_NULL` and `NULLABLE` annotations on all pointers
* feat: Add `CONTIGUOUS_MEMORY` and `NON_NULL`
* Create `InstanceMethod<...>`
* chore: Use `InstanceMethod<...>`
* feat: Add `dispose()` to Kotlin & Swift
* Mark as `noexcept`
* No return
* Test `dispose()`
* fix assignments
* fix: Test `dispose()` over `optionalCallback()`
* fix: Add additional nullptr check to `make_shared_from_jni` function
* fix: Allow move `&&` and forward
* Update JNISharedPtr.hpp
* fix: Add copy ctor
* fix: Avoid `emplace` if there can be duplicates
* Update JNISharedPtr.hpp
* fix: Don't call `release()` on global_ref!
* fix: Use `const &` to keep it lvalue
* Also check `cthis()`
* fix: Fix a case where a `nullptr` `BorrowingReference<T>` could be accessed
* Update HybridObjectPrototype.cpp
* chore: Replace `jsi::Runtime*` with `jsi::Runtime&` in `JSArrayBuffer`
* Update ArrayBuffer.cpp