react-native-nitro-modules 0.23.0 → 0.24.1
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.
- package/NitroModules.podspec +1 -1
- package/README.md +6 -0
- package/android/src/main/cpp/JNIOnLoad.cpp +0 -2
- package/android/src/main/cpp/registry/DefaultConstructableObject.hpp +1 -1
- package/android/src/main/cpp/registry/JHybridObjectInitializer.hpp +1 -1
- package/android/src/main/java/com/margelo/nitro/core/ArrayBuffer.kt +0 -5
- package/cpp/core/ArrayBuffer.cpp +3 -5
- package/cpp/core/ArrayBuffer.hpp +2 -7
- package/cpp/core/HybridFunction.hpp +2 -1
- package/cpp/core/HybridObject.cpp +3 -1
- package/cpp/core/Promise.hpp +8 -9
- package/cpp/jsi/JSICache.hpp +3 -3
- package/cpp/jsi/JSIConverter+ArrayBuffer.hpp +1 -1
- package/cpp/jsi/JSIConverter+Exception.hpp +4 -1
- package/cpp/jsi/JSIConverter+Function.hpp +24 -67
- package/cpp/jsi/JSIConverter+Promise.hpp +3 -2
- package/cpp/jsi/JSIConverter.hpp +0 -1
- package/cpp/prototype/HybridObjectPrototype.cpp +12 -9
- package/cpp/templates/PromiseType.hpp +12 -0
- package/cpp/threading/Dispatcher.cpp +7 -5
- package/cpp/utils/BorrowingReference.hpp +40 -43
- package/cpp/utils/JSCallback.hpp +132 -0
- package/cpp/utils/NitroDefines.hpp +1 -1
- package/cpp/utils/NitroTypeInfo.cpp +80 -0
- package/cpp/utils/NitroTypeInfo.hpp +8 -65
- package/cpp/utils/WeakReference.hpp +6 -7
- package/cpp/views/CachedProp.hpp +2 -1
- package/ios/core/HybridObject.swift +0 -10
- package/ios/turbomodule/NativeNitroModules+NewArch.mm +1 -1
- package/ios/utils/RuntimeError.hpp +1 -1
- package/lib/commonjs/Sync.js +2 -0
- package/lib/commonjs/Sync.js.map +1 -0
- package/lib/commonjs/index.js +11 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Sync.js +2 -0
- package/lib/module/Sync.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/lib/typescript/Sync.d.ts +11 -0
- package/lib/typescript/Sync.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Sync.ts +8 -0
- package/src/index.ts +1 -0
- package/android/src/main/cpp/registry/JHybridObjectRegistry.cpp +0 -45
- package/android/src/main/cpp/registry/JHybridObjectRegistry.hpp +0 -32
- package/android/src/main/java/com/margelo/nitro/core/HybridObjectInitializer.java +0 -17
- package/android/src/main/java/com/margelo/nitro/core/HybridObjectRegistry.java +0 -27
- package/cpp/jsi/JSIConverter+Future.hpp +0 -46
- package/cpp/utils/OwningLock.hpp +0 -56
- package/ios/core/HybridContext.hpp +0 -55
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
#pragma once
|
|
9
9
|
|
|
10
10
|
#include "NitroDefines.hpp"
|
|
11
|
-
#include "
|
|
11
|
+
#include "NitroTypeInfo.hpp"
|
|
12
12
|
#include "ReferenceState.hpp"
|
|
13
13
|
#include "WeakReference.hpp"
|
|
14
14
|
#include <atomic>
|
|
@@ -18,19 +18,15 @@
|
|
|
18
18
|
namespace margelo::nitro {
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
An `BorrowingReference<T>` is a smart-pointer that holds a strong reference to a pointer.
|
|
22
|
-
You can have multiple `BorrowingReference<T>` instances point to the same pointer, as they internally keep a ref-count.
|
|
23
|
-
As opposed to a `shared_ptr<T>`, an `BorrowingReference<T>` can also be imperatively manually deleted, even if there
|
|
24
|
-
are multiple strong references still holding onto the pointer.
|
|
25
|
-
This is useful in cases where the `BorrowingReference` might keep a reference alive, but an external value holder
|
|
26
|
-
is actually responsible for truly deleting the underlying value - like a `jsi::Runtime` for a `jsi::Value`.
|
|
27
|
-
|
|
28
|
-
An `BorrowingReference<T>` can be weakified, which gives the user a `WeakReference<T>`.
|
|
29
|
-
A `WeakReference<T>` can be locked to get an `BorrowingReference<T>` again, assuming it has not been deleted yet.
|
|
30
|
-
|
|
31
|
-
A `BorrowingReference<T>` can also be locked using `lock()`, which gives the user an `OwningLock<T>`.
|
|
32
|
-
Only an `OwningLock<T>` guarantees safe access to the underlying value reference, as any external value holders
|
|
33
|
-
that might try to delete the value will have to wait until the lock is freed again.
|
|
21
|
+
* An `BorrowingReference<T>` is a smart-pointer that holds a strong reference to a pointer.
|
|
22
|
+
* You can have multiple `BorrowingReference<T>` instances point to the same pointer, as they internally keep a ref-count.
|
|
23
|
+
* As opposed to a `shared_ptr<T>`, an `BorrowingReference<T>` can also be imperatively manually deleted, even if there
|
|
24
|
+
* are multiple strong references still holding onto the pointer.
|
|
25
|
+
* This is useful in cases where the `BorrowingReference` might keep a reference alive, but an external value holder
|
|
26
|
+
* is actually responsible for truly deleting the underlying value - like a `jsi::Runtime` for a `jsi::Value`.
|
|
27
|
+
*
|
|
28
|
+
* An `BorrowingReference<T>` can be weakified, which gives the user a `WeakReference<T>`.
|
|
29
|
+
* A `WeakReference<T>` can be locked to get an `BorrowingReference<T>` again, assuming it has not been deleted yet.
|
|
34
30
|
*/
|
|
35
31
|
template <typename T>
|
|
36
32
|
class BorrowingReference final {
|
|
@@ -46,7 +42,7 @@ public:
|
|
|
46
42
|
}
|
|
47
43
|
}
|
|
48
44
|
|
|
49
|
-
BorrowingReference(BorrowingReference&& ref) : _value(ref._value), _state(ref._state) {
|
|
45
|
+
BorrowingReference(BorrowingReference&& ref) noexcept : _value(ref._value), _state(ref._state) {
|
|
50
46
|
ref._value = nullptr;
|
|
51
47
|
ref._state = nullptr;
|
|
52
48
|
}
|
|
@@ -76,7 +72,7 @@ public:
|
|
|
76
72
|
|
|
77
73
|
private:
|
|
78
74
|
// WeakReference<T> -> BorrowingReference<T> Lock-constructor
|
|
79
|
-
BorrowingReference(const WeakReference<T>& ref) : _value(ref._value), _state(ref._state) {
|
|
75
|
+
explicit BorrowingReference(const WeakReference<T>& ref) : _value(ref._value), _state(ref._state) {
|
|
80
76
|
_state->strongRefCount++;
|
|
81
77
|
}
|
|
82
78
|
|
|
@@ -107,7 +103,7 @@ public:
|
|
|
107
103
|
|
|
108
104
|
public:
|
|
109
105
|
/**
|
|
110
|
-
Casts this `BorrowingReference<T>` to a `BorrowingReference<C>`.
|
|
106
|
+
* Casts this `BorrowingReference<T>` to a `BorrowingReference<C>`.
|
|
111
107
|
*/
|
|
112
108
|
template <typename C>
|
|
113
109
|
BorrowingReference<C> as() {
|
|
@@ -116,25 +112,15 @@ public:
|
|
|
116
112
|
|
|
117
113
|
public:
|
|
118
114
|
/**
|
|
119
|
-
|
|
120
|
-
safe access to `BorrowingReference<T>`.
|
|
121
|
-
Other threads (e.g. the Hermes garbage collector) cannot delete the `BorrowingReference<T>`
|
|
122
|
-
as long as the `OwningLock<T>` is still alive.
|
|
115
|
+
* Get whether the `BorrowingReference<T>` is still pointing to a valid value, or not.
|
|
123
116
|
*/
|
|
124
117
|
[[nodiscard]]
|
|
125
|
-
OwningLock<T> lock() const {
|
|
126
|
-
return OwningLock<T>(*this);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
Get whether the `BorrowingReference<T>` is still pointing to a valid value, or not.
|
|
131
|
-
*/
|
|
132
118
|
inline bool hasValue() const {
|
|
133
119
|
return _value != nullptr && !_state->isDeleted;
|
|
134
120
|
}
|
|
135
121
|
|
|
136
122
|
/**
|
|
137
|
-
Get a borrowing (or "weak") reference to this owning reference
|
|
123
|
+
* Get a borrowing (or "weak") reference to this owning reference
|
|
138
124
|
*/
|
|
139
125
|
[[nodiscard]]
|
|
140
126
|
WeakReference<T> weak() const {
|
|
@@ -142,10 +128,8 @@ public:
|
|
|
142
128
|
}
|
|
143
129
|
|
|
144
130
|
/**
|
|
145
|
-
Delete and destroy the value this BorrowingReference is pointing to.
|
|
146
|
-
This can even be called if there are still multiple strong references to the value.
|
|
147
|
-
|
|
148
|
-
This will block as long as one or more `OwningLock<T>`s of this `BorrowingReference<T>` are still alive.
|
|
131
|
+
* Delete and destroy the value this BorrowingReference is pointing to.
|
|
132
|
+
* This can even be called if there are still multiple strong references to the value.
|
|
149
133
|
*/
|
|
150
134
|
void destroy() {
|
|
151
135
|
std::unique_lock lock(_state->mutex);
|
|
@@ -154,40 +138,55 @@ public:
|
|
|
154
138
|
}
|
|
155
139
|
|
|
156
140
|
public:
|
|
157
|
-
|
|
158
|
-
return hasValue();
|
|
159
|
-
}
|
|
160
|
-
|
|
141
|
+
// Dereference (*)
|
|
161
142
|
inline T& operator*() const {
|
|
162
143
|
#ifdef NITRO_DEBUG
|
|
163
144
|
if (!hasValue()) [[unlikely]] {
|
|
164
|
-
|
|
145
|
+
std::string typeName = TypeInfo::getFriendlyTypename<T>(true);
|
|
146
|
+
throw std::runtime_error("Tried to dereference (*) nullptr BorrowingReference<" + typeName + ">!");
|
|
165
147
|
}
|
|
166
148
|
#endif
|
|
167
149
|
return *_value;
|
|
168
150
|
}
|
|
169
151
|
|
|
152
|
+
// Dereference (->)
|
|
170
153
|
inline T* operator->() const {
|
|
171
154
|
#ifdef NITRO_DEBUG
|
|
172
155
|
if (!hasValue()) [[unlikely]] {
|
|
173
|
-
|
|
156
|
+
std::string typeName = TypeInfo::getFriendlyTypename<T>(true);
|
|
157
|
+
throw std::runtime_error("Tried to dereference (->) nullptr BorrowingReference<" + typeName + ">!");
|
|
174
158
|
}
|
|
175
159
|
#endif
|
|
176
160
|
return _value;
|
|
177
161
|
}
|
|
178
162
|
|
|
163
|
+
// null-check (bool)
|
|
164
|
+
explicit inline operator bool() const {
|
|
165
|
+
return hasValue();
|
|
166
|
+
}
|
|
167
|
+
// null-check (== nullptr)
|
|
168
|
+
inline bool operator==(std::nullptr_t) const {
|
|
169
|
+
return !hasValue();
|
|
170
|
+
}
|
|
171
|
+
// null-check (!= nullptr)
|
|
172
|
+
inline bool operator!=(std::nullptr_t) const {
|
|
173
|
+
return hasValue();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// comparison (== *)
|
|
179
177
|
inline bool operator==(T* other) const {
|
|
180
178
|
return _value == other;
|
|
181
179
|
}
|
|
182
|
-
|
|
180
|
+
// comparison (!= *)
|
|
183
181
|
inline bool operator!=(T* other) const {
|
|
184
182
|
return _value != other;
|
|
185
183
|
}
|
|
186
184
|
|
|
185
|
+
// comparison (== BorrowingReference<T>)
|
|
187
186
|
inline bool operator==(const BorrowingReference<T>& other) const {
|
|
188
187
|
return _value == other._value;
|
|
189
188
|
}
|
|
190
|
-
|
|
189
|
+
// comparison (!= BorrowingReference<T>)
|
|
191
190
|
inline bool operator!=(const BorrowingReference<T>& other) const {
|
|
192
191
|
return _value != other._value;
|
|
193
192
|
}
|
|
@@ -198,7 +197,6 @@ private:
|
|
|
198
197
|
// free the full memory if there are no more references at all
|
|
199
198
|
delete _state;
|
|
200
199
|
_state = nullptr;
|
|
201
|
-
return;
|
|
202
200
|
}
|
|
203
201
|
}
|
|
204
202
|
|
|
@@ -214,7 +212,6 @@ private:
|
|
|
214
212
|
|
|
215
213
|
public:
|
|
216
214
|
friend class WeakReference<T>;
|
|
217
|
-
friend class OwningLock<T>;
|
|
218
215
|
|
|
219
216
|
private:
|
|
220
217
|
T* _value;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
//
|
|
2
|
+
// JSCallback.hpp
|
|
3
|
+
// Nitro
|
|
4
|
+
//
|
|
5
|
+
// Created by Marc Rousavy on 23.02.25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro {
|
|
11
|
+
template <typename T, typename Enable>
|
|
12
|
+
struct JSIConverter;
|
|
13
|
+
} // namespace margelo::nitro
|
|
14
|
+
|
|
15
|
+
#include "BorrowingReference.hpp"
|
|
16
|
+
#include "JSIConverter.hpp"
|
|
17
|
+
#include "NitroDefines.hpp"
|
|
18
|
+
#include "NitroTypeInfo.hpp"
|
|
19
|
+
#include "Promise.hpp"
|
|
20
|
+
#include <functional>
|
|
21
|
+
#include <jsi/jsi.h>
|
|
22
|
+
|
|
23
|
+
namespace margelo::nitro {
|
|
24
|
+
|
|
25
|
+
// -------- SyncJSCallback --------
|
|
26
|
+
|
|
27
|
+
template <typename Signature>
|
|
28
|
+
class SyncJSCallback;
|
|
29
|
+
|
|
30
|
+
template <typename R, typename... Args>
|
|
31
|
+
class SyncJSCallback<R(Args...)> final {
|
|
32
|
+
public:
|
|
33
|
+
SyncJSCallback(jsi::Runtime& runtime, BorrowingReference<jsi::Function>&& function) : _runtime(runtime), _function(std::move(function)) {}
|
|
34
|
+
|
|
35
|
+
public:
|
|
36
|
+
/**
|
|
37
|
+
* Calls this `SyncJSCallback` synchronously, and
|
|
38
|
+
* returns it's result (`R`).
|
|
39
|
+
* The callee is responsible for ensuring that the
|
|
40
|
+
* underlying `jsi::Function` can actually be called from this Thread.
|
|
41
|
+
* In Debug, sanity checks are made to ensure the `jsi::Function` is still alive.
|
|
42
|
+
*/
|
|
43
|
+
R call(Args... args) const {
|
|
44
|
+
if (!_function) [[unlikely]] {
|
|
45
|
+
std::string typeName = TypeInfo::getFriendlyTypename<SyncJSCallback<R(Args...)>>(true);
|
|
46
|
+
throw std::runtime_error("Cannot call " + typeName + " - the underlying `jsi::Function` has already been deleted!");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
jsi::Value result = _function->call(_runtime, JSIConverter<std::decay_t<Args>>::toJSI(_runtime, std::forward<Args>(args))...);
|
|
50
|
+
if constexpr (std::is_void_v<R>) {
|
|
51
|
+
// It's returning void. No result
|
|
52
|
+
return;
|
|
53
|
+
} else {
|
|
54
|
+
// It's returning a type `R`, convert it
|
|
55
|
+
return JSIConverter<R>::fromJSI(_runtime, result);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public:
|
|
60
|
+
inline R operator()(Args... args) const {
|
|
61
|
+
return call(args...);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private:
|
|
65
|
+
jsi::Runtime& _runtime;
|
|
66
|
+
BorrowingReference<jsi::Function> _function;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// -------- AsyncJSCallback --------
|
|
70
|
+
|
|
71
|
+
template <typename Signature>
|
|
72
|
+
class AsyncJSCallback;
|
|
73
|
+
|
|
74
|
+
template <typename R, typename... Args>
|
|
75
|
+
class AsyncJSCallback<R(Args...)> final {
|
|
76
|
+
public:
|
|
77
|
+
AsyncJSCallback(SyncJSCallback<R(Args...)>&& callback, const std::weak_ptr<Dispatcher>& dispatcher)
|
|
78
|
+
: _callback(std::move(callback)), _dispatcher(dispatcher) {}
|
|
79
|
+
|
|
80
|
+
public:
|
|
81
|
+
/**
|
|
82
|
+
* Calls this `AsyncJSCallback` asynchronously, and returns a Promise that
|
|
83
|
+
* can be awaited to receive the returned result (`R`) from JS.
|
|
84
|
+
* This can be called from any Thread.
|
|
85
|
+
* If the Runtime is no longer alive, this method throws.
|
|
86
|
+
*/
|
|
87
|
+
[[nodiscard]]
|
|
88
|
+
std::shared_ptr<Promise<R>> call(Args... args) const {
|
|
89
|
+
std::shared_ptr<Dispatcher> dispatcher = _dispatcher.lock();
|
|
90
|
+
if (dispatcher == nullptr) [[unlikely]] {
|
|
91
|
+
std::string typeName = TypeInfo::getFriendlyTypename<AsyncJSCallback<R(Args...)>>(true);
|
|
92
|
+
throw std::runtime_error("Failed to call " + typeName + " - the Dispatcher has already been destroyed!");
|
|
93
|
+
}
|
|
94
|
+
return dispatcher->runAsyncAwaitable<R>([callback = _callback, ... args = std::forward<Args>(args)]() mutable {
|
|
95
|
+
// Call actual JS callback, synchronously now.
|
|
96
|
+
return callback.call(std::forward<Args>(args)...);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Calls this `AsyncJSCallback` asynchronously, and ignore
|
|
101
|
+
* any results or completions.
|
|
102
|
+
* This can be called from any Thread.
|
|
103
|
+
* If the Runtime is no longer alive, this method ignores the function call.
|
|
104
|
+
*/
|
|
105
|
+
void callAndForget(Args... args) const {
|
|
106
|
+
std::shared_ptr<Dispatcher> dispatcher = _dispatcher.lock();
|
|
107
|
+
if (dispatcher == nullptr) [[unlikely]] {
|
|
108
|
+
std::string typeName = TypeInfo::getFriendlyTypename<AsyncJSCallback<R(Args...)>>(true);
|
|
109
|
+
Logger::log(LogLevel::Error, "AsyncJSCallback", "Failed to call %s - the Dispatcher has already been destroyed!", typeName.c_str());
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
dispatcher->runAsync([callback = _callback, ... args = std::forward<Args>(args)]() mutable {
|
|
113
|
+
// Call actual JS callback, synchronously now.
|
|
114
|
+
return callback.call(std::forward<Args>(args)...);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public:
|
|
119
|
+
inline auto operator()(Args... args) const {
|
|
120
|
+
if constexpr (std::is_void_v<R>) {
|
|
121
|
+
return callAndForget(args...);
|
|
122
|
+
} else {
|
|
123
|
+
return call(args...);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private:
|
|
128
|
+
SyncJSCallback<R(Args...)> _callback;
|
|
129
|
+
std::weak_ptr<Dispatcher> _dispatcher;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
//
|
|
2
|
+
// NitroTypeInfo.cpp
|
|
3
|
+
// Nitro
|
|
4
|
+
//
|
|
5
|
+
// Created by Marc Rousavy on 23.02.25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#include "NitroTypeInfo.hpp"
|
|
9
|
+
|
|
10
|
+
#if __has_include(<cxxabi.h>)
|
|
11
|
+
#include <cxxabi.h>
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
namespace margelo::nitro {
|
|
15
|
+
|
|
16
|
+
std::string TypeInfo::getCurrentExceptionName() {
|
|
17
|
+
#if __has_include(<cxxabi.h>)
|
|
18
|
+
std::string name = __cxxabiv1::__cxa_current_exception_type()->name();
|
|
19
|
+
return demangleName(name);
|
|
20
|
+
#else
|
|
21
|
+
return "<unknown>";
|
|
22
|
+
#endif
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
std::string TypeInfo::replaceRegex(const std::string& original, const std::string& pattern, const std::string& replacement) {
|
|
26
|
+
static std::unordered_map<std::string, std::regex> cache;
|
|
27
|
+
|
|
28
|
+
auto found = cache.find(pattern);
|
|
29
|
+
if (found != cache.end()) {
|
|
30
|
+
return std::regex_replace(original, found->second, replacement);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
std::regex regex(pattern);
|
|
34
|
+
cache.emplace(pattern, regex);
|
|
35
|
+
return std::regex_replace(original, regex, replacement);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
std::string TypeInfo::demangleName(const std::string& typeName, bool removeNamespace) {
|
|
39
|
+
#ifdef NITRO_DEBUG
|
|
40
|
+
// In debug, we demangle the name using Cxx ABI and prettify it.
|
|
41
|
+
std::string name = typeName;
|
|
42
|
+
#if __has_include(<cxxabi.h>)
|
|
43
|
+
int status = 0;
|
|
44
|
+
char* demangled_name = abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status);
|
|
45
|
+
if (demangled_name != nullptr) {
|
|
46
|
+
name = demangled_name;
|
|
47
|
+
std::free(demangled_name);
|
|
48
|
+
}
|
|
49
|
+
#endif
|
|
50
|
+
|
|
51
|
+
#ifdef ANDROID
|
|
52
|
+
// std::__ndk1 -> std::__1
|
|
53
|
+
name = replaceRegex(name, R"(std::__ndk1)", "std::__1");
|
|
54
|
+
#endif
|
|
55
|
+
|
|
56
|
+
// Make a few edge-cases nicer.
|
|
57
|
+
name = replaceRegex(name, R"(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> ?>)", "std::string");
|
|
58
|
+
name = replaceRegex(name, R"(std::__1::vector<([^>]+), std::__1::allocator<\1>>)", "std::vector<$1>");
|
|
59
|
+
name = replaceRegex(name, R"(std::__1::map<([^,]+), ([^>]+), std::__1::less<\1>, std::__1::allocator<std::__1::pair<const \1, \2>>>)",
|
|
60
|
+
"std::map<$1, $2>");
|
|
61
|
+
name = replaceRegex(name, R"(std::__1::shared_ptr<([^>]+)>)", "std::shared_ptr<$1>");
|
|
62
|
+
name = replaceRegex(name, R"(std::__1::unique_ptr<([^>]+), std::__1::default_delete<\1>>)", "std::unique_ptr<$1>");
|
|
63
|
+
name = replaceRegex(
|
|
64
|
+
name,
|
|
65
|
+
R"(std::__1::unordered_map<([^,]+), ([^>]+), std::__1::hash<\1>, std::__1::equal_to<\1>, std::__1::allocator<std::__1::pair<const \1, \2>>>)",
|
|
66
|
+
"std::unordered_map<$1, $2>");
|
|
67
|
+
|
|
68
|
+
if (removeNamespace) {
|
|
69
|
+
// replace `margelo::nitro::HybridObject` -> `HybridObject`
|
|
70
|
+
name = replaceRegex(name, R"(\b(?!std::)[a-zA-Z_]\w*::)", "");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return name;
|
|
74
|
+
#else
|
|
75
|
+
// In release, we don't do any of that. Just return the ugly name.
|
|
76
|
+
return typeName;
|
|
77
|
+
#endif
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
} // namespace margelo::nitro
|
|
@@ -14,66 +14,16 @@
|
|
|
14
14
|
#include <type_traits>
|
|
15
15
|
#include <typeindex>
|
|
16
16
|
|
|
17
|
-
#if __has_include(<cxxabi.h>)
|
|
18
|
-
#include <cxxabi.h>
|
|
19
|
-
#endif
|
|
20
|
-
|
|
21
17
|
namespace margelo::nitro {
|
|
22
18
|
|
|
23
19
|
struct TypeInfo final {
|
|
24
20
|
public:
|
|
25
21
|
TypeInfo() = delete;
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
static inline std::string demangleName(const std::string& typeName, bool removeNamespace = false) {
|
|
33
|
-
#ifdef NITRO_DEBUG
|
|
34
|
-
// In debug, we demangle the name using Cxx ABI and prettify it.
|
|
35
|
-
std::string name = typeName;
|
|
36
|
-
#if __has_include(<cxxabi.h>)
|
|
37
|
-
int status = 0;
|
|
38
|
-
char* demangled_name = abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status);
|
|
39
|
-
if (demangled_name != nullptr) {
|
|
40
|
-
name = demangled_name;
|
|
41
|
-
std::free(demangled_name);
|
|
42
|
-
}
|
|
43
|
-
#endif
|
|
44
|
-
|
|
45
|
-
#ifdef ANDROID
|
|
46
|
-
// std::__ndk1 -> std::__1
|
|
47
|
-
name = replaceRegex(name, R"(std::__ndk1)", "std::__1");
|
|
48
|
-
#endif
|
|
49
|
-
|
|
50
|
-
// Make a few edge-cases nicer.
|
|
51
|
-
name = replaceRegex(name, R"(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> ?>)", "std::string");
|
|
52
|
-
name = replaceRegex(name, R"(std::__1::vector<([^>]+), std::__1::allocator<\1>>)", "std::vector<$1>");
|
|
53
|
-
name = replaceRegex(name, R"(std::__1::map<([^,]+), ([^>]+), std::__1::less<\1>, std::__1::allocator<std::__1::pair<const \1, \2>>>)",
|
|
54
|
-
"std::map<$1, $2>");
|
|
55
|
-
name = replaceRegex(name, R"(std::__1::shared_ptr<([^>]+)>)", "std::shared_ptr<$1>");
|
|
56
|
-
name = replaceRegex(name, R"(std::__1::unique_ptr<([^>]+), std::__1::default_delete<\1>>)", "std::unique_ptr<$1>");
|
|
57
|
-
name = replaceRegex(
|
|
58
|
-
name,
|
|
59
|
-
R"(std::__1::unordered_map<([^,]+), ([^>]+), std::__1::hash<\1>, std::__1::equal_to<\1>, std::__1::allocator<std::__1::pair<const \1, \2>>>)",
|
|
60
|
-
"std::unordered_map<$1, $2>");
|
|
61
|
-
|
|
62
|
-
if (removeNamespace) [[unlikely]] {
|
|
63
|
-
// replace `margelo::nitro::HybridObject` -> `HybridObject`
|
|
64
|
-
size_t lastColon = name.rfind(':');
|
|
65
|
-
if (lastColon != std::string::npos) {
|
|
66
|
-
// Type contains a namespace - remove it
|
|
67
|
-
name = name.substr(lastColon + 1);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return name;
|
|
72
|
-
#else
|
|
73
|
-
// In release, we don't do any of that. Just return the ugly name.
|
|
74
|
-
return typeName;
|
|
75
|
-
#endif
|
|
76
|
-
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the name of the currently thrown exception
|
|
25
|
+
*/
|
|
26
|
+
static std::string getCurrentExceptionName();
|
|
77
27
|
|
|
78
28
|
/**
|
|
79
29
|
* Get a friendly name of the given `type_info` (if possible, demangled)
|
|
@@ -107,17 +57,10 @@ public:
|
|
|
107
57
|
return string.substr(0, string.length() - 2);
|
|
108
58
|
}
|
|
109
59
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
static
|
|
114
|
-
#if __has_include(<cxxabi.h>)
|
|
115
|
-
std::string name = __cxxabiv1::__cxa_current_exception_type()->name();
|
|
116
|
-
return demangleName(name);
|
|
117
|
-
#else
|
|
118
|
-
return "<unknown>";
|
|
119
|
-
#endif
|
|
120
|
-
}
|
|
60
|
+
private:
|
|
61
|
+
static std::string replaceRegex(const std::string& original, const std::string& pattern, const std::string& replacement);
|
|
62
|
+
|
|
63
|
+
static std::string demangleName(const std::string& typeName, bool removeNamespace = false);
|
|
121
64
|
};
|
|
122
65
|
|
|
123
66
|
} // namespace margelo::nitro
|
|
@@ -64,13 +64,10 @@ public:
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
~WeakReference() {
|
|
67
|
-
if (_state
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
if (_state != nullptr) {
|
|
68
|
+
_state->weakRefCount--;
|
|
69
|
+
maybeDestroy();
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
_state->weakRefCount--;
|
|
73
|
-
maybeDestroy();
|
|
74
71
|
}
|
|
75
72
|
|
|
76
73
|
/**
|
|
@@ -87,7 +84,9 @@ private:
|
|
|
87
84
|
if (_state->strongRefCount == 0 && _state->weakRefCount == 0) {
|
|
88
85
|
// free the full memory if there are no more references at all
|
|
89
86
|
if (!_state->isDeleted) [[unlikely]] {
|
|
90
|
-
|
|
87
|
+
std::string typeName = TypeInfo::getFriendlyTypename<T>(true);
|
|
88
|
+
throw std::runtime_error("WeakReference<" + typeName + "> encountered a stale `_value` - BorrowingReference<" + typeName +
|
|
89
|
+
"> should've already deleted this!");
|
|
91
90
|
}
|
|
92
91
|
delete _state;
|
|
93
92
|
_state = nullptr;
|
package/cpp/views/CachedProp.hpp
CHANGED
|
@@ -33,13 +33,3 @@ public extension HybridObject {
|
|
|
33
33
|
// By default, this returns `0`.
|
|
34
34
|
var memorySize: Int { return 0 }
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
@available(*, deprecated, message: "HybridObjectSpec has been renamed to HybridObject. Update Nitrogen and re-generate your specs.")
|
|
38
|
-
public typealias HybridObjectSpec = HybridObject
|
|
39
|
-
|
|
40
|
-
public extension HybridObjectSpec {
|
|
41
|
-
@available(*, deprecated, message: "getSizeOf(...) will now be default-computed. Please remove getSizeOf() from your code.")
|
|
42
|
-
func getSizeOf<T: AnyObject>(_ instance: T) -> Int {
|
|
43
|
-
return 0
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -36,7 +36,7 @@ RCT_EXPORT_MODULE(NitroModules)
|
|
|
36
36
|
// 1. Get CallInvoker we cached statically
|
|
37
37
|
std::shared_ptr<react::CallInvoker> callInvoker = _callInvoker.lock();
|
|
38
38
|
if (callInvoker == nullptr) {
|
|
39
|
-
throw std::runtime_error("Cannot install global.NitroModulesProxy - CallInvoker was null!");
|
|
39
|
+
throw std::runtime_error("Cannot install `global.NitroModulesProxy` - CallInvoker was null!");
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// 2. Wrap CallInvoker as Dispatcher
|
|
@@ -19,7 +19,7 @@ static inline std::exception_ptr makeException(const std::string& message) {
|
|
|
19
19
|
|
|
20
20
|
static inline std::string getExceptionMessage(const std::exception_ptr& exception) {
|
|
21
21
|
if (exception == nullptr) [[unlikely]] {
|
|
22
|
-
throw std::runtime_error("Cannot get error message of
|
|
22
|
+
throw std::runtime_error("Cannot get error message of a nullptr exception_ptr!");
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
try {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["Sync.ts"],"mappings":"","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -47,6 +47,17 @@ Object.keys(_Constructor).forEach(function (key) {
|
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
|
+
var _Sync = require("./Sync");
|
|
51
|
+
Object.keys(_Sync).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _Sync[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _Sync[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
50
61
|
var _HybridView = require("./views/HybridView");
|
|
51
62
|
Object.keys(_HybridView).forEach(function (key) {
|
|
52
63
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_HybridObject","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_NitroModules","_AnyMap","_Constructor","_HybridView","_getHostComponent"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,aAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA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;IAAA;EAAA;AAAA;
|
|
1
|
+
{"version":3,"names":["_HybridObject","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_NitroModules","_AnyMap","_Constructor","_Sync","_HybridView","_getHostComponent"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,aAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,aAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,aAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,aAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,aAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,aAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,aAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,OAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,OAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,OAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,OAAA,CAAA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AAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAU,iBAAA,CAAAV,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAM,iBAAA,CAAAV,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["Sync.ts"],"mappings":"","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export * from './HybridObject';
|
|
|
4
4
|
export * from './NitroModules';
|
|
5
5
|
export * from './AnyMap';
|
|
6
6
|
export * from './Constructor';
|
|
7
|
+
export * from './Sync';
|
|
7
8
|
export * from './views/HybridView';
|
|
8
9
|
export * from './views/getHostComponent';
|
|
9
10
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,cAAc,gBAAgB;AAC9B,cAAc,gBAAgB;AAC9B,cAAc,UAAU;AACxB,cAAc,eAAe;
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,cAAc,gBAAgB;AAC9B,cAAc,gBAAgB;AAC9B,cAAc,UAAU;AACxB,cAAc,eAAe;AAC7B,cAAc,QAAQ;AAEtB,cAAc,oBAAoB;AAClC,cAAc,0BAA0B","ignoreList":[]}
|