Commit Graph
143 Commits
Author SHA1 Message Date
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
Marc RousavyandGitHub 6998588b70 chore: Rename BorrowingReference<T> -> WeakReference<T>, and OwningReference<T> -> BorrowingReference<T> (#523)
* chore: Rename `BorrowingReference<T>` -> `WeakReference<T>`, and `OwningReference<T>` -> `BorrowingReference<T>`

* chore: Remove unused flag

* chore: Lint

* fix: remove unnecessary nullptr compare
2025-02-03 18:30:04 +01:00
Marc RousavyandGitHub d62dbfbed8 feat: Update memorySize when a HybridObject makes a round-trip (#510)
* feat: Update `memorySize` when a HybridObject makes a round-trip

* feat: Add `NitroModules.updateMemorySize(..)` to imperatively update mem size

* feat: Add test for `NitroModules.updateMemorySize`

* feat: Add some more tests for `NitroModules.*`

* feat: Add even more tests

* fix: Use `jsi::Object`

* fix: use `getObject`

* fix: Register `updateMemorySize()`

* Update HybridNitroModulesProxy.cpp
2025-01-22 15:00:01 +01:00
Marc RousavyandGitHub b387586142 fix: Rename TypeInfo.hpp to NitroTypeInfo.hpp (#498)
* fix: Replace `TypeInfo.hpp` with `NitroTypeInfo.hpp`

* fix: Format

* Update NitroTypeInfo.hpp
2025-01-15 18:57:31 +01:00
Marc RousavyandGitHub bbbeeaf6b8 feat: Specify RN version as compiler flag (#490)
* feat: Specify RN version in iOS

* Set RN version

* docs

* fix: Adjust scripts and add bootstrap

* fix: Fix react-native path again

* feat: Add `REACT_NATIVE_VERSION` flag to gradle

* fix: Use `tasks.register` to avoid reconfiguration

* fix: Use `project.layout.buildDirectory` instead of `project.buildDir`

* fix: arguments with comma

* fix: Use `buildDir` again

* fix: Pass `YES`

* feat: Add CMake C++ flags now

* fix: Indicate default overridden `HybridObject` constructor

* perf: Make `equals()` a bit faster
2025-01-13 14:13:00 +01:00
Marc RousavyandGitHub a06c7d44af feat: Add new ArrayBuffer APIs (copy(), wrap(), allocate(), toData()) (#463)
* feat: Add `ArrayBuffer::copyBuffer(..)` API

* feat: Add `wrap` API for Kotlin

* feat: Add `ArrayBuffer.copy(data:)`

* perf: Copy Data a bit more effectively

* fix: Rename a bunch of things

* docs: Add creating docs

* feat: Add `ArrayBufferHolder.toData()`

* feat: Add `ArrayBuffer::copy(std::vector&)`

* perf: Change type of `.data` to `uint8_t*` to avoid upcast

* feat: Add `copyIfNeeded` flag

* Update array-buffers.md
2025-01-07 16:35:59 +01:00
Marc RousavyandGitHub 2ebff1b4a5 fix: Reject Promise with timeout if it gets destroyed (#444)
* fix: Reject Promise with timeout if it gets destroyed

If a Promise gets destroyed without ever being resolved or rejected, it goes stale.

This PR fixes this and rejects a Promise with a timeout error if it gets destructed and is still pending

* Add promise typename

* Reject swift promise as well

* Update Promise.hpp

* fix: Build

* Update Dispatcher.cpp

* fix: Also reject `JPromise` if it gets destroyed
2024-12-22 13:53:24 +01:00
Marc RousavyandGitHub 67ee05dc52 chore: Remove unused arg names (#443)
* chore: Remove unused arg names

* More

* chore: Even more

* rename _
2024-12-20 16:00:37 +01:00
Marc RousavyandGitHub 00e9db4087 perf: Create PromiseHolder<T> (#439)
* feat: Create `PromiseHolder<T>`

* fix: Fix PromiseHolder

* partial fix

* It works now

* fix: Make `_mutex` a value

* Move ctor

* perf: Move functions

* Add back deprecated func

* more explicit
2024-12-20 11:12:08 +01:00
Marc RousavyandGitHub 196fc9d0e0 perf: Mark all types that are used only in std::shared_ptr<T> as SWIFT_NONCOPYABLE (#435)
* fix: Mark all types that are used only in `std::shared_ptr<T>` as `SWIFT_UNSAFE_REFERENCE`

* Update AnyMap.hpp

* fix: Add `SWIFT_PRIVATE`

* fix: Use `SWIFT_NONCOPYABLE` instead!! THAT WORKS
2024-12-20 10:11:25 +01:00
Marc RousavyandGitHub 27e8cbb58e fix: Add workaround for error messages on Android (#408) 2024-12-09 17:39:39 +01:00
Marc RousavyandGitHub 5147fc7944 fix: Delete HybridObject copy & move ctors (#402) 2024-12-06 14:31:25 +01:00
Marc RousavyandGitHub b916d5fd46 fix: Check std::exception_ptr for null (#381)
* fix: Check `std::exception_ptr` for null

* Replace `nullptr` with `null` in some errors
2024-12-02 15:21:38 +01:00
Marc RousavyandGitHub 826da789c8 fix: Use exception_ptr for Promise::reject (#380)
* fix: Attempt to fix exception_ptr

* fix: Remove the `reject(exception)` functions

* Update RuntimeError.hpp

* fix: Use `exception_ptr` for Promise
2024-12-02 14:12:22 +01:00
Marc RousavyandGitHub 584e38b7c7 feat: Allow using Error as type (#376)
* feat: Allow using `Error` as type

* feat: Add `throwError(error)` func to test object

* feat: Test `throwError(error)`

* Update getTests.ts

* fix: Fix bridging `std::exception_ptr` to Swift `Error`

* fix: Fix `__rejecter` still using `std.exception_ptr`

* fix: Fix Java `JThrowable` conversion

* fix: Update error message

* fix: Fix `__ndk1` prefix on Android

* fix: Make `reject` just forward to `exception_ptr`
2024-11-29 15:57:22 +01:00
Marc Rousavy 5a24994248 chore: Fix some docs 2024-11-27 19:09:57 +01:00
Marc RousavyandGitHub b069fb69a8 fix: Fix Promise rejections not having a message by using std::exception_ptr to avoid C++ object slicing (#369)
* fix: Use `std::exception_ptr` to preserve message

* fix: Catch exception

* fix: Fix `JSIConverter`

* Update AssertPromiseState.hpp

* Ok kinda fix?

* ugh

* fix again

* Update JSIConverter+Promise.hpp

* chore: Rename `_result` to `_state`

* feat: Allow comparing message

* fix: Fix `RuntimeError.description`

* feat: Test all of those error messages as well
2024-11-22 21:14:00 +01:00
Marc RousavyandGitHub ed24de61f0 fix: Catch cases where a Promise<T> could potentially be rseolved twice (#362)
* fix: Catch cases where a `Promise<T>` could potentially be rseolved twice

* Update AssertPromiseState.hpp
2024-11-20 22:08:58 +01:00
Marc RousavyandGitHub 66e72d7057 feat: Add Promise::await() to Promise.hpp (#361) 2024-11-20 22:08:49 +01:00
Marc RousavyandGitHub 6da4f98904 feat: Support awaiting JS Promise in Kotlin and Swift (#355)
* feat: Support passing `Promise` to Kotlin

* feat: Add `onResolvedListener`

* feat: Add `.then`, `.catch` and `.await` to Promise!

* feat: Use `await`

* feat: Use `Throwable` instead of `String` for error on Android

* Update Promise.kt

* chore: Remove unused `reject(string)` function now

* Update Promise.hpp

* Update Promise.hpp

* feat: Implement `awaitPromise(..)` on iOS

* feat: Add `RuntimeError` and `.toCpp` to Swift

* fix: Fix duplicate symbol in `RuntimeError`

* feat: Add `ErrorType`

* feat: Add `const&` funcs to `Promise` for Swift

* feat: Add `dependencies` to SwiftCxxBridge

* fix: `error` type

* feat: Add `RuntimeError.from(std.exception)`

* feat: Add `getFunctionCopy()` to `SwiftClosure`

* fix: Account for `Promise<void>` resolver

* fix: Fix `UnsafeMutableRawPointer` being nullable (wrong type)

* nitrogen

* clean

* Update HybridTestObjectSwiftKotlinSpecCxx.swift

* feat: Add actual Promise listeners!!

* fix: Add `addOnResolvedListenerCopy` func for some cases

* chore: Format

* fix: Make `getFunctionCopy()` const

* feat: Support `Promise<void>` from JS!

* feat: Add `awaitAndGet` and `awaitAndGetComplex` promise tests

* feat: Test both new functions

* Slap a good ol' `mutex` on `Promise`

* fix: Fix `Promise<void>` never resolving because args count was `1` (`undefined`)

* fix: Fix Android wrong return type

* Update HybridTestObjectCpp.cpp
2024-11-19 18:06:31 +01:00
Marc RousavyandGitHub b6277ea157 feat: Allow converting Promise from JS to C++ (#354)
* feat: Allow converting `Promise` from JS to C++

* feat: Only expose `create()` in Promise

* fix: Use new `create()` fn

* feat: Add test for `awaitPromise(...)`

* fix: Call `.then` / `.catch`

* Delete `JSPromise`

* fix: Don't swallow errors in timeouted promise

* chore: Add `exception` include

* fix: Fix promise test

* fix: Properly chain .then and .catch functions

* Update getTests.ts

* chore: Format

* fix: Implement `canConvert` for Promise
2024-11-19 14:04:41 +01:00
Marc RousavyandGitHub 110dcbf29d feat: Use new, faster, simpler Promise<T> in Nitrogen (#349)
* fix: Add `Promise.hpp` to podspec

* feat: Use new `Promise<T>` type for C++ and Swift

just a minor bug left

* chore: Format

* fix: Fix nitrogen to use old `future` for function return types FOR NOW

* feat: Use new `Promise<T>` on Kotlin!

* chore: Remove unused `PromiseHolder` now

* chore: Format
2024-11-19 02:21:21 +01:00