react-native-nitro-modules 0.23.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/NitroModules.podspec +1 -0
  2. package/README.md +6 -0
  3. package/android/src/main/cpp/registry/DefaultConstructableObject.hpp +1 -1
  4. package/cpp/core/ArrayBuffer.cpp +3 -5
  5. package/cpp/core/ArrayBuffer.hpp +2 -2
  6. package/cpp/core/HybridFunction.hpp +2 -1
  7. package/cpp/core/HybridObject.cpp +3 -1
  8. package/cpp/core/Promise.hpp +8 -5
  9. package/cpp/jsi/JSICache.hpp +3 -3
  10. package/cpp/jsi/JSIConverter+ArrayBuffer.hpp +1 -1
  11. package/cpp/jsi/JSIConverter+Exception.hpp +4 -1
  12. package/cpp/jsi/JSIConverter+Function.hpp +24 -67
  13. package/cpp/jsi/JSIConverter+Promise.hpp +3 -2
  14. package/cpp/prototype/HybridObjectPrototype.cpp +12 -9
  15. package/cpp/templates/PromiseType.hpp +12 -0
  16. package/cpp/threading/Dispatcher.cpp +7 -5
  17. package/cpp/utils/BorrowingReference.hpp +40 -43
  18. package/cpp/utils/JSCallback.hpp +132 -0
  19. package/cpp/utils/NitroDefines.hpp +1 -1
  20. package/cpp/utils/NitroTypeInfo.cpp +80 -0
  21. package/cpp/utils/NitroTypeInfo.hpp +8 -65
  22. package/cpp/utils/WeakReference.hpp +6 -7
  23. package/cpp/views/CachedProp.hpp +2 -1
  24. package/ios/turbomodule/NativeNitroModules+NewArch.mm +1 -1
  25. package/ios/utils/RuntimeError.hpp +1 -1
  26. package/lib/commonjs/Sync.js +2 -0
  27. package/lib/commonjs/Sync.js.map +1 -0
  28. package/lib/commonjs/index.js +11 -0
  29. package/lib/commonjs/index.js.map +1 -1
  30. package/lib/module/Sync.js +2 -0
  31. package/lib/module/Sync.js.map +1 -0
  32. package/lib/module/index.js +1 -0
  33. package/lib/module/index.js.map +1 -1
  34. package/lib/tsconfig.build.tsbuildinfo +1 -1
  35. package/lib/typescript/Sync.d.ts +11 -0
  36. package/lib/typescript/Sync.d.ts.map +1 -0
  37. package/lib/typescript/index.d.ts +1 -0
  38. package/lib/typescript/index.d.ts.map +1 -1
  39. package/package.json +1 -1
  40. package/src/Sync.ts +8 -0
  41. package/src/index.ts +1 -0
  42. package/cpp/utils/OwningLock.hpp +0 -56
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Marks the given function as _synchronous_, allowing it to be called synchronously on the same
3
+ * Thread.
4
+ *
5
+ * This allows for fast native -> JS calls and avoids any asynchronous dispatching, but requires careful
6
+ * threading considerations.
7
+ */
8
+ export type Sync<T> = T extends Function ? T & {
9
+ __syncTag?: never;
10
+ } : never;
11
+ //# sourceMappingURL=Sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Sync.d.ts","sourceRoot":"","sources":["../../src/Sync.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,QAAQ,GAAG,CAAC,GAAG;IAAE,SAAS,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG,KAAK,CAAA"}
@@ -2,6 +2,7 @@ export * from './HybridObject';
2
2
  export * from './NitroModules';
3
3
  export * from './AnyMap';
4
4
  export * from './Constructor';
5
+ export * from './Sync';
5
6
  export * from './views/HybridView';
6
7
  export * from './views/getHostComponent';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAE7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,0BAA0B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAC7B,cAAc,QAAQ,CAAA;AAEtB,cAAc,oBAAoB,CAAA;AAClC,cAAc,0BAA0B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-modules",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "Insanely fast native C++, Swift or Kotlin modules with a statically compiled binding layer to JSI.",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
package/src/Sync.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Marks the given function as _synchronous_, allowing it to be called synchronously on the same
3
+ * Thread.
4
+ *
5
+ * This allows for fast native -> JS calls and avoids any asynchronous dispatching, but requires careful
6
+ * threading considerations.
7
+ */
8
+ export type Sync<T> = T extends Function ? T & { __syncTag?: never } : never
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ export * from './HybridObject'
2
2
  export * from './NitroModules'
3
3
  export * from './AnyMap'
4
4
  export * from './Constructor'
5
+ export * from './Sync'
5
6
 
6
7
  export * from './views/HybridView'
7
8
  export * from './views/getHostComponent'
@@ -1,56 +0,0 @@
1
- //
2
- // OwningLock.hpp
3
- // Nitro
4
- //
5
- // Created by Marc Rousavy on 30.07.24.
6
- //
7
-
8
- #pragma once
9
-
10
- namespace margelo::nitro {
11
- template <typename T>
12
- class BorrowingReference;
13
- }
14
-
15
- #include "BorrowingReference.hpp"
16
- #include <cstddef>
17
- #include <mutex>
18
-
19
- namespace margelo::nitro {
20
-
21
- /**
22
- * An `OwningLock<T>` is a RAII instance that locks the given caller thread guaranteed safe access
23
- * to a `BorrowingReference<T>`.
24
- * The `BorrowingReference<T>` cannot be deleted while an `OwningLock<T>` of it is alive.
25
- *
26
- * This is useful in JSI, because Hermes runs garbage collection on a separate Thread,
27
- * and the separate Thread can delete an `BorrowingReference<T>` while it's still in use.
28
- * The `OwningLock<T>` prevents exactly this problem by blocking the GC destructor until
29
- * the `OwningLock<T>` is released.
30
- *
31
- * To create an `OwningLock<T>`, simply call `lock()` on an `BorrowingReference<T>`.
32
- */
33
- template <typename T>
34
- class OwningLock final {
35
- private:
36
- explicit OwningLock(const BorrowingReference<T>& reference) : _reference(reference) {
37
- _reference._state->mutex.lock();
38
- }
39
-
40
- public:
41
- ~OwningLock() {
42
- _reference._state->mutex.unlock();
43
- }
44
-
45
- OwningLock() = delete;
46
- OwningLock(const OwningLock&) = delete;
47
- OwningLock(OwningLock&&) = delete;
48
-
49
- private:
50
- BorrowingReference<T> _reference;
51
-
52
- private:
53
- friend class BorrowingReference<T>;
54
- };
55
-
56
- } // namespace margelo::nitro