expo-modules-core 55.0.2 → 55.0.4
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/CHANGELOG.md +12 -0
- package/android/build.gradle +2 -2
- package/android/src/main/cpp/JSIContext.cpp +14 -2
- package/android/src/main/cpp/JSIContext.h +5 -14
- package/android/src/main/cpp/JavaScriptArrayBuffer.cpp +11 -12
- package/android/src/main/cpp/JavaScriptArrayBuffer.h +2 -7
- package/android/src/main/cpp/JavaScriptFunction.cpp +9 -13
- package/android/src/main/cpp/JavaScriptFunction.h +1 -7
- package/android/src/main/cpp/JavaScriptObject.cpp +78 -44
- package/android/src/main/cpp/JavaScriptObject.h +12 -17
- package/android/src/main/cpp/JavaScriptRuntime.cpp +1 -5
- package/android/src/main/cpp/JavaScriptRuntime.h +7 -1
- package/android/src/main/cpp/JavaScriptTypedArray.cpp +16 -18
- package/android/src/main/cpp/JavaScriptTypedArray.h +0 -6
- package/android/src/main/cpp/JavaScriptValue.cpp +48 -32
- package/android/src/main/cpp/JavaScriptValue.h +1 -7
- package/android/src/main/cpp/JavaScriptWeakObject.cpp +21 -15
- package/android/src/main/cpp/JavaScriptWeakObject.h +13 -10
- package/android/src/main/java/expo/modules/kotlin/AppContext.kt +13 -4
- package/android/src/main/java/expo/modules/kotlin/jni/JNIDeallocator.kt +10 -9
- package/android/src/main/java/expo/modules/kotlin/jni/JSIContext.kt +4 -4
- package/android/src/main/java/expo/modules/kotlin/jni/JavaCallback.kt +3 -3
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptArrayBuffer.kt +3 -3
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptFunction.kt +3 -3
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptModuleObject.kt +4 -4
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptObject.kt +3 -3
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptValue.kt +3 -3
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptWeakObject.kt +4 -3
- package/android/src/main/java/expo/modules/kotlin/jni/NativeArrayBuffer.kt +3 -3
- package/android/src/main/java/expo/modules/kotlin/jni/PromiseImpl.kt +5 -5
- package/android/src/main/java/expo/modules/kotlin/jni/decorators/JSDecoratorsBridgingObject.kt +4 -4
- package/android/src/main/java/expo/modules/kotlin/jni/worklets/Serializable.kt +3 -3
- package/ios/Core/Objects/ConstantDefinition.swift +9 -0
- package/ios/DevTools/ModuleDefinitionEncoder.swift +11 -14
- package/package.json +3 -3
- package/android/src/main/cpp/WeakRuntimeHolder.cpp +0 -24
- package/android/src/main/cpp/WeakRuntimeHolder.h +0 -40
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
#include "TypedArray.h"
|
|
4
4
|
#include "JavaScriptObject.h"
|
|
5
|
-
#include "WeakRuntimeHolder.h"
|
|
6
5
|
|
|
7
6
|
#include <fbjni/fbjni.h>
|
|
8
7
|
#include <fbjni/ByteBuffer.h>
|
|
@@ -36,11 +35,6 @@ public:
|
|
|
36
35
|
std::shared_ptr<jsi::Object> jsObject
|
|
37
36
|
);
|
|
38
37
|
|
|
39
|
-
JavaScriptTypedArray(
|
|
40
|
-
WeakRuntimeHolder runtime,
|
|
41
|
-
std::shared_ptr<jsi::Object> jsObject
|
|
42
|
-
);
|
|
43
|
-
|
|
44
38
|
/**
|
|
45
39
|
* Gets a raw kind of the underlying typed array.
|
|
46
40
|
*/
|
|
@@ -39,14 +39,7 @@ JavaScriptValue::JavaScriptValue(
|
|
|
39
39
|
std::weak_ptr<JavaScriptRuntime> runtime,
|
|
40
40
|
std::shared_ptr<jsi::Value> jsValue
|
|
41
41
|
) : runtimeHolder(std::move(runtime)), jsValue(std::move(jsValue)) {
|
|
42
|
-
runtimeHolder.
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
JavaScriptValue::JavaScriptValue(
|
|
46
|
-
WeakRuntimeHolder runtime,
|
|
47
|
-
std::shared_ptr<jsi::Value> jsValue
|
|
48
|
-
) : runtimeHolder(std::move(runtime)), jsValue(std::move(jsValue)) {
|
|
49
|
-
runtimeHolder.ensureRuntimeIsValid();
|
|
42
|
+
assert((!runtimeHolder.expired()) && "JS Runtime was used after deallocation");
|
|
50
43
|
}
|
|
51
44
|
|
|
52
45
|
std::shared_ptr<jsi::Value> JavaScriptValue::get() {
|
|
@@ -113,8 +106,11 @@ bool JavaScriptValue::isSymbol() {
|
|
|
113
106
|
|
|
114
107
|
bool JavaScriptValue::isFunction() {
|
|
115
108
|
if (jsValue->isObject()) {
|
|
116
|
-
auto
|
|
117
|
-
|
|
109
|
+
auto runtime = runtimeHolder.lock();
|
|
110
|
+
assert((runtime != nullptr) && "JS Runtime was used after deallocation");
|
|
111
|
+
auto &rawRuntime = runtime->get();
|
|
112
|
+
|
|
113
|
+
return jsValue->asObject(rawRuntime).isFunction(rawRuntime);
|
|
118
114
|
}
|
|
119
115
|
|
|
120
116
|
return false;
|
|
@@ -122,8 +118,11 @@ bool JavaScriptValue::isFunction() {
|
|
|
122
118
|
|
|
123
119
|
bool JavaScriptValue::isArray() {
|
|
124
120
|
if (jsValue->isObject()) {
|
|
125
|
-
auto
|
|
126
|
-
|
|
121
|
+
auto runtime = runtimeHolder.lock();
|
|
122
|
+
assert((runtime != nullptr) && "JS Runtime was used after deallocation");
|
|
123
|
+
auto &rawRuntime = runtime->get();
|
|
124
|
+
|
|
125
|
+
return jsValue->asObject(rawRuntime).isArray(rawRuntime);
|
|
127
126
|
}
|
|
128
127
|
|
|
129
128
|
return false;
|
|
@@ -135,8 +134,11 @@ bool JavaScriptValue::isObject() {
|
|
|
135
134
|
|
|
136
135
|
bool JavaScriptValue::isTypedArray() {
|
|
137
136
|
if (jsValue->isObject()) {
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
auto runtime = runtimeHolder.lock();
|
|
138
|
+
assert((runtime != nullptr) && "JS Runtime was used after deallocation");
|
|
139
|
+
auto &rawRuntime = runtime->get();
|
|
140
|
+
|
|
141
|
+
return expo::isTypedArray(rawRuntime, jsValue->getObject(rawRuntime));
|
|
140
142
|
}
|
|
141
143
|
return false;
|
|
142
144
|
}
|
|
@@ -150,46 +152,57 @@ double JavaScriptValue::getDouble() {
|
|
|
150
152
|
}
|
|
151
153
|
|
|
152
154
|
std::string JavaScriptValue::getString() {
|
|
153
|
-
auto
|
|
154
|
-
|
|
155
|
+
auto runtime = runtimeHolder.lock();
|
|
156
|
+
assert((runtime != nullptr) && "JS Runtime was used after deallocation");
|
|
157
|
+
auto &rawRuntime = runtime->get();
|
|
158
|
+
|
|
159
|
+
return jsValue->getString(rawRuntime).utf8(rawRuntime);
|
|
155
160
|
}
|
|
156
161
|
|
|
157
162
|
jni::local_ref<JavaScriptObject::javaobject> JavaScriptValue::getObject() {
|
|
158
|
-
auto
|
|
159
|
-
|
|
163
|
+
auto runtime = runtimeHolder.lock();
|
|
164
|
+
assert((runtime != nullptr) && "JS Runtime was used after deallocation");
|
|
165
|
+
auto &rawRuntime = runtime->get();
|
|
166
|
+
|
|
167
|
+
auto jsObject = std::make_shared<jsi::Object>(jsValue->getObject(rawRuntime));
|
|
160
168
|
return JavaScriptObject::newInstance(
|
|
161
|
-
|
|
169
|
+
expo::getJSIContext(rawRuntime),
|
|
162
170
|
runtimeHolder,
|
|
163
171
|
jsObject
|
|
164
172
|
);
|
|
165
173
|
}
|
|
166
174
|
|
|
167
175
|
jni::local_ref<JavaScriptFunction::javaobject> JavaScriptValue::jniGetFunction() {
|
|
168
|
-
auto
|
|
176
|
+
auto runtime = runtimeHolder.lock();
|
|
177
|
+
assert((runtime != nullptr) && "JS Runtime was used after deallocation");
|
|
178
|
+
auto &rawRuntime = runtime->get();
|
|
179
|
+
|
|
169
180
|
auto jsFunction = std::make_shared<jsi::Function>(
|
|
170
|
-
jsValue->getObject(
|
|
181
|
+
jsValue->getObject(rawRuntime).asFunction(rawRuntime));
|
|
171
182
|
return JavaScriptFunction::newInstance(
|
|
172
|
-
|
|
183
|
+
expo::getJSIContext(rawRuntime),
|
|
173
184
|
runtimeHolder,
|
|
174
185
|
jsFunction
|
|
175
186
|
);
|
|
176
187
|
}
|
|
177
188
|
|
|
178
189
|
jni::local_ref<jni::JArrayClass<JavaScriptValue::javaobject>> JavaScriptValue::getArray() {
|
|
179
|
-
auto
|
|
180
|
-
|
|
190
|
+
auto runtime = runtimeHolder.lock();
|
|
191
|
+
assert((runtime != nullptr) && "JS Runtime was used after deallocation");
|
|
192
|
+
auto &rawRuntime = runtime->get();
|
|
193
|
+
auto jsiContext = expo::getJSIContext(rawRuntime);
|
|
181
194
|
|
|
182
195
|
auto jsArray = jsValue
|
|
183
|
-
->getObject(
|
|
184
|
-
.asArray(
|
|
185
|
-
size_t size = jsArray.size(
|
|
196
|
+
->getObject(rawRuntime)
|
|
197
|
+
.asArray(rawRuntime);
|
|
198
|
+
size_t size = jsArray.size(rawRuntime);
|
|
186
199
|
|
|
187
200
|
auto result = jni::JArrayClass<JavaScriptValue::javaobject>::newArray(size);
|
|
188
201
|
for (size_t i = 0; i < size; i++) {
|
|
189
202
|
auto element = JavaScriptValue::newInstance(
|
|
190
|
-
|
|
203
|
+
jsiContext,
|
|
191
204
|
runtimeHolder,
|
|
192
|
-
std::make_shared<jsi::Value>(jsArray.getValueAtIndex(
|
|
205
|
+
std::make_shared<jsi::Value>(jsArray.getValueAtIndex(rawRuntime, i))
|
|
193
206
|
);
|
|
194
207
|
|
|
195
208
|
result->setElement(i, element.release());
|
|
@@ -208,10 +221,13 @@ jni::local_ref<jstring> JavaScriptValue::jniGetString() {
|
|
|
208
221
|
}
|
|
209
222
|
|
|
210
223
|
jni::local_ref<JavaScriptTypedArray::javaobject> JavaScriptValue::getTypedArray() {
|
|
211
|
-
auto
|
|
212
|
-
|
|
224
|
+
auto runtime = runtimeHolder.lock();
|
|
225
|
+
assert((runtime != nullptr) && "JS Runtime was used after deallocation");
|
|
226
|
+
auto &rawRuntime = runtime->get();
|
|
227
|
+
|
|
228
|
+
auto jsObject = std::make_shared<jsi::Object>(jsValue->getObject(rawRuntime));
|
|
213
229
|
return JavaScriptTypedArray::newInstance(
|
|
214
|
-
|
|
230
|
+
expo::getJSIContext(rawRuntime),
|
|
215
231
|
runtimeHolder,
|
|
216
232
|
jsObject
|
|
217
233
|
);
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
#pragma once
|
|
4
4
|
|
|
5
5
|
#include "JSIObjectWrapper.h"
|
|
6
|
-
#include "WeakRuntimeHolder.h"
|
|
7
6
|
#include "JavaScriptTypedArray.h"
|
|
8
7
|
#include "JavaScriptArrayBuffer.h"
|
|
9
8
|
#include "JNIDeallocator.h"
|
|
@@ -49,11 +48,6 @@ public:
|
|
|
49
48
|
std::shared_ptr<jsi::Value> jsValue
|
|
50
49
|
);
|
|
51
50
|
|
|
52
|
-
JavaScriptValue(
|
|
53
|
-
WeakRuntimeHolder runtime,
|
|
54
|
-
std::shared_ptr<jsi::Value> jsValue
|
|
55
|
-
);
|
|
56
|
-
|
|
57
51
|
std::shared_ptr<jsi::Value> get() override;
|
|
58
52
|
|
|
59
53
|
std::string kind();
|
|
@@ -95,7 +89,7 @@ public:
|
|
|
95
89
|
private:
|
|
96
90
|
friend HybridBase;
|
|
97
91
|
|
|
98
|
-
|
|
92
|
+
std::weak_ptr<JavaScriptRuntime> runtimeHolder;
|
|
99
93
|
std::shared_ptr<jsi::Value> jsValue;
|
|
100
94
|
|
|
101
95
|
jni::local_ref<jstring> jniKind();
|
|
@@ -7,8 +7,8 @@ namespace expo {
|
|
|
7
7
|
|
|
8
8
|
void JavaScriptWeakObject::registerNatives() {
|
|
9
9
|
registerHybrid({
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
makeNativeMethod("lock", JavaScriptWeakObject::lock),
|
|
11
|
+
});
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
std::shared_ptr<jsi::WeakObject> JavaScriptWeakObject::getWeak() {
|
|
@@ -16,26 +16,30 @@ std::shared_ptr<jsi::WeakObject> JavaScriptWeakObject::getWeak() {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
jni::local_ref<JavaScriptObject::javaobject> JavaScriptWeakObject::lock() {
|
|
19
|
-
|
|
19
|
+
auto jsRuntime = _runtimeHolder.lock();
|
|
20
|
+
assert((jsRuntime != nullptr) && "JS Runtime was used after deallocation");
|
|
21
|
+
auto &rawRuntime = jsRuntime->get();
|
|
20
22
|
|
|
21
|
-
jsi::Value value = _weakObject->lock(
|
|
23
|
+
jsi::Value value = _weakObject->lock(rawRuntime);
|
|
22
24
|
if (value.isUndefined()) {
|
|
23
25
|
return nullptr;
|
|
24
26
|
}
|
|
25
27
|
std::shared_ptr<jsi::Object> objectPtr =
|
|
26
|
-
|
|
28
|
+
std::make_shared<jsi::Object>(value.asObject(rawRuntime));
|
|
27
29
|
if (!objectPtr) {
|
|
28
30
|
return nullptr;
|
|
29
31
|
}
|
|
30
|
-
return JavaScriptObject::newInstance(
|
|
31
|
-
|
|
32
|
+
return JavaScriptObject::newInstance(
|
|
33
|
+
expo::getJSIContext(rawRuntime),
|
|
34
|
+
_runtimeHolder, objectPtr
|
|
35
|
+
);
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
jni::local_ref<jni::HybridClass<JavaScriptWeakObject, Destructible>::javaobject>
|
|
35
39
|
JavaScriptWeakObject::newInstance(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
JSIContext *jSIContext,
|
|
41
|
+
std::weak_ptr<JavaScriptRuntime> runtime,
|
|
42
|
+
std::shared_ptr<jsi::Object> jsObject) {
|
|
39
43
|
auto weakObject = JavaScriptWeakObject::newObjectCxxArgs(std::move(runtime),
|
|
40
44
|
std::move(jsObject));
|
|
41
45
|
jSIContext->jniDeallocator->addReference(weakObject);
|
|
@@ -43,12 +47,14 @@ JavaScriptWeakObject::newInstance(
|
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
JavaScriptWeakObject::JavaScriptWeakObject(
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
const std::weak_ptr<JavaScriptRuntime> &runtime,
|
|
51
|
+
const std::shared_ptr<jsi::Object> &jsObject
|
|
48
52
|
) : _runtimeHolder(std::move(runtime)) {
|
|
49
|
-
_runtimeHolder.
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
auto jsRuntime = _runtimeHolder.lock();
|
|
54
|
+
assert((jsRuntime != nullptr) && "JS Runtime was used after deallocation");
|
|
55
|
+
auto &rawRuntime = jsRuntime->get();
|
|
56
|
+
|
|
57
|
+
_weakObject = std::make_shared<jsi::WeakObject>(rawRuntime, *jsObject);
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
} // namespace expo
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
#include "JNIDeallocator.h"
|
|
6
6
|
#include "JavaScriptObject.h"
|
|
7
|
-
#include "WeakRuntimeHolder.h"
|
|
8
7
|
|
|
9
8
|
#include <fbjni/fbjni.h>
|
|
10
9
|
#include <jsi/jsi.h>
|
|
@@ -22,32 +21,36 @@ class JavaScriptObject;
|
|
|
22
21
|
* Represents to a jsi::WeakObject.
|
|
23
22
|
*/
|
|
24
23
|
class JavaScriptWeakObject
|
|
25
|
-
|
|
24
|
+
: public jni::HybridClass<JavaScriptWeakObject, Destructible> {
|
|
26
25
|
public:
|
|
27
26
|
static auto constexpr kJavaDescriptor =
|
|
28
|
-
|
|
27
|
+
"Lexpo/modules/kotlin/jni/JavaScriptWeakObject;";
|
|
29
28
|
static auto constexpr TAG = "JavaScriptWeakObject";
|
|
30
29
|
|
|
31
30
|
static void registerNatives();
|
|
32
31
|
|
|
33
32
|
static jni::local_ref<
|
|
34
|
-
|
|
35
|
-
newInstance(
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
jni::HybridClass<JavaScriptWeakObject, Destructible>::javaobject
|
|
34
|
+
> newInstance(
|
|
35
|
+
JSIContext *jSIContext,
|
|
36
|
+
std::weak_ptr<JavaScriptRuntime> runtime,
|
|
37
|
+
std::shared_ptr<jsi::Object> jsObject
|
|
38
|
+
);
|
|
38
39
|
|
|
39
40
|
jni::local_ref<JavaScriptObject::javaobject> lock();
|
|
40
41
|
|
|
41
42
|
std::shared_ptr<jsi::WeakObject> getWeak();
|
|
42
43
|
|
|
43
44
|
private:
|
|
44
|
-
JavaScriptWeakObject(
|
|
45
|
-
|
|
45
|
+
JavaScriptWeakObject(
|
|
46
|
+
const std::weak_ptr<JavaScriptRuntime> &runtime,
|
|
47
|
+
const std::shared_ptr<jsi::Object> &jsObject
|
|
48
|
+
);
|
|
46
49
|
|
|
47
50
|
private:
|
|
48
51
|
friend HybridBase;
|
|
49
52
|
|
|
50
|
-
|
|
53
|
+
std::weak_ptr<JavaScriptRuntime> _runtimeHolder;
|
|
51
54
|
std::shared_ptr<jsi::WeakObject> _weakObject;
|
|
52
55
|
};
|
|
53
56
|
|
|
@@ -264,16 +264,25 @@ class AppContext(
|
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
internal fun onDestroy() = trace("AppContext.onDestroy") {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
267
|
+
runtime.reactContext?.run {
|
|
268
|
+
removeLifecycleEventListener(reactLifecycleDelegate)
|
|
269
|
+
removeActivityEventListener(reactLifecycleDelegate)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
with(registry) {
|
|
273
|
+
post(EventName.MODULE_DESTROY)
|
|
274
|
+
cleanUp()
|
|
275
|
+
}
|
|
276
|
+
|
|
270
277
|
modulesQueue.cancel(ContextDestroyedException())
|
|
271
278
|
mainQueue.cancel(ContextDestroyedException())
|
|
272
279
|
backgroundCoroutineScope.cancel(ContextDestroyedException())
|
|
273
|
-
|
|
280
|
+
|
|
281
|
+
runtime.deallocate()
|
|
274
282
|
if (uiRuntimeHolder.isInitialized()) {
|
|
275
283
|
uiRuntime.deallocate()
|
|
276
284
|
}
|
|
285
|
+
|
|
277
286
|
logger.info("✅ AppContext was destroyed")
|
|
278
287
|
}
|
|
279
288
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
package expo.modules.kotlin.jni
|
|
2
2
|
|
|
3
|
+
import com.facebook.jni.HybridData
|
|
3
4
|
import expo.modules.core.interfaces.DoNotStrip
|
|
4
5
|
import java.lang.ref.PhantomReference
|
|
5
6
|
import java.lang.ref.ReferenceQueue
|
|
6
|
-
import java.lang.ref.WeakReference
|
|
7
7
|
|
|
8
8
|
@DoNotStrip
|
|
9
9
|
interface Destructible {
|
|
10
|
-
fun
|
|
10
|
+
fun getHybridDataForJNIDeallocator(): HybridData
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
@DoNotStrip
|
|
@@ -24,7 +24,7 @@ class JNIDeallocator(shouldCreateDestructorThread: Boolean = true) : AutoCloseab
|
|
|
24
24
|
/**
|
|
25
25
|
* A registry to keep all active [Destructible] objects and their [PhantomReference]s
|
|
26
26
|
*/
|
|
27
|
-
private val destructorMap = mutableMapOf<PhantomReference<Destructible>,
|
|
27
|
+
private val destructorMap = mutableMapOf<PhantomReference<Destructible>, HybridData>()
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* A thread that clears your registry when an object has been garbage collected
|
|
@@ -43,9 +43,8 @@ class JNIDeallocator(shouldCreateDestructorThread: Boolean = true) : AutoCloseab
|
|
|
43
43
|
*/
|
|
44
44
|
@DoNotStrip
|
|
45
45
|
fun addReference(destructible: Destructible): Unit = synchronized(this) {
|
|
46
|
-
val weakRef = WeakReference(destructible)
|
|
47
46
|
val phantomRef = PhantomReference(destructible, referenceQueue)
|
|
48
|
-
destructorMap[phantomRef] =
|
|
47
|
+
destructorMap[phantomRef] = destructible.getHybridDataForJNIDeallocator()
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
/**
|
|
@@ -53,7 +52,7 @@ class JNIDeallocator(shouldCreateDestructorThread: Boolean = true) : AutoCloseab
|
|
|
53
52
|
*/
|
|
54
53
|
internal fun deallocate() = synchronized(this) {
|
|
55
54
|
destructorMap.values.forEach {
|
|
56
|
-
it.
|
|
55
|
+
it.resetNative()
|
|
57
56
|
}
|
|
58
57
|
destructorMap.clear()
|
|
59
58
|
destructorThread?.interrupt()
|
|
@@ -64,15 +63,17 @@ class JNIDeallocator(shouldCreateDestructorThread: Boolean = true) : AutoCloseab
|
|
|
64
63
|
* and are present in the memory.
|
|
65
64
|
*/
|
|
66
65
|
fun inspectMemory() = synchronized(this) {
|
|
67
|
-
destructorMap
|
|
66
|
+
destructorMap
|
|
67
|
+
.values
|
|
68
|
+
.filter { synchronized(it) { it.isValid } }
|
|
69
|
+
.map { it }
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
private fun Thread.deallocator() {
|
|
71
73
|
while (!isInterrupted) {
|
|
72
74
|
try {
|
|
73
|
-
// Referent of PhantomReference were garbage collected so we can remove it from our registry.
|
|
74
|
-
// Note that we don't have to call `deallocate` method - it was called [com.facebook.jni.HybridData].
|
|
75
75
|
val current = referenceQueue.remove()
|
|
76
|
+
destructorMap[current]?.resetNative()
|
|
76
77
|
synchronized(this@JNIDeallocator) {
|
|
77
78
|
destructorMap.remove(current)
|
|
78
79
|
}
|
|
@@ -124,14 +124,14 @@ class JSIContext @DoNotStrip internal constructor(
|
|
|
124
124
|
|
|
125
125
|
@Throws(Throwable::class)
|
|
126
126
|
protected fun finalize() {
|
|
127
|
-
|
|
127
|
+
close()
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
override fun
|
|
130
|
+
override fun close() {
|
|
131
131
|
mHybridData.resetNative()
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
override fun
|
|
135
|
-
|
|
134
|
+
override fun getHybridDataForJNIDeallocator(): HybridData {
|
|
135
|
+
return mHybridData
|
|
136
136
|
}
|
|
137
137
|
}
|
|
@@ -115,10 +115,10 @@ class JavaCallback @DoNotStrip internal constructor(@DoNotStrip private val mHyb
|
|
|
115
115
|
|
|
116
116
|
@Throws(Throwable::class)
|
|
117
117
|
protected fun finalize() {
|
|
118
|
-
|
|
118
|
+
mHybridData.resetNative()
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
override fun
|
|
122
|
-
mHybridData
|
|
121
|
+
override fun getHybridDataForJNIDeallocator(): HybridData {
|
|
122
|
+
return mHybridData
|
|
123
123
|
}
|
|
124
124
|
}
|
|
@@ -26,10 +26,10 @@ class JavaScriptArrayBuffer @DoNotStrip private constructor(@DoNotStrip private
|
|
|
26
26
|
|
|
27
27
|
@Throws(Throwable::class)
|
|
28
28
|
protected fun finalize() {
|
|
29
|
-
|
|
29
|
+
mHybridData.resetNative()
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
override fun
|
|
33
|
-
mHybridData
|
|
32
|
+
override fun getHybridDataForJNIDeallocator(): HybridData {
|
|
33
|
+
return mHybridData
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -42,10 +42,10 @@ class JavaScriptFunction<ReturnType : Any?> @DoNotStrip private constructor(@DoN
|
|
|
42
42
|
|
|
43
43
|
@Throws(Throwable::class)
|
|
44
44
|
protected fun finalize() {
|
|
45
|
-
|
|
45
|
+
mHybridData.resetNative()
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
override fun
|
|
49
|
-
mHybridData
|
|
48
|
+
override fun getHybridDataForJNIDeallocator(): HybridData {
|
|
49
|
+
return mHybridData
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -34,14 +34,14 @@ class JavaScriptModuleObject(
|
|
|
34
34
|
|
|
35
35
|
@Throws(Throwable::class)
|
|
36
36
|
protected fun finalize() {
|
|
37
|
-
deallocate()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
override fun deallocate() {
|
|
41
37
|
mHybridData.resetNative()
|
|
42
38
|
}
|
|
43
39
|
|
|
44
40
|
override fun toString(): String {
|
|
45
41
|
return "JavaScriptModuleObject_$name"
|
|
46
42
|
}
|
|
43
|
+
|
|
44
|
+
override fun getHybridDataForJNIDeallocator(): HybridData {
|
|
45
|
+
return mHybridData
|
|
46
|
+
}
|
|
47
47
|
}
|
|
@@ -144,11 +144,11 @@ open class JavaScriptObject @DoNotStrip internal constructor(@DoNotStrip private
|
|
|
144
144
|
|
|
145
145
|
@Throws(Throwable::class)
|
|
146
146
|
protected fun finalize() {
|
|
147
|
-
|
|
147
|
+
mHybridData.resetNative()
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
override fun
|
|
151
|
-
mHybridData
|
|
150
|
+
override fun getHybridDataForJNIDeallocator(): HybridData {
|
|
151
|
+
return mHybridData
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -56,10 +56,10 @@ class JavaScriptValue @DoNotStrip private constructor(@DoNotStrip private val mH
|
|
|
56
56
|
|
|
57
57
|
@Throws(Throwable::class)
|
|
58
58
|
protected fun finalize() {
|
|
59
|
-
|
|
59
|
+
mHybridData.resetNative()
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
override fun
|
|
63
|
-
mHybridData
|
|
62
|
+
override fun getHybridDataForJNIDeallocator(): HybridData {
|
|
63
|
+
return mHybridData
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -12,11 +12,12 @@ import expo.modules.core.interfaces.DoNotStrip
|
|
|
12
12
|
class JavaScriptWeakObject @DoNotStrip internal constructor(@DoNotStrip private val mHybridData: HybridData) : Destructible {
|
|
13
13
|
@Throws(Throwable::class)
|
|
14
14
|
protected fun finalize() {
|
|
15
|
-
|
|
15
|
+
mHybridData.resetNative()
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
override fun
|
|
19
|
-
mHybridData
|
|
18
|
+
override fun getHybridDataForJNIDeallocator(): HybridData {
|
|
19
|
+
return mHybridData
|
|
20
20
|
}
|
|
21
|
+
|
|
21
22
|
external fun lock(): JavaScriptObject
|
|
22
23
|
}
|
|
@@ -44,11 +44,11 @@ class NativeArrayBuffer : Destructible, ArrayBuffer {
|
|
|
44
44
|
|
|
45
45
|
@Throws(Throwable::class)
|
|
46
46
|
protected fun finalize() {
|
|
47
|
-
|
|
47
|
+
mHybridData.resetNative()
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
override fun
|
|
51
|
-
mHybridData
|
|
50
|
+
override fun getHybridDataForJNIDeallocator(): HybridData {
|
|
51
|
+
return mHybridData
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
companion object {
|
|
@@ -45,11 +45,11 @@ class PromiseImpl @DoNotStrip internal constructor(
|
|
|
45
45
|
callback.invoke(result)
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
override fun resolve(result: Collection<Any?>) {
|
|
48
|
+
override fun resolve(result: Collection<Any?>) = checkIfWasSettled {
|
|
49
49
|
callback.invoke(result)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
override fun resolve(result: Map<String, Any?>) {
|
|
52
|
+
override fun resolve(result: Map<String, Any?>) = checkIfWasSettled {
|
|
53
53
|
callback.invoke(result)
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -62,11 +62,11 @@ class PromiseImpl @DoNotStrip internal constructor(
|
|
|
62
62
|
private inline fun checkIfWasSettled(body: () -> Unit) {
|
|
63
63
|
if (wasSettled) {
|
|
64
64
|
val exception = PromiseAlreadySettledException(fullFunctionName ?: "unknown")
|
|
65
|
-
val
|
|
65
|
+
val jsLogger = appContextHolder?.get()?.jsLogger
|
|
66
66
|
// We want to report that a promise was settled twice in the development build.
|
|
67
67
|
// However, in production, the app should crash.
|
|
68
|
-
if (BuildConfig.DEBUG &&
|
|
69
|
-
|
|
68
|
+
if (BuildConfig.DEBUG && jsLogger != null) {
|
|
69
|
+
jsLogger.error("Trying to resolve promise that was already settled", exception)
|
|
70
70
|
logger.error("Trying to resolve promise that was already settled", exception)
|
|
71
71
|
return
|
|
72
72
|
}
|
package/android/src/main/java/expo/modules/kotlin/jni/decorators/JSDecoratorsBridgingObject.kt
CHANGED
|
@@ -98,13 +98,13 @@ class JSDecoratorsBridgingObject(jniDeallocator: JNIDeallocator) : Destructible
|
|
|
98
98
|
)
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
@Throws(Throwable::class)
|
|
102
|
+
protected fun finalize() {
|
|
102
103
|
mHybridData.resetNative()
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
deallocate()
|
|
106
|
+
override fun getHybridDataForJNIDeallocator(): HybridData {
|
|
107
|
+
return mHybridData
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
fun ObjectDefinitionData.exportConstants() {
|
|
@@ -36,10 +36,10 @@ class Serializable @DoNotStrip private constructor(
|
|
|
36
36
|
|
|
37
37
|
@Throws(Throwable::class)
|
|
38
38
|
protected fun finalize() {
|
|
39
|
-
|
|
39
|
+
mHybridData.resetNative()
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
override fun
|
|
43
|
-
mHybridData
|
|
42
|
+
override fun getHybridDataForJNIDeallocator(): HybridData {
|
|
43
|
+
return mHybridData
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -10,6 +10,11 @@ protocol AnyConstantDefinition {
|
|
|
10
10
|
Creates the JavaScript object representing the constant property descriptor.
|
|
11
11
|
*/
|
|
12
12
|
func buildDescriptor(appContext: AppContext) throws -> JavaScriptObject
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
Returns the raw value of the constant for encoding purposes.
|
|
16
|
+
*/
|
|
17
|
+
func getRawValue() -> Any?
|
|
13
18
|
}
|
|
14
19
|
|
|
15
20
|
public final class ConstantDefinition<ReturnType>: AnyDefinition, AnyConstantDefinition {
|
|
@@ -59,6 +64,10 @@ public final class ConstantDefinition<ReturnType>: AnyDefinition, AnyConstantDef
|
|
|
59
64
|
return try getter?()
|
|
60
65
|
}
|
|
61
66
|
|
|
67
|
+
internal func getRawValue() -> Any? {
|
|
68
|
+
return try? getter?()
|
|
69
|
+
}
|
|
70
|
+
|
|
62
71
|
/**
|
|
63
72
|
Creates the JavaScript function that will be used as a getter of the constant.
|
|
64
73
|
*/
|