Skip to content

Commit 9de77fc

Browse files
[NFC] BridgeJS: Move optional support test imports to their own JS class
1 parent f2a35c8 commit 9de77fc

File tree

5 files changed

+190
-164
lines changed

5 files changed

+190
-164
lines changed

Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10147,93 +10147,93 @@ func _$jsTranslatePoint(_ point: Point, _ dx: Int, _ dy: Int) throws(JSException
1014710147
}
1014810148

1014910149
#if arch(wasm32)
10150-
@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_runJsOptionalSupportTests")
10151-
fileprivate func bjs_runJsOptionalSupportTests() -> Void
10150+
@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_OptionalSupportImports_jsRoundTripOptionalNumberNull_static")
10151+
fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalNumberNull_static(_ valueIsSome: Int32, _ valueValue: Int32) -> Void
1015210152
#else
10153-
fileprivate func bjs_runJsOptionalSupportTests() -> Void {
10153+
fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalNumberNull_static(_ valueIsSome: Int32, _ valueValue: Int32) -> Void {
1015410154
fatalError("Only available on WebAssembly")
1015510155
}
1015610156
#endif
1015710157

10158-
func _$runJsOptionalSupportTests() throws(JSException) -> Void {
10159-
bjs_runJsOptionalSupportTests()
10160-
if let error = _swift_js_take_exception() {
10161-
throw error
10162-
}
10158+
#if arch(wasm32)
10159+
@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_OptionalSupportImports_jsRoundTripOptionalNumberUndefined_static")
10160+
fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalNumberUndefined_static(_ valueIsSome: Int32, _ valueValue: Int32) -> Void
10161+
#else
10162+
fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalNumberUndefined_static(_ valueIsSome: Int32, _ valueValue: Int32) -> Void {
10163+
fatalError("Only available on WebAssembly")
1016310164
}
10165+
#endif
1016410166

1016510167
#if arch(wasm32)
10166-
@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripOptionalNumberNull")
10167-
fileprivate func bjs_jsRoundTripOptionalNumberNull(_ valueIsSome: Int32, _ valueValue: Int32) -> Void
10168+
@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_OptionalSupportImports_jsRoundTripOptionalStringNull_static")
10169+
fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalStringNull_static(_ nameIsSome: Int32, _ nameValue: Int32) -> Void
1016810170
#else
10169-
fileprivate func bjs_jsRoundTripOptionalNumberNull(_ valueIsSome: Int32, _ valueValue: Int32) -> Void {
10171+
fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalStringNull_static(_ nameIsSome: Int32, _ nameValue: Int32) -> Void {
1017010172
fatalError("Only available on WebAssembly")
1017110173
}
1017210174
#endif
1017310175

10174-
func _$jsRoundTripOptionalNumberNull(_ value: Optional<Int>) throws(JSException) -> Optional<Int> {
10175-
let (valueIsSome, valueValue) = value.bridgeJSLowerParameter()
10176-
bjs_jsRoundTripOptionalNumberNull(valueIsSome, valueValue)
10177-
if let error = _swift_js_take_exception() {
10178-
throw error
10179-
}
10180-
return Optional<Int>.bridgeJSLiftReturnFromSideChannel()
10176+
#if arch(wasm32)
10177+
@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_OptionalSupportImports_jsRoundTripOptionalStringUndefined_static")
10178+
fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalStringUndefined_static(_ nameIsSome: Int32, _ nameValue: Int32) -> Void
10179+
#else
10180+
fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalStringUndefined_static(_ nameIsSome: Int32, _ nameValue: Int32) -> Void {
10181+
fatalError("Only available on WebAssembly")
1018110182
}
10183+
#endif
1018210184

1018310185
#if arch(wasm32)
10184-
@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripOptionalNumberUndefined")
10185-
fileprivate func bjs_jsRoundTripOptionalNumberUndefined(_ valueIsSome: Int32, _ valueValue: Int32) -> Void
10186+
@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_OptionalSupportImports_runJsOptionalSupportTests_static")
10187+
fileprivate func bjs_OptionalSupportImports_runJsOptionalSupportTests_static() -> Void
1018610188
#else
10187-
fileprivate func bjs_jsRoundTripOptionalNumberUndefined(_ valueIsSome: Int32, _ valueValue: Int32) -> Void {
10189+
fileprivate func bjs_OptionalSupportImports_runJsOptionalSupportTests_static() -> Void {
1018810190
fatalError("Only available on WebAssembly")
1018910191
}
1019010192
#endif
1019110193

10192-
func _$jsRoundTripOptionalNumberUndefined(_ value: JSUndefinedOr<Int>) throws(JSException) -> JSUndefinedOr<Int> {
10194+
func _$OptionalSupportImports_jsRoundTripOptionalNumberNull(_ value: Optional<Int>) throws(JSException) -> Optional<Int> {
1019310195
let (valueIsSome, valueValue) = value.bridgeJSLowerParameter()
10194-
bjs_jsRoundTripOptionalNumberUndefined(valueIsSome, valueValue)
10196+
bjs_OptionalSupportImports_jsRoundTripOptionalNumberNull_static(valueIsSome, valueValue)
1019510197
if let error = _swift_js_take_exception() {
1019610198
throw error
1019710199
}
10198-
return JSUndefinedOr<Int>.bridgeJSLiftReturnFromSideChannel()
10200+
return Optional<Int>.bridgeJSLiftReturnFromSideChannel()
1019910201
}
1020010202

10201-
#if arch(wasm32)
10202-
@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripOptionalStringNull")
10203-
fileprivate func bjs_jsRoundTripOptionalStringNull(_ nameIsSome: Int32, _ nameValue: Int32) -> Void
10204-
#else
10205-
fileprivate func bjs_jsRoundTripOptionalStringNull(_ nameIsSome: Int32, _ nameValue: Int32) -> Void {
10206-
fatalError("Only available on WebAssembly")
10203+
func _$OptionalSupportImports_jsRoundTripOptionalNumberUndefined(_ value: JSUndefinedOr<Int>) throws(JSException) -> JSUndefinedOr<Int> {
10204+
let (valueIsSome, valueValue) = value.bridgeJSLowerParameter()
10205+
bjs_OptionalSupportImports_jsRoundTripOptionalNumberUndefined_static(valueIsSome, valueValue)
10206+
if let error = _swift_js_take_exception() {
10207+
throw error
10208+
}
10209+
return JSUndefinedOr<Int>.bridgeJSLiftReturnFromSideChannel()
1020710210
}
10208-
#endif
1020910211

10210-
func _$jsRoundTripOptionalStringNull(_ name: Optional<String>) throws(JSException) -> Optional<String> {
10212+
func _$OptionalSupportImports_jsRoundTripOptionalStringNull(_ name: Optional<String>) throws(JSException) -> Optional<String> {
1021110213
let (nameIsSome, nameValue) = name.bridgeJSLowerParameter()
10212-
bjs_jsRoundTripOptionalStringNull(nameIsSome, nameValue)
10214+
bjs_OptionalSupportImports_jsRoundTripOptionalStringNull_static(nameIsSome, nameValue)
1021310215
if let error = _swift_js_take_exception() {
1021410216
throw error
1021510217
}
1021610218
return Optional<String>.bridgeJSLiftReturnFromSideChannel()
1021710219
}
1021810220

10219-
#if arch(wasm32)
10220-
@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripOptionalStringUndefined")
10221-
fileprivate func bjs_jsRoundTripOptionalStringUndefined(_ nameIsSome: Int32, _ nameValue: Int32) -> Void
10222-
#else
10223-
fileprivate func bjs_jsRoundTripOptionalStringUndefined(_ nameIsSome: Int32, _ nameValue: Int32) -> Void {
10224-
fatalError("Only available on WebAssembly")
10225-
}
10226-
#endif
10227-
10228-
func _$jsRoundTripOptionalStringUndefined(_ name: JSUndefinedOr<String>) throws(JSException) -> JSUndefinedOr<String> {
10221+
func _$OptionalSupportImports_jsRoundTripOptionalStringUndefined(_ name: JSUndefinedOr<String>) throws(JSException) -> JSUndefinedOr<String> {
1022910222
let (nameIsSome, nameValue) = name.bridgeJSLowerParameter()
10230-
bjs_jsRoundTripOptionalStringUndefined(nameIsSome, nameValue)
10223+
bjs_OptionalSupportImports_jsRoundTripOptionalStringUndefined_static(nameIsSome, nameValue)
1023110224
if let error = _swift_js_take_exception() {
1023210225
throw error
1023310226
}
1023410227
return JSUndefinedOr<String>.bridgeJSLiftReturnFromSideChannel()
1023510228
}
1023610229

10230+
func _$OptionalSupportImports_runJsOptionalSupportTests() throws(JSException) -> Void {
10231+
bjs_OptionalSupportImports_runJsOptionalSupportTests_static()
10232+
if let error = _swift_js_take_exception() {
10233+
throw error
10234+
}
10235+
}
10236+
1023710237
#if arch(wasm32)
1023810238
@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_SwiftClassSupportImports_jsRoundTripGreeter_static")
1023910239
fileprivate func bjs_SwiftClassSupportImports_jsRoundTripGreeter_static(_ greeter: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer

Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json

Lines changed: 89 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -15266,23 +15266,39 @@
1526615266
},
1526715267
{
1526815268
"functions" : [
15269+
15270+
],
15271+
"types" : [
1526915272
{
15270-
"name" : "runJsOptionalSupportTests",
15271-
"parameters" : [
15273+
"getters" : [
1527215274

1527315275
],
15274-
"returnType" : {
15275-
"void" : {
15276+
"methods" : [
1527615277

15277-
}
15278-
}
15279-
},
15280-
{
15281-
"name" : "jsRoundTripOptionalNumberNull",
15282-
"parameters" : [
15278+
],
15279+
"name" : "OptionalSupportImports",
15280+
"setters" : [
15281+
15282+
],
15283+
"staticMethods" : [
1528315284
{
15284-
"name" : "value",
15285-
"type" : {
15285+
"name" : "jsRoundTripOptionalNumberNull",
15286+
"parameters" : [
15287+
{
15288+
"name" : "value",
15289+
"type" : {
15290+
"nullable" : {
15291+
"_0" : {
15292+
"int" : {
15293+
15294+
}
15295+
},
15296+
"_1" : "null"
15297+
}
15298+
}
15299+
}
15300+
],
15301+
"returnType" : {
1528615302
"nullable" : {
1528715303
"_0" : {
1528815304
"int" : {
@@ -15292,25 +15308,25 @@
1529215308
"_1" : "null"
1529315309
}
1529415310
}
15295-
}
15296-
],
15297-
"returnType" : {
15298-
"nullable" : {
15299-
"_0" : {
15300-
"int" : {
15311+
},
15312+
{
15313+
"name" : "jsRoundTripOptionalNumberUndefined",
15314+
"parameters" : [
15315+
{
15316+
"name" : "value",
15317+
"type" : {
15318+
"nullable" : {
15319+
"_0" : {
15320+
"int" : {
1530115321

15322+
}
15323+
},
15324+
"_1" : "undefined"
15325+
}
15326+
}
1530215327
}
15303-
},
15304-
"_1" : "null"
15305-
}
15306-
}
15307-
},
15308-
{
15309-
"name" : "jsRoundTripOptionalNumberUndefined",
15310-
"parameters" : [
15311-
{
15312-
"name" : "value",
15313-
"type" : {
15328+
],
15329+
"returnType" : {
1531415330
"nullable" : {
1531515331
"_0" : {
1531615332
"int" : {
@@ -15320,25 +15336,25 @@
1532015336
"_1" : "undefined"
1532115337
}
1532215338
}
15323-
}
15324-
],
15325-
"returnType" : {
15326-
"nullable" : {
15327-
"_0" : {
15328-
"int" : {
15339+
},
15340+
{
15341+
"name" : "jsRoundTripOptionalStringNull",
15342+
"parameters" : [
15343+
{
15344+
"name" : "name",
15345+
"type" : {
15346+
"nullable" : {
15347+
"_0" : {
15348+
"string" : {
1532915349

15350+
}
15351+
},
15352+
"_1" : "null"
15353+
}
15354+
}
1533015355
}
15331-
},
15332-
"_1" : "undefined"
15333-
}
15334-
}
15335-
},
15336-
{
15337-
"name" : "jsRoundTripOptionalStringNull",
15338-
"parameters" : [
15339-
{
15340-
"name" : "name",
15341-
"type" : {
15356+
],
15357+
"returnType" : {
1534215358
"nullable" : {
1534315359
"_0" : {
1534415360
"string" : {
@@ -15348,25 +15364,25 @@
1534815364
"_1" : "null"
1534915365
}
1535015366
}
15351-
}
15352-
],
15353-
"returnType" : {
15354-
"nullable" : {
15355-
"_0" : {
15356-
"string" : {
15367+
},
15368+
{
15369+
"name" : "jsRoundTripOptionalStringUndefined",
15370+
"parameters" : [
15371+
{
15372+
"name" : "name",
15373+
"type" : {
15374+
"nullable" : {
15375+
"_0" : {
15376+
"string" : {
1535715377

15378+
}
15379+
},
15380+
"_1" : "undefined"
15381+
}
15382+
}
1535815383
}
15359-
},
15360-
"_1" : "null"
15361-
}
15362-
}
15363-
},
15364-
{
15365-
"name" : "jsRoundTripOptionalStringUndefined",
15366-
"parameters" : [
15367-
{
15368-
"name" : "name",
15369-
"type" : {
15384+
],
15385+
"returnType" : {
1537015386
"nullable" : {
1537115387
"_0" : {
1537215388
"string" : {
@@ -15376,22 +15392,20 @@
1537615392
"_1" : "undefined"
1537715393
}
1537815394
}
15379-
}
15380-
],
15381-
"returnType" : {
15382-
"nullable" : {
15383-
"_0" : {
15384-
"string" : {
15395+
},
15396+
{
15397+
"name" : "runJsOptionalSupportTests",
15398+
"parameters" : [
15399+
15400+
],
15401+
"returnType" : {
15402+
"void" : {
1538515403

1538615404
}
15387-
},
15388-
"_1" : "undefined"
15405+
}
1538915406
}
15390-
}
15407+
]
1539115408
}
15392-
],
15393-
"types" : [
15394-
1539515409
]
1539615410
},
1539715411
{

Tests/BridgeJSRuntimeTests/JavaScript/OptionalSupportTests.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,31 @@ import {
1515

1616
import { ImportedFoo } from './Types.mjs';
1717

18+
/**
19+
* @returns {import('../../../.build/plugins/PackageToJS/outputs/PackageTests/bridge-js.d.ts').Imports["OptionalSupportImports"]}
20+
*/
21+
export function getImports(importsContext) {
22+
return {
23+
jsRoundTripOptionalNumberNull: (v) => {
24+
return v ?? null;
25+
},
26+
jsRoundTripOptionalNumberUndefined: (v) => {
27+
return v === undefined ? undefined : v;
28+
},
29+
jsRoundTripOptionalStringNull: (v) => {
30+
return v ?? null;
31+
},
32+
jsRoundTripOptionalStringUndefined: (v) => {
33+
return v === undefined ? undefined : v;
34+
},
35+
runJsOptionalSupportTests: () => {
36+
const exports = importsContext.getExports();
37+
if (!exports) { throw new Error("No exports!?"); }
38+
runJsOptionalSupportTests(exports);
39+
},
40+
};
41+
}
42+
1843
/**
1944
* Optional value bridging coverage for BridgeJS runtime tests.
2045
* @param {import('../../../.build/plugins/PackageToJS/outputs/PackageTests/bridge-js.d.ts').Exports} exports

0 commit comments

Comments
 (0)