Commit Graph
240 Commits
Author SHA1 Message Date
Marc RousavyandGitHub 4ffa3ae4ce fix: Replace placeholders to make them windows compatible (<<*>> -> $$*$$) (#385) 2024-12-03 15:59:19 +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 0747e099b7 fix: Fix ref counting with recursive mutex (#368)
* fix: Fix ref counting with recursive mutex

* Xcode
2024-11-22 19:42:38 +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 Rousavy d0052ecd62 fix: Fix moving sharedFunction after first callback call 2024-11-20 21:56:20 +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 dc1fdb0ad8 chore: Add deprecation notice to JSIConverter<std::future> (#351)
* chore: Add deprecation notice to `JSIConverter<std::future>`

* Update JSIConverter+Future.hpp

* chore: Fix order of initialization
2024-11-19 12:35:20 +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
Marc Rousavy c2becae22d chore: Clean up unused imports 2024-11-19 00:59:50 +01:00
Marc RousavyandGitHub 8cd7a2912e fix: Fix Promise::awaitFuture actually locking threads (#347)
* fix: Fix `Promise::awaitFuture` actually locking threads

* fix: Make tests only wait 1s instead of 2s
2024-11-19 00:52:43 +01:00
Marc Rousavy ae7cab0557 chore: Tidy Promise.hpp 2024-11-19 00:36:19 +01:00
Marc RousavyandGitHub f94cfbcbc8 feat: Allow ThreadPool to grow dynamically (#345)
* feat: Allow `ThreadPool` to grow dynamically

* feat: Add upper limit to `ThreadPool`

* fix: Fix potential race condition when ThreadPool gets destroyed while `addThread()`
2024-11-19 00:27:27 +01:00
Marc RousavyandGitHub 8832bc5225 feat: Add new Promise<T> implementation for C++ (#343)
* feat: Create `Promise.hpp`

* feat: Add `JSIConverter+Exception`

* feat: Base for `Promise` and `Exception`

* fix: Implement Exception conversion

* Implement `Promise::awaitFuture`

* Revive `+Future`

* fix: Speed up creating `ThreadPool`

* fix: Make `+Future` also just use `+Promise` impl

* fix: Thread pool has 10 threads now.

* feat: Allow `ThreadPool` to grow dynamically

* chore: Format C++
2024-11-19 00:01:46 +01:00
Marc RousavyandGitHub c491d394c1 fix: Perform safer checks for toContain(..) in example, and add NitroModules.hasNativeState(value) (#324)
* chore: Perform safer checks for `toContain(..)` in example

* feat: Add `NitroModules.hasNativeState(value)` to avoid crashing eaxmple in release

* fix: Explicitly check for `toString()` if it has NativeState
2024-11-12 18:18:44 +01:00
Marc RousavyandGitHub 1f3a004552 fix: Fix HybridObjectRegistry not being found with JNI in release (#316)
* fix: Fix `HybridObjectRegistry` not being found with JNI in release

* chore: Rename comment
2024-11-11 11:46:36 +01:00
Marc RousavyandGitHub 25b1917f50 fix: Pre-allocate defaultValue for funcs (#255) 2024-10-23 10:11:29 +02:00
Marc RousavyandGitHub 7afac07a83 fix: Fix NONNULL function pointers (#250)
* fix: Fix `NONNULL` function pointers

* Revert "fix: Fix `NONNULL` function pointers"

This reverts commit 5a3acb46d0.

* fix: Replace `NONNULL` with `_Nonnull` compiler keyword

* fix: Format
2024-10-22 11:52:03 +02:00
Marc RousavyandGitHub 6803be8cd9 fix: Add _Nonnull modifier to void* types for Swift (#231) 2024-10-15 20:39:45 +02:00
Marc RousavyandGitHub 2f24d281ad feat: Prettify Prototype names (#229)
* feat: Prettify Prototype names

* perf: Make it fast in release as well.

* Update TypeInfo.hpp

* fix: Remove unnecessary method now

* perf: Make namespace removal `::` faster

* Update TypeInfo.hpp
2024-10-15 19:48:34 +02:00
Marc RousavyandGitHub 57e7f26e61 fix: Make Nitro core compile on non-react-native environments (#195)
* fix: Make Nitro core compile on non-react-native environments

Guards `CallInvokerDispatcher` only if CallInvoker is available

* docs: Remove "Markdown page example" lol
2024-10-08 11:28:23 +02:00
Marc RousavyandGitHub 5f4d61e3cd feat: Use more precise C++ std errors (e.g. invalid_argument) (#179)
* feat: Use more precise C++ std errors (e.g. `invalid_argument`)

* Update bun.lockb

* chore: Re-generate specs
2024-10-07 17:12:16 +02:00
Marc RousavyandGitHub dc8f8668f4 feat: Make Nitro itself a Nitro Module and add old-architecture support 🔥 (#175)
* feat: Create `HybridNitroModulesProxy`

* feat: Create `InstallNitro`

* docs: Create `entry-point.md` docs

* fix: Create `JSIConverter<HostObject>` (for BoxedHybridObject)

* Update NitroModulesProxy.ts

* feat: Refactor JS for new module

* feat: Refactor JS again

* feat: Create iOS TurboModule that installs Nitro

* feat: Implement `install()` for old arch (iOS)

* chore: Format

* feat: Implement TurboModule `install()` on Android

* fix: Use `CallInvokerHolderImpl`

* feat: Add CI that tests the build for old architecture

* fix: Fix iOS CI

* fix: Fix CI

* fix: Exclude RN `.so` libraries (like `libjsi.so`) from `packagingOptions`
2024-10-07 15:47:31 +02:00
Marc RousavyandGitHub 377fbd8a79 fix: Provide helpful error message if this is not bound (#157)
* fix: Provide helpful error message if `this` is not bound

* Update HybridFunction.hpp
2024-09-25 11:44:26 +02:00
Marc RousavyandGitHub 96d15eaa85 feat: Variants for Swift and Kotlin 🥳 (#148)
* fix: Try generating Variants for Swift

* Update SwiftCxxBridgedType.ts

* feat: Create Variant Wrapper struct

* feat: Implement Kotlin Variant

* Update Variant.kt

* feat: Try this Variant

* feat: Stub out variant conversion for JNI for now

* fix: Do not strip in Proguard

* Update Variant.kt

* Format

* Update JVariant.hpp

* feat: Implement JVariant2

* Update JVariant.hpp

* fix: Make it fully dynamic/templated

* feat: Try using JVariant<...>

* fix: Kinda works?

* Update JVariant.hpp

* feat: Fuck all this, we generate variants now

* okay creating works

* Create helper

* feat: Implement Variant parsing to C++ as well

* fix: Clean up and remove `J`

* Same line

* Rename
2024-09-24 13:56:18 +02:00
Marc RousavyandGitHub adeffdac19 fix: Remove unused args parameter in createHybridObject(..) (#145)
* fix: Remove unused `args` parameter in `createHybridObject(..)`

* Update NativeNitroModules.cpp

* fix: Tidy up the ctor and dtor
2024-09-23 12:44:22 +02:00
Marc Rousavy 89a5995dd9 fix: Explicitly check against NDEBUG on Android 2024-09-17 15:14:58 +02:00
Marc RousavyandGitHub 1128d6a3c6 feat: Add NitroModules.box(...) to support using Nitro Modules from any Runtime/Worklets context (#138)
* feat: Add `NitroModules.box(...)` to support using Nitro Modules from any Runtime/Worklets context

* feat: Add `getPropertyNames` for `BoxedHybridObject`

* docs: Create Worklets/Threading docs
2024-09-17 14:45:28 +02:00
Marc RousavyandGitHub 46c9ca0a1b fix: Make string literals throw again, and test optional enums (#135)
* fix: Make string literals throw again, and test optional enums

* Update Podfile.lock

* fix tests

* hm compiler doesnt work

* fix: Fix nitrogen for optional enums

* fix: Optional enums or ArrayBuffers can be bridged directly

* fix: Disable codegen for Nitro Modules

* fix: Rename `Spec` to avoid running codegen

* fix: Disable autolinking by renaming the file so codegen doesnt find it

* fix: Format

* Update HybridObjectRegistry.cpp

* Update HybridObjectRegistry.cpp
2024-09-16 17:34:14 +02:00
Marc RousavyandGitHub 03e1a716cf fix: Fix NITRO_DEBUG debug/release preprocessor directive (#132)
* fix: Use `NITRO_DEBUG` flag to predictably run debug/release code

* feat: Add `NitroModules.buildType`

* fix: Style `debug` label
2024-09-16 16:18:05 +02:00
Marc Rousavy d291f63ec0 fix: Remove LOG_MEMORY_ALLOCATIONS test 2024-09-16 15:47:40 +02:00
Marc Rousavy 563ad61611 fix: Delete unused _deleteFuncContext member 2024-09-16 15:47:29 +02:00
Marc RousavyandGitHub 0f04af9a89 feat: Fully automatic autolinking for Nitrogen (#117)
* move to folders

* Refactor autolinking

* Generate code

* fix: Fix `map` undefined in `unregisterHybridObjectConstructor`

* Create `<ModuleName>OnLoad.mm`

* feat: Add register calls

* hmm

* Update createHybridObjectInitializer.ts

* i am stupid

* Add `autolinking` to `nitro.json`

* Fix missing includes

* feat: Create Swift part for iOS autolinking... 👀

* fix duplicate symbols...

* feat: Properly create Swift types

* Rename to `Autolinking`

* docs: Update docs on new autogenerate setup

* Android base

* It works

* Base

* Initialize natives

* fix: Set up autolinking Cpp file

* Update NitroImageOnLoad.hpp

* feat: Try

* fix: Fix Promise using `global_ref`

* Update index.ts

* fix: Replace `CriticalNative` with `FastNative`

* feat: Generate the code to register JNI.. almost there!

* fix: Fix JNI paths (`L*;`)

* Update nitrogen.md
2024-09-12 17:19:50 +02:00
Marc Rousavy 9f2fd827c9 feat: Add unregisterHybridObjectConstructor(...) method for @jpudysz
don't use this lol
2024-09-09 17:23:35 +02:00
Marc RousavyandGitHub ded7c08220 fix: Properly forward move-only types (future!) (#104)
* fix: Properly forward types (future!)

* Forward
2024-09-06 15:57:35 +02:00
Marc RousavyandGitHub 3fa2fe9bd6 feat: Add NitroModules.hasNativeState and NitroModules.removeNativeState (#83) 2024-08-29 19:38:48 +02:00
Marc RousavyandGitHub 661bea4cec feat: Add dispose() to HybridObject (and registerRawHybridMethod(...)) (#82)
* fix: Fix `SwiftClosure` not reading `void*` properly - use `Unmanaged<T>` again

* feat: Add a `dispose()` method to `HybridObject`

* feat: Split `registerRawHybridMethod` out of `registerHybridMethod`

* fix: Throw better error for when `NativeState` is nullptr

* Better debug info

* `FunctionType` -> `FunctionKind`

* fix: Either dynamically get name, or statically through typeinfo.
2024-08-29 16:51:11 +02:00
Marc RousavyandGitHub 992c709caf feat: Safely wrap a Swift closure in a C++ accessible SwiftClosure struct and allow parameters bi-directionally (#81)
* feat: Safely wrap a Swift closure in a `SwiftClosure` struct callable from C++

* Unsafely unwrap (`!`)

* fix: Fix visibility modifiers

* fix: Rename `ClosureWrapper` -> `SwiftClosure`

* Update SwiftClosure.hpp

* Update SwiftClosure.hpp

* Create `SwiftFunction` base

* regen

* feat: Properly create `std::function` from Swift closure

* fix: Forward params I think

* Update SwiftCxxBridgedType.ts

* feat: Use static function pointer to allow for C++ types

* fix: Only do this for Swift

* Update SwiftCxxBridgedType.ts

* fix: Properly unwrap using `Unmanaged`

* fix: Fix Swift compiler crash by moving function to `std::shared_ptr` before capturing it

* feat: Properly share func before capturing it

* Update SwiftCxxTypeHelper.ts
2024-08-29 15:21:25 +02:00
Marc RousavyandGitHub b4592244f2 feat: AnyMap for Kotlin/Android (#60)
* feat: Create `JAnyMap` base

* Update JNIOnLoad.cpp

* feat: Create `AnyMap` methods

* fix: Fix wrong name & format

* feat: `setNull`

* log dimmed

* Update README.md
2024-08-27 18:02:39 +02:00
Marc RousavyandGitHub dbadcc2151 feat: Create AnyMapHolder for Swift (#56)
* feat: Create `AnyMapHolder` for Swift

* feat: Bridge other types

* fix: Fix types

* feat: Make all public

* fix: Remove Arrays because of the Swift compiler bug

* feat: Create `AnyMapHolder`

* fix: Rename record `someMap` to `someRecord`

* feat: Use `someMap`

* fix: Fix "22 duplicate symbols" by making the funcs inline

* Update README.md
2024-08-20 23:16:55 +02:00
Marc RousavyandGitHub 3d4455eaa8 feat: Add support for ArrayBuffer in Kotlin Nitro Modules (#55)
* fix: More all Java files into `.core`

* fix: Remove unused `_runtime` member in `JSICache`

* feat: Create `JArrayBuffer`

* feat: Crate `JArrayBuffer` from both ways

* feat: Implement bidirectional `ArrayBuffer` for Kotlin

* Update JArrayBuffer.hpp

* fix: Fix include

* fix: Fix non-direct buffers

* Update README.md
2024-08-20 18:10:10 +02:00
Marc RousavyandGitHub e7b9f412eb fix: Rewrite Logger to use platform NSLog / __android_log_print (#54)
* fix: Fix wrong include..?

* fix: Reimplement NitroLogger as a platform-specific logger

* fix: Copy args, and use proper tag

* fix: Fix sprintf crash because of wrong format argument

* fix: Fix Logger usage on iOS
2024-08-20 16:20:44 +02:00
Marc RousavyandGitHub acca5baaa4 fix: Replace #if DEBUG with #ifndef NDEBUG to make it work on Android (#53)
* fix: Fix `hasNativeState` checks and provide better errors

* fix: Replace `#if DEBUG` with `#ifndef NDEBUG` to make it work on Android
2024-08-20 15:30:03 +02:00
Marc Rousavy f4ef4b7665 fix: Fix raw JSI functions and add test to example module 2024-08-20 12:13:55 +02:00
Marc RousavyandGitHub 065736dc2e feat: Base for Kotlin modules (#45)
* feat: Base for Kotlin modules

* fix: Properly make sure Nitro C++ is initialized

* Update JNIOnLoad.java

* feat: Set up `initHybrid()` in JHybridObject

* chore: Fix a bunch of linter issues

* fix: Fix fbjni codegen

* Update JHybridObject.hpp

* fix: Make `initHybrid()` JVM static

* feat: Make `mHybridData` private member of each in inheritance chain

* Generate specs

* feat: Set up proper inheritance graph in FBJNI using virtual inheritance `HybridObject` (#46)

* feat: Try to set up proper inheritance in FBJNI

* Virtual inheritance

* Update JHybridImageFactorySpec.cpp

* It works...

* feat: Virtual base

* Update HybridTestObject.hpp

* Update CMakeLists.txt

* Update JHybridObject.hpp

* Virtual dtor

* Dynamic cast to NativeState 🤔

* Virtual proper

* feat: Generate as virtual base?

* chore: Change to `updateNative`

* feat: Cannot default-construct HybridObject

* fix: Use `dynamic` pointer cast for `HybridContext` because `HybridObject` is now a virtual base

* Update README.md
2024-08-19 12:40:44 +02:00