Commit Graph
228 Commits
Author SHA1 Message Date
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
Marc RousavyandGitHub 2c277fe6f0 feat: Support Promise<T> in Swift (#43)
* fix: Rename `wrap(wrappingDataWithoutCopy)`

* Update ArrayBufferHolder.swift

* Update ArrayBufferHolder.swift

* feat: Move to `utils/`

* feat: Create `Promise` base

* feat: Make `Promise` templated

* Delete HybridContext.cpp

* feat: Create `Promise<T>` in Swift

* Update Promise.swift

* feat: Add docs

* feat: Create `PromiseHolder`

* feat: Create

* `ArrayBuffer` ctors

* Create `PromiseHolder`

* feat: Convert from and to `PromiseHolder<T>`?

* fix: Remove wrong `Promise` declaration

* Update JSIConverter+Promise.hpp

* Update HybridSwiftKotlinTestObject.swift

* Update NitroModules.podspec
2024-08-15 18:30:43 +02:00
Marc RousavyandGitHub 46dc1f7fed feat: Allow passing Swift callbacks to JS (#42)
* feat: Allow converting a Swift closure to a C++ function

* Use `bind`

* return `func`

* feat: Generate std::bind placeholders

* Update ClosureWrapper.swift

* feat: Allow creating C++ func from (no argument) Swift callback!

* throw if func with more parameters is used bi-directionally

* Use helper function `ClosureWrapper.wrap`

* Update ClosureWrapper.swift
2024-08-15 13:35:21 +02:00
Marc RousavyandGitHub c31936286d feat: Support ArrayBuffer in Swift 🥳 (#37)
* feat: Support `ArrayBuffer` in Swift

* feat: Create `ArrayBufferHolder` that holds a `std::shared_ptr<ArrayBuffer>`

* fix: Fix `void*` cast in Swift

* feat: Create `.allocate(..)` helper init

* fix: Fix `initializeToZero`

* feat: Add `createNewBuffer`

* fix: regenerate missing specs

* fix: Move import to iOS only, on Android we dont have that

* chore: Format
2024-08-14 19:34:31 +02:00
Marc RousavyandGitHub 6d2338d096 feat: Add NitroModules.hasHybridObject(..) and NitroModules.getAllHybridMethodNames() (#30)
* feat: Add `NitroModules.hasHybridObject(..)` and `NitroModules.getAllHybridMethodNames()`

* Fix docs
2024-08-14 01:13:09 +02:00
Marc RousavyandGitHub f90a1325b2 feat: Approach 1 of implementing Swift (#24)
* feat: Convert `swift::String`

* Add arrays to swift

* Update createSwiftUmbrellaHeader.ts

* fix: Return values directly now, no more result types (breaks exceptions, fixes generics)

* Expose Swift test object

* feat: Try functions

* fix: Include pragma once

* Pragma

* feat: Create `Callback_...` for Swift

* add comments

* Create `Callback_*` in `bridge/`

* feat: `AnyMap` reserve ctor

* Create SwiftCxxTypeHelper.ts

* feat: Create Swift -> C++ bridged helper types

* feat: i dont even know what im doing anymore

* feat: Convert optionals

* indent

* feat: Fix umbrella

* indent
2024-08-13 22:13:29 +02:00
Marc RousavyandGitHub 0dd63227d8 fix: Fix Swift umbrella header includes (#19)
* feat: Try bridge more Swift

* Make all Promises `async` in swift

* Rename `Promise` to `JSPromise`

* Update JSPromise.hpp

* Update JSICache.cpp

* fix import

* fix: Init props

* fix: Remove AnyMap and ArrayBuffer apis for now

* fix import

* no more async? idk

* feat: Convert `std::optional<T>` to `swift::Optional<T>`

* Remove all funcs except hello

* fix: Generate Swift Umbrella header

* fix: Organize

* fix: Hardcode forward-decl

* feat: Properly generate umbrella header from known types

* fix: Fix indentation

* order

* feat: Try bridging some primitives over...

* Update NitroDefines.hpp

* Update Property.ts

* fallthrough looks better

* better error

* fix: Fix wrong enum `maxLength`

* feat: Try `CarSwift` experiment

* Revert "feat: Try `CarSwift` experiment"

This reverts commit 7794f38271.
2024-08-12 14:18:13 +02:00
Marc Rousavy f7646c34ba fix: Remove unresolved import on Android 2024-08-09 17:01:42 +02:00
Marc Rousavy ec910a7b27 fix: Add nullptr check to HybridObjectRegistry 2024-08-08 20:28:43 +02:00
Marc RousavyandGitHub c101faf948 feat: Cache toObject(...) using jsi::WeakObject and correctly set externalExternalMemoryPressure (#13)
* feat: Cache `toObject(...)` using `jsi::WeakObject` and set `externalMemoryPressure` properly

* feat: Support caching different JSI types - strongly typed
2024-08-08 12:28:33 +02:00
Marc Rousavy 0807098c86 Update HybridObject.cpp 2024-08-08 11:48:49 +02:00
Marc Rousavy f5bd9e157d perf: Do all .is.. checks only in DEBUG 2024-08-08 11:45:02 +02:00
Marc RousavyandGitHub 86c3702ffc feat: Make HybridObject a NativeState (#11)
* feat: Make `HybridObject` a `NativeState`

* feat: Get `NativeState` inside `callMethod(...)`, no more passing `this*`

* Update HybridObject.hpp

* fix: Convert NativeState to `jsi::Value` again

* Use `Object.create`

* fix broken test

* feat: Add `__type` hidden state to objects

* chore: Format

* `makeGlobal` -> `makeShared`

* feat: Extract to `HybridObjectPrototype`

* Update HybridObject.hpp

* feat: Properly build Prototype chain

* Cache prototypes

* fix: Fix prototype caching

* Extract to separate file

* fix: Some comments

* chore: Format

* feat: Freeze prototypes

* Remove freeze

* feat: Optimize `NativeState` performance, make it 56x faster (#12)

* fix: Fix `HybridFunction` usage

* Update HybridFunction.hpp

* mark final

* feat: Add new `registerHybrids(...)` API

* fix: Remove logs

* perf: Make `registerHybrids` faster by using function pointer instead of `std::function<...>`

* fix: Turn off memory allocations debugger

* refactor

* Format

* fix: Fix cyclic includes for `JSIConverter+HybridObject`

* DO_NULL_CHECKS

* fix: Use `jsi::Value` directly to avoid down and up casting again

* Add `__type` to `HybridObject` declaration

* feat: Throw `jsi::JSError` again

* feat: Add prototype tests

* feat: Set `__type` on Prototypes as well

* Delete PointerHolder.hpp

* Delete `JSIPrototypeCache`

* fix: Use `jsi::Value` directly
2024-08-08 11:39:17 +02:00