Skip to content

Commit 6716b07

Browse files
BridgeJS: Ensure extern func decl won't be visible outside of the generated file
1 parent eddc81f commit 6716b07

File tree

18 files changed

+163
-160
lines changed

18 files changed

+163
-160
lines changed

Benchmarks/Sources/Generated/BridgeJS.ImportTS.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
#if arch(wasm32)
1010
@_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkHelperNoop")
11-
func bjs_benchmarkHelperNoop() -> Void
11+
fileprivate func bjs_benchmarkHelperNoop() -> Void
1212
#else
13-
func bjs_benchmarkHelperNoop() -> Void {
13+
fileprivate func bjs_benchmarkHelperNoop() -> Void {
1414
fatalError("Only available on WebAssembly")
1515
}
1616
#endif
@@ -24,9 +24,9 @@ func benchmarkHelperNoop() throws(JSException) -> Void {
2424

2525
#if arch(wasm32)
2626
@_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkHelperNoopWithNumber")
27-
func bjs_benchmarkHelperNoopWithNumber(_ n: Float64) -> Void
27+
fileprivate func bjs_benchmarkHelperNoopWithNumber(_ n: Float64) -> Void
2828
#else
29-
func bjs_benchmarkHelperNoopWithNumber(_ n: Float64) -> Void {
29+
fileprivate func bjs_benchmarkHelperNoopWithNumber(_ n: Float64) -> Void {
3030
fatalError("Only available on WebAssembly")
3131
}
3232
#endif
@@ -40,9 +40,9 @@ func benchmarkHelperNoopWithNumber(_ n: Double) throws(JSException) -> Void {
4040

4141
#if arch(wasm32)
4242
@_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkRunner")
43-
func bjs_benchmarkRunner(_ name: Int32, _ body: Int32) -> Void
43+
fileprivate func bjs_benchmarkRunner(_ name: Int32, _ body: Int32) -> Void
4444
#else
45-
func bjs_benchmarkRunner(_ name: Int32, _ body: Int32) -> Void {
45+
fileprivate func bjs_benchmarkRunner(_ name: Int32, _ body: Int32) -> Void {
4646
fatalError("Only available on WebAssembly")
4747
}
4848
#endif

Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.ImportTS.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
#if arch(wasm32)
1010
@_extern(wasm, module: "PlayBridgeJS", name: "bjs_createTS2Skeleton")
11-
func bjs_createTS2Skeleton() -> Int32
11+
fileprivate func bjs_createTS2Skeleton() -> Int32
1212
#else
13-
func bjs_createTS2Skeleton() -> Int32 {
13+
fileprivate func bjs_createTS2Skeleton() -> Int32 {
1414
fatalError("Only available on WebAssembly")
1515
}
1616
#endif
@@ -25,9 +25,9 @@ func createTS2Skeleton() throws(JSException) -> TS2Skeleton {
2525

2626
#if arch(wasm32)
2727
@_extern(wasm, module: "PlayBridgeJS", name: "bjs_TS2Skeleton_convert")
28-
func bjs_TS2Skeleton_convert(_ self: Int32, _ ts: Int32) -> Int32
28+
fileprivate func bjs_TS2Skeleton_convert(_ self: Int32, _ ts: Int32) -> Int32
2929
#else
30-
func bjs_TS2Skeleton_convert(_ self: Int32, _ ts: Int32) -> Int32 {
30+
fileprivate func bjs_TS2Skeleton_convert(_ self: Int32, _ ts: Int32) -> Int32 {
3131
fatalError("Only available on WebAssembly")
3232
}
3333
#endif

Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2501,11 +2501,11 @@ public class ExportSwift {
25012501
/// ```swift
25022502
/// extension Greeter: ConvertibleToJSValue, _BridgedSwiftHeapObject {
25032503
/// var jsValue: JSValue {
2504-
/// @_extern(wasm, module: "MyModule", name: "bjs_Greeter_wrap")
2505-
/// func _bjs_Greeter_wrap(_: UnsafeMutableRawPointer) -> Int32
25062504
/// return JSObject(id: UInt32(bitPattern: _bjs_Greeter_wrap(Unmanaged.passRetained(self).toOpaque())))
25072505
/// }
25082506
/// }
2507+
/// @_extern(wasm, module: "MyModule", name: "bjs_Greeter_wrap")
2508+
/// fileprivate func _bjs_Greeter_wrap(_: UnsafeMutableRawPointer) -> Int32
25092509
/// ```
25102510
func renderConvertibleToJSValueExtension(klass: ExportedClass) -> [DeclSyntax] {
25112511
let wrapFunctionName = "_bjs_\(klass.name)_wrap"

Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ public struct ImportTS {
116116

117117
func renderImportDecl() -> DeclSyntax {
118118
let baseDecl = FunctionDeclSyntax(
119+
modifiers: DeclModifierListSyntax(itemsBuilder: {
120+
DeclModifierSyntax(name: .keyword(.fileprivate)).with(\.trailingTrivia, .space)
121+
}),
119122
funcKeyword: .keyword(.func).with(\.trailingTrivia, .space),
120123
name: .identifier(abiName),
121124
signature: FunctionSignatureSyntax(

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ArrayParameter.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
#if arch(wasm32)
1010
@_extern(wasm, module: "Check", name: "bjs_checkArray")
11-
func bjs_checkArray(_ a: Int32) -> Void
11+
fileprivate func bjs_checkArray(_ a: Int32) -> Void
1212
#else
13-
func bjs_checkArray(_ a: Int32) -> Void {
13+
fileprivate func bjs_checkArray(_ a: Int32) -> Void {
1414
fatalError("Only available on WebAssembly")
1515
}
1616
#endif
@@ -24,9 +24,9 @@ func checkArray(_ a: JSObject) throws(JSException) -> Void {
2424

2525
#if arch(wasm32)
2626
@_extern(wasm, module: "Check", name: "bjs_checkArrayWithLength")
27-
func bjs_checkArrayWithLength(_ a: Int32, _ b: Float64) -> Void
27+
fileprivate func bjs_checkArrayWithLength(_ a: Int32, _ b: Float64) -> Void
2828
#else
29-
func bjs_checkArrayWithLength(_ a: Int32, _ b: Float64) -> Void {
29+
fileprivate func bjs_checkArrayWithLength(_ a: Int32, _ b: Float64) -> Void {
3030
fatalError("Only available on WebAssembly")
3131
}
3232
#endif
@@ -40,9 +40,9 @@ func checkArrayWithLength(_ a: JSObject, _ b: Double) throws(JSException) -> Voi
4040

4141
#if arch(wasm32)
4242
@_extern(wasm, module: "Check", name: "bjs_checkArray")
43-
func bjs_checkArray(_ a: Int32) -> Void
43+
fileprivate func bjs_checkArray(_ a: Int32) -> Void
4444
#else
45-
func bjs_checkArray(_ a: Int32) -> Void {
45+
fileprivate func bjs_checkArray(_ a: Int32) -> Void {
4646
fatalError("Only available on WebAssembly")
4747
}
4848
#endif

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Async.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
#if arch(wasm32)
1010
@_extern(wasm, module: "Check", name: "bjs_asyncReturnVoid")
11-
func bjs_asyncReturnVoid() -> Int32
11+
fileprivate func bjs_asyncReturnVoid() -> Int32
1212
#else
13-
func bjs_asyncReturnVoid() -> Int32 {
13+
fileprivate func bjs_asyncReturnVoid() -> Int32 {
1414
fatalError("Only available on WebAssembly")
1515
}
1616
#endif
@@ -25,9 +25,9 @@ func asyncReturnVoid() throws(JSException) -> JSPromise {
2525

2626
#if arch(wasm32)
2727
@_extern(wasm, module: "Check", name: "bjs_asyncRoundTripInt")
28-
func bjs_asyncRoundTripInt(_ v: Float64) -> Int32
28+
fileprivate func bjs_asyncRoundTripInt(_ v: Float64) -> Int32
2929
#else
30-
func bjs_asyncRoundTripInt(_ v: Float64) -> Int32 {
30+
fileprivate func bjs_asyncRoundTripInt(_ v: Float64) -> Int32 {
3131
fatalError("Only available on WebAssembly")
3232
}
3333
#endif
@@ -42,9 +42,9 @@ func asyncRoundTripInt(_ v: Double) throws(JSException) -> JSPromise {
4242

4343
#if arch(wasm32)
4444
@_extern(wasm, module: "Check", name: "bjs_asyncRoundTripString")
45-
func bjs_asyncRoundTripString(_ v: Int32) -> Int32
45+
fileprivate func bjs_asyncRoundTripString(_ v: Int32) -> Int32
4646
#else
47-
func bjs_asyncRoundTripString(_ v: Int32) -> Int32 {
47+
fileprivate func bjs_asyncRoundTripString(_ v: Int32) -> Int32 {
4848
fatalError("Only available on WebAssembly")
4949
}
5050
#endif
@@ -59,9 +59,9 @@ func asyncRoundTripString(_ v: String) throws(JSException) -> JSPromise {
5959

6060
#if arch(wasm32)
6161
@_extern(wasm, module: "Check", name: "bjs_asyncRoundTripBool")
62-
func bjs_asyncRoundTripBool(_ v: Int32) -> Int32
62+
fileprivate func bjs_asyncRoundTripBool(_ v: Int32) -> Int32
6363
#else
64-
func bjs_asyncRoundTripBool(_ v: Int32) -> Int32 {
64+
fileprivate func bjs_asyncRoundTripBool(_ v: Int32) -> Int32 {
6565
fatalError("Only available on WebAssembly")
6666
}
6767
#endif
@@ -76,9 +76,9 @@ func asyncRoundTripBool(_ v: Bool) throws(JSException) -> JSPromise {
7676

7777
#if arch(wasm32)
7878
@_extern(wasm, module: "Check", name: "bjs_asyncRoundTripFloat")
79-
func bjs_asyncRoundTripFloat(_ v: Float64) -> Int32
79+
fileprivate func bjs_asyncRoundTripFloat(_ v: Float64) -> Int32
8080
#else
81-
func bjs_asyncRoundTripFloat(_ v: Float64) -> Int32 {
81+
fileprivate func bjs_asyncRoundTripFloat(_ v: Float64) -> Int32 {
8282
fatalError("Only available on WebAssembly")
8383
}
8484
#endif
@@ -93,9 +93,9 @@ func asyncRoundTripFloat(_ v: Double) throws(JSException) -> JSPromise {
9393

9494
#if arch(wasm32)
9595
@_extern(wasm, module: "Check", name: "bjs_asyncRoundTripDouble")
96-
func bjs_asyncRoundTripDouble(_ v: Float64) -> Int32
96+
fileprivate func bjs_asyncRoundTripDouble(_ v: Float64) -> Int32
9797
#else
98-
func bjs_asyncRoundTripDouble(_ v: Float64) -> Int32 {
98+
fileprivate func bjs_asyncRoundTripDouble(_ v: Float64) -> Int32 {
9999
fatalError("Only available on WebAssembly")
100100
}
101101
#endif
@@ -110,9 +110,9 @@ func asyncRoundTripDouble(_ v: Double) throws(JSException) -> JSPromise {
110110

111111
#if arch(wasm32)
112112
@_extern(wasm, module: "Check", name: "bjs_asyncRoundTripJSObject")
113-
func bjs_asyncRoundTripJSObject(_ v: Int32) -> Int32
113+
fileprivate func bjs_asyncRoundTripJSObject(_ v: Int32) -> Int32
114114
#else
115-
func bjs_asyncRoundTripJSObject(_ v: Int32) -> Int32 {
115+
fileprivate func bjs_asyncRoundTripJSObject(_ v: Int32) -> Int32 {
116116
fatalError("Only available on WebAssembly")
117117
}
118118
#endif

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Interface.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
#if arch(wasm32)
1010
@_extern(wasm, module: "Check", name: "bjs_returnAnimatable")
11-
func bjs_returnAnimatable() -> Int32
11+
fileprivate func bjs_returnAnimatable() -> Int32
1212
#else
13-
func bjs_returnAnimatable() -> Int32 {
13+
fileprivate func bjs_returnAnimatable() -> Int32 {
1414
fatalError("Only available on WebAssembly")
1515
}
1616
#endif
@@ -25,18 +25,18 @@ func returnAnimatable() throws(JSException) -> Animatable {
2525

2626
#if arch(wasm32)
2727
@_extern(wasm, module: "Check", name: "bjs_Animatable_animate")
28-
func bjs_Animatable_animate(_ self: Int32, _ keyframes: Int32, _ options: Int32) -> Int32
28+
fileprivate func bjs_Animatable_animate(_ self: Int32, _ keyframes: Int32, _ options: Int32) -> Int32
2929
#else
30-
func bjs_Animatable_animate(_ self: Int32, _ keyframes: Int32, _ options: Int32) -> Int32 {
30+
fileprivate func bjs_Animatable_animate(_ self: Int32, _ keyframes: Int32, _ options: Int32) -> Int32 {
3131
fatalError("Only available on WebAssembly")
3232
}
3333
#endif
3434

3535
#if arch(wasm32)
3636
@_extern(wasm, module: "Check", name: "bjs_Animatable_getAnimations")
37-
func bjs_Animatable_getAnimations(_ self: Int32, _ options: Int32) -> Int32
37+
fileprivate func bjs_Animatable_getAnimations(_ self: Int32, _ options: Int32) -> Int32
3838
#else
39-
func bjs_Animatable_getAnimations(_ self: Int32, _ options: Int32) -> Int32 {
39+
fileprivate func bjs_Animatable_getAnimations(_ self: Int32, _ options: Int32) -> Int32 {
4040
fatalError("Only available on WebAssembly")
4141
}
4242
#endif

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/InvalidPropertyNames.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
#if arch(wasm32)
1010
@_extern(wasm, module: "Check", name: "bjs_createArrayBuffer")
11-
func bjs_createArrayBuffer() -> Int32
11+
fileprivate func bjs_createArrayBuffer() -> Int32
1212
#else
13-
func bjs_createArrayBuffer() -> Int32 {
13+
fileprivate func bjs_createArrayBuffer() -> Int32 {
1414
fatalError("Only available on WebAssembly")
1515
}
1616
#endif
@@ -25,9 +25,9 @@ func createArrayBuffer() throws(JSException) -> ArrayBufferLike {
2525

2626
#if arch(wasm32)
2727
@_extern(wasm, module: "Check", name: "bjs_createWeirdObject")
28-
func bjs_createWeirdObject() -> Int32
28+
fileprivate func bjs_createWeirdObject() -> Int32
2929
#else
30-
func bjs_createWeirdObject() -> Int32 {
30+
fileprivate func bjs_createWeirdObject() -> Int32 {
3131
fatalError("Only available on WebAssembly")
3232
}
3333
#endif
@@ -42,18 +42,18 @@ func createWeirdObject() throws(JSException) -> WeirdNaming {
4242

4343
#if arch(wasm32)
4444
@_extern(wasm, module: "Check", name: "bjs_ArrayBufferLike_byteLength_get")
45-
func bjs_ArrayBufferLike_byteLength_get(_ self: Int32) -> Float64
45+
fileprivate func bjs_ArrayBufferLike_byteLength_get(_ self: Int32) -> Float64
4646
#else
47-
func bjs_ArrayBufferLike_byteLength_get(_ self: Int32) -> Float64 {
47+
fileprivate func bjs_ArrayBufferLike_byteLength_get(_ self: Int32) -> Float64 {
4848
fatalError("Only available on WebAssembly")
4949
}
5050
#endif
5151

5252
#if arch(wasm32)
5353
@_extern(wasm, module: "Check", name: "bjs_ArrayBufferLike_slice")
54-
func bjs_ArrayBufferLike_slice(_ self: Int32, _ begin: Float64, _ end: Float64) -> Int32
54+
fileprivate func bjs_ArrayBufferLike_slice(_ self: Int32, _ begin: Float64, _ end: Float64) -> Int32
5555
#else
56-
func bjs_ArrayBufferLike_slice(_ self: Int32, _ begin: Float64, _ end: Float64) -> Int32 {
56+
fileprivate func bjs_ArrayBufferLike_slice(_ self: Int32, _ begin: Float64, _ end: Float64) -> Int32 {
5757
fatalError("Only available on WebAssembly")
5858
}
5959
#endif
@@ -87,63 +87,63 @@ struct ArrayBufferLike: _JSBridgedClass {
8787

8888
#if arch(wasm32)
8989
@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_normalProperty_get")
90-
func bjs_WeirdNaming_normalProperty_get(_ self: Int32) -> Int32
90+
fileprivate func bjs_WeirdNaming_normalProperty_get(_ self: Int32) -> Int32
9191
#else
92-
func bjs_WeirdNaming_normalProperty_get(_ self: Int32) -> Int32 {
92+
fileprivate func bjs_WeirdNaming_normalProperty_get(_ self: Int32) -> Int32 {
9393
fatalError("Only available on WebAssembly")
9494
}
9595
#endif
9696

9797
#if arch(wasm32)
9898
@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_normalProperty_set")
99-
func bjs_WeirdNaming_normalProperty_set(_ self: Int32, _ newValue: Int32) -> Void
99+
fileprivate func bjs_WeirdNaming_normalProperty_set(_ self: Int32, _ newValue: Int32) -> Void
100100
#else
101-
func bjs_WeirdNaming_normalProperty_set(_ self: Int32, _ newValue: Int32) -> Void {
101+
fileprivate func bjs_WeirdNaming_normalProperty_set(_ self: Int32, _ newValue: Int32) -> Void {
102102
fatalError("Only available on WebAssembly")
103103
}
104104
#endif
105105

106106
#if arch(wasm32)
107107
@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_for_get")
108-
func bjs_WeirdNaming_for_get(_ self: Int32) -> Int32
108+
fileprivate func bjs_WeirdNaming_for_get(_ self: Int32) -> Int32
109109
#else
110-
func bjs_WeirdNaming_for_get(_ self: Int32) -> Int32 {
110+
fileprivate func bjs_WeirdNaming_for_get(_ self: Int32) -> Int32 {
111111
fatalError("Only available on WebAssembly")
112112
}
113113
#endif
114114

115115
#if arch(wasm32)
116116
@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_for_set")
117-
func bjs_WeirdNaming_for_set(_ self: Int32, _ newValue: Int32) -> Void
117+
fileprivate func bjs_WeirdNaming_for_set(_ self: Int32, _ newValue: Int32) -> Void
118118
#else
119-
func bjs_WeirdNaming_for_set(_ self: Int32, _ newValue: Int32) -> Void {
119+
fileprivate func bjs_WeirdNaming_for_set(_ self: Int32, _ newValue: Int32) -> Void {
120120
fatalError("Only available on WebAssembly")
121121
}
122122
#endif
123123

124124
#if arch(wasm32)
125125
@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_Any_get")
126-
func bjs_WeirdNaming_Any_get(_ self: Int32) -> Int32
126+
fileprivate func bjs_WeirdNaming_Any_get(_ self: Int32) -> Int32
127127
#else
128-
func bjs_WeirdNaming_Any_get(_ self: Int32) -> Int32 {
128+
fileprivate func bjs_WeirdNaming_Any_get(_ self: Int32) -> Int32 {
129129
fatalError("Only available on WebAssembly")
130130
}
131131
#endif
132132

133133
#if arch(wasm32)
134134
@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_Any_set")
135-
func bjs_WeirdNaming_Any_set(_ self: Int32, _ newValue: Int32) -> Void
135+
fileprivate func bjs_WeirdNaming_Any_set(_ self: Int32, _ newValue: Int32) -> Void
136136
#else
137-
func bjs_WeirdNaming_Any_set(_ self: Int32, _ newValue: Int32) -> Void {
137+
fileprivate func bjs_WeirdNaming_Any_set(_ self: Int32, _ newValue: Int32) -> Void {
138138
fatalError("Only available on WebAssembly")
139139
}
140140
#endif
141141

142142
#if arch(wasm32)
143143
@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_as")
144-
func bjs_WeirdNaming_as(_ self: Int32) -> Void
144+
fileprivate func bjs_WeirdNaming_as(_ self: Int32) -> Void
145145
#else
146-
func bjs_WeirdNaming_as(_ self: Int32) -> Void {
146+
fileprivate func bjs_WeirdNaming_as(_ self: Int32) -> Void {
147147
fatalError("Only available on WebAssembly")
148148
}
149149
#endif

0 commit comments

Comments
 (0)