expo-modules-core 0.11.8 → 0.11.9

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 CHANGED
@@ -10,6 +10,12 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 0.11.9 — 2022-11-09
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - Fixed `~CallbackWrapper()` dangling pointer crashes when reloading the app on Android. ([#19699](https://github.com/expo/expo/pull/19699) by [@kudo](https://github.com/kudo), [@kudo](https://github.com/kudo))
18
+
13
19
  ## 0.11.8 — 2022-10-13
14
20
 
15
21
  ### 🐛 Bug fixes
@@ -6,7 +6,7 @@ apply plugin: 'maven-publish'
6
6
  apply plugin: "de.undercouch.download"
7
7
 
8
8
  group = 'host.exp.exponent'
9
- version = '0.11.8'
9
+ version = '0.11.9'
10
10
 
11
11
  buildscript {
12
12
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
@@ -161,7 +161,7 @@ android {
161
161
  targetSdkVersion safeExtGet("targetSdkVersion", 31)
162
162
  consumerProguardFiles 'proguard-rules.pro'
163
163
  versionCode 1
164
- versionName "0.11.8"
164
+ versionName "0.11.9"
165
165
 
166
166
  testInstrumentationRunner "expo.modules.TestRunner"
167
167
 
@@ -73,6 +73,7 @@ void JavaScriptModuleObject::registerSyncFunction(
73
73
 
74
74
  methodsMetadata.try_emplace(
75
75
  cName,
76
+ longLivedObjectCollection_,
76
77
  cName,
77
78
  args,
78
79
  false,
@@ -92,6 +93,7 @@ void JavaScriptModuleObject::registerAsyncFunction(
92
93
 
93
94
  methodsMetadata.try_emplace(
94
95
  cName,
96
+ longLivedObjectCollection_,
95
97
  cName,
96
98
  args,
97
99
  true,
@@ -111,6 +113,7 @@ void JavaScriptModuleObject::registerProperty(
111
113
  types[0] = desiredType;
112
114
 
113
115
  auto getterMetadata = MethodMetadata(
116
+ longLivedObjectCollection_,
114
117
  cName,
115
118
  0,
116
119
  false,
@@ -119,6 +122,7 @@ void JavaScriptModuleObject::registerProperty(
119
122
  );
120
123
 
121
124
  auto setterMetadata = MethodMetadata(
125
+ longLivedObjectCollection_,
122
126
  cName,
123
127
  1,
124
128
  false,
@@ -147,6 +151,7 @@ JavaScriptModuleObject::HostObject::~HostObject() {
147
151
  jsModule->methodsMetadata.clear();
148
152
  jsModule->constants.clear();
149
153
  jsModule->properties.clear();
154
+ jsModule->longLivedObjectCollection_->clear();
150
155
  }
151
156
 
152
157
  jsi::Value JavaScriptModuleObject::HostObject::get(jsi::Runtime &runtime,
@@ -228,4 +233,10 @@ std::vector<jsi::PropNameID> JavaScriptModuleObject::HostObject::getPropertyName
228
233
 
229
234
  return result;
230
235
  }
236
+
237
+ JavaScriptModuleObject::JavaScriptModuleObject(jni::alias_ref<jhybridobject> jThis)
238
+ : javaPart_(jni::make_global(jThis)) {
239
+ longLivedObjectCollection_ = std::make_shared<react::LongLivedObjectCollection>();
240
+ }
241
+
231
242
  } // namespace expo
@@ -4,6 +4,7 @@
4
4
 
5
5
  #include <fbjni/fbjni.h>
6
6
  #include <jsi/jsi.h>
7
+ #include <react/bridging/LongLivedObject.h>
7
8
  #include <react/jni/ReadableNativeArray.h>
8
9
  #include <jni/JCallback.h>
9
10
 
@@ -115,6 +116,9 @@ public:
115
116
  JavaScriptModuleObject *jsModule;
116
117
  };
117
118
 
119
+ private:
120
+ explicit JavaScriptModuleObject(jni::alias_ref<jhybridobject> jThis);
121
+
118
122
  private:
119
123
  friend HybridBase;
120
124
  /**
@@ -140,7 +144,10 @@ private:
140
144
  */
141
145
  std::map<std::string, std::pair<MethodMetadata, MethodMetadata>> properties;
142
146
 
143
- explicit JavaScriptModuleObject(jni::alias_ref<jhybridobject> jThis)
144
- : javaPart_(jni::make_global(jThis)) {}
147
+ /**
148
+ * The `LongLivedObjectCollection` to hold `LongLivedObject` (callbacks or promises) for this module.
149
+ */
150
+ std::shared_ptr<react::LongLivedObjectCollection> longLivedObjectCollection_;
151
+
145
152
  };
146
153
  } // namespace expo
@@ -19,10 +19,16 @@ namespace expo {
19
19
  // https://github.com/facebook/react-native/blob/7dceb9b63c0bfd5b13bf6d26f9530729506e9097/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp#L57
20
20
  jni::local_ref<react::JCxxCallbackImpl::JavaPart> createJavaCallbackFromJSIFunction(
21
21
  jsi::Function &&function,
22
+ std::weak_ptr<react::LongLivedObjectCollection> longLivedObjectCollection,
22
23
  jsi::Runtime &rt,
23
24
  std::shared_ptr<react::CallInvoker> jsInvoker
24
25
  ) {
25
- auto weakWrapper = react::CallbackWrapper::createWeak(std::move(function), rt,
26
+ auto strongLongLiveObjectCollection = longLivedObjectCollection.lock();
27
+ if (!strongLongLiveObjectCollection) {
28
+ throw std::runtime_error("The LongLivedObjectCollection for MethodMetadata is not alive.");
29
+ }
30
+ auto weakWrapper = react::CallbackWrapper::createWeak(strongLongLiveObjectCollection,
31
+ std::move(function), rt,
26
32
  std::move(jsInvoker));
27
33
 
28
34
  // This needs to be a shared_ptr because:
@@ -150,12 +156,14 @@ std::vector<jvalue> MethodMetadata::convertJSIArgsToJNI(
150
156
  }
151
157
 
152
158
  MethodMetadata::MethodMetadata(
159
+ std::weak_ptr<react::LongLivedObjectCollection> longLivedObjectCollection,
153
160
  std::string name,
154
161
  int args,
155
162
  bool isAsync,
156
163
  std::unique_ptr<int[]> desiredTypes,
157
164
  jni::global_ref<jobject> &&jBodyReference
158
- ) : name(std::move(name)),
165
+ ) : longLivedObjectCollection_(longLivedObjectCollection),
166
+ name(std::move(name)),
159
167
  args(args),
160
168
  isAsync(isAsync),
161
169
  desiredTypes(std::move(desiredTypes)),
@@ -308,12 +316,14 @@ jsi::Function MethodMetadata::createPromiseBody(
308
316
  auto &runtimeHolder = moduleRegistry->runtimeHolder;
309
317
  jobject resolve = createJavaCallbackFromJSIFunction(
310
318
  std::move(resolveJSIFn),
319
+ longLivedObjectCollection_,
311
320
  rt,
312
321
  runtimeHolder->jsInvoker
313
322
  ).release();
314
323
 
315
324
  jobject reject = createJavaCallbackFromJSIFunction(
316
325
  std::move(rejectJSIFn),
326
+ longLivedObjectCollection_,
317
327
  rt,
318
328
  runtimeHolder->jsInvoker
319
329
  ).release();
@@ -5,6 +5,7 @@
5
5
  #include <jsi/jsi.h>
6
6
  #include <fbjni/fbjni.h>
7
7
  #include <ReactCommon/TurboModuleUtils.h>
8
+ #include <react/bridging/LongLivedObject.h>
8
9
  #include <react/jni/ReadableNativeArray.h>
9
10
  #include <memory>
10
11
  #include <folly/dynamic.h>
@@ -52,6 +53,7 @@ public:
52
53
  std::unique_ptr<int[]> desiredTypes;
53
54
 
54
55
  MethodMetadata(
56
+ std::weak_ptr<react::LongLivedObjectCollection> longLivedObjectCollection,
55
57
  std::string name,
56
58
  int args,
57
59
  bool isAsync,
@@ -110,6 +112,8 @@ private:
110
112
  */
111
113
  std::shared_ptr<jsi::Function> body = nullptr;
112
114
 
115
+ std::weak_ptr<react::LongLivedObjectCollection> longLivedObjectCollection_;
116
+
113
117
  jsi::Function toSyncFunction(jsi::Runtime &runtime, JSIInteropModuleRegistry *moduleRegistry);
114
118
 
115
119
  jsi::Function toAsyncFunction(jsi::Runtime &runtime, JSIInteropModuleRegistry *moduleRegistry);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-modules-core",
3
- "version": "0.11.8",
3
+ "version": "0.11.9",
4
4
  "description": "The core of Expo Modules architecture",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -42,5 +42,5 @@
42
42
  "@testing-library/react-hooks": "^7.0.1",
43
43
  "expo-module-scripts": "^2.0.0"
44
44
  },
45
- "gitHead": "da2b9d2bb73100781b31906967669fe521d55e8a"
45
+ "gitHead": "903a8208ae60dc6d70fdc5b01c61b201af17faae"
46
46
  }