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.
Files changed (49) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/CLAUDE.md +4 -0
  3. package/apple/Package.swift +15 -11
  4. package/apple/Sources/ExpoModulesJSI/Contexts/CleanupContext.swift +2 -4
  5. package/apple/Sources/ExpoModulesJSI/Contexts/HostFunctionContext.swift +1 -3
  6. package/apple/Sources/ExpoModulesJSI/Contexts/HostObjectContext.swift +1 -3
  7. package/apple/Sources/ExpoModulesJSI/Extensions/Task+immediate.swift +2 -0
  8. package/apple/Sources/ExpoModulesJSI/Protocols/JSIRepresentable.swift +17 -14
  9. package/apple/Sources/ExpoModulesJSI/Protocols/JavaScriptRepresentable.swift +3 -9
  10. package/apple/Sources/ExpoModulesJSI/Protocols/JavaScriptThrowable.swift +21 -27
  11. package/apple/Sources/ExpoModulesJSI/Protocols/JavaScriptType.swift +10 -18
  12. package/apple/Sources/ExpoModulesJSI/Runtime/JavaScriptActor.swift +22 -41
  13. package/apple/Sources/ExpoModulesJSI/Runtime/JavaScriptNativeState.swift +7 -15
  14. package/apple/Sources/ExpoModulesJSI/Runtime/JavaScriptPropNameID.swift +5 -15
  15. package/apple/Sources/ExpoModulesJSI/Runtime/JavaScriptRef.swift +21 -43
  16. package/apple/Sources/ExpoModulesJSI/Runtime/JavaScriptRuntime.swift +152 -202
  17. package/apple/Sources/ExpoModulesJSI/Runtime/JavaScriptValuesBuffer.swift +38 -41
  18. package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptArray.swift +340 -381
  19. package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptArrayBuffer.swift +9 -21
  20. package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptBigInt.swift +162 -190
  21. package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptError.swift +12 -15
  22. package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptFunction.swift +23 -27
  23. package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptObject.swift +175 -207
  24. package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptPromise.swift +22 -24
  25. package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptTypedArray.swift +34 -49
  26. package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptValue.swift +122 -176
  27. package/apple/Sources/ExpoModulesJSI/Runtime/Values/JavaScriptWeakObject.swift +6 -14
  28. package/apple/Sources/ExpoModulesJSI/Utilities/ErrorHandling.swift +12 -20
  29. package/apple/Sources/ExpoModulesJSI/Utilities/Errors.swift +10 -22
  30. package/apple/Sources/ExpoModulesJSI/Utilities/NonisolatedUnsafeVar.swift +2 -4
  31. package/apple/Sources/ExpoModulesJSI-Cxx/include/JSIUtils.h +11 -0
  32. package/apple/Tests/JavaScriptActorTests.swift +3 -3
  33. package/apple/Tests/JavaScriptArrayBufferTests.swift +1 -1
  34. package/apple/Tests/JavaScriptArrayTests.swift +6 -4
  35. package/apple/Tests/JavaScriptBigIntTests.swift +20 -20
  36. package/apple/Tests/JavaScriptErrorTests.swift +15 -11
  37. package/apple/Tests/JavaScriptFunctionTests.swift +26 -26
  38. package/apple/Tests/JavaScriptNativeStateTests.swift +1 -1
  39. package/apple/Tests/JavaScriptObjectTests.swift +25 -13
  40. package/apple/Tests/JavaScriptPromiseTests.swift +56 -28
  41. package/apple/Tests/JavaScriptRefTests.swift +1 -1
  42. package/apple/Tests/JavaScriptRuntimeTests.swift +93 -60
  43. package/apple/Tests/JavaScriptTypedArrayTests.swift +20 -14
  44. package/apple/Tests/JavaScriptValueTests.swift +1 -1
  45. package/apple/Tests/JavaScriptValuesBufferTests.swift +1 -1
  46. package/apple/Tests/JavaScriptWeakObjectTests.swift +1 -1
  47. package/apple/scripts/build-xcframework.sh +96 -13
  48. package/apple/scripts/xcframework-helpers.sh +4 -0
  49. package/package.json +4 -2
@@ -1,10 +1,8 @@
1
1
  internal import jsi
2
2
 
3
- /**
4
- A buffer that stores instances of `facebook.jsi.Value` with the ability to convert them to `JavaScriptValue` on element access
5
- without the need to create a new container (e.g. `std.vector<facebook.jsi.Value>` or `[JavaScriptValue]`).
6
- Used mainly to pass function arguments from C++ to Swift.
7
- */
3
+ /// A buffer that stores instances of `facebook.jsi.Value` with the ability to convert them to `JavaScriptValue` on element access
4
+ /// without the need to create a new container (e.g. `std.vector<facebook.jsi.Value>` or `[JavaScriptValue]`).
5
+ /// Used mainly to pass function arguments from C++ to Swift.
8
6
  public struct JavaScriptValuesBuffer: JavaScriptType, ~Copyable {
9
7
  // Safe to use unowned — the buffer's lifetime is scoped to a host function call,
10
8
  // so the runtime is always alive while the buffer exists.
@@ -13,38 +11,37 @@ public struct JavaScriptValuesBuffer: JavaScriptType, ~Copyable {
13
11
  internal nonisolated(unsafe) let bufferPointer: UnsafeMutableBufferPointer<facebook.jsi.Value>
14
12
  private let ownsMemory: Bool
15
13
 
16
- /**
17
- A pointer to the first value of the buffer.
18
- If the baseAddress of this buffer is `nil`, the `count` is zero.
19
- */
14
+ /// A pointer to the first value of the buffer.
15
+ /// If the baseAddress of this buffer is `nil`, the `count` is zero.
20
16
  internal var baseAddress: UnsafePointer<facebook.jsi.Value>? {
21
17
  return UnsafePointer(bufferPointer.baseAddress)
22
18
  }
23
19
 
24
- /**
25
- A type-erased raw pointer to the first value of the buffer, suitable for
26
- passing across Swift/ObjC++ boundaries where `facebook.jsi.Value` cannot
27
- appear in a public signature.
28
- */
20
+ /// A type-erased raw pointer to the first value of the buffer, suitable for
21
+ /// passing across Swift/ObjC++ boundaries where `facebook.jsi.Value` cannot
22
+ /// appear in a public signature.
29
23
  public var rawBaseAddress: UnsafeRawPointer? {
30
24
  return baseAddress.map { UnsafeRawPointer($0) }
31
25
  }
32
26
 
33
- /**
34
- The number of values in the buffer.
35
- */
27
+ /// The number of values in the buffer.
36
28
  public var count: Int {
37
29
  return bufferPointer.count
38
30
  }
39
31
 
40
- internal init(_ runtime: JavaScriptRuntime, buffer: consuming UnsafeMutableBufferPointer<facebook.jsi.Value>, ownsMemory: Bool = false) {
32
+ internal init(
33
+ _ runtime: JavaScriptRuntime, buffer: consuming UnsafeMutableBufferPointer<facebook.jsi.Value>,
34
+ ownsMemory: Bool = false
35
+ ) {
41
36
  self.runtime = runtime
42
37
  self.bufferPointer = buffer
43
38
  self.ownsMemory = ownsMemory
44
39
  }
45
40
 
46
41
  internal init(_ runtime: JavaScriptRuntime, start: consuming UnsafePointer<facebook.jsi.Value>?, count: Int) {
47
- self.init(runtime, buffer: UnsafeMutableBufferPointer(start: UnsafeMutablePointer(mutating: start), count: count), ownsMemory: false)
42
+ self.init(
43
+ runtime, buffer: UnsafeMutableBufferPointer(start: UnsafeMutablePointer(mutating: start), count: count),
44
+ ownsMemory: false)
48
45
  }
49
46
 
50
47
  internal init(_ runtime: JavaScriptRuntime, buffer: consuming UnsafeBufferPointer<facebook.jsi.Value>) {
@@ -65,7 +62,8 @@ public struct JavaScriptValuesBuffer: JavaScriptType, ~Copyable {
65
62
  }
66
63
 
67
64
  @discardableResult
68
- internal consuming func set<T: JSIRepresentable>(value: borrowing T, atIndex index: Int) -> JavaScriptValuesBuffer where T: ~Copyable {
65
+ internal consuming func set<T: JSIRepresentable>(value: borrowing T, atIndex index: Int) -> JavaScriptValuesBuffer
66
+ where T: ~Copyable {
69
67
  guard (0..<count).contains(index) else {
70
68
  FatalError.valuesBufferIndexOutRange(index: index, capacity: count)
71
69
  }
@@ -74,7 +72,8 @@ public struct JavaScriptValuesBuffer: JavaScriptType, ~Copyable {
74
72
  }
75
73
 
76
74
  @JavaScriptActor
77
- public func map<T>(_ transform: @JavaScriptActor (_ value: JavaScriptValue, _ index: Int) throws -> T) rethrows -> [T] {
75
+ public func map<T>(_ transform: @JavaScriptActor (_ value: JavaScriptValue, _ index: Int) throws -> T) rethrows -> [T]
76
+ {
78
77
  var result: [T] = []
79
78
  result.reserveCapacity(count)
80
79
  for index in 0..<count {
@@ -85,9 +84,7 @@ public struct JavaScriptValuesBuffer: JavaScriptType, ~Copyable {
85
84
  return result
86
85
  }
87
86
 
88
- /**
89
- Allocates a new buffer of the same capacity with copies of `facebook.jsi.Value` it stores.
90
- */
87
+ /// Allocates a new buffer of the same capacity with copies of `facebook.jsi.Value` it stores.
91
88
  @JavaScriptActor
92
89
  public func copy() -> JavaScriptValuesBuffer {
93
90
  let bufferCopy = JavaScriptValuesBuffer.copying(in: runtime, buffer: bufferPointer)
@@ -103,19 +100,18 @@ public struct JavaScriptValuesBuffer: JavaScriptType, ~Copyable {
103
100
 
104
101
  // MARK: - Allocation
105
102
 
106
- /**
107
- Allocates new values buffer with the given capacity. The buffer is in uninitialized state.
108
- You must initialize all elements using `set(value:atIndex)` method.
109
- */
103
+ /// Allocates new values buffer with the given capacity. The buffer is in uninitialized state.
104
+ /// You must initialize all elements using `set(value:atIndex)` method.
110
105
  public static func allocate(in runtime: JavaScriptRuntime, capacity: Int) -> JavaScriptValuesBuffer {
111
- return JavaScriptValuesBuffer(runtime, buffer: UnsafeMutableBufferPointer<facebook.jsi.Value>.allocate(capacity: capacity), ownsMemory: true)
106
+ return JavaScriptValuesBuffer(
107
+ runtime, buffer: UnsafeMutableBufferPointer<facebook.jsi.Value>.allocate(capacity: capacity), ownsMemory: true)
112
108
  }
113
109
 
114
- /**
115
- Allocates new values buffer with the given JS representables.
116
- Note that parameter packs still do not support non-copyable types so they need to be passed as `JavaScriptRef`.
117
- */
118
- public static func allocate<each T: JavaScriptRepresentable>(in runtime: JavaScriptRuntime, with values: repeat each T) -> JavaScriptValuesBuffer {
110
+ /// Allocates new values buffer with the given JS representables.
111
+ /// Note that parameter packs still do not support non-copyable types so they need to be passed as `JavaScriptRef`.
112
+ public static func allocate<each T: JavaScriptRepresentable>(
113
+ in runtime: JavaScriptRuntime, with values: repeat each T
114
+ ) -> JavaScriptValuesBuffer {
119
115
  // First we count parameters in a pack to find the proper buffer capacity. This is still the simplest way.
120
116
  var capacity = 0
121
117
  for _ in repeat each values {
@@ -138,7 +134,9 @@ public struct JavaScriptValuesBuffer: JavaScriptType, ~Copyable {
138
134
  return JavaScriptValuesBuffer(runtime, buffer: buffer, ownsMemory: true)
139
135
  }
140
136
 
141
- internal static func copying(in runtime: JavaScriptRuntime, buffer: UnsafeMutableBufferPointer<facebook.jsi.Value>) -> UnsafeMutableBufferPointer<facebook.jsi.Value> {
137
+ internal static func copying(in runtime: JavaScriptRuntime, buffer: UnsafeMutableBufferPointer<facebook.jsi.Value>)
138
+ -> UnsafeMutableBufferPointer<facebook.jsi.Value>
139
+ {
142
140
  let copy = UnsafeMutableBufferPointer<facebook.jsi.Value>.allocate(capacity: buffer.count)
143
141
  for index in 0..<buffer.count {
144
142
  copy.initializeElement(at: index, to: facebook.jsi.Value(runtime.pointee, buffer[index]))
@@ -146,16 +144,15 @@ public struct JavaScriptValuesBuffer: JavaScriptType, ~Copyable {
146
144
  return copy
147
145
  }
148
146
 
149
- /**
150
- Allocates a new owning buffer holding a runtime-aware copy of each value's
151
- underlying `facebook.jsi.Value`. The given `JavaScriptValue`s must all belong
152
- to `runtime`; mixing runtimes will crash deep inside JSI.
153
- */
147
+ /// Allocates a new owning buffer holding a runtime-aware copy of each value's
148
+ /// underlying `facebook.jsi.Value`. The given `JavaScriptValue`s must all belong
149
+ /// to `runtime`; mixing runtimes will crash deep inside JSI.
154
150
  @JavaScriptActor
155
151
  public static func copying(in runtime: JavaScriptRuntime, values: [JavaScriptValue]) -> JavaScriptValuesBuffer {
156
152
  let buffer = UnsafeMutableBufferPointer<facebook.jsi.Value>.allocate(capacity: values.count)
157
153
  for (index, value) in values.enumerated() {
158
- assert(value.runtime === runtime, "JavaScriptValue belongs to a different runtime than the buffer being initialized")
154
+ assert(
155
+ value.runtime === runtime, "JavaScriptValue belongs to a different runtime than the buffer being initialized")
159
156
  buffer.initializeElement(at: index, to: facebook.jsi.Value(runtime.pointee, value.pointee))
160
157
  }
161
158
  return JavaScriptValuesBuffer(runtime, buffer: buffer, ownsMemory: true)