expo-modules-jsi 56.0.7 → 56.0.8
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/CLAUDE.md +4 -0
- package/apple/Package.swift +15 -11
- package/apple/Sources/ExpoModulesJSI/Contexts/CleanupContext.swift +2 -4
- package/apple/Sources/ExpoModulesJSI/Contexts/HostFunctionContext.swift +1 -3
- package/apple/Sources/ExpoModulesJSI/Contexts/HostObjectContext.swift +1 -3
- package/apple/Sources/ExpoModulesJSI/Extensions/Task+immediate.swift +2 -0
- package/apple/Sources/ExpoModulesJSI/Protocols/JSIRepresentable.swift +17 -14
- package/apple/Sources/ExpoModulesJSI/Protocols/JavaScriptRepresentable.swift +3 -9
- package/apple/Sources/ExpoModulesJSI/Protocols/JavaScriptThrowable.swift +21 -27
- package/apple/Sources/ExpoModulesJSI/Protocols/JavaScriptType.swift +10 -18
- package/apple/Sources/ExpoModulesJSI/Runtime/JavaScriptActor.swift +22 -41
- package/apple/Sources/ExpoModulesJSI/Runtime/JavaScriptNativeState.swift +7 -15
- package/apple/Sources/ExpoModulesJSI/Runtime/JavaScriptPropNameID.swift +5 -15
- package/apple/Sources/ExpoModulesJSI/Runtime/JavaScriptRef.swift +21 -43
- package/apple/Sources/ExpoModulesJSI/Runtime/JavaScriptRuntime.swift +152 -202
- package/apple/Sources/ExpoModulesJSI/Runtime/JavaScriptValuesBuffer.swift +38 -41
- package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptArray.swift +340 -381
- package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptArrayBuffer.swift +9 -21
- package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptBigInt.swift +162 -190
- package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptError.swift +12 -15
- package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptFunction.swift +23 -27
- package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptObject.swift +175 -207
- package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptPromise.swift +22 -24
- package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptTypedArray.swift +34 -49
- package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptValue.swift +122 -176
- package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptWeakObject.swift +6 -14
- package/apple/Sources/ExpoModulesJSI/Utilities/ErrorHandling.swift +12 -20
- package/apple/Sources/ExpoModulesJSI/Utilities/Errors.swift +10 -22
- package/apple/Sources/ExpoModulesJSI/Utilities/NonisolatedUnsafeVar.swift +2 -4
- package/apple/Sources/ExpoModulesJSI-Cxx/include/JSIUtils.h +11 -0
- package/apple/Tests/JavaScriptActorTests.swift +3 -3
- package/apple/Tests/JavaScriptArrayBufferTests.swift +1 -1
- package/apple/Tests/JavaScriptArrayTests.swift +6 -4
- package/apple/Tests/JavaScriptBigIntTests.swift +20 -20
- package/apple/Tests/JavaScriptErrorTests.swift +15 -11
- package/apple/Tests/JavaScriptFunctionTests.swift +26 -26
- package/apple/Tests/JavaScriptNativeStateTests.swift +1 -1
- package/apple/Tests/JavaScriptObjectTests.swift +25 -13
- package/apple/Tests/JavaScriptPromiseTests.swift +56 -28
- package/apple/Tests/JavaScriptRefTests.swift +1 -1
- package/apple/Tests/JavaScriptRuntimeTests.swift +93 -60
- package/apple/Tests/JavaScriptTypedArrayTests.swift +20 -14
- package/apple/Tests/JavaScriptValueTests.swift +1 -1
- package/apple/Tests/JavaScriptValuesBufferTests.swift +1 -1
- package/apple/Tests/JavaScriptWeakObjectTests.swift +1 -1
- package/apple/scripts/build-xcframework.sh +96 -13
- package/apple/scripts/xcframework-helpers.sh +4 -0
- package/package.json +4 -2
|
@@ -1,60 +1,44 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
internal import jsi
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- TODO: Annotate `value` and friends with `@JavaScriptActor`.
|
|
14
|
-
*/
|
|
4
|
+
/// Reference to a non-copyable JavaScript value. Use it only when you have to:
|
|
5
|
+
/// - Switch from value semantics to reference semantics.
|
|
6
|
+
/// - Send a value through different isolation contexts.
|
|
7
|
+
/// - Capture by escaping closures.
|
|
8
|
+
/// - Store in containers that do not support non-copyable types.
|
|
9
|
+
/// Swift (v6.2 at the time of writing) still has very limited support for non-copyable types.
|
|
10
|
+
/// Many built-in types (including collections, containers, tuples) and protocols are not supporting them.
|
|
11
|
+
/// There is a new ``InlineArray`` that supports them, but it requires iOS 26.
|
|
12
|
+
/// - TODO: Annotate `value` and friends with `@JavaScriptActor`.
|
|
15
13
|
public final class JavaScriptRef<T: JavaScriptType & ~Copyable>: JavaScriptType, Sendable, Copyable, Escapable {
|
|
16
|
-
|
|
17
|
-
The referenced non-copyable value. It is consumed by the ref until it is taken (see `take()`) by a new owner.
|
|
18
|
-
*/
|
|
14
|
+
/// The referenced non-copyable value. It is consumed by the ref until it is taken (see `take()`) by a new owner.
|
|
19
15
|
nonisolated(unsafe) private var value: T?
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
Returns `true` if the reference does not reference any value, `false` otherwise.
|
|
23
|
-
*/
|
|
17
|
+
/// Returns `true` if the reference does not reference any value, `false` otherwise.
|
|
24
18
|
public var isEmpty: Bool {
|
|
25
19
|
return value == nil
|
|
26
20
|
}
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
Initializes a ref without an initial value.
|
|
30
|
-
*/
|
|
22
|
+
/// Initializes a ref without an initial value.
|
|
31
23
|
public init() {}
|
|
32
24
|
|
|
33
|
-
|
|
34
|
-
Makes a reference to the value. The value is consumed and cannot be used anymore in the calling scope.
|
|
35
|
-
*/
|
|
25
|
+
/// Makes a reference to the value. The value is consumed and cannot be used anymore in the calling scope.
|
|
36
26
|
public init(_ value: consuming sending T) {
|
|
37
27
|
self.value = consume value
|
|
38
28
|
}
|
|
39
29
|
|
|
40
|
-
|
|
41
|
-
Replaces the referenced value with a new value.
|
|
42
|
-
*/
|
|
30
|
+
/// Replaces the referenced value with a new value.
|
|
43
31
|
public func reset(_ value: consuming sending T) {
|
|
44
32
|
self.value = consume value
|
|
45
33
|
}
|
|
46
34
|
|
|
47
|
-
|
|
48
|
-
Releases the value. Any subsequent `take()` calls with throw or return `nil`.
|
|
49
|
-
*/
|
|
35
|
+
/// Releases the value. Any subsequent `take()` calls with throw or return `nil`.
|
|
50
36
|
public func release() {
|
|
51
37
|
self.value = nil
|
|
52
38
|
}
|
|
53
39
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
Throws when the reference does not hold any value, i.e. it has already been taken or never set.
|
|
57
|
-
*/
|
|
40
|
+
/// Takes the value out of the reference and transfers the ownership to the caller.
|
|
41
|
+
/// Throws when the reference does not hold any value, i.e. it has already been taken or never set.
|
|
58
42
|
public func take() throws(InvalidRefError) -> sending T {
|
|
59
43
|
guard let value = value.take() else {
|
|
60
44
|
throw InvalidRefError()
|
|
@@ -62,24 +46,18 @@ public final class JavaScriptRef<T: JavaScriptType & ~Copyable>: JavaScriptType,
|
|
|
62
46
|
return value
|
|
63
47
|
}
|
|
64
48
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
Returns `nil` if the reference does not hold any value, i.e. it has already been taken or never set.
|
|
68
|
-
*/
|
|
49
|
+
/// Takes the value out of the reference and transfers the ownership to the caller.
|
|
50
|
+
/// Returns `nil` if the reference does not hold any value, i.e. it has already been taken or never set.
|
|
69
51
|
public func take() -> sending T? {
|
|
70
52
|
return value.take()
|
|
71
53
|
}
|
|
72
54
|
|
|
73
|
-
|
|
74
|
-
Takes the value as a `JavaScriptValue`. Returns `undefined` value if the reference does not hold any value.
|
|
75
|
-
*/
|
|
55
|
+
/// Takes the value as a `JavaScriptValue`. Returns `undefined` value if the reference does not hold any value.
|
|
76
56
|
public func asValue() -> JavaScriptValue {
|
|
77
57
|
return take()?.asValue() ?? .undefined
|
|
78
58
|
}
|
|
79
59
|
|
|
80
|
-
|
|
81
|
-
An error thrown when attempting to `take()` a value from a ref that has already been taken, released, or was never set.
|
|
82
|
-
*/
|
|
60
|
+
/// An error thrown when attempting to `take()` a value from a ref that has already been taken, released, or was never set.
|
|
83
61
|
public struct InvalidRefError: Error, CustomStringConvertible {
|
|
84
62
|
public init() {}
|
|
85
63
|
|