164 Commits
Author SHA1 Message Date
Marc RousavyandGitHub 84d184dd61 fix: Report native ArrayBuffer memory pressure (#1523)
* fix: Report native ArrayBuffer memory pressure

* test: Move ArrayBuffer memory pressure coverage
2026-08-21 18:34:36 +02:00
Ritesh ShuklaandGitHub 5d155afb60 fix: Re-create JS object on dead runtime cache entry (#1442) 2026-07-27 18:09:37 +02:00
cd3d48677e fix: Synchronize C++ Promise<T> state-inspection accessors (#1398)
* 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>
2026-06-22 15:13:29 +02:00
Marc RousavyandGitHub ab2a05085f fix: Some code cleanups (atomic<bool>, move assignment, const) (#1269)
* fix: Make more stuff `const`

* fix: Add move assignment operator for `WeakReference`

* fix: Use `atomic<bool>` for `ReferenceState`
2026-03-18 12:09:26 +01:00
Marc RousavyandGitHub 176530872b chore: Add tests for verifying Java GC leaks (#1239)
* chore: Add tests for verifying Java GC leaks

* feat: Add `debug_getTotalAllocatedHybridObjects()`

* chore: Update leak test

* fix: Fix allocation test

* fix: Require at least 10% GC cleanup

* Update HybridNitroModulesProxy.cpp
2026-03-03 15:54:31 +01:00
Marc RousavyandGitHub a42b35e478 feat: Expose Int64 and UInt64 - deprecate bigint (#1212)
* feat: Add `Int64` and `UInt64` types

* fix: Migrate `BigInt` to `Int64`

* feat: Support Int64 now

* Implement tests

* fix: AnyMap bigint APIs

* fix: Replace `bigint` remainings 1/2

* Update HybridTestObjectSwift.swift

* fix: Replace wrong case

* chore: Lint

* chore: Add test for uint lossy error

* Rename remaining pieces

* Update JAnyMap.cpp

* fix: Pass signedness to `AnyValue` Kotlin

* i thought I kinda did it

* fix: Remove UInt64 support from `AnyMap`

* fix: `static_cast` longs

* ok fix anymap tests at least

* fix: Parse `ULong` separately on Kotlin

* chore: Lint

* docs: Add docs for `bigint`
2026-02-10 19:44:31 +01:00
Marc RousavyandGitHub 7c5666ccba fix: Fix AnyMap not overwriting keys (#1204) 2026-02-04 20:21:11 +01:00
Marc RousavyandGitHub d67af1264e fix: Fix potential deadlocks by releasing JSICacheReference earlier (#1191)
* fix: Fix potential deadlocks by releasing `JSICacheReference` earlier

* chore: Format
2026-01-29 16:24:48 +01:00
Marc RousavyandGitHub be0e02422c perf: Make BoxedHybridObject a tiny bit faster via PropNameIDCache (#1156)
* perf: Make `BoxedHybridObject` a tiny bit faster

* Update BoxedHybridObject.cpp

* feat: Add `PropNameIDCache::names(...)`
2026-01-14 22:42:14 +01:00
Marc RousavyandGitHub 7a801842be perf: Use ASCII instead of UTF8 for PropNames (#1133) 2026-01-07 15:21:39 +01:00
Marc RousavyandGitHub 6505c2a43d fix: Compare Swift/Kotlin references in equals(...) (#1129)
* fix: Compare Swift/Kotlin references in `equals(...)`

* Update Podfile.lock
2026-01-04 18:07:29 +01:00
Marc RousavyandGitHub 1e22bbeb1e perf: Cache HybridFunction's PropNameID (#1127)
* perf: Cache `HybridFunction`'s `PropNameID`

* fix: Use utf8 prop name
2025-12-23 16:26:18 +01:00
Marc RousavyandGitHub 2eb56b1b3a docs: Fix it's -> its (#1125) 2025-12-23 12:55:57 +01:00
5e5312a89a perf: Add bulk converter for AnyMap.fromMap(...) for Kotlin (~29% faster) (#1118)
* perf: Use Bulk fromMap in AnyMap

* fix: lint

* fix: lint

* fix: lint

* fix: lint

* fix: linting

* chore: Make it a static initializer on native/C++

* fix: Proper static JNI (`jclass` argument)

---------

Co-authored-by: Marc Rousavy <me@mrousavy.com>
2025-12-21 11:47:45 +01:00
Marc RousavyandGitHub 27dd56795d chore: Type out Object, Promise, Date and Error under CommonGlobals.cpp (#1113)
* chore: Split `Object`, `Promise`, `Date` and `Error` under `CommonGlobals.hpp`

* feat: Use it everywhere

* fix: Implement them

* fix: `resolved` -> `resolve`
2025-12-18 17:14:35 +01:00
4c7eb731c0 perf: Add bulk HashMap conversion method to AnyMap to make conversion faster (#1109)
* 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>
2025-12-18 16:13:31 +01:00
Marc RousavyandGitHub 0c4306cbd7 feat: Add explicit null type (#1032)
* feat: Add explicit `null` type

* Handle the cases

* Use NullType instead of `std::monostate`

* null is now variant! nice

* fix: Add missing imports

* fix: Fix podspec

* whoops now its fixed

* we're getting there...

* it builds on Android!

* fix: Add monostate back

* fix: Fix JNull lookup

* fix: Fix Swift build

* feat: Add tests for `null` type

* remove `UndefinedType`

* Now iOS builds???

* Nulls docs

* fix: Build with Xcode 26.1

* Revert "fix: Build with Xcode 26.1"

This reverts commit 41d1efea7a.
2025-11-10 22:31:22 +01:00
Marc RousavyandGitHub 6593698b54 feat: Add AnyMap <> Any converters and AnyMap::merge (#1012)
* feat: Add `merge` and `Any` helpers

* feat: Add merge maps test

* Update TestObject.nitro.ts

* Implement merge in kotlin

* fix: ctor

* feat: Add Any Value test

* Prevent accidental boxing twice

* fix: Make iOS work now

* fix: Fix `jni::local_ref` return

* feat: Add preallocated size ctor to Kotlin

* rename
2025-10-30 19:08:03 +01:00
Marc RousavyandGitHub 1a61db1e0b chore: Move Promise<void> implementation to .cpp (#982)
* chore: Move `Promise<void>` implementation to .cpp

* tidy up

* Update Promise.hpp

* fix: Specify `<void>` template

* fix: Avoid inline
2025-10-24 10:31:49 +02:00
Marc RousavyandGitHub f2ddc4597f feat: Add broader ArrayBuffer.copy, ArrayBuffer.asOwning() and ArrayBuffer.toByteArray() (#981)
* feat: Add broader `ArrayBuffer.copy`, `ArrayBuffer.asOwning()` and `ArrayBuffer.toByteArray()`

* Make `ArrayBuffer` constructors internal

* Update HybridTestObjectSwift.swift

* feat: Add `ArrayBuffer::move`
2025-10-22 18:31:28 +02:00
Marc RousavyandGitHub 964f705723 fix: Set .configurable = true and .enumerable = true (#978) 2025-10-21 18:01:17 +02:00
Marc RousavyandGitHub 229e7d83db feat: Create ObjectUtils for Object.freeze, Object.defineProperty, ... (#967)
* 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.
2025-10-17 18:35:16 +02:00
Marc RousavyandGitHub ca3c82ffd7 fix: Fix missing include for NULLABLE (NitroDefines.hpp) (#914) 2025-10-01 12:30:54 +02:00
Marc RousavyandGitHub 6dbb34f9d3 fix: Add NON_NULL, NULLABLE and CONTIGUOUS_MEMORY annotations on pointers (#902)
* chore: Add `NON_NULL` and `NULLABLE` annotations on all pointers

* feat: Add `CONTIGUOUS_MEMORY` and `NON_NULL`

* Create `InstanceMethod<...>`

* chore: Use `InstanceMethod<...>`
2025-09-26 13:45:54 +02:00
Marc RousavyandGitHub 39de15eb82 perf: Make C++ -> Swift Result<T> final (#894)
* perf: Make C++ -> Swift `Result<T>` final

* perf: Add some `noexcept` annotations to Result

* perf: Mark some classes as `final`
2025-09-22 15:02:35 +02:00
Marc RousavyandGitHub a16c4dc389 fix: Throw better error message in default HybridObject constructor (#836)
* fix: Remove default `HybridObject` constructor

avoids confusion.

* fix: Add it back but with better error
2025-08-26 13:02:43 +02:00
Marc RousavyandGitHub f4371fd286 perf: Use the shared() cache for JNI -> shared_ptr conversion (#810)
* perf: Use the `shared()` cache for JNI -> shared_ptr conversion

* fix: Fix `extractMap` test

* Lint
2025-08-11 18:06:18 +02:00
Marc RousavyandGitHub d66f9d22c9 fix: Access shared() more safely by using jni::global_ref (virtual) (#803)
* fix: Access `shared()` more safely

* Update HybridObject.cpp

* fix: Call `initSharedBase` on JNI init

* fix: Nitrogen

* Revert "fix: Nitrogen"

This reverts commit c794810d2e6247fe4a158e35faa72600a4a0b5de.

* Revert "fix: Call `initSharedBase` on JNI init"

This reverts commit a5a8a66a9de3b9c467b9be067925fe489e22397b.

* fix: Override `shared` with JNI impl

* fix: Call `HybridBase` with `javaThis` to safely do `::shared()`

* fix: stringify can do JSON now

* fix: Lint

* fix: Fix `length` of JS func

* Update getTests.ts

* fix: Pin react properly

* fix: Throw

* Update JHybridObject.cpp
2025-08-11 13:58:44 +02:00
Marc RousavyandGitHub ea39757017 feat: Add dispose() to Kotlin & Swift (#770)
* feat: Add `dispose()` to Kotlin & Swift

* Mark as `noexcept`

* No return

* Test `dispose()`

* fix assignments

* fix: Test `dispose()` over `optionalCallback()`
2025-07-25 12:22:20 +02:00
Marc RousavyandGitHub 1e863ecaaf fix: Properly throw errors on Android now on RN 0.80 (#741) 2025-07-15 17:33:55 +02:00
Marc RousavyandGitHub c0af3f603f feat: Attach jsi::MutableBuffer as jsi::NativeState to allow native buffer roundtrips (#736)
* feat: Attach `jsi::MutableBuffer` as `jsi::NativeState` for native buffer roundtrips

* feat: Cast to JS too

* Lint C++

* feat: Add `bounceArrayBuffer(...)` tests

* Update getTests.ts
2025-07-15 16:51:53 +02:00
Marc RousavyandGitHub 7fc091773e chore: Slap [[maybe_unused]] onto debug-only parameters to clean up build logs (#693) 2025-06-11 18:09:00 +02:00
Marc RousavyandGitHub 52ff673034 feat: Add ArrayBuffer.wrap(HardwareBuffer) API (#691)
* feat: Add `ArrayBuffer.wrap(HardwareBuffer)` API

* fix: Rename it

* Add `#if __ANDROID_API__ >= 26` check to C++

* Format

* feat: Implement `copyHardwareBuffer(..)`

* fix: Throw runtime error

* feat: Add `isHardwareBuffer` and `getHardwareBuffer()` for Kotlin

* fix: Register `copyHardwareBuffer` static JNI method properly

* feat: Add tests for "native" buffer

* Fix `_isLocked`

* chore: Move ArrayBuffer + HardwareBuffer to `HardwareBufferUtils`

* fix: It's called `getHardwareBufferBoxed()`

* fix: `@JvmStatic`

* feat: Implement `copyBuffer()` tests

* fix: Compile below API 26

* fix: Add SDK 26 check to `isHardwareBuffer` fast path

* fix: `getHardwareBufferBoxed` API 26

* fix: Slap good ol' API 26 `@RequiresApi` on it
2025-06-11 15:58:33 +02:00
Marc RousavyandGitHub 78059cef5c feat: Add AnyMap::getAllKeys() function (#688)
* feat: Add `AnyMap::getAllKeys()` function

* feat: Add `AnyMap.getAllKeys()` for Swift

* feat: Add `AnyMap.getAllKeys()` for Kotlin

* ctor explicit

* chore: Add tests for getMapKeys()

* fix: Fix sort order
2025-06-06 14:18:07 +02:00
Marc RousavyandGitHub 72e7cabb92 fix: Clear Promise callbacks after resolve or reject to prevent JNI dtor error (#683) 2025-06-05 14:05:49 +02:00
Jacek PudyszandGitHub 94a702e480 fix: revert Object.freeze (#612) 2025-03-19 21:37:40 +09:00
Marc RousavyandGitHub ca86d9d296 feat: Freeze objects in debug (#602) 2025-03-06 15:12:04 +01:00
Marc RousavyandGitHub 13e9977e9a fix: Make ArrayBuffer::copy(..) methods const (#596) 2025-03-03 16:12:11 +01:00
Marc RousavyandGitHub b9ce7462a3 fix: Add additional nullptr check to make_shared_from_jni function (#584)
* 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()`
2025-02-24 18:09:50 +01:00
Marc RousavyandGitHub 995646890b chore: Remove deprecated Promise::addOnResolvedListenerCopy(…) (#576) 2025-02-24 15:42:47 +01:00
Marc RousavyandGitHub 7f54e269e9 chore: Remove deprecated ArrayBuffer::makeBuffer(...) (#575) 2025-02-24 15:42:39 +01:00
Marc RousavyandGitHub 2e579922bf fix: Fix implicit size_t conversion (#572) 2025-02-24 15:34:55 +01:00
Marc RousavyandGitHub 0c5e716ab1 fix: Fix a case where a nullptr BorrowingReference<T> could be accessed (#568)
* 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
2025-02-23 17:16:50 +01:00
Marc Rousavy 29cfa85198 chore: Allow comparing BorrowingReference<T> to nullptr 2025-02-23 16:46:04 +01:00
Marc RousavyandGitHub 9adb7df925 perf: Remove OwningLock<T> (#567)
* perf: Remove `OwningLock<T>`

* fix: Fix Java Class name
2025-02-23 16:33:53 +01:00
Marc RousavyandGitHub 4d7cf329dd fix: Log proper generic T types when throwing exceptions (#566)
* fix: Log proper `BorrowingReference<T>` type in error handler

* fix: Log types for even more cases
2025-02-23 16:30:16 +01:00
Marc RousavyandGitHub 5e063414fc chore: Disable -Wexceptions warning on Android specific block (#549) 2025-02-19 21:01:49 +01:00
Marc Rousavy 892799e8ef chore: Simpler 2025-02-12 12:24:56 -08:00
Marc Rousavy 48b17d148e Revert "fix: Generate @JvmName prop for Kotlin methods (#534)"
This reverts commit 897b5c6f8c.
2025-02-12 12:24:17 -08:00
Marc RousavyandGitHub 897b5c6f8c fix: Generate @JvmName prop for Kotlin methods (#534)
* fix: Generate `@JvmName` prop for Kotlin methods

* fix: Promise

* Update Promise.hpp

* ignore jvmname annotation bug

* fix: Move it down
2025-02-10 14:07:00 -08:00