expo-modules-core 58.0.15 → 58.0.17
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 +32 -0
- package/android/build.gradle +2 -2
- package/android/prebuilt/metadata.json +2 -2
- package/android/prebuilt/native-libs.tar.xz +0 -0
- package/android/src/main/cpp/fabric/AndroidExpoViewComponentDescriptor.cpp +0 -18
- package/ios/Core/AppContext.swift +15 -12
- package/ios/Core/ArrayBuffers/ArrayBuffer.swift +4 -1
- package/ios/Core/Classes/ClassDefinition.swift +1 -1
- package/ios/Core/Classes/ClassRegistry.swift +5 -3
- package/ios/Core/Conversions.swift +43 -5
- package/ios/Core/DynamicTypes/AnyDynamicType.swift +1 -1
- package/ios/Core/DynamicTypes/DynamicArrayBufferType.swift +1 -1
- package/ios/Core/DynamicTypes/DynamicArrayType.swift +2 -2
- package/ios/Core/DynamicTypes/DynamicBoolType.swift +1 -1
- package/ios/Core/DynamicTypes/DynamicCodableType.swift +5 -5
- package/ios/Core/DynamicTypes/DynamicConvertibleType.swift +1 -7
- package/ios/Core/DynamicTypes/DynamicDataType.swift +1 -1
- package/ios/Core/DynamicTypes/DynamicDictionaryType.swift +2 -2
- package/ios/Core/DynamicTypes/DynamicEitherType.swift +1 -1
- package/ios/Core/DynamicTypes/DynamicEnumType.swift +1 -1
- package/ios/Core/DynamicTypes/DynamicJavaScriptType.swift +12 -6
- package/ios/Core/DynamicTypes/DynamicNumberType.swift +1 -1
- package/ios/Core/DynamicTypes/DynamicOptionalType.swift +4 -4
- package/ios/Core/DynamicTypes/DynamicRawType.swift +3 -3
- package/ios/Core/DynamicTypes/DynamicSharedObjectType.swift +2 -2
- package/ios/Core/DynamicTypes/DynamicStringType.swift +1 -1
- package/ios/Core/DynamicTypes/DynamicSwiftUIViewType.swift +2 -2
- package/ios/Core/DynamicTypes/DynamicTypedArrayType.swift +1 -1
- package/ios/Core/DynamicTypes/DynamicValueOrUndefinedType.swift +5 -5
- package/ios/Core/DynamicTypes/DynamicViewType.swift +2 -2
- package/ios/Core/DynamicTypes/DynamicVoidType.swift +2 -2
- package/ios/Core/Events/EventEmitter.swift +9 -3
- package/ios/Core/Functions/AnyFunctionDefinition.swift +1 -1
- package/ios/Core/Functions/AsyncFunctionDefinition.swift +2 -2
- package/ios/Core/Functions/ConcurrentFunctionDefinition.swift +2 -2
- package/ios/Core/Functions/OptimizedAsyncFunctionDefinition.swift +1 -1
- package/ios/Core/Functions/OptimizedSyncFunctionDefinition.swift +3 -3
- package/ios/Core/Functions/SyncFunctionDefinition.swift +5 -5
- package/ios/Core/JSValueDecoder.swift +32 -17
- package/ios/Core/JSValueEncoder.swift +17 -10
- package/ios/Core/MainValueConverter.swift +1 -1
- package/ios/Core/ModuleHolder.swift +4 -4
- package/ios/Core/Modules/CoreModule.swift +37 -48
- package/ios/Core/Objects/ConstantDefinition.swift +5 -3
- package/ios/Core/Objects/PropertyDefinition.swift +2 -2
- package/ios/Core/Promise.swift +1 -1
- package/ios/Core/Records/AnyField.swift +1 -1
- package/ios/Core/Records/Field.swift +3 -3
- package/ios/Core/Records/Record.swift +1 -4
- package/ios/Core/SharedObjects/SharedObject.swift +1 -1
- package/ios/Core/SharedObjects/SharedObjectNativeState.swift +1 -1
- package/ios/Core/Views/SwiftUI/SwiftUIHostingView.swift +9 -0
- package/ios/JS/ExpoRuntimeInstaller.swift +1 -1
- package/ios/Worklets/Core/DynamicSerializableType.swift +1 -1
- package/ios/Worklets/Core/DynamicWorkletType.swift +1 -1
- package/package.json +3 -3
- package/prebuilds/output/debug/xcframeworks/ExpoModulesCore.tar.gz +0 -0
- package/prebuilds/output/debug/xcframeworks/ExpoModulesWorklets.tar.gz +0 -0
- package/prebuilds/output/release/xcframeworks/ExpoModulesCore.tar.gz +0 -0
- package/prebuilds/output/release/xcframeworks/ExpoModulesWorklets.tar.gz +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 58.0.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [iOS] Fix a launch crash (`Symbol not found: _swift_allocateMetadataPack`) in apps that use precompiled Expo modules and build with Xcode 27. `ExpoModulesJSI` no longer exports Swift runtime symbols, so the precompiled `ExpoModulesCore` no longer depends on them. ([#51463](https://github.com/expo/expo/pull/51463) by [@chrfalch](https://github.com/chrfalch))
|
|
8
|
+
- [iOS] Fix a `UIViewControllerHierarchyInconsistency` crash when a SwiftUI view (such as `@expo/ui`'s `Host`) is rendered inside a text input's accessory view, for example React Native's `InputAccessoryView` or react-native-keyboard-controller's `KeyboardExtender`. ([#51420](https://github.com/expo/expo/pull/51420) by [@kirillzyusko](https://github.com/kirillzyusko))
|
|
9
|
+
- Updated dependencies. ([#51463](https://github.com/expo/expo/pull/51463), [#51451](https://github.com/expo/expo/pull/51451))
|
|
10
|
+
- expo-modules-jsi@58.0.12
|
|
11
|
+
|
|
12
|
+
## 58.0.16
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [Internal] Bump precompiled artifacts due to ABI breakage in expo-modules-jsi, which makes `JavaScriptValue` a non-copyable struct. ([#51368](https://github.com/expo/expo/pull/51368) by [@tsapeta](https://github.com/tsapeta))
|
|
17
|
+
- [iOS] Update `expo-modules-macros` to 0.16.0, which supports closure arguments in `@JS` functions and initializers. ([#51037](https://github.com/expo/expo/pull/51037) by [@tsapeta](https://github.com/tsapeta))
|
|
18
|
+
- [iOS] [Internal] Hold cached JavaScript values and the encoder and decoder state behind `JavaScriptRef`. ([#50978](https://github.com/expo/expo/pull/50978) by [@tsapeta](https://github.com/tsapeta))
|
|
19
|
+
- [Android] Fix build errors with React Native nightlies by removing an unneeded `enableCppPropsIteratorSetter` check from Expo views. ([#51405](https://github.com/expo/expo/pull/51405) by [@Kudo](https://github.com/Kudo))
|
|
20
|
+
- [iOS] Make `JavaScriptValue` a non-copyable struct. This is a breaking change for Swift code that uses `JavaScriptValue` directly:
|
|
21
|
+
|
|
22
|
+
- Values are moved, not shared. Pass them as `borrowing` or `consuming` parameters, and call `copy()` where a second owned value is needed.
|
|
23
|
+
- `JavaScriptValue.undefined` and `JavaScriptValue.null` are functions now: write `.undefined()` and `.null()`.
|
|
24
|
+
- A `JavaScriptValue` can no longer be an argument or a result of a `Function`, `AsyncFunction`, `Property` or `Field` definition. Declare the function with the `@JS` macro instead (in an `@ExpoModule` or `@SharedObject` class) and take the value as `borrowing JavaScriptValue`, or use a typed argument.
|
|
25
|
+
- To keep a value in an array, an escaping closure or another place that takes copyable types only, wrap it with `value.ref()` and read it back with `take()` or `withUnwrappedValue(_:)`.
|
|
26
|
+
- `JavaScriptArray.init(_:items:)`, `JavaScriptArray.enumerated()`, `JavaScriptArray.filter(_:)` and `JavaScriptValuesBuffer.copying(in:values:)` with an array of values are removed. Use the parameter pack initializer, `forEach`, `forEachIndexed`, `reduce`, or the `[JavaScriptValue.Ref]` overload.
|
|
27
|
+
|
|
28
|
+
([#51368](https://github.com/expo/expo/pull/51368) by [@tsapeta](https://github.com/tsapeta))
|
|
29
|
+
|
|
30
|
+
- [iOS] [Internal] Remove `copy runtime` where a borrowed `JavaScriptRuntime` is passed to a function, which already borrows its parameters. ([#51439](https://github.com/expo/expo/pull/51439) by [@tsapeta](https://github.com/tsapeta))
|
|
31
|
+
- [iOS] Read the properties of a typed array through property names cached per runtime, which makes `JavaScriptValue.getTypedArray()` about twice as fast. `getTypedArray()` is now isolated to `JavaScriptActor`, like `asTypedArray()`. ([#51436](https://github.com/expo/expo/pull/51436) by [@tsapeta](https://github.com/tsapeta))
|
|
32
|
+
- Updated dependencies. ([#51373](https://github.com/expo/expo/pull/51373), [#51037](https://github.com/expo/expo/pull/51037), [#51368](https://github.com/expo/expo/pull/51368), [#50977](https://github.com/expo/expo/pull/50977), [#51438](https://github.com/expo/expo/pull/51438), [#51439](https://github.com/expo/expo/pull/51439), [#51435](https://github.com/expo/expo/pull/51435), [#51436](https://github.com/expo/expo/pull/51436))
|
|
33
|
+
- expo-modules-jsi@58.0.11
|
|
34
|
+
|
|
3
35
|
## 58.0.15
|
|
4
36
|
|
|
5
37
|
### Patch Changes
|
package/android/build.gradle
CHANGED
|
@@ -46,7 +46,7 @@ if (shouldIncludeCompose) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
group = 'host.exp.exponent'
|
|
49
|
-
version = '58.0.
|
|
49
|
+
version = '58.0.17'
|
|
50
50
|
|
|
51
51
|
def isExpoModulesCoreTests = {
|
|
52
52
|
Gradle gradle = getGradle()
|
|
@@ -175,7 +175,7 @@ android {
|
|
|
175
175
|
defaultConfig {
|
|
176
176
|
consumerProguardFiles 'proguard-rules.pro'
|
|
177
177
|
versionCode 1
|
|
178
|
-
versionName "58.0.
|
|
178
|
+
versionName "58.0.17"
|
|
179
179
|
buildConfigField "String", "EXPO_MODULES_CORE_VERSION", "\"${versionName}\""
|
|
180
180
|
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true"
|
|
181
181
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"reactNativeVersion": "0.88.0",
|
|
3
|
-
"sourceHash": "
|
|
3
|
+
"sourceHash": "4a484f59a9d342285a14ab862c0ea08a",
|
|
4
4
|
"variants": [
|
|
5
5
|
"debug",
|
|
6
6
|
"release"
|
|
@@ -16,5 +16,5 @@
|
|
|
16
16
|
"libexpo-modules-jsi.so"
|
|
17
17
|
],
|
|
18
18
|
"stripped": true,
|
|
19
|
-
"createdAt": "2026-10-
|
|
19
|
+
"createdAt": "2026-10-13T15:42:19.061709444Z"
|
|
20
20
|
}
|
|
Binary file
|
|
@@ -45,24 +45,6 @@ react::Props::Shared AndroidExpoViewComponentDescriptor::cloneProps(
|
|
|
45
45
|
shadowNodeProps->initializeDynamicProps(sourceProps, rawProps, filterObjectKeys_);
|
|
46
46
|
#endif
|
|
47
47
|
|
|
48
|
-
// TODO(@lukmccall): We probably can remove this loop
|
|
49
|
-
if (react::ReactNativeFeatureFlags::enableCppPropsIteratorSetter()) {
|
|
50
|
-
#ifdef RN_SERIALIZABLE_STATE
|
|
51
|
-
const auto &dynamic = shadowNodeProps->rawProps;
|
|
52
|
-
#else
|
|
53
|
-
const auto &dynamic = static_cast<folly::dynamic>(rawProps);
|
|
54
|
-
#endif
|
|
55
|
-
for (const auto &pair: dynamic.items()) {
|
|
56
|
-
const auto &name = pair.first.getString();
|
|
57
|
-
shadowNodeProps->setProp(
|
|
58
|
-
context,
|
|
59
|
-
RAW_PROPS_KEY_HASH(name),
|
|
60
|
-
name.c_str(),
|
|
61
|
-
react::RawValue(pair.second)
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
48
|
if (!stateProps_.empty()) {
|
|
67
49
|
JNIEnv *env = jni::Environment::current();
|
|
68
50
|
const auto &rawPropsAccessor = *((RawPropsAccessor *) &rawProps);
|
|
@@ -92,7 +92,7 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
|
|
|
92
92
|
|
|
93
93
|
public typealias UIRuntimeFactory = (
|
|
94
94
|
_ appContext: AppContext,
|
|
95
|
-
_ pointerValue: JavaScriptValue,
|
|
95
|
+
_ pointerValue: borrowing JavaScriptValue,
|
|
96
96
|
_ runtime: JavaScriptRuntime
|
|
97
97
|
) throws -> JavaScriptRuntime
|
|
98
98
|
|
|
@@ -495,6 +495,9 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
|
|
|
495
495
|
|
|
496
496
|
try coreModuleHolder.definition.decorate(object: coreObject, appContext: self)
|
|
497
497
|
|
|
498
|
+
// Bind the `@JS` members of the core module, such as `installOnUIRuntime`.
|
|
499
|
+
try coreModule._decorateModule(object: coreObject, in: runtime)
|
|
500
|
+
|
|
498
501
|
// Install `global.expo.EventEmitter`.
|
|
499
502
|
installer.installEventEmitterClass()
|
|
500
503
|
|
|
@@ -561,8 +564,8 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
|
|
|
561
564
|
let sharedObjectClass = try coreObject.getPropertyAsObject("SharedObject")
|
|
562
565
|
let sharedObjectBaseProto = sharedObjectClass.getProperty("prototype")
|
|
563
566
|
|
|
564
|
-
//
|
|
565
|
-
//
|
|
567
|
+
// Prototypes are cached behind `JavaScriptRef` because `JavaScriptObject` is ~Copyable and
|
|
568
|
+
// cannot be a Dictionary value.
|
|
566
569
|
let prototypeCache = WorkletPrototypeCache()
|
|
567
570
|
|
|
568
571
|
// Called by the worklet serializer's `unpack` to recreate a SharedObject proxy.
|
|
@@ -580,8 +583,10 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
|
|
|
580
583
|
let typeId = ObjectIdentifier(type(of: nativeObject))
|
|
581
584
|
let instance: JavaScriptObject
|
|
582
585
|
|
|
583
|
-
if let
|
|
584
|
-
|
|
586
|
+
if let cachedInstance = prototypeCache.store[typeId]?.withUnwrappedValue({ (prototype: borrowing JavaScriptObject) in
|
|
587
|
+
runtime.createObject(prototype: prototype)
|
|
588
|
+
}) {
|
|
589
|
+
instance = cachedInstance
|
|
585
590
|
} else {
|
|
586
591
|
guard let classDefinition = self.findClassDefinition(for: typeId) else {
|
|
587
592
|
throw SharedObjectClassNotRegisteredException(String(describing: type(of: nativeObject)))
|
|
@@ -591,8 +596,8 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
|
|
|
591
596
|
appContext: self,
|
|
592
597
|
basePrototype: sharedObjectBaseProto.getObject()
|
|
593
598
|
)
|
|
594
|
-
prototypeCache.store[typeId] = built.asValue()
|
|
595
599
|
instance = runtime.createObject(prototype: built)
|
|
600
|
+
prototypeCache.store[typeId] = built.ref()
|
|
596
601
|
}
|
|
597
602
|
|
|
598
603
|
instance.defineProperty(sharedObjectIdPropertyName, value: objectId, options: [])
|
|
@@ -640,9 +645,7 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
|
|
|
640
645
|
public static func from(runtime: borrowing JavaScriptRuntime) -> AppContext? {
|
|
641
646
|
// Recovery may happen on every conversion, so look the core object up through a cached
|
|
642
647
|
// prop name id to avoid re-interning the "expo" string into JSI on each call.
|
|
643
|
-
|
|
644
|
-
// taking it owned — it only reads the runtime, so the owned convention forces a needless retain.
|
|
645
|
-
let coreObjectPropName = JavaScriptPropNameID.cached(copy runtime, globalCoreObjectPropertyName)
|
|
648
|
+
let coreObjectPropName = JavaScriptPropNameID.cached(runtime, globalCoreObjectPropertyName)
|
|
646
649
|
guard let coreObject = try? runtime.global().getPropertyAsObject(coreObjectPropName) else {
|
|
647
650
|
return nil
|
|
648
651
|
}
|
|
@@ -820,12 +823,12 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
|
|
|
820
823
|
|
|
821
824
|
/**
|
|
822
825
|
Reference-type store for cached worklet prototypes. Needed because JavaScriptObject
|
|
823
|
-
is ~Copyable and cannot be stored in a Dictionary; we cache
|
|
824
|
-
|
|
826
|
+
is ~Copyable and cannot be stored in a Dictionary; we cache the prototype as a
|
|
827
|
+
`JavaScriptValue.Ref` and rehydrate a JavaScriptObject on use.
|
|
825
828
|
*/
|
|
826
829
|
@JavaScriptActor
|
|
827
830
|
private final class WorkletPrototypeCache {
|
|
828
|
-
var store: [ObjectIdentifier:
|
|
831
|
+
var store: [ObjectIdentifier: JavaScriptObject.Ref] = [:]
|
|
829
832
|
}
|
|
830
833
|
|
|
831
834
|
// MARK: - Public exceptions
|
|
@@ -157,6 +157,7 @@ public final class ArrayBuffer: AnyArrayBuffer, Sendable {
|
|
|
157
157
|
// MARK: - JavaScript conversion
|
|
158
158
|
|
|
159
159
|
/// Converts a JavaScript ArrayBuffer or TypedArray to Expo's safe native ArrayBuffer representation.
|
|
160
|
+
@JavaScriptActor
|
|
160
161
|
@usableFromInline
|
|
161
162
|
internal static func from(value: borrowing JavaScriptValue) throws -> ArrayBuffer {
|
|
162
163
|
guard value.isObject() else {
|
|
@@ -166,6 +167,7 @@ public final class ArrayBuffer: AnyArrayBuffer, Sendable {
|
|
|
166
167
|
}
|
|
167
168
|
|
|
168
169
|
/// Converts a borrowed JavaScript ArrayBuffer or TypedArray without materializing an owning JavaScriptValue.
|
|
170
|
+
@JavaScriptActor
|
|
169
171
|
@usableFromInline
|
|
170
172
|
internal static func from(
|
|
171
173
|
unownedValue: borrowing JavaScriptUnownedValue,
|
|
@@ -177,6 +179,7 @@ public final class ArrayBuffer: AnyArrayBuffer, Sendable {
|
|
|
177
179
|
return try ArrayBuffer.from(jsObject: unownedValue.getObject(in: runtime))
|
|
178
180
|
}
|
|
179
181
|
|
|
182
|
+
@JavaScriptActor
|
|
180
183
|
private static func from(jsObject: consuming JavaScriptObject) throws -> ArrayBuffer {
|
|
181
184
|
if jsObject.isArrayBuffer() {
|
|
182
185
|
return ArrayBuffer.from(jsArrayBuffer: jsObject.getArrayBuffer())
|
|
@@ -256,7 +259,7 @@ extension ArrayBuffer: JavaScriptDecodable, JavaScriptEncodable {
|
|
|
256
259
|
_ value: ArrayBuffer,
|
|
257
260
|
in runtime: borrowing JavaScriptRuntime
|
|
258
261
|
) throws -> JavaScriptValue {
|
|
259
|
-
return value.asJavaScriptArrayBuffer(runtime:
|
|
262
|
+
return value.asJavaScriptArrayBuffer(runtime: runtime).asValue()
|
|
260
263
|
}
|
|
261
264
|
}
|
|
262
265
|
|
|
@@ -157,7 +157,7 @@ extension JavaScriptObject: ClassAssociatedObject, AnyArgument {
|
|
|
157
157
|
return DynamicJavaScriptType.shared
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
public static func convert(from value: JavaScriptValue, appContext: AppContext) throws -> Self {
|
|
160
|
+
public static func convert(from value: borrowing JavaScriptValue, appContext: AppContext) throws -> Self {
|
|
161
161
|
guard value.kind == .object else {
|
|
162
162
|
throw Conversions.UnexpectedValueType((received: value.kind, expected: .object))
|
|
163
163
|
}
|
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
import ExpoModulesJSI
|
|
4
4
|
|
|
5
5
|
internal final class ClassRegistry {
|
|
6
|
-
|
|
6
|
+
// Classes are kept behind `JavaScriptRef` because `JavaScriptObject` is ~Copyable and cannot be a
|
|
7
|
+
// Dictionary value.
|
|
8
|
+
var nativeToJS = [ObjectIdentifier: JavaScriptValue.Ref]()
|
|
7
9
|
|
|
8
10
|
// MARK: - Accessing
|
|
9
11
|
|
|
10
12
|
func getJavaScriptClass(nativeClassId: ObjectIdentifier) -> JavaScriptObject? {
|
|
11
|
-
return nativeToJS[nativeClassId]?.getObject()
|
|
13
|
+
return nativeToJS[nativeClassId]?.withUnwrappedValue { (value: borrowing JavaScriptValue) in value.getObject() }
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
func getJavaScriptClass(nativeClass: SharedObject.Type) -> JavaScriptObject? {
|
|
@@ -19,7 +21,7 @@ internal final class ClassRegistry {
|
|
|
19
21
|
// MARK: - Registration
|
|
20
22
|
|
|
21
23
|
func register(nativeClassId: ObjectIdentifier, javaScriptClass: borrowing JavaScriptObject) {
|
|
22
|
-
nativeToJS[nativeClassId] = javaScriptClass.
|
|
24
|
+
nativeToJS[nativeClassId] = javaScriptClass.refToValue()
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
func register(nativeClass: SharedObject.Type, javaScriptClass: borrowing JavaScriptObject) {
|
|
@@ -163,7 +163,7 @@ public struct Conversions {
|
|
|
163
163
|
*/
|
|
164
164
|
static func anyToJavaScriptValue<ValueType>(_ value: ValueType, appContext: AppContext, in runtime: JavaScriptRuntime) throws -> JavaScriptValue {
|
|
165
165
|
if ValueType.self is AnyOptional.Type, Optional.isNil(value) {
|
|
166
|
-
return .null
|
|
166
|
+
return .null()
|
|
167
167
|
}
|
|
168
168
|
if let value = value as? AnyArgument {
|
|
169
169
|
return try type(of: value).getDynamicType().castToJS(value, appContext: appContext, in: runtime)
|
|
@@ -185,15 +185,18 @@ public struct Conversions {
|
|
|
185
185
|
path so produced dicts/arrays live in the calling runtime, not the main runtime.
|
|
186
186
|
*/
|
|
187
187
|
static func unknownToJavaScriptValue(_ value: Any, appContext: AppContext, in runtime: JavaScriptRuntime) throws -> JavaScriptValue {
|
|
188
|
+
if let converted = value as? ConvertedJavaScriptValue {
|
|
189
|
+
return converted.takeValue()
|
|
190
|
+
}
|
|
188
191
|
if let value = value as? JavaScriptRepresentable {
|
|
189
192
|
return .representing(value: value, in: runtime)
|
|
190
193
|
}
|
|
191
194
|
|
|
192
195
|
switch value {
|
|
193
196
|
case is Void:
|
|
194
|
-
return .undefined
|
|
197
|
+
return .undefined()
|
|
195
198
|
case is NSNull:
|
|
196
|
-
return .null
|
|
199
|
+
return .null()
|
|
197
200
|
case let number as NSNumber:
|
|
198
201
|
if number === kCFBooleanTrue {
|
|
199
202
|
return .true()
|
|
@@ -221,7 +224,7 @@ public struct Conversions {
|
|
|
221
224
|
return jsObject.asValue()
|
|
222
225
|
default:
|
|
223
226
|
log.warn("unknownToJavaScriptValue: unsupported native type '\(type(of: value))', returning undefined")
|
|
224
|
-
return .undefined
|
|
227
|
+
return .undefined()
|
|
225
228
|
}
|
|
226
229
|
}
|
|
227
230
|
|
|
@@ -236,7 +239,7 @@ public struct Conversions {
|
|
|
236
239
|
}
|
|
237
240
|
}
|
|
238
241
|
let uint8ArrayCtor = try runtime.global().getPropertyAsFunction("Uint8Array")
|
|
239
|
-
return try uint8ArrayCtor.callAsConstructor(arrayBuffer.asValue())
|
|
242
|
+
return try uint8ArrayCtor.callAsConstructor(arrayBuffer.asValue().ref())
|
|
240
243
|
}
|
|
241
244
|
|
|
242
245
|
// MARK: - Exceptions
|
|
@@ -349,3 +352,38 @@ public struct Conversions {
|
|
|
349
352
|
}
|
|
350
353
|
|
|
351
354
|
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
A JavaScript value carried through `Any` inside the conversion pipeline, between a dynamic type's
|
|
358
|
+
`convertResult` and its `castToJS` (for example a record field that is already a JS object). It is
|
|
359
|
+
needed because `JavaScriptValue` is non-copyable and cannot be boxed in `Any` itself. Internal to the
|
|
360
|
+
pipeline: the module API never hands it to user code.
|
|
361
|
+
*/
|
|
362
|
+
internal final class ConvertedJavaScriptValue: @unchecked Sendable {
|
|
363
|
+
/**
|
|
364
|
+
The shared box for `undefined`. It holds no value and `takeValue()` creates a fresh `undefined`
|
|
365
|
+
each time, so one instance serves every use without an allocation.
|
|
366
|
+
*/
|
|
367
|
+
static let undefined = ConvertedJavaScriptValue()
|
|
368
|
+
|
|
369
|
+
private let ref: JavaScriptValue.Ref?
|
|
370
|
+
|
|
371
|
+
init(_ value: consuming JavaScriptValue) {
|
|
372
|
+
self.ref = value.ref()
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
private init() {
|
|
376
|
+
self.ref = nil
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
Moves the value out of the box, so the pipeline reads it without cloning the engine value. A box is
|
|
381
|
+
read once, where the converted value becomes a JS value; a later read yields `undefined`.
|
|
382
|
+
*/
|
|
383
|
+
func takeValue() -> JavaScriptValue {
|
|
384
|
+
guard let ref else {
|
|
385
|
+
return .undefined()
|
|
386
|
+
}
|
|
387
|
+
return ref.take() ?? .undefined()
|
|
388
|
+
}
|
|
389
|
+
}
|
|
@@ -24,7 +24,7 @@ public protocol AnyDynamicType: CustomStringConvertible, Sendable {
|
|
|
24
24
|
It **must** be run on the thread used by the JavaScript runtime.
|
|
25
25
|
*/
|
|
26
26
|
@JavaScriptActor
|
|
27
|
-
func cast(jsValue: JavaScriptValue, appContext: AppContext) throws -> Any
|
|
27
|
+
func cast(jsValue: borrowing JavaScriptValue, appContext: AppContext) throws -> Any
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
Casts the given Swift-side value to the wrapped type and returns it as `Any`.
|
|
@@ -17,7 +17,7 @@ internal struct DynamicArrayBufferType: AnyDynamicType {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/// Converts JS array buffer to its native representation.
|
|
20
|
-
func cast(jsValue: JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
20
|
+
func cast(jsValue: borrowing JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
21
21
|
do {
|
|
22
22
|
return try ArrayBuffer.from(value: jsValue)
|
|
23
23
|
} catch is ArrayBufferJavaScriptValueConversionException {
|
|
@@ -23,7 +23,7 @@ internal struct DynamicArrayType: AnyDynamicType {
|
|
|
23
23
|
return false
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
func cast(jsValue: JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
26
|
+
func cast(jsValue: borrowing JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
27
27
|
if jsValue.isArray() {
|
|
28
28
|
return try jsValue.getArray().map { value in
|
|
29
29
|
return try elementType.cast(jsValue: value, appContext: appContext)
|
|
@@ -52,7 +52,7 @@ internal struct DynamicArrayType: AnyDynamicType {
|
|
|
52
52
|
/**
|
|
53
53
|
Type-aware conversion for arrays that were already normalized by `convertResult`.
|
|
54
54
|
Elements must use `castToJS` here to avoid re-entering `convertResult` for values that
|
|
55
|
-
are already in their post-conversion shape, such as `JavaScriptValue.undefined`.
|
|
55
|
+
are already in their post-conversion shape, such as `JavaScriptValue.undefined()`.
|
|
56
56
|
*/
|
|
57
57
|
func castToJS<ValueType>(_ value: ValueType, appContext: AppContext) throws -> JavaScriptValue {
|
|
58
58
|
return try castToJS(value, appContext: appContext, in: try appContext.runtime)
|
|
@@ -28,7 +28,7 @@ internal struct DynamicBoolType: AnyDynamicType {
|
|
|
28
28
|
throw Conversions.CastingException<Bool>(value)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
func cast(jsValue: JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
31
|
+
func cast(jsValue: borrowing JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
32
32
|
if jsValue.kind == .bool {
|
|
33
33
|
return jsValue.getBool()
|
|
34
34
|
}
|
|
@@ -17,11 +17,11 @@ internal struct DynamicCodableType<InnerType>: AnyDynamicType {
|
|
|
17
17
|
return type is Self
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
func cast(jsValue: JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
20
|
+
func cast(jsValue: borrowing JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
21
21
|
guard let DecodableType = InnerType.self as? Decodable.Type else {
|
|
22
22
|
throw Conversions.CastingJSValueException<InnerType>(jsValue.kind)
|
|
23
23
|
}
|
|
24
|
-
let decoder = try JSValueDecoder(value: jsValue, appContext: appContext)
|
|
24
|
+
let decoder = try JSValueDecoder(value: jsValue.copy(), appContext: appContext)
|
|
25
25
|
return try DecodableType.init(from: decoder)
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -37,8 +37,8 @@ internal struct DynamicCodableType<InnerType>: AnyDynamicType {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
func castToJS<ValueType>(_ value: ValueType, appContext: AppContext, in runtime: JavaScriptRuntime) throws -> JavaScriptValue {
|
|
40
|
-
if let
|
|
41
|
-
return
|
|
40
|
+
if let converted = value as? ConvertedJavaScriptValue {
|
|
41
|
+
return converted.takeValue()
|
|
42
42
|
}
|
|
43
43
|
if let value = value as? Encodable {
|
|
44
44
|
let encoder = JSValueEncoder(appContext: appContext, runtime: runtime)
|
|
@@ -50,7 +50,7 @@ internal struct DynamicCodableType<InnerType>: AnyDynamicType {
|
|
|
50
50
|
|
|
51
51
|
func convertResult<ResultType>(_ result: ResultType, appContext: AppContext) throws -> Any {
|
|
52
52
|
// TODO: We should get rid of this function, but it seems it's still used in some places
|
|
53
|
-
return try castToJS(result, appContext: appContext)
|
|
53
|
+
return ConvertedJavaScriptValue(try castToJS(result, appContext: appContext))
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
var description: String {
|
|
@@ -20,7 +20,7 @@ internal struct DynamicConvertibleType: AnyDynamicType {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
@JavaScriptActor
|
|
23
|
-
func cast(jsValue: JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
23
|
+
func cast(jsValue: borrowing JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
24
24
|
// `from(object:)` dispatches dynamically: reflection-based hydration for `@Field` records,
|
|
25
25
|
// a direct statically-typed factory for `@Record`-synthesized ones.
|
|
26
26
|
if let recordType = innerType as? any Record.Type {
|
|
@@ -37,9 +37,6 @@ internal struct DynamicConvertibleType: AnyDynamicType {
|
|
|
37
37
|
if let directJSValue = try directJSValueIfPossible(value, appContext: appContext) {
|
|
38
38
|
return directJSValue
|
|
39
39
|
}
|
|
40
|
-
if let jsValue = value as? JavaScriptValue {
|
|
41
|
-
return jsValue
|
|
42
|
-
}
|
|
43
40
|
if value is AnyArgument {
|
|
44
41
|
return try convertOriginalValueToJS(value, appContext: appContext)
|
|
45
42
|
}
|
|
@@ -97,9 +94,6 @@ internal struct DynamicConvertibleType: AnyDynamicType {
|
|
|
97
94
|
}
|
|
98
95
|
|
|
99
96
|
private func serializeConvertedValue(_ value: Any, appContext: AppContext) throws -> JavaScriptValue {
|
|
100
|
-
if let result = value as? JavaScriptValue {
|
|
101
|
-
return result
|
|
102
|
-
}
|
|
103
97
|
if let result = value as? AnyArgument {
|
|
104
98
|
let dynamicType = type(of: result).getDynamicType()
|
|
105
99
|
// A `Convertible` that keeps the default `convertResult` returns the value unchanged,
|
|
@@ -19,7 +19,7 @@ internal struct DynamicDataType: AnyDynamicType {
|
|
|
19
19
|
/**
|
|
20
20
|
Converts JS typed array to its native representation.
|
|
21
21
|
*/
|
|
22
|
-
func cast(jsValue: JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
22
|
+
func cast(jsValue: borrowing JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
23
23
|
guard jsValue.isTypedArray() else {
|
|
24
24
|
throw Conversions.CastingJSValueException<Uint8Array>(jsValue.kind)
|
|
25
25
|
}
|
|
@@ -23,7 +23,7 @@ internal struct DynamicDictionaryType: AnyDynamicType {
|
|
|
23
23
|
return false
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
func cast(jsValue: JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
26
|
+
func cast(jsValue: borrowing JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
27
27
|
if let jsObject = try? jsValue.asObject() {
|
|
28
28
|
var result: [AnyHashable: Any] = [:]
|
|
29
29
|
for key in jsObject.getPropertyNames() {
|
|
@@ -58,7 +58,7 @@ internal struct DynamicDictionaryType: AnyDynamicType {
|
|
|
58
58
|
/**
|
|
59
59
|
Type-aware conversion for dictionaries that were already normalized by `convertResult`.
|
|
60
60
|
Values must use `castToJS` here to avoid re-entering `convertResult` for values that
|
|
61
|
-
are already in their post-conversion shape, such as `JavaScriptValue.undefined`.
|
|
61
|
+
are already in their post-conversion shape, such as `JavaScriptValue.undefined()`.
|
|
62
62
|
*/
|
|
63
63
|
func castToJS<ValueType>(_ value: ValueType, appContext: AppContext) throws -> JavaScriptValue {
|
|
64
64
|
return try castToJS(value, appContext: appContext, in: try appContext.runtime)
|
|
@@ -15,7 +15,7 @@ internal struct DynamicEitherType<EitherType: AnyEither>: AnyDynamicType {
|
|
|
15
15
|
return type is Self
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
func cast(jsValue: JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
18
|
+
func cast(jsValue: borrowing JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
19
19
|
let types = eitherType.dynamicTypes()
|
|
20
20
|
|
|
21
21
|
for type in types {
|
|
@@ -19,7 +19,7 @@ internal struct DynamicEnumType: AnyDynamicType {
|
|
|
19
19
|
return false
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
func cast(jsValue: JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
22
|
+
func cast(jsValue: borrowing JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
23
23
|
let rawValue = try innerType.getRawValueDynamicType().cast(jsValue: jsValue, appContext: appContext)
|
|
24
24
|
return try innerType.create(fromRawValue: rawValue)
|
|
25
25
|
}
|
|
@@ -16,18 +16,24 @@ internal struct DynamicJavaScriptType: AnyDynamicType {
|
|
|
16
16
|
return type is Self
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
// `JavaScriptValue` is non-copyable, so it can neither be boxed in `Any` nor appear in a definition
|
|
20
|
+
// closure's argument tuple or result. The compiler rejects such a definition, so these paths are
|
|
21
|
+
// unreachable from the DSL; they throw for completeness.
|
|
22
|
+
func cast(jsValue: borrowing JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
23
|
+
throw NonCopyableValueException()
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
func castToJS<ValueType>(_ value: ValueType, appContext: AppContext) throws -> JavaScriptValue {
|
|
24
|
-
|
|
25
|
-
return value
|
|
26
|
-
}
|
|
27
|
-
throw Conversions.ConversionToJSFailedException((kind: .undefined, nativeType: ValueType.self))
|
|
27
|
+
throw NonCopyableValueException()
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
var description: String {
|
|
31
31
|
return "JavaScriptValue"
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
internal final class NonCopyableValueException: Exception, @unchecked Sendable {
|
|
36
|
+
override var reason: String {
|
|
37
|
+
return "JavaScriptValue is non-copyable and cannot be passed through the module definition as a native value"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -13,7 +13,7 @@ internal struct DynamicNumberType<NumberType>: AnyDynamicType {
|
|
|
13
13
|
return type is Self
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
func cast(jsValue: JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
16
|
+
func cast(jsValue: borrowing JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
17
17
|
if jsValue.isNumber() {
|
|
18
18
|
// Fast paths for common types avoid expensive `as? any BinaryFloatingPoint` conformance lookups.
|
|
19
19
|
let double = jsValue.getDouble()
|
|
@@ -23,7 +23,7 @@ internal struct DynamicOptionalType: AnyDynamicType {
|
|
|
23
23
|
return false
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
func cast(jsValue: JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
26
|
+
func cast(jsValue: borrowing JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
27
27
|
if jsValue.isUndefined() || jsValue.isNull() {
|
|
28
28
|
return Optional<Any>.none as Any
|
|
29
29
|
}
|
|
@@ -39,21 +39,21 @@ internal struct DynamicOptionalType: AnyDynamicType {
|
|
|
39
39
|
|
|
40
40
|
func castToJS<ValueType>(_ value: ValueType, appContext: AppContext) throws -> JavaScriptValue {
|
|
41
41
|
if Optional.isNil(value) || value is NSNull {
|
|
42
|
-
return .null
|
|
42
|
+
return .null()
|
|
43
43
|
}
|
|
44
44
|
return try wrappedType.castToJS(value, appContext: appContext)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
func convertToJS<ValueType>(_ value: ValueType, appContext: AppContext) throws -> JavaScriptValue {
|
|
48
48
|
if Optional.isNil(value) || value is NSNull {
|
|
49
|
-
return .null
|
|
49
|
+
return .null()
|
|
50
50
|
}
|
|
51
51
|
return try wrappedType.convertToJS(value, appContext: appContext)
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
func convertToJS<ValueType>(_ value: ValueType, appContext: AppContext, in runtime: JavaScriptRuntime) throws -> JavaScriptValue {
|
|
55
55
|
if Optional.isNil(value) || value is NSNull {
|
|
56
|
-
return .null
|
|
56
|
+
return .null()
|
|
57
57
|
}
|
|
58
58
|
return try wrappedType.convertToJS(value, appContext: appContext, in: runtime)
|
|
59
59
|
}
|
|
@@ -17,7 +17,7 @@ internal struct DynamicRawType<InnerType>: AnyDynamicType {
|
|
|
17
17
|
return type is Self
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
func cast(jsValue: JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
20
|
+
func cast(jsValue: borrowing JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
21
21
|
return try cast(jsValue.getAny(), appContext: appContext)
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -43,7 +43,7 @@ internal struct DynamicRawType<InnerType>: AnyDynamicType {
|
|
|
43
43
|
|
|
44
44
|
func castToJS<ValueType>(_ value: ValueType, appContext: AppContext, in runtime: JavaScriptRuntime) throws -> JavaScriptValue {
|
|
45
45
|
if Optional.isNil(value) {
|
|
46
|
-
return .null
|
|
46
|
+
return .null()
|
|
47
47
|
}
|
|
48
48
|
// When `InnerType` is `Any` (e.g. `[String: Any]` value slot), the runtime type of the
|
|
49
49
|
// value is more specific than the static type, so we dispatch on it to reach proper
|
|
@@ -60,7 +60,7 @@ internal struct DynamicRawType<InnerType>: AnyDynamicType {
|
|
|
60
60
|
// We use `DynamicRawType` for this only temporarily.
|
|
61
61
|
if let objectBuilder = result as? JavaScriptObjectBuilder {
|
|
62
62
|
return try JavaScriptActor.assumeIsolated {
|
|
63
|
-
return try objectBuilder.build(appContext: appContext).asValue()
|
|
63
|
+
return ConvertedJavaScriptValue(try objectBuilder.build(appContext: appContext).asValue())
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
return result
|
|
@@ -44,7 +44,7 @@ internal struct DynamicSharedObjectType: AnyDynamicType {
|
|
|
44
44
|
throw SharedObject.NotFoundException()
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
func cast(jsValue: JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
47
|
+
func cast(jsValue: borrowing JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
48
48
|
if jsValue.kind == .number {
|
|
49
49
|
let sharedObjectId = jsValue.getInt() as SharedObjectId
|
|
50
50
|
|
|
@@ -74,7 +74,7 @@ internal struct DynamicSharedObjectType: AnyDynamicType {
|
|
|
74
74
|
guard let jsObject = (try? appContext.newObject(nativeClassId: typeIdentifier)) ?? (try? newBaseSharedObject(appContext, nativeType: innerType)) else {
|
|
75
75
|
// Throwing is not possible here due to swift-objC interop.
|
|
76
76
|
log.warn("Unable to create a JS object for \(description)")
|
|
77
|
-
return JavaScriptValue.undefined
|
|
77
|
+
return JavaScriptValue.undefined()
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
// Add newly created objects to the registry.
|
|
@@ -20,7 +20,7 @@ internal struct DynamicStringType: AnyDynamicType {
|
|
|
20
20
|
throw Conversions.CastingException<String>(value)
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
func cast(jsValue: JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
23
|
+
func cast(jsValue: borrowing JavaScriptValue, appContext: AppContext) throws -> Any {
|
|
24
24
|
if jsValue.kind == .string {
|
|
25
25
|
return jsValue.getString()
|
|
26
26
|
}
|