Skip to content

Commit fc5b2d9

Browse files
authored
Merge pull request #493 from PassiveLogic/fix/enum-helper-availability
BridgeJS: Fix enumHelper availability
1 parent 0ca4256 commit fc5b2d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+129
-55
lines changed

Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,7 @@ struct BridgeJSLink {
209209
}
210210

211211
private func generateVariableDeclarations() -> [String] {
212-
let hasAssociatedValueEnums = exportedSkeletons.contains { skeleton in
213-
skeleton.enums.contains { $0.enumType == .associatedValue }
214-
}
215-
216-
var declarations = [
212+
return [
217213
"let \(JSGlueVariableScope.reservedInstance);",
218214
"let \(JSGlueVariableScope.reservedMemory);",
219215
"let \(JSGlueVariableScope.reservedSetException);",
@@ -237,25 +233,12 @@ struct BridgeJSLink {
237233
"let \(JSGlueVariableScope.reservedTmpParamF64s) = [];",
238234
"let \(JSGlueVariableScope.reservedTmpRetPointers) = [];",
239235
"let \(JSGlueVariableScope.reservedTmpParamPointers) = [];",
236+
"const \(JSGlueVariableScope.reservedEnumHelpers) = {};",
237+
"const \(JSGlueVariableScope.reservedStructHelpers) = {};",
238+
"",
239+
"let _exports = null;",
240+
"let bjs = null;",
240241
]
241-
242-
let hasStructs = exportedSkeletons.contains { skeleton in
243-
!skeleton.structs.isEmpty
244-
}
245-
246-
if hasAssociatedValueEnums {
247-
declarations.append("const enumHelpers = {};")
248-
}
249-
250-
if hasStructs {
251-
declarations.append("const structHelpers = {};")
252-
}
253-
254-
declarations.append("")
255-
declarations.append("let _exports = null;")
256-
declarations.append("let bjs = null;")
257-
258-
return declarations
259242
}
260243

261244
/// Checks if a skeleton contains any closure types
@@ -1050,7 +1033,7 @@ struct BridgeJSLink {
10501033
printer.write(
10511034
"const \(enumDef.name)Helpers = __bjs_create\(enumDef.valuesName)Helpers()(\(JSGlueVariableScope.reservedTmpParamInts), \(JSGlueVariableScope.reservedTmpParamF32s), \(JSGlueVariableScope.reservedTmpParamF64s), \(JSGlueVariableScope.reservedTextEncoder), \(JSGlueVariableScope.reservedSwift));"
10521035
)
1053-
printer.write("enumHelpers.\(enumDef.name) = \(enumDef.name)Helpers;")
1036+
printer.write("\(JSGlueVariableScope.reservedEnumHelpers).\(enumDef.name) = \(enumDef.name)Helpers;")
10541037
printer.nextLine()
10551038
}
10561039
}
@@ -1064,9 +1047,11 @@ struct BridgeJSLink {
10641047
for skeleton in exportedSkeletons {
10651048
for structDef in skeleton.structs {
10661049
printer.write(
1067-
"const \(structDef.name)Helpers = __bjs_create\(structDef.name)Helpers()(\(JSGlueVariableScope.reservedTmpParamInts), \(JSGlueVariableScope.reservedTmpParamF32s), \(JSGlueVariableScope.reservedTmpParamF64s), \(JSGlueVariableScope.reservedTmpParamPointers), \(JSGlueVariableScope.reservedTmpRetPointers), \(JSGlueVariableScope.reservedTextEncoder), \(JSGlueVariableScope.reservedSwift), enumHelpers);"
1050+
"const \(structDef.name)Helpers = __bjs_create\(structDef.name)Helpers()(\(JSGlueVariableScope.reservedTmpParamInts), \(JSGlueVariableScope.reservedTmpParamF32s), \(JSGlueVariableScope.reservedTmpParamF64s), \(JSGlueVariableScope.reservedTmpParamPointers), \(JSGlueVariableScope.reservedTmpRetPointers), \(JSGlueVariableScope.reservedTextEncoder), \(JSGlueVariableScope.reservedSwift), \(JSGlueVariableScope.reservedEnumHelpers));"
1051+
)
1052+
printer.write(
1053+
"\(JSGlueVariableScope.reservedStructHelpers).\(structDef.name) = \(structDef.name)Helpers;"
10681054
)
1069-
printer.write("structHelpers.\(structDef.name) = \(structDef.name)Helpers;")
10701055
printer.nextLine()
10711056
}
10721057
}

Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift

Lines changed: 43 additions & 29 deletions
Large diffs are not rendered by default.

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayParameter.Import.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export async function createInstantiator(options, swift) {
2828
let tmpParamF64s = [];
2929
let tmpRetPointers = [];
3030
let tmpParamPointers = [];
31+
const enumHelpers = {};
32+
const structHelpers = {};
3133

3234
let _exports = null;
3335
let bjs = null;

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Export.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export async function createInstantiator(options, swift) {
2828
let tmpParamF64s = [];
2929
let tmpRetPointers = [];
3030
let tmpParamPointers = [];
31+
const enumHelpers = {};
32+
const structHelpers = {};
3133

3234
let _exports = null;
3335
let bjs = null;

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Import.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export async function createInstantiator(options, swift) {
2828
let tmpParamF64s = [];
2929
let tmpRetPointers = [];
3030
let tmpParamPointers = [];
31+
const enumHelpers = {};
32+
const structHelpers = {};
3133

3234
let _exports = null;
3335
let bjs = null;

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.Export.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export async function createInstantiator(options, swift) {
3434
let tmpParamF64s = [];
3535
let tmpRetPointers = [];
3636
let tmpParamPointers = [];
37+
const enumHelpers = {};
3738
const structHelpers = {};
3839

3940
let _exports = null;

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.Export.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ export async function createInstantiator(options, swift) {
504504
let tmpRetPointers = [];
505505
let tmpParamPointers = [];
506506
const enumHelpers = {};
507+
const structHelpers = {};
507508

508509
let _exports = null;
509510
let bjs = null;

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.Export.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export async function createInstantiator(options, swift) {
5252
let tmpParamF64s = [];
5353
let tmpRetPointers = [];
5454
let tmpParamPointers = [];
55+
const enumHelpers = {};
56+
const structHelpers = {};
5557

5658
let _exports = null;
5759
let bjs = null;

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Export.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export async function createInstantiator(options, swift) {
5353
let tmpParamF64s = [];
5454
let tmpRetPointers = [];
5555
let tmpParamPointers = [];
56+
const enumHelpers = {};
57+
const structHelpers = {};
5658

5759
let _exports = null;
5860
let bjs = null;

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.Export.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ export async function createInstantiator(options, swift) {
7272
let tmpParamF64s = [];
7373
let tmpRetPointers = [];
7474
let tmpParamPointers = [];
75+
const enumHelpers = {};
76+
const structHelpers = {};
7577

7678
let _exports = null;
7779
let bjs = null;

0 commit comments

Comments
 (0)