Commit Graph
94 Commits
Author SHA1 Message Date
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 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 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 25b1917f50 fix: Pre-allocate defaultValue for funcs (#255) 2024-10-23 10:11:29 +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 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 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 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 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 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 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 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 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 Rousavy f7646c34ba fix: Remove unresolved import on Android 2024-08-09 17:01:42 +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
Marc Rousavy 0b7e2b5561 fix: Fix JSICache<T> being recreated each time because of C++ template specialization 2024-08-06 01:37:08 +02:00
Marc Rousavy 0e51985a82 feat: Add tests for ArrayBuffer 2024-08-06 00:33:00 +02:00
Marc Rousavy 592ceb94ff feat: Support ArrayBuffers from JS, and fix JSIConverter<T> template 2024-08-06 00:22:26 +02:00
Marc Rousavy 1c46d3056a fix: Fix includes 2024-08-05 18:33:04 +02:00
Marc Rousavy 401743cdde perf: Make args check constexpr 2024-08-05 18:22:19 +02:00
Marc Rousavy 7b0a0b5736 Forward declare JSIConverter 2024-08-05 17:55:58 +02:00
Marc Rousavy 7f2ccbec0b fix: Move HybridContext.hpp to iOS 2024-08-05 17:44:40 +02:00
Marc Rousavy da52559049 fix: Fix some headers 2024-08-05 17:31:09 +02:00
Marc RousavyandGitHub 273772c181 feat: Support optional parameters (#9)
* feat: Support optional parameters

* Update App.tsx

* Update HybridObject.hpp

* feat: Check min args count

* Try use optional approach

* fix: Count total optionals

* it works?

* Update NonDefaultArgsCount.hpp

* rename

* format

* fix: Codegen it

* Add better tests

* fix equals

* fix: Make `trailing_optionals_count_v` kinda work.

* fix: Remove `cvref`

* Run tests

* fix: Properly constexpr count trailing optionals only

* Improve callback tests
2024-08-05 02:03:00 +02:00
Marc Rousavy 87eae31207 feat: Move to templates 2024-08-02 21:45:48 +02:00
Marc Rousavy a522f09327 fix: Put template<...> on a separate line 2024-08-02 12:37:03 +02:00
Marc Rousavy 49ed078d1e fix: Unify error catching in createMethod 2024-07-31 18:21:42 +02:00
Marc Rousavy 1c19ec8309 chore: Format 2024-07-31 18:11:57 +02:00
Marc Rousavy 1eda72abab feat: Provide object and method name when throwing errors 2024-07-31 18:11:29 +02:00
Marc Rousavy 50507b693a fix: Fix imports 2024-07-31 17:41:25 +02:00
Marc Rousavy 9d69ba04ab chore: Run clang format 2024-07-31 17:39:56 +02:00
Marc Rousavy 37fe1a8cad feat: Support JS -> C++ variant parsing 2024-07-30 18:28:37 +02:00
Marc Rousavy 18d509ca56 feat: Map roundtrip (JS -> C++) 2024-07-30 18:01:06 +02:00
Marc Rousavy 4a073978e4 YAY Maps work!!! :) 2024-07-30 17:38:43 +02:00
Marc Rousavy c043b61cc6 feat: Create AnyMap 2024-07-30 16:51:09 +02:00
Marc Rousavy bc26711f21 replace is_same_v<T, void> -> is_void_v<T> 2024-07-30 13:51:39 +02:00
Marc Rousavy 3e0279a71f feat: Create JSICacheReference for safer cache access 2024-07-30 11:41:01 +02:00