expo-modules-core 1.6.0 → 1.7.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 (78) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/android/build.gradle +26 -19
  3. package/android/src/main/cpp/JSIInteropModuleRegistry.cpp +19 -2
  4. package/android/src/main/cpp/JSIInteropModuleRegistry.h +11 -1
  5. package/android/src/main/cpp/JavaScriptModuleObject.cpp +14 -13
  6. package/android/src/main/cpp/JavaScriptModuleObject.h +4 -1
  7. package/android/src/main/cpp/JavaScriptObject.cpp +12 -27
  8. package/android/src/main/cpp/JavaScriptObject.h +2 -8
  9. package/android/src/main/cpp/JavaScriptRuntime.cpp +44 -17
  10. package/android/src/main/cpp/JavaScriptRuntime.h +9 -16
  11. package/android/src/main/cpp/MethodMetadata.cpp +12 -13
  12. package/android/src/main/cpp/types/FrontendConverter.cpp +20 -3
  13. package/android/src/main/cpp/types/JNIToJSIConverter.cpp +7 -8
  14. package/android/src/main/java/expo/modules/adapters/react/ModuleRegistryAdapter.java +1 -14
  15. package/android/src/main/java/expo/modules/adapters/react/NativeModulesProxy.java +1 -11
  16. package/android/src/main/java/expo/modules/adapters/react/views/ViewManagerAdapterUtils.java +0 -54
  17. package/android/src/main/java/expo/modules/core/ModuleRegistry.java +0 -16
  18. package/android/src/main/java/expo/modules/core/ViewManager.java +3 -130
  19. package/android/src/main/java/expo/modules/kotlin/AppContext.kt +21 -3
  20. package/android/src/main/java/expo/modules/kotlin/KotlinInteropModuleRegistry.kt +3 -2
  21. package/android/src/main/java/expo/modules/kotlin/Promise.kt +5 -1
  22. package/android/src/main/java/expo/modules/kotlin/activityresult/ActivityResultsManager.kt +1 -2
  23. package/android/src/main/java/expo/modules/kotlin/classcomponent/ClassComponentBuilder.kt +18 -1
  24. package/android/src/main/java/expo/modules/kotlin/defaultmodules/ErrorManagerModule.kt +12 -1
  25. package/android/src/main/java/expo/modules/kotlin/functions/AnyFunction.kt +1 -0
  26. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunction.kt +1 -13
  27. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionBuilder.kt +106 -13
  28. package/android/src/main/java/expo/modules/kotlin/functions/FunctionBuilder.kt +103 -0
  29. package/android/src/main/java/expo/modules/kotlin/jni/JSIInteropModuleRegistry.kt +2 -1
  30. package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptModuleObject.kt +10 -2
  31. package/android/src/main/java/expo/modules/kotlin/modules/Module.kt +32 -1
  32. package/android/src/main/java/expo/modules/kotlin/objects/ObjectDefinitionBuilder.kt +43 -20
  33. package/android/src/main/java/expo/modules/kotlin/objects/PropertyComponent.kt +11 -7
  34. package/android/src/main/java/expo/modules/kotlin/objects/PropertyComponentBuilder.kt +35 -3
  35. package/android/src/main/java/expo/modules/kotlin/sharedobjects/SharedObjectRegistry.kt +12 -2
  36. package/android/src/main/java/expo/modules/kotlin/sharedobjects/SharedObjectTypeConverter.kt +11 -3
  37. package/android/src/main/java/expo/modules/kotlin/types/EnumTypeConverter.kt +0 -1
  38. package/android/src/main/java/expo/modules/kotlin/types/MapTypeConverter.kt +0 -2
  39. package/android/src/main/java/expo/modules/kotlin/types/ReadableArgumentsTypeConverter.kt +24 -0
  40. package/android/src/main/java/expo/modules/kotlin/types/TypeConverterProvider.kt +3 -2
  41. package/android/src/main/java/expo/modules/kotlin/viewevent/ViewEventDelegate.kt +0 -2
  42. package/android/src/main/java/expo/modules/kotlin/views/AnyViewProp.kt +2 -1
  43. package/android/src/main/java/expo/modules/kotlin/views/ConcreteViewProp.kt +3 -2
  44. package/android/src/main/java/expo/modules/kotlin/views/ViewDefinitionBuilder.kt +1 -2
  45. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinition.kt +3 -4
  46. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerType.kt +5 -0
  47. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerWrapperDelegate.kt +1 -1
  48. package/android/src/main/java/expo/modules/kotlin/views/ViewTypeConverter.kt +3 -3
  49. package/android/src/reactnative/expo/modules/kotlin/ReactNativeCompatibleHelper.kt +12 -0
  50. package/android/src/reactnative72/expo/modules/kotlin/ReactNativeCompatibleHelper.kt +12 -0
  51. package/android-annotation/build.gradle +6 -3
  52. package/android-annotation-processor/build.gradle +6 -3
  53. package/build/errors/UnavailabilityError.d.ts.map +1 -1
  54. package/build/errors/UnavailabilityError.js +1 -1
  55. package/build/errors/UnavailabilityError.js.map +1 -1
  56. package/build/sweet/setUpErrorManager.fx.js +5 -1
  57. package/build/sweet/setUpErrorManager.fx.js.map +1 -1
  58. package/build/uuid/v4.js +2 -7
  59. package/build/uuid/v4.js.map +1 -1
  60. package/common/cpp/JSIUtils.cpp +23 -2
  61. package/common/cpp/JSIUtils.h +12 -2
  62. package/common/cpp/LazyObject.cpp +1 -1
  63. package/common/cpp/ObjectDeallocator.cpp +21 -0
  64. package/common/cpp/ObjectDeallocator.h +37 -0
  65. package/ios/JSI/EXJSIUtils.h +1 -12
  66. package/ios/JSI/EXJSIUtils.mm +5 -27
  67. package/ios/JSI/EXJavaScriptObject.mm +8 -21
  68. package/ios/ReactDelegates/EXReactCompatibleHelpers.m +7 -7
  69. package/ios/Swift/Views/ViewModuleWrapper.swift +3 -1
  70. package/package.json +2 -2
  71. package/src/errors/UnavailabilityError.ts +1 -1
  72. package/src/sweet/setUpErrorManager.fx.ts +6 -1
  73. package/src/uuid/v4.ts +2 -6
  74. package/tsconfig.json +1 -1
  75. package/android/src/main/cpp/ObjectDeallocator.h +0 -25
  76. package/android/src/main/java/expo/modules/adapters/react/views/SimpleViewManagerAdapter.java +0 -62
  77. package/android/src/main/java/expo/modules/adapters/react/views/ViewGroupManagerAdapter.java +0 -62
  78. package/ios/JSI/EXObjectDeallocator.h +0 -27
@@ -1,5 +1,6 @@
1
1
  package expo.modules.kotlin.sharedobjects
2
2
 
3
+ import com.facebook.react.bridge.Dynamic
3
4
  import expo.modules.kotlin.AppContext
4
5
  import expo.modules.kotlin.exception.InvalidSharedObjectException
5
6
  import expo.modules.kotlin.jni.CppType
@@ -13,15 +14,22 @@ class SharedObjectTypeConverter<T : SharedObject>(
13
14
  ) : NullAwareTypeConverter<T>(type.isMarkedNullable) {
14
15
  @Suppress("UNCHECKED_CAST")
15
16
  override fun convertNonOptional(value: Any, context: AppContext?): T {
16
- val id = SharedObjectId(value as Int)
17
+ val id = SharedObjectId(
18
+ if (value is Dynamic) {
19
+ value.asInt()
20
+ } else {
21
+ value as Int
22
+ }
23
+ )
24
+
17
25
  val appContext = context.toStrongReference()
18
- val result = appContext.sharedObjectRegistry.toNativeObject(id)
26
+ val result = id.toNativeObject(appContext)
19
27
  ?: throw InvalidSharedObjectException(type)
20
28
 
21
29
  return result as T
22
30
  }
23
31
 
24
- override fun getCppRequiredTypes() = ExpectedType(CppType.SHARED_OBJECT_ID)
32
+ override fun getCppRequiredTypes() = ExpectedType(CppType.SHARED_OBJECT_ID, CppType.INT)
25
33
 
26
34
  override fun isTrivial(): Boolean = false
27
35
  }
@@ -88,7 +88,6 @@ class EnumTypeConverter(
88
88
  parameterName: String
89
89
  ): Enum<*> {
90
90
  // To obtain the value of parameter, we have to find a property that is connected with this parameter.
91
- @Suppress("UNCHECKED_CAST")
92
91
  val parameterProperty = enumClass
93
92
  .declaredMemberProperties
94
93
  .find { it.name == parameterName }
@@ -1,5 +1,3 @@
1
- @file:OptIn(ExperimentalStdlibApi::class)
2
-
3
1
  package expo.modules.kotlin.types
4
2
 
5
3
  import com.facebook.react.bridge.Dynamic
@@ -0,0 +1,24 @@
1
+ package expo.modules.kotlin.types
2
+
3
+ import com.facebook.react.bridge.Dynamic
4
+ import com.facebook.react.bridge.ReadableMap
5
+ import expo.modules.core.arguments.MapArguments
6
+ import expo.modules.core.arguments.ReadableArguments
7
+ import expo.modules.kotlin.jni.CppType
8
+ import expo.modules.kotlin.jni.ExpectedType
9
+
10
+ class ReadableArgumentsTypeConverter(
11
+ isOptional: Boolean,
12
+ ) : DynamicAwareTypeConverters<ReadableArguments>(isOptional) {
13
+ override fun convertFromDynamic(value: Dynamic): ReadableArguments {
14
+ return MapArguments(value.asMap().toHashMap())
15
+ }
16
+
17
+ override fun convertFromAny(value: Any): ReadableArguments {
18
+ return MapArguments((value as ReadableMap).toHashMap())
19
+ }
20
+
21
+ override fun getCppRequiredTypes(): ExpectedType = ExpectedType(CppType.READABLE_MAP)
22
+
23
+ override fun isTrivial(): Boolean = false
24
+ }
@@ -1,5 +1,3 @@
1
- @file:OptIn(ExperimentalStdlibApi::class)
2
-
3
1
  package expo.modules.kotlin.types
4
2
 
5
3
  import android.graphics.Color
@@ -9,6 +7,7 @@ import com.facebook.react.bridge.Dynamic
9
7
  import com.facebook.react.bridge.ReadableArray
10
8
  import com.facebook.react.bridge.ReadableMap
11
9
  import expo.modules.annotation.Config
10
+ import expo.modules.core.arguments.ReadableArguments
12
11
  import expo.modules.kotlin.apifeatures.EitherType
13
12
  import expo.modules.kotlin.exception.MissingTypeConverter
14
13
  import expo.modules.kotlin.jni.CppType
@@ -288,6 +287,8 @@ object TypeConverterProviderImpl : TypeConverterProvider {
288
287
  File::class to FileTypeConverter(isOptional),
289
288
 
290
289
  Any::class to AnyTypeConverter(isOptional),
290
+
291
+ ReadableArguments::class to ReadableArgumentsTypeConverter(isOptional),
291
292
  )
292
293
 
293
294
  if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
@@ -1,5 +1,3 @@
1
- @file:OptIn(ExperimentalStdlibApi::class)
2
-
3
1
  package expo.modules.kotlin.viewevent
4
2
 
5
3
  import android.view.View
@@ -2,13 +2,14 @@ package expo.modules.kotlin.views
2
2
 
3
3
  import android.view.View
4
4
  import com.facebook.react.bridge.Dynamic
5
+ import expo.modules.kotlin.AppContext
5
6
  import expo.modules.kotlin.types.AnyType
6
7
 
7
8
  abstract class AnyViewProp(
8
9
  val name: String,
9
10
  internal val type: AnyType
10
11
  ) {
11
- abstract fun set(prop: Dynamic, onView: View)
12
+ abstract fun set(prop: Dynamic, onView: View, appContext: AppContext? = null)
12
13
 
13
14
  abstract val isNullable: Boolean
14
15
  }
@@ -2,6 +2,7 @@ package expo.modules.kotlin.views
2
2
 
3
3
  import android.view.View
4
4
  import com.facebook.react.bridge.Dynamic
5
+ import expo.modules.kotlin.AppContext
5
6
  import expo.modules.kotlin.exception.PropSetException
6
7
  import expo.modules.kotlin.exception.exceptionDecorator
7
8
  import expo.modules.kotlin.types.AnyType
@@ -13,11 +14,11 @@ class ConcreteViewProp<ViewType : View, PropType>(
13
14
  ) : AnyViewProp(name, propType) {
14
15
 
15
16
  @Suppress("UNCHECKED_CAST")
16
- override fun set(prop: Dynamic, onView: View) {
17
+ override fun set(prop: Dynamic, onView: View, appContext: AppContext?) {
17
18
  exceptionDecorator({
18
19
  PropSetException(name, onView::class, it)
19
20
  }) {
20
- setter(onView as ViewType, type.convert(prop) as PropType)
21
+ setter(onView as ViewType, type.convert(prop, appContext) as PropType)
21
22
  }
22
23
  }
23
24
 
@@ -1,4 +1,3 @@
1
- @file:OptIn(ExperimentalStdlibApi::class)
2
1
  @file:Suppress("FunctionName")
3
2
 
4
3
  package expo.modules.kotlin.views
@@ -52,6 +51,7 @@ class ViewDefinitionBuilder<T : View>(
52
51
  asyncFunctions.forEach { (_, function) ->
53
52
  function.runOnQueue(Queues.MAIN)
54
53
  function.ownerType = viewType
54
+ function.canTakeOwner = true
55
55
  }
56
56
 
57
57
  return ViewManagerDefinition(
@@ -186,7 +186,6 @@ class ViewDefinitionBuilder<T : View>(
186
186
  } else {
187
187
  AsyncFunctionComponent(name, arrayOf({ typeOf<P0>() }.toAnyType<P0>())) { body(it[0] as P0) }
188
188
  }.also {
189
- it.ownerType = viewType
190
189
  asyncFunctions[name] = it
191
190
  }
192
191
  }
@@ -5,7 +5,6 @@ import android.view.View
5
5
  import android.view.ViewGroup
6
6
  import com.facebook.react.bridge.ReactContext
7
7
  import expo.modules.adapters.react.NativeModulesProxy
8
- import expo.modules.core.ViewManager
9
8
  import expo.modules.kotlin.AppContext
10
9
  import expo.modules.kotlin.exception.CodedException
11
10
  import expo.modules.kotlin.functions.BaseAsyncFunctionComponent
@@ -25,11 +24,11 @@ class ViewManagerDefinition(
25
24
 
26
25
  val propsNames: List<String> = props.keys.toList()
27
26
 
28
- fun getViewManagerType(): ViewManager.ViewManagerType {
27
+ fun getViewManagerType(): ViewManagerType {
29
28
  return if (ViewGroup::class.java.isAssignableFrom(viewType)) {
30
- ViewManager.ViewManagerType.GROUP
29
+ ViewManagerType.GROUP
31
30
  } else {
32
- ViewManager.ViewManagerType.SIMPLE
31
+ ViewManagerType.SIMPLE
33
32
  }
34
33
  }
35
34
 
@@ -0,0 +1,5 @@
1
+ package expo.modules.kotlin.views
2
+
3
+ enum class ViewManagerType {
4
+ SIMPLE, GROUP
5
+ }
@@ -73,7 +73,7 @@ class ViewManagerWrapperDelegate(internal var moduleHolder: ModuleHolder) {
73
73
  val key = iterator.nextKey()
74
74
  expoProps[key]?.let { expoProp ->
75
75
  try {
76
- expoProp.set(propsMap.getDynamic(key), view)
76
+ expoProp.set(propsMap.getDynamic(key), view, moduleHolder.module._appContext)
77
77
  } catch (exception: Throwable) {
78
78
  // The view wasn't constructed correctly, so errors are expected.
79
79
  // We can ignore them.
@@ -2,7 +2,6 @@ package expo.modules.kotlin.views
2
2
 
3
3
  import android.view.View
4
4
  import expo.modules.kotlin.AppContext
5
- import expo.modules.kotlin.Utils
6
5
  import expo.modules.kotlin.exception.Exceptions
7
6
  import expo.modules.kotlin.exception.NullArgumentException
8
7
  import expo.modules.kotlin.jni.CppType
@@ -17,7 +16,9 @@ class ViewTypeConverter<T : View>(
17
16
  ) : TypeConverter<T>() {
18
17
 
19
18
  override fun convert(value: Any?, context: AppContext?): T? {
20
- Utils.assertMainThread()
19
+ val appContext = context.toStrongReference()
20
+ appContext.assertMainThread()
21
+
21
22
  if (value == null) {
22
23
  if (type.isMarkedNullable) {
23
24
  return null
@@ -25,7 +26,6 @@ class ViewTypeConverter<T : View>(
25
26
  throw NullArgumentException()
26
27
  }
27
28
 
28
- val appContext = context.toStrongReference()
29
29
  val viewTag = value as Int
30
30
  val view = appContext.findView<T>(viewTag)
31
31
  if (!type.isMarkedNullable && view == null) {
@@ -0,0 +1,12 @@
1
+ package expo.modules.kotlin
2
+
3
+ import com.facebook.react.bridge.CatalystInstance
4
+ import com.facebook.react.turbomodule.core.NativeMethodCallInvokerHolderImpl
5
+
6
+ typealias NativeMethodCallInvokerHolderImplCompatible = NativeMethodCallInvokerHolderImpl
7
+
8
+ object ReactNativeCompatibleHelper {
9
+ fun getNativeMethodCallInvokerHolderImplCompatible(catalystInstance: CatalystInstance): NativeMethodCallInvokerHolderImplCompatible {
10
+ return catalystInstance.nativeMethodCallInvokerHolder as NativeMethodCallInvokerHolderImplCompatible
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ package expo.modules.kotlin
2
+
3
+ import com.facebook.react.bridge.CatalystInstance
4
+ import com.facebook.react.turbomodule.core.CallInvokerHolderImpl
5
+
6
+ typealias NativeMethodCallInvokerHolderImplCompatible = CallInvokerHolderImpl
7
+
8
+ object ReactNativeCompatibleHelper {
9
+ fun getNativeMethodCallInvokerHolderImplCompatible(catalystInstance: CatalystInstance): NativeMethodCallInvokerHolderImplCompatible {
10
+ return catalystInstance.nativeCallInvokerHolder as NativeMethodCallInvokerHolderImplCompatible
11
+ }
12
+ }
@@ -35,9 +35,12 @@ buildscript {
35
35
  }
36
36
  }
37
37
 
38
- java {
39
- sourceCompatibility = JavaVersion.VERSION_11
40
- targetCompatibility = JavaVersion.VERSION_11
38
+ def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
39
+ if (agpVersion.tokenize('.')[0].toInteger() < 8) {
40
+ java {
41
+ sourceCompatibility = JavaVersion.VERSION_11
42
+ targetCompatibility = JavaVersion.VERSION_11
43
+ }
41
44
  }
42
45
 
43
46
  dependencies {
@@ -35,9 +35,12 @@ buildscript {
35
35
  }
36
36
  }
37
37
 
38
- java {
39
- sourceCompatibility = JavaVersion.VERSION_11
40
- targetCompatibility = JavaVersion.VERSION_11
38
+ def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
39
+ if (agpVersion.tokenize('.')[0].toInteger() < 8) {
40
+ java {
41
+ sourceCompatibility = JavaVersion.VERSION_11
42
+ targetCompatibility = JavaVersion.VERSION_11
43
+ }
41
44
  }
42
45
 
43
46
  dependencies {
@@ -1 +1 @@
1
- {"version":3,"file":"UnavailabilityError.d.ts","sourceRoot":"","sources":["../../src/errors/UnavailabilityError.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,UAAU;gBACrC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;CAMrD"}
1
+ {"version":3,"file":"UnavailabilityError.d.ts","sourceRoot":"","sources":["../../src/errors/UnavailabilityError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,UAAU;gBACrC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;CAMrD"}
@@ -1,5 +1,5 @@
1
- import Platform from '../Platform';
2
1
  import { CodedError } from './CodedError';
2
+ import Platform from '../Platform';
3
3
  /**
4
4
  * A class for errors to be thrown when a property is accessed which is
5
5
  * unavailable, unsupported, or not currently implemented on the running
@@ -1 +1 @@
1
- {"version":3,"file":"UnavailabilityError.js","sourceRoot":"","sources":["../../src/errors/UnavailabilityError.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;GAIG;AACH,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IACjD,YAAY,UAAkB,EAAE,YAAoB;QAClD,KAAK,CACH,iBAAiB,EACjB,0BAA0B,UAAU,IAAI,YAAY,wBAAwB,QAAQ,CAAC,EAAE,oEAAoE,CAC5J,CAAC;IACJ,CAAC;CACF","sourcesContent":["import Platform from '../Platform';\nimport { CodedError } from './CodedError';\n\n/**\n * A class for errors to be thrown when a property is accessed which is\n * unavailable, unsupported, or not currently implemented on the running\n * platform.\n */\nexport class UnavailabilityError extends CodedError {\n constructor(moduleName: string, propertyName: string) {\n super(\n 'ERR_UNAVAILABLE',\n `The method or property ${moduleName}.${propertyName} is not available on ${Platform.OS}, are you sure you've linked all the native dependencies properly?`\n );\n }\n}\n"]}
1
+ {"version":3,"file":"UnavailabilityError.js","sourceRoot":"","sources":["../../src/errors/UnavailabilityError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,QAAQ,MAAM,aAAa,CAAC;AAEnC;;;;GAIG;AACH,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IACjD,YAAY,UAAkB,EAAE,YAAoB;QAClD,KAAK,CACH,iBAAiB,EACjB,0BAA0B,UAAU,IAAI,YAAY,wBAAwB,QAAQ,CAAC,EAAE,oEAAoE,CAC5J,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { CodedError } from './CodedError';\nimport Platform from '../Platform';\n\n/**\n * A class for errors to be thrown when a property is accessed which is\n * unavailable, unsupported, or not currently implemented on the running\n * platform.\n */\nexport class UnavailabilityError extends CodedError {\n constructor(moduleName: string, propertyName: string) {\n super(\n 'ERR_UNAVAILABLE',\n `The method or property ${moduleName}.${propertyName} is not available on ${Platform.OS}, are you sure you've linked all the native dependencies properly?`\n );\n }\n}\n"]}
@@ -1,13 +1,17 @@
1
+ import NativeErrorManager from './NativeErrorManager';
1
2
  import { EventEmitter } from '../EventEmitter';
2
3
  import Platform from '../Platform';
3
4
  import { CodedError } from '../errors/CodedError';
4
- import NativeErrorManager from './NativeErrorManager';
5
5
  if (__DEV__ && Platform.OS === 'android' && NativeErrorManager) {
6
6
  const onNewException = 'ExpoModulesCoreErrorManager.onNewException';
7
+ const onNewWarning = 'ExpoModulesCoreErrorManager.onNewWarning';
7
8
  const eventEmitter = new EventEmitter(NativeErrorManager);
8
9
  eventEmitter.addListener(onNewException, ({ message }) => {
9
10
  console.error(message);
10
11
  });
12
+ eventEmitter.addListener(onNewWarning, ({ message }) => {
13
+ console.warn(message);
14
+ });
11
15
  }
12
16
  // We have to export `CodedError` via global object to use in later in the C++ code.
13
17
  globalThis.ExpoModulesCore_CodedError = CodedError;
@@ -1 +1 @@
1
- {"version":3,"file":"setUpErrorManager.fx.js","sourceRoot":"","sources":["../../src/sweet/setUpErrorManager.fx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAEtD,IAAI,OAAO,IAAI,QAAQ,CAAC,EAAE,KAAK,SAAS,IAAI,kBAAkB,EAAE;IAC9D,MAAM,cAAc,GAAG,4CAA4C,CAAC;IACpE,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,kBAAkB,CAAC,CAAC;IAE1D,YAAY,CAAC,WAAW,CAAC,cAAc,EAAE,CAAC,EAAE,OAAO,EAAuB,EAAE,EAAE;QAC5E,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;CACJ;AAED,oFAAoF;AACpF,UAAU,CAAC,0BAA0B,GAAG,UAAU,CAAC","sourcesContent":["import { EventEmitter } from '../EventEmitter';\nimport Platform from '../Platform';\nimport { CodedError } from '../errors/CodedError';\nimport NativeErrorManager from './NativeErrorManager';\n\nif (__DEV__ && Platform.OS === 'android' && NativeErrorManager) {\n const onNewException = 'ExpoModulesCoreErrorManager.onNewException';\n const eventEmitter = new EventEmitter(NativeErrorManager);\n\n eventEmitter.addListener(onNewException, ({ message }: { message: string }) => {\n console.error(message);\n });\n}\n\n// We have to export `CodedError` via global object to use in later in the C++ code.\nglobalThis.ExpoModulesCore_CodedError = CodedError;\n"]}
1
+ {"version":3,"file":"setUpErrorManager.fx.js","sourceRoot":"","sources":["../../src/sweet/setUpErrorManager.fx.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,IAAI,OAAO,IAAI,QAAQ,CAAC,EAAE,KAAK,SAAS,IAAI,kBAAkB,EAAE;IAC9D,MAAM,cAAc,GAAG,4CAA4C,CAAC;IACpE,MAAM,YAAY,GAAG,0CAA0C,CAAC;IAChE,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,kBAAkB,CAAC,CAAC;IAE1D,YAAY,CAAC,WAAW,CAAC,cAAc,EAAE,CAAC,EAAE,OAAO,EAAuB,EAAE,EAAE;QAC5E,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,YAAY,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC,EAAE,OAAO,EAAuB,EAAE,EAAE;QAC1E,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;CACJ;AAED,oFAAoF;AACpF,UAAU,CAAC,0BAA0B,GAAG,UAAU,CAAC","sourcesContent":["import NativeErrorManager from './NativeErrorManager';\nimport { EventEmitter } from '../EventEmitter';\nimport Platform from '../Platform';\nimport { CodedError } from '../errors/CodedError';\n\nif (__DEV__ && Platform.OS === 'android' && NativeErrorManager) {\n const onNewException = 'ExpoModulesCoreErrorManager.onNewException';\n const onNewWarning = 'ExpoModulesCoreErrorManager.onNewWarning';\n const eventEmitter = new EventEmitter(NativeErrorManager);\n\n eventEmitter.addListener(onNewException, ({ message }: { message: string }) => {\n console.error(message);\n });\n\n eventEmitter.addListener(onNewWarning, ({ message }: { message: string }) => {\n console.warn(message);\n });\n}\n\n// We have to export `CodedError` via global object to use in later in the C++ code.\nglobalThis.ExpoModulesCore_CodedError = CodedError;\n"]}
package/build/uuid/v4.js CHANGED
@@ -8,13 +8,8 @@ export function uuidv4(options, buf, offset) {
8
8
  options = undefined;
9
9
  }
10
10
  options = options || undefined;
11
- let rnds = [];
12
- if (options && 'random' in options) {
13
- rnds = options.random;
14
- }
15
- else if (options && 'rng' in options) {
16
- rnds = (options.rng || rng)();
17
- }
11
+ // @ts-expect-error
12
+ const rnds = options?.random || (options?.rng || rng)();
18
13
  // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
19
14
  rnds[6] = (rnds[6] & 0x0f) | 0x40;
20
15
  rnds[8] = (rnds[8] & 0x3f) | 0x80;
@@ -1 +1 @@
1
- {"version":3,"file":"v4.js","sourceRoot":"","sources":["../../src/uuid/v4.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAC5C,OAAO,GAAG,MAAM,WAAW,CAAC;AAO5B,MAAM,UAAU,MAAM,CACpB,OAAqC,EACrC,GAAO,EACP,MAAe;IAEf,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;IAE/B,IAAI,MAAM,GAAoB,IAAI,CAAC;IAEnC,IAAI,OAAO,OAAO,IAAI,QAAQ,EAAE;QAC9B,MAAM,GAAG,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACrD,OAAO,GAAG,SAAS,CAAC;KACrB;IAED,OAAO,GAAG,OAAO,IAAI,SAAS,CAAC;IAE/B,IAAI,IAAI,GAAa,EAAE,CAAC;IACxB,IAAI,OAAO,IAAI,QAAQ,IAAI,OAAO,EAAE;QAClC,IAAI,GAAG,OAAO,CAAC,MAAkB,CAAC;KACnC;SAAM,IAAI,OAAO,IAAI,KAAK,IAAI,OAAO,EAAE;QACtC,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,EAAc,CAAC;KAC3C;IAED,gEAAgE;IAChE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAClC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAElC,oCAAoC;IACpC,IAAI,MAAM,EAAE;QACV,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE;YAC9B,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;SAC3B;KACF;IAED,OAAO,MAAM,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import bytesToUuid from './lib/bytesToUuid';\nimport rng from './lib/rng';\nimport { OutputBuffer, V4Options } from './types/uuid.types';\n\n/**\n * DO NOT USE this function in security-sensitive contexts.\n */\nexport function uuidv4(options?: V4Options): string;\nexport function uuidv4<T extends OutputBuffer>(\n options: V4Options | null | undefined,\n buf?: T,\n offset?: number\n) {\n const i = (buf && offset) || 0;\n\n let buffer: number[] | null = null;\n\n if (typeof options == 'string') {\n buffer = options === 'binary' ? new Array(16) : null;\n options = undefined;\n }\n\n options = options || undefined;\n\n let rnds: number[] = [];\n if (options && 'random' in options) {\n rnds = options.random as number[];\n } else if (options && 'rng' in options) {\n rnds = (options.rng || rng)() as number[];\n }\n\n // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n\n // Copy bytes to buffer, if provided\n if (buffer) {\n for (let ii = 0; ii < 16; ++ii) {\n buffer[i + ii] = rnds[ii];\n }\n }\n\n return buffer || bytesToUuid(rnds);\n}\n"]}
1
+ {"version":3,"file":"v4.js","sourceRoot":"","sources":["../../src/uuid/v4.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAC5C,OAAO,GAAG,MAAM,WAAW,CAAC;AAO5B,MAAM,UAAU,MAAM,CACpB,OAAqC,EACrC,GAAO,EACP,MAAe;IAEf,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;IAE/B,IAAI,MAAM,GAAoB,IAAI,CAAC;IAEnC,IAAI,OAAO,OAAO,IAAI,QAAQ,EAAE;QAC9B,MAAM,GAAG,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACrD,OAAO,GAAG,SAAS,CAAC;KACrB;IAED,OAAO,GAAG,OAAO,IAAI,SAAS,CAAC;IAE/B,mBAAmB;IACnB,MAAM,IAAI,GAAa,OAAO,EAAE,MAAM,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC;IAElE,gEAAgE;IAChE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAClC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAElC,oCAAoC;IACpC,IAAI,MAAM,EAAE;QACV,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE;YAC9B,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;SAC3B;KACF;IAED,OAAO,MAAM,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import bytesToUuid from './lib/bytesToUuid';\nimport rng from './lib/rng';\nimport { OutputBuffer, V4Options } from './types/uuid.types';\n\n/**\n * DO NOT USE this function in security-sensitive contexts.\n */\nexport function uuidv4(options?: V4Options): string;\nexport function uuidv4<T extends OutputBuffer>(\n options: V4Options | null | undefined,\n buf?: T,\n offset?: number\n) {\n const i = (buf && offset) || 0;\n\n let buffer: number[] | null = null;\n\n if (typeof options == 'string') {\n buffer = options === 'binary' ? new Array(16) : null;\n options = undefined;\n }\n\n options = options || undefined;\n\n // @ts-expect-error\n const rnds: number[] = options?.random || (options?.rng || rng)();\n\n // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n\n // Copy bytes to buffer, if provided\n if (buffer) {\n for (let ii = 0; ii < 16; ++ii) {\n buffer[i + ii] = rnds[ii];\n }\n }\n\n return buffer || bytesToUuid(rnds);\n}\n"]}
@@ -2,7 +2,7 @@
2
2
 
3
3
  #include "JSIUtils.h"
4
4
 
5
- namespace expo {
5
+ namespace expo::common {
6
6
 
7
7
  std::vector<jsi::PropNameID> jsiArrayToPropNameIdsVector(jsi::Runtime &runtime, const jsi::Array &array) {
8
8
  size_t size = array.size(runtime);
@@ -17,4 +17,25 @@ std::vector<jsi::PropNameID> jsiArrayToPropNameIdsVector(jsi::Runtime &runtime,
17
17
  return vector;
18
18
  }
19
19
 
20
- } // namespace expo
20
+ void definePropertyOnJSIObject(
21
+ jsi::Runtime &runtime,
22
+ jsi::Object *jsthis,
23
+ const char *name,
24
+ jsi::Object descriptor
25
+ ) {
26
+ jsi::Object global = runtime.global();
27
+ jsi::Object objectClass = global.getPropertyAsObject(runtime, "Object");
28
+ jsi::Function definePropertyFunction = objectClass.getPropertyAsFunction(
29
+ runtime,
30
+ "defineProperty"
31
+ );
32
+
33
+ // This call is basically the same as `Object.defineProperty(object, name, descriptor)` in JS
34
+ definePropertyFunction.callWithThis(runtime, objectClass, {
35
+ jsi::Value(runtime, *jsthis),
36
+ jsi::String::createFromUtf8(runtime, name),
37
+ std::move(descriptor),
38
+ });
39
+ }
40
+
41
+ } // namespace expo::common
@@ -7,13 +7,23 @@
7
7
 
8
8
  namespace jsi = facebook::jsi;
9
9
 
10
- namespace expo {
10
+ namespace expo::common {
11
11
 
12
12
  /**
13
13
  Converts `jsi::Array` to a vector with prop name ids (`std::vector<jsi::PropNameID>`).
14
14
  */
15
15
  std::vector<jsi::PropNameID> jsiArrayToPropNameIdsVector(jsi::Runtime &runtime, const jsi::Array &array);
16
16
 
17
- } // namespace expo
17
+ /**
18
+ Calls Object.defineProperty(jsThis, name, descriptor)`.
19
+ */
20
+ void definePropertyOnJSIObject(
21
+ jsi::Runtime &runtime,
22
+ jsi::Object *jsthis,
23
+ const char *name,
24
+ jsi::Object descriptor
25
+ );
26
+
27
+ } // namespace expo::common
18
28
 
19
29
  #endif // __cplusplus
@@ -37,7 +37,7 @@ std::vector<jsi::PropNameID> LazyObject::getPropertyNames(jsi::Runtime &runtime)
37
37
  }
38
38
  if (backedObject) {
39
39
  jsi::Array propertyNames = backedObject->getPropertyNames(runtime);
40
- return jsiArrayToPropNameIdsVector(runtime, propertyNames);
40
+ return common::jsiArrayToPropNameIdsVector(runtime, propertyNames);
41
41
  }
42
42
  return {};
43
43
  }
@@ -0,0 +1,21 @@
1
+ // Copyright 2022-present 650 Industries. All rights reserved.
2
+
3
+ #include "ObjectDeallocator.h"
4
+ #include "JSIUtils.h"
5
+
6
+ namespace expo::common {
7
+
8
+ void setDeallocator(
9
+ jsi::Runtime &runtime,
10
+ const std::shared_ptr<jsi::Object> &jsThis,
11
+ ObjectDeallocator::Block deallocatorBlock,
12
+ const std::string &key
13
+ ) {
14
+ std::shared_ptr<ObjectDeallocator> hostObjectPtr = std::make_shared<ObjectDeallocator>(
15
+ deallocatorBlock
16
+ );
17
+ jsi::Object jsDeallocator = jsi::Object::createFromHostObject(runtime, hostObjectPtr);
18
+ jsThis->setProperty(runtime, key.c_str(), jsi::Value(runtime, jsDeallocator));
19
+ }
20
+
21
+ } // namespace expo::common
@@ -0,0 +1,37 @@
1
+ // Copyright 2022-present 650 Industries. All rights reserved.
2
+
3
+ #ifdef __cplusplus
4
+
5
+ #import <jsi/jsi.h>
6
+
7
+ namespace jsi = facebook::jsi;
8
+
9
+ namespace expo::common {
10
+
11
+ class JSI_EXPORT ObjectDeallocator : public jsi::HostObject {
12
+ public:
13
+ typedef std::function<void()> Block;
14
+
15
+ ObjectDeallocator(const Block deallocator) : deallocator(deallocator) {};
16
+
17
+ virtual ~ObjectDeallocator() {
18
+ deallocator();
19
+ }
20
+
21
+ const Block deallocator;
22
+
23
+ }; // class ObjectDeallocator
24
+
25
+ /**
26
+ Sets the deallocator block on a given object, which is called when the object is being deallocated.
27
+ */
28
+ void setDeallocator(
29
+ jsi::Runtime &runtime,
30
+ const std::shared_ptr<jsi::Object> &jsThis,
31
+ ObjectDeallocator::Block deallocatorBlock,
32
+ const std::string &key = "__expo_object_deallocator__"
33
+ );
34
+
35
+ } // namespace expo::common
36
+
37
+ #endif
@@ -7,7 +7,7 @@
7
7
  #import <jsi/jsi.h>
8
8
  #import <ReactCommon/RCTTurboModule.h>
9
9
  #import <ReactCommon/TurboModuleUtils.h>
10
- #import <ExpoModulesCore/EXObjectDeallocator.h>
10
+ #import <ExpoModulesCore/ObjectDeallocator.h>
11
11
 
12
12
  namespace jsi = facebook::jsi;
13
13
  namespace react = facebook::react;
@@ -53,17 +53,6 @@ std::shared_ptr<jsi::Object> createWeakRef(jsi::Runtime &runtime, std::shared_pt
53
53
  */
54
54
  std::shared_ptr<jsi::Object> derefWeakRef(jsi::Runtime &runtime, std::shared_ptr<jsi::Object> object);
55
55
 
56
- #pragma mark - Define property
57
-
58
- void defineProperty(jsi::Runtime &runtime, const jsi::Object *object, const char *name, jsi::Value value);
59
-
60
- #pragma mark - Deallocator
61
-
62
- /**
63
- Sets the deallocator block on a given object, which is called when the object is being deallocated.
64
- */
65
- void setDeallocator(jsi::Runtime &runtime, std::shared_ptr<jsi::Object> object, ObjectDeallocatorBlock deallocatorBlock);
66
-
67
56
  #pragma mark - Errors
68
57
 
69
58
  jsi::Value makeCodedError(jsi::Runtime &runtime, NSString *code, NSString *message);
@@ -5,6 +5,7 @@
5
5
  #import <React/RCTUtils.h>
6
6
  #import <ExpoModulesCore/EXJSIConversions.h>
7
7
  #import <ExpoModulesCore/EXJSIUtils.h>
8
+ #import <ExpoModulesCore/JSIUtils.h>
8
9
 
9
10
  namespace expo {
10
11
 
@@ -110,7 +111,10 @@ std::shared_ptr<jsi::Function> createClass(jsi::Runtime &runtime, const char *na
110
111
  return jsi::Value::undefined();
111
112
  });
112
113
 
113
- defineProperty(runtime, &prototype, nativeConstructorKey.c_str(), jsi::Value(runtime, nativeConstructor));
114
+ jsi::Object descriptor(runtime);
115
+ descriptor.setProperty(runtime, "value", jsi::Value(runtime, nativeConstructor));
116
+
117
+ common::definePropertyOnJSIObject(runtime, &prototype, nativeConstructorKey.c_str(), std::move(descriptor));
114
118
 
115
119
  return std::make_shared<jsi::Function>(klass.asFunction(runtime));
116
120
  }
@@ -161,32 +165,6 @@ std::shared_ptr<jsi::Object> derefWeakRef(jsi::Runtime &runtime, std::shared_ptr
161
165
  return std::make_shared<jsi::Object>(ref.asObject(runtime));
162
166
  }
163
167
 
164
- #pragma mark - Define property
165
-
166
- void defineProperty(jsi::Runtime &runtime, const jsi::Object *object, const char *name, jsi::Value value) {
167
- jsi::Object global = runtime.global();
168
- jsi::Object objectClass = global.getPropertyAsObject(runtime, "Object");
169
- jsi::Function definePropertyFunction = objectClass.getPropertyAsFunction(runtime, "defineProperty");
170
-
171
- jsi::Object descriptor(runtime);
172
- descriptor.setProperty(runtime, "value", value);
173
-
174
- definePropertyFunction.callWithThis(runtime, objectClass, {
175
- jsi::Value(runtime, *object),
176
- jsi::String::createFromUtf8(runtime, name),
177
- std::move(descriptor),
178
- });
179
- }
180
-
181
- #pragma mark - Deallocator
182
-
183
- void setDeallocator(jsi::Runtime &runtime, std::shared_ptr<jsi::Object> object, ObjectDeallocatorBlock deallocatorBlock) {
184
- std::shared_ptr<expo::ObjectDeallocator> hostObjectPtr = std::make_shared<ObjectDeallocator>(deallocatorBlock);
185
- jsi::Object jsObject = jsi::Object::createFromHostObject(runtime, hostObjectPtr);
186
-
187
- object->setProperty(runtime, "__expo_object_deallocator__", jsi::Value(runtime, jsObject));
188
- }
189
-
190
168
  #pragma mark - Errors
191
169
 
192
170
  jsi::Value makeCodedError(jsi::Runtime &runtime, NSString *code, NSString *message) {
@@ -6,6 +6,7 @@
6
6
  #import <ExpoModulesCore/EXJavaScriptRuntime.h>
7
7
  #import <ExpoModulesCore/EXJavaScriptWeakObject.h>
8
8
  #import <ExpoModulesCore/EXJSIUtils.h>
9
+ #import <ExpoModulesCore/JSIUtils.h>
9
10
 
10
11
  @implementation EXJavaScriptObject {
11
12
  /**
@@ -73,34 +74,20 @@
73
74
  - (void)defineProperty:(nonnull NSString *)name descriptor:(nonnull EXJavaScriptObject *)descriptor
74
75
  {
75
76
  jsi::Runtime *runtime = [_runtime get];
76
- jsi::Object global = runtime->global();
77
- jsi::Object objectClass = global.getPropertyAsObject(*runtime, "Object");
78
- jsi::Function definePropertyFunction = objectClass.getPropertyAsFunction(*runtime, "defineProperty");
79
-
80
- // This call is basically the same as `Object.defineProperty(object, name, descriptor)` in JS
81
- definePropertyFunction.callWithThis(*runtime, objectClass, {
82
- jsi::Value(*runtime, *_jsObjectPtr.get()),
83
- jsi::String::createFromUtf8(*runtime, [name UTF8String]),
84
- std::move(*[descriptor get]),
85
- });
77
+ jsi::Object *jsThis = _jsObjectPtr.get();
78
+
79
+ expo::common::definePropertyOnJSIObject(*runtime, jsThis, [name UTF8String], std::move(*[descriptor get]));
86
80
  }
87
81
 
88
82
  - (void)defineProperty:(nonnull NSString *)name value:(nullable id)value options:(EXJavaScriptObjectPropertyDescriptor)options
89
83
  {
90
84
  jsi::Runtime *runtime = [_runtime get];
91
- jsi::Object global = runtime->global();
92
- jsi::Object objectClass = global.getPropertyAsObject(*runtime, "Object");
93
- jsi::Function definePropertyFunction = objectClass.getPropertyAsFunction(*runtime, "defineProperty");
94
- jsi::Object descriptor = [self preparePropertyDescriptorWithOptions:options];
85
+ jsi::Object *jsThis = _jsObjectPtr.get();
95
86
 
87
+ jsi::Object descriptor = [self preparePropertyDescriptorWithOptions:options];
96
88
  descriptor.setProperty(*runtime, "value", expo::convertObjCObjectToJSIValue(*runtime, value));
97
89
 
98
- // This call is basically the same as `Object.defineProperty(object, name, descriptor)` in JS
99
- definePropertyFunction.callWithThis(*runtime, objectClass, {
100
- jsi::Value(*runtime, *_jsObjectPtr.get()),
101
- jsi::String::createFromUtf8(*runtime, [name UTF8String]),
102
- std::move(descriptor),
103
- });
90
+ expo::common::definePropertyOnJSIObject(*runtime, jsThis, [name UTF8String], std::move(descriptor));
104
91
  }
105
92
 
106
93
  #pragma mark - WeakObject
@@ -114,7 +101,7 @@
114
101
 
115
102
  - (void)setObjectDeallocator:(void (^)(void))deallocatorBlock
116
103
  {
117
- expo::setDeallocator(*[_runtime get], _jsObjectPtr, deallocatorBlock);
104
+ expo::common::setDeallocator(*[_runtime get], _jsObjectPtr, deallocatorBlock);
118
105
  }
119
106
 
120
107
  #pragma mark - Equality