@expo/expo-modules-macros-plugin 0.6.1 → 0.6.2
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.
|
Binary file
|
|
@@ -60,7 +60,7 @@ internal struct JSFunction {
|
|
|
60
60
|
let maximum = parameters.count
|
|
61
61
|
var lines: [String] = []
|
|
62
62
|
|
|
63
|
-
if let unwrap = receiver.unwrapStatement {
|
|
63
|
+
if let unwrap = receiver.unwrapStatement(isAsync: isAsync) {
|
|
64
64
|
lines.append(unwrap)
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -253,8 +253,9 @@ internal struct JSProperty {
|
|
|
253
253
|
let callee = receiver.callee
|
|
254
254
|
let object = receiver.decoratedObject
|
|
255
255
|
// A shared object's accessors unwrap the JS `this` into `_self` before reading/writing; a module
|
|
256
|
-
// reads `self` directly. The unwrap leads each accessor body.
|
|
257
|
-
|
|
256
|
+
// reads `self` directly. The unwrap leads each accessor body. Property accessors are synchronous, so
|
|
257
|
+
// they take the borrowed unowned `this`.
|
|
258
|
+
let unwrap = receiver.unwrapStatement(isAsync: false).map { "\($0)\n" } ?? ""
|
|
258
259
|
var lines: [String] = []
|
|
259
260
|
|
|
260
261
|
lines.append("let \(descriptorName) = runtime.createObject()")
|
|
@@ -145,14 +145,13 @@ internal func memberHasJSAttribute(_ decl: DeclSyntaxProtocol) -> Bool {
|
|
|
145
145
|
return false
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
*/
|
|
148
|
+
/// Decides whether the macro should stamp `@JavaScriptActor` on a `@JS`-marked member.
|
|
149
|
+
/// The macro defers to the user when they've already chosen an isolation:
|
|
150
|
+
/// - the `nonisolated` modifier is present on the member
|
|
151
|
+
/// - any attribute whose name matches a known global actor (`@MainActor`, `@JavaScriptActor`)
|
|
152
|
+
/// or follows the `*Actor` naming convention is present on the member or its enclosing type
|
|
153
|
+
/// `async` members are stamped too: an `async` function starts its execution on the JS thread and
|
|
154
|
+
/// stays there until the first suspension point, where it may hop to another executor.
|
|
156
155
|
internal func shouldStampJavaScriptActor(
|
|
157
156
|
on member: DeclSyntaxProtocol,
|
|
158
157
|
enclosedBy enclosing: some DeclGroupSyntax
|
|
@@ -162,11 +161,6 @@ internal func shouldStampJavaScriptActor(
|
|
|
162
161
|
return false
|
|
163
162
|
}
|
|
164
163
|
|
|
165
|
-
if let funcDecl = member.as(FunctionDeclSyntax.self),
|
|
166
|
-
funcDecl.signature.effectSpecifiers?.asyncSpecifier != nil {
|
|
167
|
-
return false
|
|
168
|
-
}
|
|
169
|
-
|
|
170
164
|
let memberAttributes = memberAttributes(of: member)
|
|
171
165
|
if memberAttributes.contains(where: hasGlobalActorShape) {
|
|
172
166
|
return false
|
|
@@ -33,14 +33,19 @@ internal enum Receiver {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/// The leading body line binding the receiver, or `nil` for a module (it reads `self` directly). For a
|
|
36
|
-
/// shared object, `native(from:as:)` recovers the typed instance from
|
|
37
|
-
///
|
|
38
|
-
|
|
36
|
+
/// shared object, `native(from:as:)` recovers the typed instance from `this`, throwing on a foreign
|
|
37
|
+
/// object or a type mismatch.
|
|
38
|
+
///
|
|
39
|
+
/// The `this` object comes from the borrowed `JavaScriptUnownedValue` in a sync binding (`asObject(in:)`)
|
|
40
|
+
/// and from the owning `JavaScriptValue` in an async one (`asObject()`). An async binding must take an
|
|
41
|
+
/// owning `this` because a borrowed unowned value can't survive the closure's suspension points.
|
|
42
|
+
func unwrapStatement(isAsync: Bool) -> String? {
|
|
39
43
|
switch self {
|
|
40
44
|
case .module:
|
|
41
45
|
return nil
|
|
42
46
|
case .sharedObject(let typeName):
|
|
43
|
-
|
|
47
|
+
let thisObject = isAsync ? "this.asObject()" : "this.asObject(in: runtime)"
|
|
48
|
+
return "let _self = try SharedObject.native(from: \(thisObject), as: \(typeName).self)"
|
|
44
49
|
}
|
|
45
50
|
}
|
|
46
51
|
|