From edca6f9f4fe2a7d3b3cf6ea99c86562bef9488c3 Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Tue, 22 Sep 2026 15:48:17 +0200 Subject: [PATCH 01/18] BridgeJS: Support protocol refinement and constrained imports --- .../Sources/BridgeJSCore/ExportSwift.swift | 52 +- .../BridgeJSCore/ExternalModuleIndex.swift | 15 +- .../Sources/BridgeJSCore/ImportTS.swift | 18 +- .../BridgeJSCore/SwiftToSkeleton.swift | 157 +++++- .../Sources/BridgeJSLink/BridgeJSLink.swift | 36 +- .../BridgeJSSkeleton/BridgeJSSkeleton.swift | 70 ++- .../GenericImportDiagnosticsTests.swift | 113 ++++- .../Inputs/MacroSwift/GenericImports.swift | 22 + .../BridgeJSCodegenTests/Alias.swift | 8 +- .../BridgeJSCodegenTests/DocComments.swift | 18 +- .../BridgeJSCodegenTests/GenericImports.json | 289 ++++++++++- .../BridgeJSCodegenTests/GenericImports.swift | 199 ++++++++ .../BridgeJSCodegenTests/Protocol.swift | 128 ++--- .../ProtocolInClosure.swift | 18 +- .../BridgeJSLinkTests/GenericImports.d.ts | 20 + .../BridgeJSLinkTests/GenericImports.js | 101 ++++ .../Exporting-Swift-Protocols.md | 12 +- .../Importing-JS-Function.md | 12 + .../Generated/BridgeJS.swift | 476 +++++++++++++++--- .../Generated/JavaScript/BridgeJS.json | 366 +++++++++++++- .../ImportGenericAPIs.swift | 54 ++ Tests/prelude.mjs | 9 + 22 files changed, 1933 insertions(+), 260 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index 55e3b063c..6b5d3ef76 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -1425,7 +1425,7 @@ struct ProtocolCodegen { for method in proto.methods { let builder = try ImportTS.CallJSEmission( moduleName: moduleName, - abiName: "_extern_\(method.name)", + abiName: method.abiName, effects: method.effects, returnType: method.returnType, context: .exportSwift @@ -1450,7 +1450,7 @@ struct ProtocolCodegen { printer: externDeclPrinter, moduleName: moduleName, abiName: method.abiName, - functionName: "_extern_\(method.name)", + functionName: method.abiName, abiParameters: builder.abiParameterSignatures, returnType: builder.abiReturnType ) @@ -1478,32 +1478,34 @@ struct ProtocolCodegen { externDecls.append(contentsOf: propertyExternDecls) } - let structDeclPrinter = CodeFragmentPrinter() - structDeclPrinter.write("struct \(wrapperName): \(protocolName), _BridgedSwiftProtocolWrapper {") - structDeclPrinter.indent { - structDeclPrinter.write("let jsObject: JSObject") - structDeclPrinter.nextLine() - - for methodDecl in methodDecls { - structDeclPrinter.write(lines: methodDecl.lines) - structDeclPrinter.nextLine() - } - - for decl in propertyDecls { - structDeclPrinter.write(lines: decl.lines) - structDeclPrinter.nextLine() + var decls: [DeclSyntax] = [] + if !methodDecls.isEmpty || !propertyDecls.isEmpty { + let extensionPrinter = CodeFragmentPrinter() + extensionPrinter.write("extension \(protocolName) where Self: _BridgedSwiftProtocolWrapper {") + extensionPrinter.indent { + var first = true + for decl in methodDecls + propertyDecls { + if !first { extensionPrinter.nextLine() } + first = false + extensionPrinter.write(lines: decl.lines) + } } - structDeclPrinter.write( - multilineString: """ - static func bridgeJSLiftParameter(_ value: Int32) -> Self { - return \(wrapperName)(jsObject: JSObject(id: UInt32(bitPattern: value))) - } - """ - ) + extensionPrinter.write("}") + decls.append("\(raw: extensionPrinter.lines.joined(separator: "\n"))") } - structDeclPrinter.write("}") - return ["\(raw: structDeclPrinter.lines.joined(separator: "\n"))"] + externDecls + decls.append( + """ + struct \(raw: wrapperName): \(raw: protocolName), _BridgedSwiftProtocolWrapper { + let jsObject: JSObject + + static func bridgeJSLiftParameter(_ value: Int32) -> Self { + return \(raw: wrapperName)(jsObject: JSObject(id: UInt32(bitPattern: value))) + } + } + """ + ) + return decls + externDecls } private func renderProtocolProperty( diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExternalModuleIndex.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExternalModuleIndex.swift index 33a27d087..b07fada44 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExternalModuleIndex.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExternalModuleIndex.swift @@ -7,6 +7,7 @@ public struct ExternalModuleIndex { public struct ExternalType: Equatable { public let moduleName: String public let bridgeType: BridgeType + public var isGenericBridgeableProtocol = false } public enum LookupResult: Equatable { @@ -31,8 +32,12 @@ public struct ExternalModuleIndex { guard let exported = skeleton.exported else { continue } var moduleEntries = entriesByModule[moduleName] ?? [:] - func register(dotPath: String, bridgeType: BridgeType) { - let externalType = ExternalType(moduleName: moduleName, bridgeType: bridgeType) + func register(dotPath: String, bridgeType: BridgeType, isGenericBridgeableProtocol: Bool = false) { + let externalType = ExternalType( + moduleName: moduleName, + bridgeType: bridgeType, + isGenericBridgeableProtocol: isGenericBridgeableProtocol + ) if moduleEntries[dotPath] == nil { moduleEntries[dotPath] = externalType entriesByDotPath[dotPath, default: []].append(externalType) @@ -61,7 +66,11 @@ public struct ExternalModuleIndex { register(dotPath: enumDef.swiftCallName, bridgeType: bridgeType) } for proto in exported.protocols { - register(dotPath: proto.name, bridgeType: .swiftProtocol(proto.name)) + register( + dotPath: proto.name, + bridgeType: .swiftProtocol(proto.name), + isGenericBridgeableProtocol: proto.isGenericBridgeable == true + ) } for alias in exported.aliases { register( diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift index 0ec5457fa..378fe2012 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift @@ -381,7 +381,7 @@ public struct ImportTS { parameters: [Parameter], returnType: BridgeType, effects: Effects, - genericParameters: [String] = [] + genericParameters: [GenericParameter] = [] ) -> DeclSyntax { let printer = CodeFragmentPrinter() let signature = SwiftSignatureBuilder.buildFunctionSignature( @@ -393,7 +393,13 @@ public struct ImportTS { let genericClause = genericParameters.isEmpty ? "" - : "<" + genericParameters.map { "\($0): BridgedSwiftGenericBridgeable" }.joined(separator: ", ") + : "<" + + genericParameters.map { genericParameter in + let constraints = + ["BridgedSwiftGenericBridgeable"] + + (genericParameter.swiftConstraints ?? genericParameter.constraints) + return "\(genericParameter.name): \(constraints.joined(separator: " & "))" + }.joined(separator: ", ") + ">" printer.write("func \(name.backtickIfNeeded())\(genericClause)\(signature) {") printer.indent { @@ -465,7 +471,7 @@ public struct ImportTS { parameters: function.parameters, returnType: function.returnType, effects: function.effects, - genericParameters: function.genericParameterNames + genericParameters: function.genericParameters ?? [] ) .with(\.leadingTrivia, Self.renderDocumentation(documentation: function.documentation)) ] @@ -496,7 +502,7 @@ public struct ImportTS { parameters: [selfParameter] + method.parameters, returnType: method.returnType, effects: method.effects, - genericParameters: method.genericParameterNames + genericParameters: method.genericParameters ?? [] ) ] } @@ -522,7 +528,7 @@ public struct ImportTS { parameters: method.parameters, returnType: method.returnType, effects: method.effects, - genericParameters: method.genericParameterNames + genericParameters: method.genericParameters ?? [] ) ] } @@ -548,7 +554,7 @@ public struct ImportTS { parameters: constructor.parameters, returnType: .jsObject(nil), effects: effects, - genericParameters: constructor.genericParameterNames + genericParameters: constructor.genericParameters ?? [] ) ] } diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index 63ce68fe5..0f9f79c06 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -7,6 +7,11 @@ import BridgeJSUtilities import BridgeJSSkeleton #endif +enum GenericConstraintParseResult { + case parsed(GenericParameter) + case failed(message: String) +} + /// Outcome of attempting to resolve a type as a reference to a generic parameter. enum GenericParameterResolution { case resolved(BridgeType) @@ -762,6 +767,13 @@ public final class SwiftToSkeleton { } private func resolveExternal(for type: TypeSyntax, errors: inout [DiagnosticError]) -> BridgeType? { + resolveExternalType(for: type, errors: &errors)?.bridgeType + } + + private func resolveExternalType( + for type: TypeSyntax, + errors: inout [DiagnosticError] + ) -> ExternalModuleIndex.ExternalType? { guard !externalModuleIndex.isEmpty, var components = type.qualifiedComponents @@ -787,7 +799,7 @@ public final class SwiftToSkeleton { switch lookupResult { case .unique(let externalType): usedExternalModules.insert(externalType.moduleName) - return externalType.bridgeType + return externalType case .ambiguous(let candidates): let moduleNames = candidates.map(\.moduleName).sorted().joined(separator: ", ") errors.append( @@ -981,11 +993,94 @@ public final class SwiftToSkeleton { return name.unicodeScalars.dropFirst().allSatisfy { isIdentifierPart($0, isStart: false) } } - fileprivate static func isBridgeableGenericConstraint(_ constraint: String?) -> Bool { + fileprivate static func isBridgeableGenericConstraint(_ constraint: String) -> Bool { constraint == "BridgedSwiftGenericBridgeable" || constraint == "JavaScriptKit.BridgedSwiftGenericBridgeable" } + fileprivate func inheritsGenericBridgeability(for type: TypeSyntax, visited: Set = []) -> Bool { + if Self.isBridgeableGenericConstraint(type.trimmedDescription) { return true } + if let proto = typeDeclResolver.resolve(type)?.as(ProtocolDeclSyntax.self) { + guard !visited.contains(proto.id) else { return false } + return (proto.inheritanceClause?.inheritedTypes ?? []).contains { + inheritsGenericBridgeability(for: $0.type, visited: visited.union([proto.id])) + } + } + var errors: [DiagnosticError] = [] + return resolveExternalType(for: type, errors: &errors)?.isGenericBridgeableProtocol == true + } + + fileprivate func resolveJSProtocolConstraint(for type: TypeSyntax) -> String? { + if let typeDecl = typeDeclResolver.resolve(type) { + guard let protocolDecl = typeDecl.as(ProtocolDeclSyntax.self), + protocolDecl.attributes.hasJSAttribute() + else { + return nil + } + return protocolDecl.name.text + } + var scratchErrors: [DiagnosticError] = [] + if let externalType = resolveExternal(for: type, errors: &scratchErrors), + case .swiftProtocol(let name) = externalType + { + return name + } + return nil + } + + fileprivate func parseGenericParameterConstraints( + _ genericParam: GenericParameterSyntax, + attributeName: String + ) -> GenericConstraintParseResult { + let paramName = genericParam.name.text + guard let inheritedType = genericParam.inheritedType else { + return .failed( + message: + "Generic parameter '\(paramName)' must be constrained to 'BridgedSwiftGenericBridgeable' to be used with \(attributeName)." + ) + } + let elements: [TypeSyntax] + if let composition = inheritedType.as(CompositionTypeSyntax.self) { + elements = composition.elements.map { TypeSyntax($0.type) } + } else { + elements = [inheritedType] + } + var hasBridgeableConstraint = false + var constraints: [String] = [] + var swiftConstraints: [String] = [] + for element in elements { + if SwiftToSkeleton.isBridgeableGenericConstraint(element.trimmedDescription) { + hasBridgeableConstraint = true + continue + } + guard let protocolName = resolveJSProtocolConstraint(for: element) else { + return .failed( + message: + "Generic parameter '\(paramName)' has unsupported constraint '\(element.trimmedDescription)'. " + + "Constraints on generic \(attributeName) declarations must be 'BridgedSwiftGenericBridgeable', " + + "optionally composed with '@JS' protocols (e.g. '\(paramName): BridgedSwiftGenericBridgeable & MyProtocol')." + ) + } + hasBridgeableConstraint = hasBridgeableConstraint || inheritsGenericBridgeability(for: element) + if !constraints.contains(protocolName) { + constraints.append(protocolName) + } + let swiftConstraint = element.is(MemberTypeSyntax.self) ? element.trimmedDescription : protocolName + if !swiftConstraints.contains(swiftConstraint) { + swiftConstraints.append(swiftConstraint) + } + } + guard hasBridgeableConstraint else { + let suggested = (["BridgedSwiftGenericBridgeable"] + swiftConstraints).joined(separator: " & ") + return .failed( + message: + "Generic parameter '\(paramName)' is missing the 'BridgedSwiftGenericBridgeable' constraint. " + + "Write '\(paramName): \(suggested)' to combine it with '@JS' protocol constraints on \(attributeName) declarations." + ) + } + return .parsed(GenericParameter(name: paramName, constraints: constraints, swiftConstraints: swiftConstraints)) + } + } private enum ExportSwiftConstants { @@ -2321,6 +2416,23 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { let protocolUniqueKey = makeKey(name: name, namespace: effectiveNamespace) + var inheritedJSProtocols: [String] = [] + for inherited in node.inheritanceClause?.inheritedTypes ?? [] { + guard let baseName = parent.resolveJSProtocolConstraint(for: inherited.type) else { continue } + guard parent.typeDeclResolver.resolve(inherited.type)?.is(ProtocolDeclSyntax.self) == true else { + diagnose( + node: inherited, + message: "Refining @JS protocol '\(baseName)' from another module is not supported yet.", + hint: + "Declare the inherited requirements on '\(name)' directly, or move the base protocol into this module." + ) + return .skipChildren + } + if !inheritedJSProtocols.contains(baseName) { + inheritedJSProtocols.append(baseName) + } + } + exportedProtocolByName[protocolUniqueKey] = ExportedProtocol( name: name, jsName: jsName, @@ -2355,7 +2467,11 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { properties: exportedProtocolByName[protocolUniqueKey]?.properties ?? [], namespace: effectiveNamespace, jsNamespace: namespaceResult.jsNamespace, - documentation: extractDocumentation(from: node) + documentation: extractDocumentation(from: node), + inheritedJSProtocols: inheritedJSProtocols.isEmpty ? nil : inheritedJSProtocols, + isGenericBridgeable: (node.inheritanceClause?.inheritedTypes ?? []).contains { + parent.inheritsGenericBridgeability(for: $0.type) + } ? true : nil ) exportedProtocolByName[protocolUniqueKey] = exportedProtocol @@ -3453,27 +3569,21 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { /// /// Returns `nil` when a diagnostic was emitted; an empty array when the /// declaration is not generic. - private func parseGenericParameterNames( + private func parseGenericParameters( genericParameterClause: GenericParameterClauseSyntax?, genericWhereClause: GenericWhereClauseSyntax?, node: Syntax - ) -> [String]? { - var genericParameterNames: [String] = [] + ) -> [GenericParameter]? { + var genericParameters: [GenericParameter] = [] if let genericParameterClause { for genericParam in genericParameterClause.parameters { - let paramName = genericParam.name.text - let constraintText = genericParam.inheritedType?.trimmedDescription - guard SwiftToSkeleton.isBridgeableGenericConstraint(constraintText) else { - errors.append( - DiagnosticError( - node: Syntax(genericParam), - message: - "Generic parameter '\(paramName)' must be constrained to 'BridgedSwiftGenericBridgeable' to be used with @JSFunction." - ) - ) + switch parent.parseGenericParameterConstraints(genericParam, attributeName: "@JSFunction") { + case .failed(let message): + errors.append(DiagnosticError(node: Syntax(genericParam), message: message)) return nil + case .parsed(let genericParameter): + genericParameters.append(genericParameter) } - genericParameterNames.append(paramName) } } if genericWhereClause != nil { @@ -3485,7 +3595,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { ) return nil } - return genericParameterNames + return genericParameters } private func parseConstructor( @@ -3502,7 +3612,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { return nil } guard - let genericParameterNames = parseGenericParameterNames( + let genericParameters = parseGenericParameters( genericParameterClause: initializer.genericParameterClause, genericWhereClause: initializer.genericWhereClause, node: Syntax(initializer) @@ -3510,6 +3620,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { else { return nil } + let genericParameterNames = genericParameters.map(\.name) if !genericParameterNames.isEmpty && effects.isAsync { errors.append( DiagnosticError( @@ -3542,7 +3653,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { return ImportedConstructorSkeleton( parameters: parameters, accessLevel: accessLevel, - genericParameters: genericParameterNames.isEmpty ? nil : genericParameterNames + genericParameters: genericParameters.isEmpty ? nil : genericParameters ) } @@ -3561,7 +3672,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { } guard - let genericParameterNames = parseGenericParameterNames( + let genericParameters = parseGenericParameters( genericParameterClause: node.genericParameterClause, genericWhereClause: node.genericWhereClause, node: Syntax(node) @@ -3570,6 +3681,8 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { return nil } + let genericParameterNames = genericParameters.map(\.name) + let baseName = SwiftToSkeleton.normalizeIdentifier(node.name.text) let extractedJSName = extractJSName(from: jsFunction) let from = extractJSImportFrom(from: jsFunction) @@ -3632,7 +3745,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { effects: effects, documentation: nil, accessLevel: accessLevel, - genericParameters: genericParameterNames.isEmpty ? nil : genericParameterNames + genericParameters: genericParameters.isEmpty ? nil : genericParameters ) } diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 5d41869f8..40b1c13c3 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -1021,7 +1021,10 @@ public struct BridgeJSLink { for skeleton in exportedSkeletons { for proto in skeleton.protocols { printer.write(lines: renderJSDoc(documentation: proto.documentation, parameters: [])) - printer.write("export interface \(proto.resolvedJSName) {") + let extendsClause = + inheritedProtocolTSNames(of: proto, in: exportedSkeletons) + .map { " extends \($0.joined(separator: ", "))" } ?? "" + printer.write("export interface \(proto.resolvedJSName)\(extendsClause) {") printer.indent { for method in proto.methods { printer.write( @@ -1521,7 +1524,7 @@ public struct BridgeJSLink { // Add methods for method in type.methods { let methodName = method.resolvedJSName - let genericClause = renderGenericClause(method.genericParameterNames) + let genericClause = renderGenericClause(method.genericParameters ?? []) let methodSignature = "\(renderTSPropertyName(methodName))\(genericClause)\(renderTSSignature(parameters: method.parameters, returnType: method.returnType, effects: method.effects));" printer.write(methodSignature) @@ -1681,6 +1684,18 @@ public struct BridgeJSLink { } } + private func inheritedProtocolTSNames(of proto: ExportedProtocol, in skeletons: [ExportedSkeleton]) -> [String]? { + guard let inherited = proto.inheritedJSProtocols, !inherited.isEmpty else { return nil } + return inherited.map { baseName in + for skeleton in skeletons { + if let base = skeleton.protocols.first(where: { $0.name == baseName }) { + return base.resolvedJSName + } + } + return baseName + } + } + /// Resolves public TypeScript names without changing the skeleton's Swift type identities. private func resolveTypeScriptType(_ type: BridgeType) -> String { return Self.resolveTypeScriptType(type, exportedSkeletons: skeletons.compactMap(\.exported)) @@ -1771,8 +1786,15 @@ public struct BridgeJSLink { return "(\(parameterSignatures.joined(separator: ", "))): \(returnTypeWithEffect)" } - private func renderGenericClause(_ genericParameterNames: [String]) -> String { - genericParameterNames.isEmpty ? "" : "<\(genericParameterNames.joined(separator: ", "))>" + private func renderGenericClause(_ genericParameters: [GenericParameter]) -> String { + guard !genericParameters.isEmpty else { return "" } + let renderedParameters = genericParameters.map { genericParameter in + let constraints = genericParameter.constraints.map { resolveTypeScriptType(.swiftProtocol($0)) } + return constraints.isEmpty + ? genericParameter.name + : "\(genericParameter.name) extends \(constraints.joined(separator: " & "))" + } + return "<\(renderedParameters.joined(separator: ", "))>" } private func renderTSPropertyName(_ name: String) -> String { @@ -3767,7 +3789,7 @@ extension BridgeJSLink { try thunkBuilder.call(calleeExpr: calleeExpr) let funcLines = thunkBuilder.renderFunction(name: function.abiName(context: nil)) if function.from == nil { - let genericClause = renderGenericClause(genericParameters) + let genericClause = renderGenericClause(function.genericParameters ?? []) importObjectBuilder.appendDts( [ "\(renderTSPropertyName(jsName))\(genericClause)\(renderTSSignature(parameters: function.parameters, returnType: function.returnType, effects: function.effects));" @@ -3861,14 +3883,14 @@ extension BridgeJSLink { dtsPrinter.indent { if let constructor = type.constructor { let returnType = BridgeType.jsObject(type.name) - let genericClause = renderGenericClause(constructor.genericParameterNames) + let genericClause = renderGenericClause(constructor.genericParameters ?? []) dtsPrinter.write( "new\(genericClause)\(renderTSSignature(parameters: constructor.parameters, returnType: returnType, effects: Effects(isAsync: false, isThrows: false)));" ) } for method in type.staticMethods { let methodName = method.resolvedJSName - let genericClause = renderGenericClause(method.genericParameterNames) + let genericClause = renderGenericClause(method.genericParameters ?? []) let signature = "\(renderTSPropertyName(methodName))\(genericClause)\(renderTSSignature(parameters: method.parameters, returnType: method.returnType, effects: method.effects));" dtsPrinter.write(signature) diff --git a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift index ce85176cc..8da9f2e4e 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift @@ -382,6 +382,14 @@ extension ExportedSkeleton { guard let bridgeType = enumDef.genericBridgeType else { continue } entries.append(GenericBridgeableTypeEntry(swiftName: enumDef.swiftCallName, bridgeType: bridgeType)) } + for proto in protocols where proto.isGenericBridgeable == true { + entries.append( + GenericBridgeableTypeEntry( + swiftName: "Any\(proto.name)", + bridgeType: .swiftProtocol(proto.name) + ) + ) + } return entries } } @@ -546,6 +554,44 @@ public struct Parameter: Codable, Equatable, Sendable { } } +public struct GenericParameter: Codable, Equatable, Hashable, Sendable { + public let name: String + public let constraints: [String] + public let swiftConstraints: [String]? + + public init(name: String, constraints: [String] = [], swiftConstraints: [String]? = nil) { + self.name = name + self.constraints = constraints + self.swiftConstraints = swiftConstraints == constraints ? nil : swiftConstraints + } + + private enum CodingKeys: String, CodingKey { + case name, constraints, swiftConstraints + } + + public init(from decoder: any Decoder) throws { + if let single = try? decoder.singleValueContainer(), let name = try? single.decode(String.self) { + self.name = name + self.constraints = [] + self.swiftConstraints = nil + return + } + let container = try decoder.container(keyedBy: CodingKeys.self) + self.name = try container.decode(String.self, forKey: .name) + self.constraints = try container.decodeIfPresent([String].self, forKey: .constraints) ?? [] + self.swiftConstraints = try container.decodeIfPresent([String].self, forKey: .swiftConstraints) + } + + public func encode(to encoder: any Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(name, forKey: .name) + if !constraints.isEmpty { + try container.encode(constraints, forKey: .constraints) + } + try container.encodeIfPresent(swiftConstraints, forKey: .swiftConstraints) + } +} + // MARK: - BridgeSkeleton Visitor public protocol BridgeSkeletonVisitor { @@ -973,6 +1019,8 @@ public struct ExportedProtocol: Codable, Equatable, NamespacedExportedType { public let namespace: [String]? public let jsNamespace: [String]? public var documentation: String? + public var inheritedJSProtocols: [String]? + public var isGenericBridgeable: Bool? public init( name: String, @@ -981,7 +1029,9 @@ public struct ExportedProtocol: Codable, Equatable, NamespacedExportedType { properties: [ExportedProtocolProperty] = [], namespace: [String]? = nil, jsNamespace: [String]? = nil, - documentation: String? = nil + documentation: String? = nil, + inheritedJSProtocols: [String]? = nil, + isGenericBridgeable: Bool? = nil ) { self.name = name self.jsName = jsName @@ -990,6 +1040,8 @@ public struct ExportedProtocol: Codable, Equatable, NamespacedExportedType { self.namespace = namespace self.jsNamespace = jsNamespace self.documentation = documentation + self.inheritedJSProtocols = inheritedJSProtocols + self.isGenericBridgeable = isGenericBridgeable } } @@ -1397,8 +1449,8 @@ public struct ImportedFunctionSkeleton: Codable { /// determine the access level of bridge-generated helpers (e.g. typed /// closure inits) that surface through this function's signature. public let accessLevel: BridgeJSAccessLevel - public let genericParameters: [String]? - public var genericParameterNames: [String] { genericParameters ?? [] } + public let genericParameters: [GenericParameter]? + public var genericParameterNames: [String] { (genericParameters ?? []).map(\.name) } public var isGeneric: Bool { !genericParameterNames.isEmpty } public var resolvedJSName: String { jsName ?? name } @@ -1412,7 +1464,7 @@ public struct ImportedFunctionSkeleton: Codable { effects: Effects = Effects(isAsync: false, isThrows: true), documentation: String? = nil, accessLevel: BridgeJSAccessLevel = .internal, - genericParameters: [String]? = nil + genericParameters: [GenericParameter]? = nil ) { self.name = name self.jsName = jsName @@ -1439,7 +1491,7 @@ public struct ImportedFunctionSkeleton: Codable { self.effects = try container.decode(Effects.self, forKey: .effects) self.documentation = try container.decodeIfPresent(String.self, forKey: .documentation) self.accessLevel = try container.decodeIfPresent(BridgeJSAccessLevel.self, forKey: .accessLevel) ?? .internal - self.genericParameters = try container.decodeIfPresent([String].self, forKey: .genericParameters) + self.genericParameters = try container.decodeIfPresent([GenericParameter].self, forKey: .genericParameters) } public func abiName(context: ImportedTypeSkeleton?) -> String { @@ -1460,14 +1512,14 @@ public struct ImportedConstructorSkeleton: Codable { /// Source access level of the originating Swift `init`. Inherits from the /// enclosing `@JSClass` type when not annotated explicitly. public let accessLevel: BridgeJSAccessLevel - public let genericParameters: [String]? - public var genericParameterNames: [String] { genericParameters ?? [] } + public let genericParameters: [GenericParameter]? + public var genericParameterNames: [String] { (genericParameters ?? []).map(\.name) } public var isGeneric: Bool { !genericParameterNames.isEmpty } public init( parameters: [Parameter], accessLevel: BridgeJSAccessLevel = .internal, - genericParameters: [String]? = nil + genericParameters: [GenericParameter]? = nil ) { self.parameters = parameters self.accessLevel = accessLevel @@ -1482,7 +1534,7 @@ public struct ImportedConstructorSkeleton: Codable { let container = try decoder.container(keyedBy: CodingKeys.self) self.parameters = try container.decode([Parameter].self, forKey: .parameters) self.accessLevel = try container.decodeIfPresent(BridgeJSAccessLevel.self, forKey: .accessLevel) ?? .internal - self.genericParameters = try container.decodeIfPresent([String].self, forKey: .genericParameters) + self.genericParameters = try container.decodeIfPresent([GenericParameter].self, forKey: .genericParameters) } public func abiName(context: ImportedTypeSkeleton) -> String { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/GenericImportDiagnosticsTests.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/GenericImportDiagnosticsTests.swift index 4a421b73b..f2ff5dc81 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/GenericImportDiagnosticsTests.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/GenericImportDiagnosticsTests.swift @@ -1,9 +1,116 @@ +import Foundation import Testing +@testable import BridgeJSCore +@testable import BridgeJSLink @testable import BridgeJSSkeleton @Suite struct GenericImportDiagnosticsTests { + @Test(arguments: [ + ("protocol P {}", "BridgedSwiftGenericBridgeable & P", "unsupported constraint 'P'"), + ("@JS protocol P {}", "P", "missing the 'BridgedSwiftGenericBridgeable' constraint"), + ]) + func invalidProtocolConstraint(declaration: String, constraint: String, diagnostic: String) { + expectDiagnostic( + source: "\(declaration)\n@JSFunction func f(_ value: T) throws(JSException) -> T", + contains: diagnostic + ) + } + + @Test func qualifiedExternalProtocolConstraint() throws { + let dependency = try makeSkeleton( + "@JS public protocol Node: BridgedSwiftGenericBridgeable {}", + moduleName: "GraphKit" + ) + let decoded = try JSONDecoder().decode(BridgeJSSkeleton.self, from: JSONEncoder().encode(dependency)) + let skeleton = try makeSkeleton( + """ + import GraphKit + protocol Node {} + @JSFunction func f(_ value: T) throws(JSException) -> T + """, + dependencies: [(moduleName: "GraphKit", skeleton: decoded)] + ) + let roundTrip = try JSONDecoder().decode(BridgeJSSkeleton.self, from: JSONEncoder().encode(skeleton)) + let imported = try #require(roundTrip.imported) + #expect( + imported.children.flatMap(\.functions).first?.genericParameters == [ + GenericParameter(name: "T", constraints: ["Node"], swiftConstraints: ["GraphKit.Node"]) + ] + ) + let glue = try #require( + try ImportTS(progress: .silent, moduleName: skeleton.moduleName, skeleton: imported).finalize() + ) + #expect(glue.contains("T: BridgedSwiftGenericBridgeable & GraphKit.Node")) + #expect(roundTrip.usedExternalModules == ["GraphKit"]) + } + + @Test func refinedProtocolRequirementsAndAdapter() throws { + let skeleton = try makeSkeleton( + """ + @JS(namespace: "API") protocol Base: BridgedSwiftGenericBridgeable { + func read() -> Int + var value: Int { get set } + } + @JS protocol Middle: Base {} + @JS("PublicNode", namespace: "API") protocol Node: Middle { + var value: Int { get } + } + @JSFunction func f(_ value: T) throws(JSException) -> T + """ + ) + let exported = try #require(skeleton.exported) + let node = try #require(exported.protocols.first { $0.name == "Node" }) + #expect(node.methods.isEmpty) + #expect(node.properties.map(\.name) == ["value"]) + #expect(node.inheritedJSProtocols == ["Middle"]) + #expect(node.jsName == "PublicNode") + #expect( + exported.genericBridgeableTypeEntries.contains { + $0.swiftName == "AnyNode" && $0.bridgeType == .swiftProtocol("Node") + } + ) + let glue = try #require( + try ExportSwift(progress: .silent, moduleName: skeleton.moduleName, skeleton: exported).finalize() + ) + #expect(glue.contains("extension Base where Self: _BridgedSwiftProtocolWrapper {")) + #expect(glue.contains("extension Node where Self: _BridgedSwiftProtocolWrapper {")) + #expect(!glue.contains("extension Middle where Self")) + #expect(glue.contains("struct AnyNode: Node, _BridgedSwiftProtocolWrapper {")) + #expect(glue.contains("name: \"bjs_Base_read\"")) + #expect(!glue.contains("bjs_Node_read")) + let linked = try BridgeJSLink(skeletons: [skeleton]).link() + #expect(linked.outputDts.contains("f")) + #expect(linked.outputDts.contains("export interface PublicNode extends Middle {")) + #expect(linked.outputDts.contains("export interface Middle extends Base {")) + } + + @Test func externalProtocolRefinementIsRejected() throws { + let dependency = try makeSkeleton("@JS public protocol Base {}", moduleName: "GraphKit") + do { + _ = try makeSkeleton( + "import GraphKit\n@JS protocol Child: GraphKit.Base {}", + dependencies: [(moduleName: "GraphKit", skeleton: dependency)] + ) + Issue.record("Expected external refinement diagnostic") + } catch let error as BridgeJSCoreDiagnosticError { + #expect( + error.diagnostics.contains { + $0.diagnostic.message.contains("from another module is not supported") + } + ) + } + } + + @Test func legacyGenericParameterDecoding() throws { + let constructor = try JSONDecoder().decode( + ImportedConstructorSkeleton.self, + from: Data(#"{"parameters":[],"genericParameters":["T"]}"#.utf8) + ) + #expect(constructor.genericParameters == [GenericParameter(name: "T")]) + } + @Test func genericParameterRequiresBridgeableConstraint() { expectDiagnostic( @@ -48,7 +155,7 @@ import Testing let types = imported.children.flatMap { $0.types } let box = try #require(types.first { $0.name == "Box" }) let method = try #require(box.methods.first { $0.name == "member" }) - #expect(method.genericParameters == ["T"]) + #expect(method.genericParameters == [GenericParameter(name: "T")]) } @Test @@ -65,7 +172,7 @@ import Testing let types = imported.children.flatMap { $0.types } let box = try #require(types.first { $0.name == "Box" }) let constructor = try #require(box.constructor) - #expect(constructor.genericParameters == ["T"]) + #expect(constructor.genericParameters == [GenericParameter(name: "T")]) #expect(constructor.parameters.map(\.type) == [.generic("T")]) } @@ -205,6 +312,6 @@ import Testing let imported = try #require(skeleton.imported) let functions = imported.children.flatMap { $0.functions } let function = try #require(functions.first { $0.name == "make" }) - #expect(function.genericParameters == ["T"]) + #expect(function.genericParameters == [GenericParameter(name: "T")]) } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/GenericImports.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/GenericImports.swift index 5fd3d0226..546207cd3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/GenericImports.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/GenericImports.swift @@ -72,3 +72,25 @@ struct GenericPoint { @JSFunction func identity(_ value: T) throws(JSException) -> T @JSFunction static func box(_ value: T) throws(JSException) -> T } + +@JS protocol GenericReadable: BridgedSwiftGenericBridgeable { + func read() -> Int +} + +@JS protocol GenericWritable { + var value: Int { get set } +} + +@JS protocol GenericNode: GenericReadable, GenericWritable {} + +@JSFunction func constrainedRoundTrip(_ value: T) throws(JSException) -> T + +@JSFunction func constrainedComposition( + _ value: T +) throws(JSException) -> T + +@JSClass struct ConstrainedConsumer { + @JSFunction init(_ value: T) throws(JSException) + @JSFunction func accept(_ value: T) throws(JSException) -> T + @JSFunction static func identity(_ value: T) throws(JSException) -> T +} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Alias.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Alias.swift index af8a8a453..2529f22d3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Alias.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Alias.swift @@ -1,6 +1,4 @@ -struct AnyHasOptionalUserId: HasOptionalUserId, _BridgedSwiftProtocolWrapper { - let jsObject: JSObject - +extension HasOptionalUserId where Self: _BridgedSwiftProtocolWrapper { var userId: Optional { get { let jsObjectValue = jsObject.bridgeJSLowerParameter() @@ -8,6 +6,10 @@ struct AnyHasOptionalUserId: HasOptionalUserId, _BridgedSwiftProtocolWrapper { return Optional.bridgeJSLiftReturnFromSideChannel() } } +} + +struct AnyHasOptionalUserId: HasOptionalUserId, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject static func bridgeJSLiftParameter(_ value: Int32) -> Self { return AnyHasOptionalUserId(jsObject: JSObject(id: UInt32(bitPattern: value))) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DocComments.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DocComments.swift index b9c65e28f..05c575b73 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DocComments.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DocComments.swift @@ -1,10 +1,8 @@ -struct AnyListener: Listener, _BridgedSwiftProtocolWrapper { - let jsObject: JSObject - +extension Listener where Self: _BridgedSwiftProtocolWrapper { func onEvent(id: Int) -> Void { let idValue = id.bridgeJSLowerParameter() let jsObjectValue = jsObject.bridgeJSLowerParameter() - _extern_onEvent(jsObjectValue, idValue) + bjs_Listener_onEvent(jsObjectValue, idValue) } var name: String { @@ -14,6 +12,10 @@ struct AnyListener: Listener, _BridgedSwiftProtocolWrapper { return String.bridgeJSLiftReturn(ret) } } +} + +struct AnyListener: Listener, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject static func bridgeJSLiftParameter(_ value: Int32) -> Self { return AnyListener(jsObject: JSObject(id: UInt32(bitPattern: value))) @@ -22,14 +24,14 @@ struct AnyListener: Listener, _BridgedSwiftProtocolWrapper { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_Listener_onEvent") -fileprivate func _extern_onEvent_extern(_ jsObject: Int32, _ id: Int32) -> Void +fileprivate func bjs_Listener_onEvent_extern(_ jsObject: Int32, _ id: Int32) -> Void #else -fileprivate func _extern_onEvent_extern(_ jsObject: Int32, _ id: Int32) -> Void { +fileprivate func bjs_Listener_onEvent_extern(_ jsObject: Int32, _ id: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_onEvent(_ jsObject: Int32, _ id: Int32) -> Void { - return _extern_onEvent_extern(jsObject, id) +@inline(never) fileprivate func bjs_Listener_onEvent(_ jsObject: Int32, _ id: Int32) -> Void { + return bjs_Listener_onEvent_extern(jsObject, id) } #if arch(wasm32) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GenericImports.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GenericImports.json index c7f3e98ae..9f9f7a834 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GenericImports.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GenericImports.json @@ -172,7 +172,69 @@ ], "protocols" : [ + { + "isGenericBridgeable" : true, + "methods" : [ + { + "abiName" : "bjs_GenericReadable_read", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "read", + "parameters" : [ + ], + "returnType" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } + ], + "name" : "GenericReadable", + "properties" : [ + + ] + }, + { + "methods" : [ + + ], + "name" : "GenericWritable", + "properties" : [ + { + "isReadonly" : false, + "name" : "value", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } + ] + }, + { + "inheritedJSProtocols" : [ + "GenericReadable", + "GenericWritable" + ], + "isGenericBridgeable" : true, + "methods" : [ + + ], + "name" : "GenericNode", + "properties" : [ + + ] + } ], "structs" : [ { @@ -224,7 +286,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "genericRoundTrip", "parameters" : [ @@ -251,7 +315,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "genericParse", "parameters" : [ @@ -278,8 +344,12 @@ "isThrows" : true }, "genericParameters" : [ - "T", - "U" + { + "name" : "T" + }, + { + "name" : "U" + } ], "name" : "importGenericCombine", "parameters" : [ @@ -314,8 +384,12 @@ "isThrows" : true }, "genericParameters" : [ - "T", - "t" + { + "name" : "T" + }, + { + "name" : "t" + } ], "name" : "importGenericCaseDistinct", "parameters" : [ @@ -350,7 +424,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "importGenericArray", "parameters" : [ @@ -385,7 +461,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "importGenericOptional", "parameters" : [ @@ -422,7 +500,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "importGenericDictionary", "parameters" : [ @@ -457,7 +537,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "importGenericAfterOptionalArray", "parameters" : [ @@ -495,6 +577,70 @@ "_0" : "T" } } + }, + { + "accessLevel" : "internal", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "genericParameters" : [ + { + "constraints" : [ + "GenericNode" + ], + "name" : "T" + } + ], + "name" : "constrainedRoundTrip", + "parameters" : [ + { + "name" : "value", + "type" : { + "generic" : { + "_0" : "T" + } + } + } + ], + "returnType" : { + "generic" : { + "_0" : "T" + } + } + }, + { + "accessLevel" : "internal", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "genericParameters" : [ + { + "constraints" : [ + "GenericWritable" + ], + "name" : "T" + } + ], + "name" : "constrainedComposition", + "parameters" : [ + { + "name" : "value", + "type" : { + "generic" : { + "_0" : "T" + } + } + } + ], + "returnType" : { + "generic" : { + "_0" : "T" + } + } } ], "types" : [ @@ -503,8 +649,12 @@ "constructor" : { "accessLevel" : "internal", "genericParameters" : [ - "T", - "U" + { + "name" : "T" + }, + { + "name" : "U" + } ], "parameters" : [ { @@ -552,7 +702,9 @@ "constructor" : { "accessLevel" : "internal", "genericParameters" : [ - "T" + { + "name" : "T" + } ], "parameters" : [ { @@ -577,7 +729,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "accept", "parameters" : [ @@ -604,7 +758,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "identity", "parameters" : [ @@ -637,7 +793,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "box", "parameters" : [ @@ -657,6 +815,105 @@ } } ] + }, + { + "accessLevel" : "internal", + "constructor" : { + "accessLevel" : "internal", + "genericParameters" : [ + { + "constraints" : [ + "GenericNode" + ], + "name" : "T" + } + ], + "parameters" : [ + { + "name" : "value", + "type" : { + "generic" : { + "_0" : "T" + } + } + } + ] + }, + "getters" : [ + + ], + "methods" : [ + { + "accessLevel" : "internal", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "genericParameters" : [ + { + "constraints" : [ + "GenericNode" + ], + "name" : "T" + } + ], + "name" : "accept", + "parameters" : [ + { + "name" : "value", + "type" : { + "generic" : { + "_0" : "T" + } + } + } + ], + "returnType" : { + "generic" : { + "_0" : "T" + } + } + } + ], + "name" : "ConstrainedConsumer", + "setters" : [ + + ], + "staticMethods" : [ + { + "accessLevel" : "internal", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "genericParameters" : [ + { + "constraints" : [ + "GenericNode" + ], + "name" : "T" + } + ], + "name" : "identity", + "parameters" : [ + { + "name" : "value", + "type" : { + "generic" : { + "_0" : "T" + } + } + } + ], + "returnType" : { + "generic" : { + "_0" : "T" + } + } + } + ] } ] } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GenericImports.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GenericImports.swift index cf07236fc..ecb1512cf 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GenericImports.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GenericImports.swift @@ -1,3 +1,86 @@ +extension GenericReadable where Self: _BridgedSwiftProtocolWrapper { + func read() -> Int { + let jsObjectValue = jsObject.bridgeJSLowerParameter() + let ret = bjs_GenericReadable_read(jsObjectValue) + return Int.bridgeJSLiftReturn(ret) + } +} + +struct AnyGenericReadable: GenericReadable, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject + + static func bridgeJSLiftParameter(_ value: Int32) -> Self { + return AnyGenericReadable(jsObject: JSObject(id: UInt32(bitPattern: value))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_GenericReadable_read") +fileprivate func bjs_GenericReadable_read_extern(_ jsObject: Int32) -> Int32 +#else +fileprivate func bjs_GenericReadable_read_extern(_ jsObject: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_GenericReadable_read(_ jsObject: Int32) -> Int32 { + return bjs_GenericReadable_read_extern(jsObject) +} + +extension GenericWritable where Self: _BridgedSwiftProtocolWrapper { + var value: Int { + get { + let jsObjectValue = jsObject.bridgeJSLowerParameter() + let ret = bjs_GenericWritable_value_get(jsObjectValue) + return Int.bridgeJSLiftReturn(ret) + } + set { + let newValueValue = newValue.bridgeJSLowerParameter() + let jsObjectValue = jsObject.bridgeJSLowerParameter() + bjs_GenericWritable_value_set(jsObjectValue, newValueValue) + } + } +} + +struct AnyGenericWritable: GenericWritable, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject + + static func bridgeJSLiftParameter(_ value: Int32) -> Self { + return AnyGenericWritable(jsObject: JSObject(id: UInt32(bitPattern: value))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_GenericWritable_value_get") +fileprivate func bjs_GenericWritable_value_get_extern(_ jsObject: Int32) -> Int32 +#else +fileprivate func bjs_GenericWritable_value_get_extern(_ jsObject: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_GenericWritable_value_get(_ jsObject: Int32) -> Int32 { + return bjs_GenericWritable_value_get_extern(jsObject) +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_GenericWritable_value_set") +fileprivate func bjs_GenericWritable_value_set_extern(_ jsObject: Int32, _ newValue: Int32) -> Void +#else +fileprivate func bjs_GenericWritable_value_set_extern(_ jsObject: Int32, _ newValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_GenericWritable_value_set(_ jsObject: Int32, _ newValue: Int32) -> Void { + return bjs_GenericWritable_value_set_extern(jsObject, newValue) +} + +struct AnyGenericNode: GenericNode, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject + + static func bridgeJSLiftParameter(_ value: Int32) -> Self { + return AnyGenericNode(jsObject: JSObject(id: UInt32(bitPattern: value))) + } +} + extension GenericColor: _BridgedSwiftCaseEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { return bridgeJSRawValue @@ -207,6 +290,14 @@ extension GenericTagged: BridgedSwiftGenericBridgeable { @_spi(BridgeJS) public static let bridgeJSTypeHandle = GenericTagged.bridgeJSMakeTypeHandle() } +extension AnyGenericReadable: BridgedSwiftGenericBridgeable { + @_spi(BridgeJS) public static let bridgeJSTypeHandle = AnyGenericReadable.bridgeJSMakeTypeHandle() +} + +extension AnyGenericNode: BridgedSwiftGenericBridgeable { + @_spi(BridgeJS) public static let bridgeJSTypeHandle = AnyGenericNode.bridgeJSMakeTypeHandle() +} + #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_genericRoundTrip") fileprivate func bjs_genericRoundTrip_extern(_ _generic0TypeId: Int32) -> Void @@ -379,6 +470,48 @@ func _$importGenericAfterOptionalArray(_ value return T.bridgeJSStackPop() } +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_constrainedRoundTrip") +fileprivate func bjs_constrainedRoundTrip_extern(_ _generic0TypeId: Int32) -> Void +#else +fileprivate func bjs_constrainedRoundTrip_extern(_ _generic0TypeId: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_constrainedRoundTrip(_ _generic0TypeId: Int32) -> Void { + return bjs_constrainedRoundTrip_extern(_generic0TypeId) +} + +func _$constrainedRoundTrip(_ value: T) throws(JSException) -> T { + value.bridgeJSStackPush() + bjs_constrainedRoundTrip(T.bridgeJSTypeID) + if let error = _swift_js_take_exception() { + throw error + } + return T.bridgeJSStackPop() +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_constrainedComposition") +fileprivate func bjs_constrainedComposition_extern(_ _generic0TypeId: Int32) -> Void +#else +fileprivate func bjs_constrainedComposition_extern(_ _generic0TypeId: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_constrainedComposition(_ _generic0TypeId: Int32) -> Void { + return bjs_constrainedComposition_extern(_generic0TypeId) +} + +func _$constrainedComposition(_ value: T) throws(JSException) -> T { + value.bridgeJSStackPush() + bjs_constrainedComposition(T.bridgeJSTypeID) + if let error = _swift_js_take_exception() { + throw error + } + return T.bridgeJSStackPop() +} + #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_GenericPairFactory_init") fileprivate func bjs_GenericPairFactory_init_extern(_ tagBytes: Int32, _ tagLength: Int32, _ _generic0TypeId: Int32, _ _generic1TypeId: Int32) -> Int32 @@ -490,6 +623,70 @@ func _$GenericConsumer_identity(_ self: JSObje return T.bridgeJSStackPop() } +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_ConstrainedConsumer_init") +fileprivate func bjs_ConstrainedConsumer_init_extern(_ _generic0TypeId: Int32) -> Int32 +#else +fileprivate func bjs_ConstrainedConsumer_init_extern(_ _generic0TypeId: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ConstrainedConsumer_init(_ _generic0TypeId: Int32) -> Int32 { + return bjs_ConstrainedConsumer_init_extern(_generic0TypeId) +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_ConstrainedConsumer_identity_static") +fileprivate func bjs_ConstrainedConsumer_identity_static_extern(_ _generic0TypeId: Int32) -> Void +#else +fileprivate func bjs_ConstrainedConsumer_identity_static_extern(_ _generic0TypeId: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ConstrainedConsumer_identity_static(_ _generic0TypeId: Int32) -> Void { + return bjs_ConstrainedConsumer_identity_static_extern(_generic0TypeId) +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_ConstrainedConsumer_accept") +fileprivate func bjs_ConstrainedConsumer_accept_extern(_ self: Int32, _ _generic0TypeId: Int32) -> Void +#else +fileprivate func bjs_ConstrainedConsumer_accept_extern(_ self: Int32, _ _generic0TypeId: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ConstrainedConsumer_accept(_ self: Int32, _ _generic0TypeId: Int32) -> Void { + return bjs_ConstrainedConsumer_accept_extern(self, _generic0TypeId) +} + +func _$ConstrainedConsumer_init(_ value: T) throws(JSException) -> JSObject { + value.bridgeJSStackPush() + let ret = bjs_ConstrainedConsumer_init(T.bridgeJSTypeID) + if let error = _swift_js_take_exception() { + throw error + } + return JSObject.bridgeJSLiftReturn(ret) +} + +func _$ConstrainedConsumer_identity(_ value: T) throws(JSException) -> T { + value.bridgeJSStackPush() + bjs_ConstrainedConsumer_identity_static(T.bridgeJSTypeID) + if let error = _swift_js_take_exception() { + throw error + } + return T.bridgeJSStackPop() +} + +func _$ConstrainedConsumer_accept(_ self: JSObject, _ value: T) throws(JSException) -> T { + value.bridgeJSStackPush() + let selfValue = self.bridgeJSLowerParameter() + bjs_ConstrainedConsumer_accept(selfValue, T.bridgeJSTypeID) + if let error = _swift_js_take_exception() { + throw error + } + return T.bridgeJSStackPop() +} + #if arch(wasm32) @_extern(wasm, module: "bjs", name: "bjs_TestModule_register_type_handles") fileprivate func _bjs_TestModule_register_type_handles_extern(_ base: UnsafePointer?, _ count: Int32) @@ -502,6 +699,8 @@ public func _bjs_TestModule_register_type_handles() { GenericColor.bridgeJSTypeID, GenericMode.bridgeJSTypeID, GenericTagged.bridgeJSTypeID, + AnyGenericReadable.bridgeJSTypeID, + AnyGenericNode.bridgeJSTypeID, ] typeIds.withUnsafeBufferPointer { buffer in _bjs_TestModule_register_type_handles_extern(buffer.baseAddress, Int32(buffer.count)) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift index ef9beefac..ec3d2f65a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift @@ -1,22 +1,20 @@ -struct AnyMyViewControllerDelegate: MyViewControllerDelegate, _BridgedSwiftProtocolWrapper { - let jsObject: JSObject - +extension MyViewControllerDelegate where Self: _BridgedSwiftProtocolWrapper { func onSomethingHappened() -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() - _extern_onSomethingHappened(jsObjectValue) + bjs_MyViewControllerDelegate_onSomethingHappened(jsObjectValue) } func onValueChanged(_ value: String) -> Void { value.bridgeJSWithLoweredParameter { (valueBytes, valueLength) in let jsObjectValue = jsObject.bridgeJSLowerParameter() - _extern_onValueChanged(jsObjectValue, valueBytes, valueLength) + bjs_MyViewControllerDelegate_onValueChanged(jsObjectValue, valueBytes, valueLength) } } func onCountUpdated(count: Int) -> Bool { let countValue = count.bridgeJSLowerParameter() let jsObjectValue = jsObject.bridgeJSLowerParameter() - let ret = _extern_onCountUpdated(jsObjectValue, countValue) + let ret = bjs_MyViewControllerDelegate_onCountUpdated(jsObjectValue, countValue) return Bool.bridgeJSLiftReturn(ret) } @@ -24,56 +22,56 @@ struct AnyMyViewControllerDelegate: MyViewControllerDelegate, _BridgedSwiftProto prefix.bridgeJSWithLoweredParameter { (prefixBytes, prefixLength) in suffix.bridgeJSWithLoweredParameter { (suffixBytes, suffixLength) in let jsObjectValue = jsObject.bridgeJSLowerParameter() - _extern_onLabelUpdated(jsObjectValue, prefixBytes, prefixLength, suffixBytes, suffixLength) + bjs_MyViewControllerDelegate_onLabelUpdated(jsObjectValue, prefixBytes, prefixLength, suffixBytes, suffixLength) } } } func isCountEven() -> Bool { let jsObjectValue = jsObject.bridgeJSLowerParameter() - let ret = _extern_isCountEven(jsObjectValue) + let ret = bjs_MyViewControllerDelegate_isCountEven(jsObjectValue) return Bool.bridgeJSLiftReturn(ret) } func onHelperUpdated(_ helper: Helper) -> Void { let helperPointer = helper.bridgeJSLowerParameter() let jsObjectValue = jsObject.bridgeJSLowerParameter() - _extern_onHelperUpdated(jsObjectValue, helperPointer) + bjs_MyViewControllerDelegate_onHelperUpdated(jsObjectValue, helperPointer) } func createHelper() -> Helper { let jsObjectValue = jsObject.bridgeJSLowerParameter() - let ret = _extern_createHelper(jsObjectValue) + let ret = bjs_MyViewControllerDelegate_createHelper(jsObjectValue) return Helper.bridgeJSLiftReturn(ret) } func onOptionalHelperUpdated(_ helper: Optional) -> Void { let (helperIsSome, helperPointer) = helper.bridgeJSLowerParameter() let jsObjectValue = jsObject.bridgeJSLowerParameter() - _extern_onOptionalHelperUpdated(jsObjectValue, helperIsSome, helperPointer) + bjs_MyViewControllerDelegate_onOptionalHelperUpdated(jsObjectValue, helperIsSome, helperPointer) } func createOptionalHelper() -> Optional { let jsObjectValue = jsObject.bridgeJSLowerParameter() - let ret = _extern_createOptionalHelper(jsObjectValue) + let ret = bjs_MyViewControllerDelegate_createOptionalHelper(jsObjectValue) return Optional.bridgeJSLiftReturn(ret) } func createEnum() -> ExampleEnum { let jsObjectValue = jsObject.bridgeJSLowerParameter() - let ret = _extern_createEnum(jsObjectValue) + let ret = bjs_MyViewControllerDelegate_createEnum(jsObjectValue) return ExampleEnum.bridgeJSLiftReturn(ret) } func handleResult(_ result: Result) -> Void { let resultCaseId = result.bridgeJSLowerParameter() let jsObjectValue = jsObject.bridgeJSLowerParameter() - _extern_handleResult(jsObjectValue, resultCaseId) + bjs_MyViewControllerDelegate_handleResult(jsObjectValue, resultCaseId) } func getResult() -> Result { let jsObjectValue = jsObject.bridgeJSLowerParameter() - let ret = _extern_getResult(jsObjectValue) + let ret = bjs_MyViewControllerDelegate_getResult(jsObjectValue) return Result.bridgeJSLiftReturn(ret) } @@ -217,6 +215,10 @@ struct AnyMyViewControllerDelegate: MyViewControllerDelegate, _BridgedSwiftProto bjs_MyViewControllerDelegate_priorityOptional_set(jsObjectValue, newValueIsSome, newValueValue) } } +} + +struct AnyMyViewControllerDelegate: MyViewControllerDelegate, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject static func bridgeJSLiftParameter(_ value: Int32) -> Self { return AnyMyViewControllerDelegate(jsObject: JSObject(id: UInt32(bitPattern: value))) @@ -225,146 +227,146 @@ struct AnyMyViewControllerDelegate: MyViewControllerDelegate, _BridgedSwiftProto #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_onSomethingHappened") -fileprivate func _extern_onSomethingHappened_extern(_ jsObject: Int32) -> Void +fileprivate func bjs_MyViewControllerDelegate_onSomethingHappened_extern(_ jsObject: Int32) -> Void #else -fileprivate func _extern_onSomethingHappened_extern(_ jsObject: Int32) -> Void { +fileprivate func bjs_MyViewControllerDelegate_onSomethingHappened_extern(_ jsObject: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_onSomethingHappened(_ jsObject: Int32) -> Void { - return _extern_onSomethingHappened_extern(jsObject) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_onSomethingHappened(_ jsObject: Int32) -> Void { + return bjs_MyViewControllerDelegate_onSomethingHappened_extern(jsObject) } #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_onValueChanged") -fileprivate func _extern_onValueChanged_extern(_ jsObject: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void +fileprivate func bjs_MyViewControllerDelegate_onValueChanged_extern(_ jsObject: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void #else -fileprivate func _extern_onValueChanged_extern(_ jsObject: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { +fileprivate func bjs_MyViewControllerDelegate_onValueChanged_extern(_ jsObject: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_onValueChanged(_ jsObject: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - return _extern_onValueChanged_extern(jsObject, valueBytes, valueLength) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_onValueChanged(_ jsObject: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { + return bjs_MyViewControllerDelegate_onValueChanged_extern(jsObject, valueBytes, valueLength) } #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_onCountUpdated") -fileprivate func _extern_onCountUpdated_extern(_ jsObject: Int32, _ count: Int32) -> Int32 +fileprivate func bjs_MyViewControllerDelegate_onCountUpdated_extern(_ jsObject: Int32, _ count: Int32) -> Int32 #else -fileprivate func _extern_onCountUpdated_extern(_ jsObject: Int32, _ count: Int32) -> Int32 { +fileprivate func bjs_MyViewControllerDelegate_onCountUpdated_extern(_ jsObject: Int32, _ count: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_onCountUpdated(_ jsObject: Int32, _ count: Int32) -> Int32 { - return _extern_onCountUpdated_extern(jsObject, count) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_onCountUpdated(_ jsObject: Int32, _ count: Int32) -> Int32 { + return bjs_MyViewControllerDelegate_onCountUpdated_extern(jsObject, count) } #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_onLabelUpdated") -fileprivate func _extern_onLabelUpdated_extern(_ jsObject: Int32, _ prefixBytes: Int32, _ prefixLength: Int32, _ suffixBytes: Int32, _ suffixLength: Int32) -> Void +fileprivate func bjs_MyViewControllerDelegate_onLabelUpdated_extern(_ jsObject: Int32, _ prefixBytes: Int32, _ prefixLength: Int32, _ suffixBytes: Int32, _ suffixLength: Int32) -> Void #else -fileprivate func _extern_onLabelUpdated_extern(_ jsObject: Int32, _ prefixBytes: Int32, _ prefixLength: Int32, _ suffixBytes: Int32, _ suffixLength: Int32) -> Void { +fileprivate func bjs_MyViewControllerDelegate_onLabelUpdated_extern(_ jsObject: Int32, _ prefixBytes: Int32, _ prefixLength: Int32, _ suffixBytes: Int32, _ suffixLength: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_onLabelUpdated(_ jsObject: Int32, _ prefixBytes: Int32, _ prefixLength: Int32, _ suffixBytes: Int32, _ suffixLength: Int32) -> Void { - return _extern_onLabelUpdated_extern(jsObject, prefixBytes, prefixLength, suffixBytes, suffixLength) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_onLabelUpdated(_ jsObject: Int32, _ prefixBytes: Int32, _ prefixLength: Int32, _ suffixBytes: Int32, _ suffixLength: Int32) -> Void { + return bjs_MyViewControllerDelegate_onLabelUpdated_extern(jsObject, prefixBytes, prefixLength, suffixBytes, suffixLength) } #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_isCountEven") -fileprivate func _extern_isCountEven_extern(_ jsObject: Int32) -> Int32 +fileprivate func bjs_MyViewControllerDelegate_isCountEven_extern(_ jsObject: Int32) -> Int32 #else -fileprivate func _extern_isCountEven_extern(_ jsObject: Int32) -> Int32 { +fileprivate func bjs_MyViewControllerDelegate_isCountEven_extern(_ jsObject: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_isCountEven(_ jsObject: Int32) -> Int32 { - return _extern_isCountEven_extern(jsObject) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_isCountEven(_ jsObject: Int32) -> Int32 { + return bjs_MyViewControllerDelegate_isCountEven_extern(jsObject) } #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_onHelperUpdated") -fileprivate func _extern_onHelperUpdated_extern(_ jsObject: Int32, _ helper: UnsafeMutableRawPointer) -> Void +fileprivate func bjs_MyViewControllerDelegate_onHelperUpdated_extern(_ jsObject: Int32, _ helper: UnsafeMutableRawPointer) -> Void #else -fileprivate func _extern_onHelperUpdated_extern(_ jsObject: Int32, _ helper: UnsafeMutableRawPointer) -> Void { +fileprivate func bjs_MyViewControllerDelegate_onHelperUpdated_extern(_ jsObject: Int32, _ helper: UnsafeMutableRawPointer) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_onHelperUpdated(_ jsObject: Int32, _ helper: UnsafeMutableRawPointer) -> Void { - return _extern_onHelperUpdated_extern(jsObject, helper) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_onHelperUpdated(_ jsObject: Int32, _ helper: UnsafeMutableRawPointer) -> Void { + return bjs_MyViewControllerDelegate_onHelperUpdated_extern(jsObject, helper) } #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_createHelper") -fileprivate func _extern_createHelper_extern(_ jsObject: Int32) -> UnsafeMutableRawPointer +fileprivate func bjs_MyViewControllerDelegate_createHelper_extern(_ jsObject: Int32) -> UnsafeMutableRawPointer #else -fileprivate func _extern_createHelper_extern(_ jsObject: Int32) -> UnsafeMutableRawPointer { +fileprivate func bjs_MyViewControllerDelegate_createHelper_extern(_ jsObject: Int32) -> UnsafeMutableRawPointer { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_createHelper(_ jsObject: Int32) -> UnsafeMutableRawPointer { - return _extern_createHelper_extern(jsObject) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_createHelper(_ jsObject: Int32) -> UnsafeMutableRawPointer { + return bjs_MyViewControllerDelegate_createHelper_extern(jsObject) } #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_onOptionalHelperUpdated") -fileprivate func _extern_onOptionalHelperUpdated_extern(_ jsObject: Int32, _ helperIsSome: Int32, _ helperPointer: UnsafeMutableRawPointer) -> Void +fileprivate func bjs_MyViewControllerDelegate_onOptionalHelperUpdated_extern(_ jsObject: Int32, _ helperIsSome: Int32, _ helperPointer: UnsafeMutableRawPointer) -> Void #else -fileprivate func _extern_onOptionalHelperUpdated_extern(_ jsObject: Int32, _ helperIsSome: Int32, _ helperPointer: UnsafeMutableRawPointer) -> Void { +fileprivate func bjs_MyViewControllerDelegate_onOptionalHelperUpdated_extern(_ jsObject: Int32, _ helperIsSome: Int32, _ helperPointer: UnsafeMutableRawPointer) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_onOptionalHelperUpdated(_ jsObject: Int32, _ helperIsSome: Int32, _ helperPointer: UnsafeMutableRawPointer) -> Void { - return _extern_onOptionalHelperUpdated_extern(jsObject, helperIsSome, helperPointer) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_onOptionalHelperUpdated(_ jsObject: Int32, _ helperIsSome: Int32, _ helperPointer: UnsafeMutableRawPointer) -> Void { + return bjs_MyViewControllerDelegate_onOptionalHelperUpdated_extern(jsObject, helperIsSome, helperPointer) } #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_createOptionalHelper") -fileprivate func _extern_createOptionalHelper_extern(_ jsObject: Int32) -> UnsafeMutableRawPointer +fileprivate func bjs_MyViewControllerDelegate_createOptionalHelper_extern(_ jsObject: Int32) -> UnsafeMutableRawPointer #else -fileprivate func _extern_createOptionalHelper_extern(_ jsObject: Int32) -> UnsafeMutableRawPointer { +fileprivate func bjs_MyViewControllerDelegate_createOptionalHelper_extern(_ jsObject: Int32) -> UnsafeMutableRawPointer { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_createOptionalHelper(_ jsObject: Int32) -> UnsafeMutableRawPointer { - return _extern_createOptionalHelper_extern(jsObject) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_createOptionalHelper(_ jsObject: Int32) -> UnsafeMutableRawPointer { + return bjs_MyViewControllerDelegate_createOptionalHelper_extern(jsObject) } #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_createEnum") -fileprivate func _extern_createEnum_extern(_ jsObject: Int32) -> Int32 +fileprivate func bjs_MyViewControllerDelegate_createEnum_extern(_ jsObject: Int32) -> Int32 #else -fileprivate func _extern_createEnum_extern(_ jsObject: Int32) -> Int32 { +fileprivate func bjs_MyViewControllerDelegate_createEnum_extern(_ jsObject: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_createEnum(_ jsObject: Int32) -> Int32 { - return _extern_createEnum_extern(jsObject) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_createEnum(_ jsObject: Int32) -> Int32 { + return bjs_MyViewControllerDelegate_createEnum_extern(jsObject) } #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_handleResult") -fileprivate func _extern_handleResult_extern(_ jsObject: Int32, _ result: Int32) -> Void +fileprivate func bjs_MyViewControllerDelegate_handleResult_extern(_ jsObject: Int32, _ result: Int32) -> Void #else -fileprivate func _extern_handleResult_extern(_ jsObject: Int32, _ result: Int32) -> Void { +fileprivate func bjs_MyViewControllerDelegate_handleResult_extern(_ jsObject: Int32, _ result: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_handleResult(_ jsObject: Int32, _ result: Int32) -> Void { - return _extern_handleResult_extern(jsObject, result) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_handleResult(_ jsObject: Int32, _ result: Int32) -> Void { + return bjs_MyViewControllerDelegate_handleResult_extern(jsObject, result) } #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_getResult") -fileprivate func _extern_getResult_extern(_ jsObject: Int32) -> Int32 +fileprivate func bjs_MyViewControllerDelegate_getResult_extern(_ jsObject: Int32) -> Int32 #else -fileprivate func _extern_getResult_extern(_ jsObject: Int32) -> Int32 { +fileprivate func bjs_MyViewControllerDelegate_getResult_extern(_ jsObject: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_getResult(_ jsObject: Int32) -> Int32 { - return _extern_getResult_extern(jsObject) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_getResult(_ jsObject: Int32) -> Int32 { + return bjs_MyViewControllerDelegate_getResult_extern(jsObject) } #if arch(wasm32) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ProtocolInClosure.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ProtocolInClosure.swift index f02cd4019..bc63b1f65 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ProtocolInClosure.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ProtocolInClosure.swift @@ -257,14 +257,16 @@ public func _invoke_swift_closure_TestModule_10TestModuley_10RenderableP(_ boxPt #endif } -struct AnyRenderable: Renderable, _BridgedSwiftProtocolWrapper { - let jsObject: JSObject - +extension Renderable where Self: _BridgedSwiftProtocolWrapper { func render() -> String { let jsObjectValue = jsObject.bridgeJSLowerParameter() - let ret = _extern_render(jsObjectValue) + let ret = bjs_Renderable_render(jsObjectValue) return String.bridgeJSLiftReturn(ret) } +} + +struct AnyRenderable: Renderable, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject static func bridgeJSLiftParameter(_ value: Int32) -> Self { return AnyRenderable(jsObject: JSObject(id: UInt32(bitPattern: value))) @@ -273,14 +275,14 @@ struct AnyRenderable: Renderable, _BridgedSwiftProtocolWrapper { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_Renderable_render") -fileprivate func _extern_render_extern(_ jsObject: Int32) -> Int32 +fileprivate func bjs_Renderable_render_extern(_ jsObject: Int32) -> Int32 #else -fileprivate func _extern_render_extern(_ jsObject: Int32) -> Int32 { +fileprivate func bjs_Renderable_render_extern(_ jsObject: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_render(_ jsObject: Int32) -> Int32 { - return _extern_render_extern(jsObject) +@inline(never) fileprivate func bjs_Renderable_render(_ jsObject: Int32) -> Int32 { + return bjs_Renderable_render_extern(jsObject) } @_expose(wasm, "bjs_processRenderable") diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.d.ts index 026713ce3..8ff2aad15 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.d.ts @@ -4,6 +4,17 @@ // To update this file, just rebuild your project or run // `swift package bridge-js`. +export interface GenericReadable { + read(): number; +} + +export interface GenericWritable { + value: number; +} + +export interface GenericNode extends GenericReadable, GenericWritable { +} + export const GenericColorValues: { readonly Red: 0; readonly Green: 1; @@ -53,6 +64,9 @@ export interface GenericConsumer { accept(value: T): void; identity(value: T): T; } +export interface ConstrainedConsumer { + accept(value: T): T; +} export type Exports = { GenericColor: GenericColorObject GenericMode: GenericModeObject @@ -70,6 +84,8 @@ export type Imports = { importGenericOptional(value: T | null): T | null; importGenericDictionary(values: Record): Record; importGenericAfterOptionalArray(values: number[] | null, value: T): T; + constrainedRoundTrip(value: T): T; + constrainedComposition(value: T): T; GenericPairFactory: { new(tag: string, first: T, second: U): GenericPairFactory; } @@ -77,6 +93,10 @@ export type Imports = { new(value: T): GenericConsumer; box(value: T): T; } + ConstrainedConsumer: { + new(value: T): ConstrainedConsumer; + identity(value: T): T; + } } export function createInstantiator(options: { imports: Imports; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js index d8b1fdf15..529f1772e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js @@ -428,6 +428,30 @@ export async function createInstantiator(options, swift) { return enumValue; }, }; + const __bjs_codec_M10TestModuleT15GenericReadable = { + lower: (v) => { + const objId = swift.memory.retain(v); + i32Stack.push(objId); + }, + lift: () => { + const objId = i32Stack.pop(); + const obj = swift.memory.getObject(objId); + swift.memory.release(objId); + return obj; + }, + }; + const __bjs_codec_M10TestModuleT11GenericNode = { + lower: (v) => { + const objId = swift.memory.retain(v); + i32Stack.push(objId); + }, + lift: () => { + const objId = i32Stack.pop(); + const obj = swift.memory.getObject(objId); + swift.memory.release(objId); + return obj; + }, + }; const __bjs_createStructHelpers_M10TestModuleT12GenericPoint = () => ({ lower: (value) => { @@ -586,6 +610,8 @@ export async function createInstantiator(options, swift) { __bjs_codec_M10TestModuleT12GenericColor, __bjs_stringCodec, __bjs_codec_M10TestModuleT13GenericTagged, + __bjs_codec_M10TestModuleT15GenericReadable, + __bjs_codec_M10TestModuleT11GenericNode, ]; const typeIds = new Int32Array(memory.buffer, base >>> 0, count >>> 0); for (let i = 0; i < count; i++) { @@ -783,6 +809,26 @@ export async function createInstantiator(options, swift) { setException(error); } } + TestModule["bjs_constrainedRoundTrip"] = function bjs_constrainedRoundTrip(tTypeId) { + try { + const codecT = __bjs_codecForTypeId(tTypeId); + const value = codecT.lift(); + let ret = imports.constrainedRoundTrip(value); + codecT.lower(ret); + } catch (error) { + setException(error); + } + } + TestModule["bjs_constrainedComposition"] = function bjs_constrainedComposition(tTypeId) { + try { + const codecT = __bjs_codecForTypeId(tTypeId); + const value = codecT.lift(); + let ret = imports.constrainedComposition(value); + codecT.lower(ret); + } catch (error) { + setException(error); + } + } TestModule["bjs_GenericPairFactory_init"] = function bjs_GenericPairFactory_init(tagBytes, tagCount, tTypeId, uTypeId) { try { const codecT = __bjs_codecForTypeId(tTypeId); @@ -835,6 +881,61 @@ export async function createInstantiator(options, swift) { setException(error); } } + TestModule["bjs_ConstrainedConsumer_init"] = function bjs_ConstrainedConsumer_init(tTypeId) { + try { + const codecT = __bjs_codecForTypeId(tTypeId); + const value = codecT.lift(); + return swift.memory.retain(new imports.ConstrainedConsumer(value)); + } catch (error) { + setException(error); + return 0 + } + } + TestModule["bjs_ConstrainedConsumer_identity_static"] = function bjs_ConstrainedConsumer_identity_static(tTypeId) { + try { + const codecT = __bjs_codecForTypeId(tTypeId); + const value = codecT.lift(); + let ret = imports.ConstrainedConsumer.identity(value); + codecT.lower(ret); + } catch (error) { + setException(error); + } + } + TestModule["bjs_ConstrainedConsumer_accept"] = function bjs_ConstrainedConsumer_accept(self, tTypeId) { + try { + const codecT = __bjs_codecForTypeId(tTypeId); + const value = codecT.lift(); + let ret = swift.memory.getObject(self).accept(value); + codecT.lower(ret); + } catch (error) { + setException(error); + } + } + TestModule["bjs_GenericReadable_read"] = function bjs_GenericReadable_read(self) { + try { + let ret = swift.memory.getObject(self).read(); + return ret; + } catch (error) { + setException(error); + return 0 + } + } + TestModule["bjs_GenericWritable_value_get"] = function bjs_GenericWritable_value_get(self) { + try { + let ret = swift.memory.getObject(self).value; + return ret; + } catch (error) { + setException(error); + return 0 + } + } + TestModule["bjs_GenericWritable_value_set"] = function bjs_GenericWritable_value_set(self, value) { + try { + swift.memory.getObject(self).value = value; + } catch (error) { + setException(error); + } + } }, setInstance: (i) => { instance = i; diff --git a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Protocols.md b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Protocols.md index d62d71051..4c91ba749 100644 --- a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Protocols.md +++ b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Protocols.md @@ -15,6 +15,8 @@ When you mark a protocol with `@JS`, BridgeJS generates: Use `@JS("PublicName")` on a protocol to rename its TypeScript interface and generated type references. Swift still uses the original protocol name for conformances and signatures. JavaScript objects still satisfy the interface structurally; renaming does not create a protocol constructor or change how callbacks and protocol values cross the boundary. Unlike `@JS(as: Other.self)`, it does not change the representation, and combining the two options is not supported. +An `@JS` protocol can refine other `@JS` protocols declared in the same module. Its generated TypeScript interface and Swift wrapper expose inherited methods and properties. Cross-module protocol refinement is not supported. + ## Example: Counter Protocol Mark a Swift protocol with `@JS` to expose it: @@ -220,8 +222,10 @@ struct AnyCounter: Counter, _BridgedSwiftProtocolWrapper { | Optional properties | ✅ | | Optional protocol methods | ❌ | | Associated types | ❌ | -| Protocol inheritance | ❌ | -| Protocol composition: `Protocol1 & Protocol2` | ❌ | -| Generics | ❌ | +| Same-module `@JS` protocol inheritance | ✅ | +| Cross-module protocol inheritance | ❌ | +| Existential protocol composition: `any Protocol1 & Protocol2` | ❌ | +| Generic requirements | ❌ | +| Protocol-valued properties, parameters, or results in requirements | ❌ | -> Note: Protocol type support matches that of regular `@JS func` and `@JS class` exports. See , , and for more information. +> Note: For supported requirement types, see , , and . diff --git a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Importing-JavaScript/Importing-JS-Function.md b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Importing-JavaScript/Importing-JS-Function.md index ebc9ac857..02f0a349d 100644 --- a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Importing-JavaScript/Importing-JS-Function.md +++ b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Importing-JavaScript/Importing-JS-Function.md @@ -89,6 +89,17 @@ let user: User = try parse(jsonString) // T inferred from the call site `T` can be any supported primitive, `String`, `JSValue`, or a `@JS` struct, `@JS` enum, or `final @JS class` (see ), used bare or wrapped as `[T]`, `T?`, or `[String: T]`. A function may declare multiple type parameters, and a return-only generic (`func make() -> T`) works too. Generic initializers, methods, and static methods on `@JSClass` types are supported the same way. `async` generic functions and `where` clauses are not supported. +Generic imports can also constrain `T` to `@JS` protocols, as in `T: BridgedSwiftGenericBridgeable & P & Q`. If `P` inherits `BridgedSwiftGenericBridgeable`, use `T: P`: + +```swift +import JavaScriptKit + +@JS protocol Named: BridgedSwiftGenericBridgeable { var name: String { get } } +@JSFunction func display(_ value: T) throws(JSException) +``` + +Constraints may use `@JS` protocols from dependency modules, including qualified names such as `T: BridgedSwiftGenericBridgeable & Models.Named`. Concrete conformers must expose the required members to JavaScript too, including marking methods with `@JS`. This does not enable existential compositions such as `any P & Q`; the generic-import limitations above still apply. + ## Supported features | Feature | Status | @@ -96,4 +107,5 @@ let user: User = try parse(jsonString) // T inferred from the call site | Primitive parameter/result types (e.g. `Double`, `Bool`) | ✅ | | `String` parameter/result type | ✅ | | Generic parameter/result types (constrained to `BridgedSwiftGenericBridgeable`) | ✅ | +| `@JS` protocol constraints on generic imports | ✅ | | Async function | ❌ | diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index 4496316e7..acb3e23f1 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -4247,9 +4247,7 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsy_y #endif } -struct AnyArrayElementProtocol: ArrayElementProtocol, _BridgedSwiftProtocolWrapper { - let jsObject: JSObject - +extension ArrayElementProtocol where Self: _BridgedSwiftProtocolWrapper { var value: Int { get { let jsObjectValue = jsObject.bridgeJSLowerParameter() @@ -4262,6 +4260,10 @@ struct AnyArrayElementProtocol: ArrayElementProtocol, _BridgedSwiftProtocolWrapp bjs_ArrayElementProtocol_value_set(jsObjectValue, newValueValue) } } +} + +struct AnyArrayElementProtocol: ArrayElementProtocol, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject static func bridgeJSLiftParameter(_ value: Int32) -> Self { return AnyArrayElementProtocol(jsObject: JSObject(id: UInt32(bitPattern: value))) @@ -4292,18 +4294,16 @@ fileprivate func bjs_ArrayElementProtocol_value_set_extern(_ jsObject: Int32, _ return bjs_ArrayElementProtocol_value_set_extern(jsObject, newValue) } -struct AnyDataProcessor: DataProcessor, _BridgedSwiftProtocolWrapper { - let jsObject: JSObject - +extension DataProcessor where Self: _BridgedSwiftProtocolWrapper { func increment(by amount: Int) -> Void { let amountValue = amount.bridgeJSLowerParameter() let jsObjectValue = jsObject.bridgeJSLowerParameter() - _extern_increment(jsObjectValue, amountValue) + bjs_DataProcessor_increment(jsObjectValue, amountValue) } func getValue() -> Int { let jsObjectValue = jsObject.bridgeJSLowerParameter() - let ret = _extern_getValue(jsObjectValue) + let ret = bjs_DataProcessor_getValue(jsObjectValue) return Int.bridgeJSLiftReturn(ret) } @@ -4311,58 +4311,58 @@ struct AnyDataProcessor: DataProcessor, _BridgedSwiftProtocolWrapper { labelPrefix.bridgeJSWithLoweredParameter { (labelPrefixBytes, labelPrefixLength) in labelSuffix.bridgeJSWithLoweredParameter { (labelSuffixBytes, labelSuffixLength) in let jsObjectValue = jsObject.bridgeJSLowerParameter() - _extern_setLabelElements(jsObjectValue, labelPrefixBytes, labelPrefixLength, labelSuffixBytes, labelSuffixLength) + bjs_DataProcessor_setLabelElements(jsObjectValue, labelPrefixBytes, labelPrefixLength, labelSuffixBytes, labelSuffixLength) } } } func getLabel() -> String { let jsObjectValue = jsObject.bridgeJSLowerParameter() - let ret = _extern_getLabel(jsObjectValue) + let ret = bjs_DataProcessor_getLabel(jsObjectValue) return String.bridgeJSLiftReturn(ret) } func isEven() -> Bool { let jsObjectValue = jsObject.bridgeJSLowerParameter() - let ret = _extern_isEven(jsObjectValue) + let ret = bjs_DataProcessor_isEven(jsObjectValue) return Bool.bridgeJSLiftReturn(ret) } func processGreeter(_ greeter: Greeter) -> String { let greeterPointer = greeter.bridgeJSLowerParameter() let jsObjectValue = jsObject.bridgeJSLowerParameter() - let ret = _extern_processGreeter(jsObjectValue, greeterPointer) + let ret = bjs_DataProcessor_processGreeter(jsObjectValue, greeterPointer) return String.bridgeJSLiftReturn(ret) } func createGreeter() -> Greeter { let jsObjectValue = jsObject.bridgeJSLowerParameter() - let ret = _extern_createGreeter(jsObjectValue) + let ret = bjs_DataProcessor_createGreeter(jsObjectValue) return Greeter.bridgeJSLiftReturn(ret) } func processOptionalGreeter(_ greeter: Optional) -> String { let (greeterIsSome, greeterPointer) = greeter.bridgeJSLowerParameter() let jsObjectValue = jsObject.bridgeJSLowerParameter() - let ret = _extern_processOptionalGreeter(jsObjectValue, greeterIsSome, greeterPointer) + let ret = bjs_DataProcessor_processOptionalGreeter(jsObjectValue, greeterIsSome, greeterPointer) return String.bridgeJSLiftReturn(ret) } func createOptionalGreeter() -> Optional { let jsObjectValue = jsObject.bridgeJSLowerParameter() - let ret = _extern_createOptionalGreeter(jsObjectValue) + let ret = bjs_DataProcessor_createOptionalGreeter(jsObjectValue) return Optional.bridgeJSLiftReturn(ret) } func handleAPIResult(_ result: Optional) -> Void { let (resultIsSome, resultCaseId) = result.bridgeJSLowerParameter() let jsObjectValue = jsObject.bridgeJSLowerParameter() - _extern_handleAPIResult(jsObjectValue, resultIsSome, resultCaseId) + bjs_DataProcessor_handleAPIResult(jsObjectValue, resultIsSome, resultCaseId) } func getAPIResult() -> Optional { let jsObjectValue = jsObject.bridgeJSLowerParameter() - let ret = _extern_getAPIResult(jsObjectValue) + let ret = bjs_DataProcessor_getAPIResult(jsObjectValue) return Optional.bridgeJSLiftReturn(ret) } @@ -4492,6 +4492,10 @@ struct AnyDataProcessor: DataProcessor, _BridgedSwiftProtocolWrapper { bjs_DataProcessor_optionalHelper_set(jsObjectValue, newValueIsSome, newValuePointer) } } +} + +struct AnyDataProcessor: DataProcessor, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject static func bridgeJSLiftParameter(_ value: Int32) -> Self { return AnyDataProcessor(jsObject: JSObject(id: UInt32(bitPattern: value))) @@ -4500,134 +4504,134 @@ struct AnyDataProcessor: DataProcessor, _BridgedSwiftProtocolWrapper { #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_increment") -fileprivate func _extern_increment_extern(_ jsObject: Int32, _ amount: Int32) -> Void +fileprivate func bjs_DataProcessor_increment_extern(_ jsObject: Int32, _ amount: Int32) -> Void #else -fileprivate func _extern_increment_extern(_ jsObject: Int32, _ amount: Int32) -> Void { +fileprivate func bjs_DataProcessor_increment_extern(_ jsObject: Int32, _ amount: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_increment(_ jsObject: Int32, _ amount: Int32) -> Void { - return _extern_increment_extern(jsObject, amount) +@inline(never) fileprivate func bjs_DataProcessor_increment(_ jsObject: Int32, _ amount: Int32) -> Void { + return bjs_DataProcessor_increment_extern(jsObject, amount) } #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_getValue") -fileprivate func _extern_getValue_extern(_ jsObject: Int32) -> Int32 +fileprivate func bjs_DataProcessor_getValue_extern(_ jsObject: Int32) -> Int32 #else -fileprivate func _extern_getValue_extern(_ jsObject: Int32) -> Int32 { +fileprivate func bjs_DataProcessor_getValue_extern(_ jsObject: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_getValue(_ jsObject: Int32) -> Int32 { - return _extern_getValue_extern(jsObject) +@inline(never) fileprivate func bjs_DataProcessor_getValue(_ jsObject: Int32) -> Int32 { + return bjs_DataProcessor_getValue_extern(jsObject) } #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_setLabelElements") -fileprivate func _extern_setLabelElements_extern(_ jsObject: Int32, _ labelPrefixBytes: Int32, _ labelPrefixLength: Int32, _ labelSuffixBytes: Int32, _ labelSuffixLength: Int32) -> Void +fileprivate func bjs_DataProcessor_setLabelElements_extern(_ jsObject: Int32, _ labelPrefixBytes: Int32, _ labelPrefixLength: Int32, _ labelSuffixBytes: Int32, _ labelSuffixLength: Int32) -> Void #else -fileprivate func _extern_setLabelElements_extern(_ jsObject: Int32, _ labelPrefixBytes: Int32, _ labelPrefixLength: Int32, _ labelSuffixBytes: Int32, _ labelSuffixLength: Int32) -> Void { +fileprivate func bjs_DataProcessor_setLabelElements_extern(_ jsObject: Int32, _ labelPrefixBytes: Int32, _ labelPrefixLength: Int32, _ labelSuffixBytes: Int32, _ labelSuffixLength: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_setLabelElements(_ jsObject: Int32, _ labelPrefixBytes: Int32, _ labelPrefixLength: Int32, _ labelSuffixBytes: Int32, _ labelSuffixLength: Int32) -> Void { - return _extern_setLabelElements_extern(jsObject, labelPrefixBytes, labelPrefixLength, labelSuffixBytes, labelSuffixLength) +@inline(never) fileprivate func bjs_DataProcessor_setLabelElements(_ jsObject: Int32, _ labelPrefixBytes: Int32, _ labelPrefixLength: Int32, _ labelSuffixBytes: Int32, _ labelSuffixLength: Int32) -> Void { + return bjs_DataProcessor_setLabelElements_extern(jsObject, labelPrefixBytes, labelPrefixLength, labelSuffixBytes, labelSuffixLength) } #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_getLabel") -fileprivate func _extern_getLabel_extern(_ jsObject: Int32) -> Int32 +fileprivate func bjs_DataProcessor_getLabel_extern(_ jsObject: Int32) -> Int32 #else -fileprivate func _extern_getLabel_extern(_ jsObject: Int32) -> Int32 { +fileprivate func bjs_DataProcessor_getLabel_extern(_ jsObject: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_getLabel(_ jsObject: Int32) -> Int32 { - return _extern_getLabel_extern(jsObject) +@inline(never) fileprivate func bjs_DataProcessor_getLabel(_ jsObject: Int32) -> Int32 { + return bjs_DataProcessor_getLabel_extern(jsObject) } #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_isEven") -fileprivate func _extern_isEven_extern(_ jsObject: Int32) -> Int32 +fileprivate func bjs_DataProcessor_isEven_extern(_ jsObject: Int32) -> Int32 #else -fileprivate func _extern_isEven_extern(_ jsObject: Int32) -> Int32 { +fileprivate func bjs_DataProcessor_isEven_extern(_ jsObject: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_isEven(_ jsObject: Int32) -> Int32 { - return _extern_isEven_extern(jsObject) +@inline(never) fileprivate func bjs_DataProcessor_isEven(_ jsObject: Int32) -> Int32 { + return bjs_DataProcessor_isEven_extern(jsObject) } #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_processGreeter") -fileprivate func _extern_processGreeter_extern(_ jsObject: Int32, _ greeter: UnsafeMutableRawPointer) -> Int32 +fileprivate func bjs_DataProcessor_processGreeter_extern(_ jsObject: Int32, _ greeter: UnsafeMutableRawPointer) -> Int32 #else -fileprivate func _extern_processGreeter_extern(_ jsObject: Int32, _ greeter: UnsafeMutableRawPointer) -> Int32 { +fileprivate func bjs_DataProcessor_processGreeter_extern(_ jsObject: Int32, _ greeter: UnsafeMutableRawPointer) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_processGreeter(_ jsObject: Int32, _ greeter: UnsafeMutableRawPointer) -> Int32 { - return _extern_processGreeter_extern(jsObject, greeter) +@inline(never) fileprivate func bjs_DataProcessor_processGreeter(_ jsObject: Int32, _ greeter: UnsafeMutableRawPointer) -> Int32 { + return bjs_DataProcessor_processGreeter_extern(jsObject, greeter) } #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_createGreeter") -fileprivate func _extern_createGreeter_extern(_ jsObject: Int32) -> UnsafeMutableRawPointer +fileprivate func bjs_DataProcessor_createGreeter_extern(_ jsObject: Int32) -> UnsafeMutableRawPointer #else -fileprivate func _extern_createGreeter_extern(_ jsObject: Int32) -> UnsafeMutableRawPointer { +fileprivate func bjs_DataProcessor_createGreeter_extern(_ jsObject: Int32) -> UnsafeMutableRawPointer { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_createGreeter(_ jsObject: Int32) -> UnsafeMutableRawPointer { - return _extern_createGreeter_extern(jsObject) +@inline(never) fileprivate func bjs_DataProcessor_createGreeter(_ jsObject: Int32) -> UnsafeMutableRawPointer { + return bjs_DataProcessor_createGreeter_extern(jsObject) } #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_processOptionalGreeter") -fileprivate func _extern_processOptionalGreeter_extern(_ jsObject: Int32, _ greeterIsSome: Int32, _ greeterPointer: UnsafeMutableRawPointer) -> Int32 +fileprivate func bjs_DataProcessor_processOptionalGreeter_extern(_ jsObject: Int32, _ greeterIsSome: Int32, _ greeterPointer: UnsafeMutableRawPointer) -> Int32 #else -fileprivate func _extern_processOptionalGreeter_extern(_ jsObject: Int32, _ greeterIsSome: Int32, _ greeterPointer: UnsafeMutableRawPointer) -> Int32 { +fileprivate func bjs_DataProcessor_processOptionalGreeter_extern(_ jsObject: Int32, _ greeterIsSome: Int32, _ greeterPointer: UnsafeMutableRawPointer) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_processOptionalGreeter(_ jsObject: Int32, _ greeterIsSome: Int32, _ greeterPointer: UnsafeMutableRawPointer) -> Int32 { - return _extern_processOptionalGreeter_extern(jsObject, greeterIsSome, greeterPointer) +@inline(never) fileprivate func bjs_DataProcessor_processOptionalGreeter(_ jsObject: Int32, _ greeterIsSome: Int32, _ greeterPointer: UnsafeMutableRawPointer) -> Int32 { + return bjs_DataProcessor_processOptionalGreeter_extern(jsObject, greeterIsSome, greeterPointer) } #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_createOptionalGreeter") -fileprivate func _extern_createOptionalGreeter_extern(_ jsObject: Int32) -> UnsafeMutableRawPointer +fileprivate func bjs_DataProcessor_createOptionalGreeter_extern(_ jsObject: Int32) -> UnsafeMutableRawPointer #else -fileprivate func _extern_createOptionalGreeter_extern(_ jsObject: Int32) -> UnsafeMutableRawPointer { +fileprivate func bjs_DataProcessor_createOptionalGreeter_extern(_ jsObject: Int32) -> UnsafeMutableRawPointer { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_createOptionalGreeter(_ jsObject: Int32) -> UnsafeMutableRawPointer { - return _extern_createOptionalGreeter_extern(jsObject) +@inline(never) fileprivate func bjs_DataProcessor_createOptionalGreeter(_ jsObject: Int32) -> UnsafeMutableRawPointer { + return bjs_DataProcessor_createOptionalGreeter_extern(jsObject) } #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_handleAPIResult") -fileprivate func _extern_handleAPIResult_extern(_ jsObject: Int32, _ resultIsSome: Int32, _ resultCaseId: Int32) -> Void +fileprivate func bjs_DataProcessor_handleAPIResult_extern(_ jsObject: Int32, _ resultIsSome: Int32, _ resultCaseId: Int32) -> Void #else -fileprivate func _extern_handleAPIResult_extern(_ jsObject: Int32, _ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { +fileprivate func bjs_DataProcessor_handleAPIResult_extern(_ jsObject: Int32, _ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_handleAPIResult(_ jsObject: Int32, _ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { - return _extern_handleAPIResult_extern(jsObject, resultIsSome, resultCaseId) +@inline(never) fileprivate func bjs_DataProcessor_handleAPIResult(_ jsObject: Int32, _ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { + return bjs_DataProcessor_handleAPIResult_extern(jsObject, resultIsSome, resultCaseId) } #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_getAPIResult") -fileprivate func _extern_getAPIResult_extern(_ jsObject: Int32) -> Int32 +fileprivate func bjs_DataProcessor_getAPIResult_extern(_ jsObject: Int32) -> Int32 #else -fileprivate func _extern_getAPIResult_extern(_ jsObject: Int32) -> Int32 { +fileprivate func bjs_DataProcessor_getAPIResult_extern(_ jsObject: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_getAPIResult(_ jsObject: Int32) -> Int32 { - return _extern_getAPIResult_extern(jsObject) +@inline(never) fileprivate func bjs_DataProcessor_getAPIResult(_ jsObject: Int32) -> Int32 { + return bjs_DataProcessor_getAPIResult_extern(jsObject) } #if arch(wasm32) @@ -4858,15 +4862,266 @@ fileprivate func bjs_DataProcessor_optionalHelper_set_extern(_ jsObject: Int32, return bjs_DataProcessor_optionalHelper_set_extern(jsObject, newValueIsSome, newValuePointer) } -struct AnyJSNameTransformer: JSNameTransformer, _BridgedSwiftProtocolWrapper { +extension GenericRTPosition where Self: _BridgedSwiftProtocolWrapper { + func sum() -> Int { + let jsObjectValue = jsObject.bridgeJSLowerParameter() + let ret = bjs_GenericRTPosition_sum(jsObjectValue) + return Int.bridgeJSLiftReturn(ret) + } + + var x: Int { + get { + let jsObjectValue = jsObject.bridgeJSLowerParameter() + let ret = bjs_GenericRTPosition_x_get(jsObjectValue) + return Int.bridgeJSLiftReturn(ret) + } + } +} + +struct AnyGenericRTPosition: GenericRTPosition, _BridgedSwiftProtocolWrapper { let jsObject: JSObject + static func bridgeJSLiftParameter(_ value: Int32) -> Self { + return AnyGenericRTPosition(jsObject: JSObject(id: UInt32(bitPattern: value))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_GenericRTPosition_sum") +fileprivate func bjs_GenericRTPosition_sum_extern(_ jsObject: Int32) -> Int32 +#else +fileprivate func bjs_GenericRTPosition_sum_extern(_ jsObject: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_GenericRTPosition_sum(_ jsObject: Int32) -> Int32 { + return bjs_GenericRTPosition_sum_extern(jsObject) +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_GenericRTPosition_x_get") +fileprivate func bjs_GenericRTPosition_x_get_extern(_ jsObject: Int32) -> Int32 +#else +fileprivate func bjs_GenericRTPosition_x_get_extern(_ jsObject: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_GenericRTPosition_x_get(_ jsObject: Int32) -> Int32 { + return bjs_GenericRTPosition_x_get_extern(jsObject) +} + +extension GenericRTNode where Self: _BridgedSwiftProtocolWrapper { + var y: Int { + get { + let jsObjectValue = jsObject.bridgeJSLowerParameter() + let ret = bjs_GenericRTNode_y_get(jsObjectValue) + return Int.bridgeJSLiftReturn(ret) + } + } +} + +struct AnyGenericRTNode: GenericRTNode, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject + + static func bridgeJSLiftParameter(_ value: Int32) -> Self { + return AnyGenericRTNode(jsObject: JSObject(id: UInt32(bitPattern: value))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_GenericRTNode_y_get") +fileprivate func bjs_GenericRTNode_y_get_extern(_ jsObject: Int32) -> Int32 +#else +fileprivate func bjs_GenericRTNode_y_get_extern(_ jsObject: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_GenericRTNode_y_get(_ jsObject: Int32) -> Int32 { + return bjs_GenericRTNode_y_get_extern(jsObject) +} + +extension RefineIdentified where Self: _BridgedSwiftProtocolWrapper { + var id: String { + get { + let jsObjectValue = jsObject.bridgeJSLowerParameter() + let ret = bjs_RefineIdentified_id_get(jsObjectValue) + return String.bridgeJSLiftReturn(ret) + } + } + + var score: Int { + get { + let jsObjectValue = jsObject.bridgeJSLowerParameter() + let ret = bjs_RefineIdentified_score_get(jsObjectValue) + return Int.bridgeJSLiftReturn(ret) + } + set { + let newValueValue = newValue.bridgeJSLowerParameter() + let jsObjectValue = jsObject.bridgeJSLowerParameter() + bjs_RefineIdentified_score_set(jsObjectValue, newValueValue) + } + } +} + +struct AnyRefineIdentified: RefineIdentified, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject + + static func bridgeJSLiftParameter(_ value: Int32) -> Self { + return AnyRefineIdentified(jsObject: JSObject(id: UInt32(bitPattern: value))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_RefineIdentified_id_get") +fileprivate func bjs_RefineIdentified_id_get_extern(_ jsObject: Int32) -> Int32 +#else +fileprivate func bjs_RefineIdentified_id_get_extern(_ jsObject: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_RefineIdentified_id_get(_ jsObject: Int32) -> Int32 { + return bjs_RefineIdentified_id_get_extern(jsObject) +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_RefineIdentified_score_get") +fileprivate func bjs_RefineIdentified_score_get_extern(_ jsObject: Int32) -> Int32 +#else +fileprivate func bjs_RefineIdentified_score_get_extern(_ jsObject: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_RefineIdentified_score_get(_ jsObject: Int32) -> Int32 { + return bjs_RefineIdentified_score_get_extern(jsObject) +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_RefineIdentified_score_set") +fileprivate func bjs_RefineIdentified_score_set_extern(_ jsObject: Int32, _ newValue: Int32) -> Void +#else +fileprivate func bjs_RefineIdentified_score_set_extern(_ jsObject: Int32, _ newValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_RefineIdentified_score_set(_ jsObject: Int32, _ newValue: Int32) -> Void { + return bjs_RefineIdentified_score_set_extern(jsObject, newValue) +} + +extension RefineNamed where Self: _BridgedSwiftProtocolWrapper { + func label() -> String { + let jsObjectValue = jsObject.bridgeJSLowerParameter() + let ret = bjs_RefineNamed_label(jsObjectValue) + return String.bridgeJSLiftReturn(ret) + } + + var name: String { + get { + let jsObjectValue = jsObject.bridgeJSLowerParameter() + let ret = bjs_RefineNamed_name_get(jsObjectValue) + return String.bridgeJSLiftReturn(ret) + } + } +} + +struct AnyRefineNamed: RefineNamed, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject + + static func bridgeJSLiftParameter(_ value: Int32) -> Self { + return AnyRefineNamed(jsObject: JSObject(id: UInt32(bitPattern: value))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_RefineNamed_label") +fileprivate func bjs_RefineNamed_label_extern(_ jsObject: Int32) -> Int32 +#else +fileprivate func bjs_RefineNamed_label_extern(_ jsObject: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_RefineNamed_label(_ jsObject: Int32) -> Int32 { + return bjs_RefineNamed_label_extern(jsObject) +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_RefineNamed_name_get") +fileprivate func bjs_RefineNamed_name_get_extern(_ jsObject: Int32) -> Int32 +#else +fileprivate func bjs_RefineNamed_name_get_extern(_ jsObject: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_RefineNamed_name_get(_ jsObject: Int32) -> Int32 { + return bjs_RefineNamed_name_get_extern(jsObject) +} + +extension RefineEntity where Self: _BridgedSwiftProtocolWrapper { + func label() -> String { + let jsObjectValue = jsObject.bridgeJSLowerParameter() + let ret = bjs_RefineEntity_label(jsObjectValue) + return String.bridgeJSLiftReturn(ret) + } + + var id: String { + get { + let jsObjectValue = jsObject.bridgeJSLowerParameter() + let ret = bjs_RefineEntity_id_get(jsObjectValue) + return String.bridgeJSLiftReturn(ret) + } + } +} + +struct AnyRefineEntity: RefineEntity, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject + + static func bridgeJSLiftParameter(_ value: Int32) -> Self { + return AnyRefineEntity(jsObject: JSObject(id: UInt32(bitPattern: value))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_RefineEntity_label") +fileprivate func bjs_RefineEntity_label_extern(_ jsObject: Int32) -> Int32 +#else +fileprivate func bjs_RefineEntity_label_extern(_ jsObject: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_RefineEntity_label(_ jsObject: Int32) -> Int32 { + return bjs_RefineEntity_label_extern(jsObject) +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_RefineEntity_id_get") +fileprivate func bjs_RefineEntity_id_get_extern(_ jsObject: Int32) -> Int32 +#else +fileprivate func bjs_RefineEntity_id_get_extern(_ jsObject: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_RefineEntity_id_get(_ jsObject: Int32) -> Int32 { + return bjs_RefineEntity_id_get_extern(jsObject) +} + +struct AnyRefineTagged: RefineTagged, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject + + static func bridgeJSLiftParameter(_ value: Int32) -> Self { + return AnyRefineTagged(jsObject: JSObject(id: UInt32(bitPattern: value))) + } +} + +extension JSNameTransformer where Self: _BridgedSwiftProtocolWrapper { func apply(_ value: Int) -> Int { let valueValue = value.bridgeJSLowerParameter() let jsObjectValue = jsObject.bridgeJSLowerParameter() - let ret = _extern_apply(jsObjectValue, valueValue) + let ret = bjs_JSNameTransformer_apply(jsObjectValue, valueValue) return Int.bridgeJSLiftReturn(ret) } +} + +struct AnyJSNameTransformer: JSNameTransformer, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject static func bridgeJSLiftParameter(_ value: Int32) -> Self { return AnyJSNameTransformer(jsObject: JSObject(id: UInt32(bitPattern: value))) @@ -4875,14 +5130,14 @@ struct AnyJSNameTransformer: JSNameTransformer, _BridgedSwiftProtocolWrapper { #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JSNameTransformer_apply") -fileprivate func _extern_apply_extern(_ jsObject: Int32, _ value: Int32) -> Int32 +fileprivate func bjs_JSNameTransformer_apply_extern(_ jsObject: Int32, _ value: Int32) -> Int32 #else -fileprivate func _extern_apply_extern(_ jsObject: Int32, _ value: Int32) -> Int32 { +fileprivate func bjs_JSNameTransformer_apply_extern(_ jsObject: Int32, _ value: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func _extern_apply(_ jsObject: Int32, _ value: Int32) -> Int32 { - return _extern_apply_extern(jsObject, value) +@inline(never) fileprivate func bjs_JSNameTransformer_apply(_ jsObject: Int32, _ value: Int32) -> Int32 { + return bjs_JSNameTransformer_apply_extern(jsObject, value) } extension Severity: _BridgedSwiftCaseEnum { @@ -7841,6 +8096,18 @@ fileprivate func _bjs_struct_lift_GenericRTPoint_extern() -> Int32 { return _bjs_struct_lift_GenericRTPoint_extern() } +@_expose(wasm, "bjs_GenericRTPoint_sum") +@_cdecl("bjs_GenericRTPoint_sum") +public func _bjs_GenericRTPoint_sum() -> Int32 { + #if arch(wasm32) + let _self = GenericRTPoint.bridgeJSLiftParameter() + let ret = _self.sum() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + extension GenericRTNamespace.Metadata: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSStackPop() -> GenericRTNamespace.Metadata { let count = Int.bridgeJSStackPop() @@ -11254,6 +11521,30 @@ public func _bjs_roundTripMessage(_ message: Int32) -> Void { #endif } +@_expose(wasm, "bjs_describeRefinedEntity") +@_cdecl("bjs_describeRefinedEntity") +public func _bjs_describeRefinedEntity(_ entity: Int32) -> Void { + #if arch(wasm32) + let entity = AnyRefineEntity.bridgeJSLiftParameter(entity) + let ret = describeRefinedEntity(_: entity) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_describeTaggedEntity") +@_cdecl("bjs_describeTaggedEntity") +public func _bjs_describeTaggedEntity(_ entity: Int32) -> Void { + #if arch(wasm32) + let entity = AnyRefineTagged.bridgeJSLiftParameter(entity) + let ret = describeTaggedEntity(_: entity) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + @_expose(wasm, "bjs_renamedEcho") @_cdecl("bjs_renamedEcho") public func _bjs_renamedEcho(_ valueBytes: Int32, _ valueLength: Int32) -> Void { @@ -15910,6 +16201,14 @@ extension APIOptionalResult: BridgedSwiftGenericBridgeable { @_spi(BridgeJS) public static let bridgeJSTypeHandle = APIOptionalResult.bridgeJSMakeTypeHandle() } +extension AnyGenericRTPosition: BridgedSwiftGenericBridgeable { + @_spi(BridgeJS) public static let bridgeJSTypeHandle = AnyGenericRTPosition.bridgeJSMakeTypeHandle() +} + +extension AnyGenericRTNode: BridgedSwiftGenericBridgeable { + @_spi(BridgeJS) public static let bridgeJSTypeHandle = AnyGenericRTNode.bridgeJSMakeTypeHandle() +} + @JSFunction func Promise_reject(_ promise: JSObject, _ value: JSValue) throws(JSException) #if arch(wasm32) @@ -19464,6 +19763,47 @@ func _$jsGenericThrowOrRoundTrip(_ shouldThrow return T.bridgeJSStackPop() } +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsGenericNodeRoundTrip") +fileprivate func bjs_jsGenericNodeRoundTrip_extern(_ _generic0TypeId: Int32) -> Void +#else +fileprivate func bjs_jsGenericNodeRoundTrip_extern(_ _generic0TypeId: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_jsGenericNodeRoundTrip(_ _generic0TypeId: Int32) -> Void { + return bjs_jsGenericNodeRoundTrip_extern(_generic0TypeId) +} + +func _$jsGenericNodeRoundTrip(_ value: T) throws(JSException) -> T { + value.bridgeJSStackPush() + bjs_jsGenericNodeRoundTrip(T.bridgeJSTypeID) + if let error = _swift_js_take_exception() { + throw error + } + return T.bridgeJSStackPop() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsGenericMakeNode") +fileprivate func bjs_jsGenericMakeNode_extern(_ _generic0TypeId: Int32) -> Void +#else +fileprivate func bjs_jsGenericMakeNode_extern(_ _generic0TypeId: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_jsGenericMakeNode(_ _generic0TypeId: Int32) -> Void { + return bjs_jsGenericMakeNode_extern(_generic0TypeId) +} + +func _$jsGenericMakeNode() throws(JSException) -> T { + bjs_jsGenericMakeNode(T.bridgeJSTypeID) + if let error = _swift_js_take_exception() { + throw error + } + return T.bridgeJSStackPop() +} + #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ImportGenericConsumer_init") fileprivate func bjs_ImportGenericConsumer_init_extern() -> Int32 @@ -21026,6 +21366,8 @@ public func _bjs_BridgeJSRuntimeTests_register_type_handles() { GenericRTOutcome.bridgeJSTypeID, OptionalAllTypesResult.bridgeJSTypeID, APIOptionalResult.bridgeJSTypeID, + AnyGenericRTPosition.bridgeJSTypeID, + AnyGenericRTNode.bridgeJSTypeID, ] typeIds.withUnsafeBufferPointer { buffer in _bjs_BridgeJSRuntimeTests_register_type_handles_extern(buffer.baseAddress, Int32(buffer.count)) diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index 0084d9f6a..4749c6eb3 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -17671,6 +17671,56 @@ } } }, + { + "abiName" : "bjs_describeRefinedEntity", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "describeRefinedEntity", + "parameters" : [ + { + "label" : "_", + "name" : "entity", + "type" : { + "swiftProtocol" : { + "_0" : "RefineEntity" + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_describeTaggedEntity", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "describeTaggedEntity", + "parameters" : [ + { + "label" : "_", + "name" : "entity", + "type" : { + "swiftProtocol" : { + "_0" : "RefineTagged" + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, { "abiName" : "bjs_renamedEcho", "effects" : { @@ -18984,6 +19034,181 @@ } ] }, + { + "isGenericBridgeable" : true, + "methods" : [ + { + "abiName" : "bjs_GenericRTPosition_sum", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "sum", + "parameters" : [ + + ], + "returnType" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } + ], + "name" : "GenericRTPosition", + "properties" : [ + { + "isReadonly" : true, + "name" : "x", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } + ] + }, + { + "inheritedJSProtocols" : [ + "GenericRTPosition" + ], + "isGenericBridgeable" : true, + "methods" : [ + + ], + "name" : "GenericRTNode", + "properties" : [ + { + "isReadonly" : true, + "name" : "y", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } + ] + }, + { + "methods" : [ + + ], + "name" : "RefineIdentified", + "properties" : [ + { + "isReadonly" : true, + "name" : "id", + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : false, + "name" : "score", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } + ] + }, + { + "methods" : [ + { + "abiName" : "bjs_RefineNamed_label", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "label", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "RefineNamed", + "properties" : [ + { + "isReadonly" : true, + "name" : "name", + "type" : { + "string" : { + + } + } + } + ] + }, + { + "inheritedJSProtocols" : [ + "RefineIdentified", + "RefineNamed" + ], + "methods" : [ + { + "abiName" : "bjs_RefineEntity_label", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "label", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "RefineEntity", + "properties" : [ + { + "isReadonly" : true, + "name" : "id", + "type" : { + "string" : { + + } + } + } + ] + }, + { + "inheritedJSProtocols" : [ + "RefineEntity" + ], + "methods" : [ + + ], + "name" : "RefineTagged", + "properties" : [ + + ] + }, { "jsName" : "CounterTransform", "methods" : [ @@ -19377,7 +19602,26 @@ }, { "methods" : [ + { + "abiName" : "bjs_GenericRTPoint_sum", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "sum", + "parameters" : [ + ], + "returnType" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } ], "name" : "GenericRTPoint", "properties" : [ @@ -25257,7 +25501,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "jsGenericRoundTrip", "parameters" : [ @@ -25284,7 +25530,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "jsGenericRoundTripClass", "parameters" : [ @@ -25311,7 +25559,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "jsGenericParsePoint", "parameters" : [ @@ -25338,7 +25588,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "jsImportPickFirst", "parameters" : [ @@ -25373,7 +25625,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "jsImportMakeInt", "parameters" : [ @@ -25393,8 +25647,12 @@ "isThrows" : true }, "genericParameters" : [ - "T", - "U" + { + "name" : "T" + }, + { + "name" : "U" + } ], "name" : "jsImportCombineSecond", "parameters" : [ @@ -25429,7 +25687,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "jsGenericArrayRoundTrip", "parameters" : [ @@ -25464,7 +25724,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "jsGenericOptionalRoundTrip", "parameters" : [ @@ -25501,7 +25763,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "jsGenericDictRoundTrip", "parameters" : [ @@ -25536,7 +25800,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "jsGenericAfterOptionalArray", "parameters" : [ @@ -25583,7 +25849,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "jsGenericThrowOrRoundTrip", "parameters" : [ @@ -25609,6 +25877,64 @@ "_0" : "T" } } + }, + { + "accessLevel" : "internal", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "genericParameters" : [ + { + "constraints" : [ + "GenericRTNode" + ], + "name" : "T" + } + ], + "name" : "jsGenericNodeRoundTrip", + "parameters" : [ + { + "name" : "value", + "type" : { + "generic" : { + "_0" : "T" + } + } + } + ], + "returnType" : { + "generic" : { + "_0" : "T" + } + } + }, + { + "accessLevel" : "internal", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "genericParameters" : [ + { + "constraints" : [ + "GenericRTPosition", + "GenericRTNode" + ], + "name" : "T" + } + ], + "name" : "jsGenericMakeNode", + "parameters" : [ + + ], + "returnType" : { + "generic" : { + "_0" : "T" + } + } } ], "types" : [ @@ -25632,7 +25958,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "identity", "parameters" : [ @@ -25665,7 +25993,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "box", "parameters" : [ @@ -25691,7 +26021,9 @@ "constructor" : { "accessLevel" : "internal", "genericParameters" : [ - "T" + { + "name" : "T" + } ], "parameters" : [ { @@ -25716,7 +26048,9 @@ "isThrows" : true }, "genericParameters" : [ - "T" + { + "name" : "T" + } ], "name" : "unwrap", "parameters" : [ diff --git a/Tests/BridgeJSRuntimeTests/ImportGenericAPIs.swift b/Tests/BridgeJSRuntimeTests/ImportGenericAPIs.swift index bfd63839f..c5484edc6 100644 --- a/Tests/BridgeJSRuntimeTests/ImportGenericAPIs.swift +++ b/Tests/BridgeJSRuntimeTests/ImportGenericAPIs.swift @@ -79,7 +79,34 @@ import JavaScriptKit @JSFunction func unwrap() throws(JSException) -> T } +@JS protocol GenericRTPosition: BridgedSwiftGenericBridgeable { + var x: Int { get } + func sum() -> Int +} + +@JS protocol GenericRTNode: GenericRTPosition { + var y: Int { get } +} + +extension GenericRTPoint: GenericRTNode { + @JS func sum() -> Int { x + y } +} + +@JSFunction func jsGenericNodeRoundTrip(_ value: T) throws(JSException) -> T +@JSFunction func jsGenericMakeNode() + throws(JSException) -> T + @Suite struct ImportGenericAPITests { + @Test func constrainedProtocolRoundTrip() throws { + let point = try jsGenericNodeRoundTrip(GenericRTPoint(x: 1, y: 2)) + #expect(point.sum() == 3) + let node: AnyGenericRTNode = try jsGenericMakeNode() + #expect(node.x == 3) + #expect(node.y == 4) + #expect(node.sum() == 7) + #expect(try jsGenericNodeRoundTrip(node).jsObject == node.jsObject) + } + @Test func genericRoundTripScalars() throws { #expect(try jsGenericRoundTrip(42) == 42) #expect(try jsGenericRoundTrip(-7) == -7) @@ -278,3 +305,30 @@ import JavaScriptKit #expect(color == .green) } } + +@JS protocol RefineIdentified { + var id: String { get } + var score: Int { get set } +} + +@JS protocol RefineNamed { + var name: String { get } + func label() -> String +} + +@JS protocol RefineEntity: RefineIdentified, RefineNamed { + var id: String { get } + func label() -> String +} + +@JS func describeRefinedEntity(_ entity: RefineEntity) -> String { + var identified: any RefineIdentified = entity + identified.score = entity.score + 1 + return "\(entity.id):\(entity.name):\(entity.label()):\(identified.score)" +} + +@JS protocol RefineTagged: RefineEntity {} + +@JS func describeTaggedEntity(_ entity: RefineTagged) -> String { + "\(entity.id)/\(entity.name)/\(entity.score)" +} diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index 977a1f386..5287df791 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -178,6 +178,11 @@ export async function setupOptions(options, context) { jsGenericOptionalRoundTrip: (v) => v, jsGenericDictRoundTrip: (v) => v, jsGenericAfterOptionalArray: (a, b) => `${JSON.stringify(a)}|${JSON.stringify(b)}`, + jsGenericNodeRoundTrip: (value) => { + if (value.sum() !== value.x + value.y) throw new Error("Invalid protocol method result"); + return value; + }, + jsGenericMakeNode: () => ({ x: 3, y: 4, sum() { return this.x + this.y; } }), ImportGenericConsumer: class { identity(value) { return value; @@ -296,6 +301,10 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { const optDict = { hello: "world" }; assert.deepEqual(exports.roundTripOptionalDictionaryExport(optDict), optDict); assert.equal(exports.roundTripOptionalDictionaryExport(null), null); + const entity = { id: "e1", name: "Main", score: 10, label() { return "L" + this.score; } }; + assert.equal(exports.describeRefinedEntity(entity), "e1:Main:L11:11"); + assert.equal(entity.score, 11); + assert.equal(exports.describeTaggedEntity(entity), "e1/Main/11"); const arrayStruct = { ints: [1, 2, 3], optStrings: ["a", "b"] }; const arrayStructRoundTrip = exports.roundTripArrayMembers(arrayStruct); assert.deepEqual(arrayStructRoundTrip.ints, [1, 2, 3]); From 299008330714094ba52f955695ce47faaf868ca8 Mon Sep 17 00:00:00 2001 From: Simon Leeb <52261246+sliemeobn@users.noreply.github.com> Date: Thu, 8 Oct 2026 19:39:24 +0200 Subject: [PATCH 02/18] Optimized String bridging (Swift -> JS) (#816) --- Benchmarks/Sources/Generated/BridgeJS.swift | 12 +- .../PlayBridgeJS/Generated/BridgeJS.swift | 12 +- Plugins/BridgeJS/README.md | 5 +- .../Sources/BridgeJSCore/ExportSwift.swift | 4 +- .../Sources/BridgeJSCore/ImportTS.swift | 2 +- .../Sources/BridgeJSLink/BridgeJSLink.swift | 194 +++- .../Sources/BridgeJSLink/JSGlueGen.swift | 13 +- .../Inputs/StringDecoderTests.mjs | 98 ++ .../StringDecoderTests.swift | 44 + .../BridgeJSCodegenTests/Alias.swift | 36 +- .../BridgeJSCodegenTests/Async.swift | 36 +- .../BridgeJSCodegenTests/AsyncImport.swift | 24 +- .../BridgeJSCodegenTests/EnumRawType.swift | 12 +- .../BridgeJSCodegenTests/GenericImports.swift | 24 +- .../BridgeJSCodegenTests/GlobalGetter.swift | 12 +- .../GlobalThisImports.swift | 36 +- .../BridgeJSCodegenTests/ImportArray.swift | 12 +- .../InvalidPropertyNames.swift | 60 +- .../BridgeJSCodegenTests/JSClass.swift | 36 +- .../JSImportBareModule.swift | 24 +- .../JSImportBareModuleFallback.swift | 14 +- .../BridgeJSCodegenTests/Optionals.swift | 62 +- .../BridgeJSCodegenTests/Protocol.swift | 62 +- .../StringParameter.swift | 24 +- .../BridgeJSCodegenTests/SwiftClosure.swift | 132 +-- .../SwiftClosureImports.swift | 48 +- .../__Snapshots__/BridgeJSLinkTests/Alias.js | 183 +++- .../BridgeJSLinkTests/AliasInClosure.js | 173 +++- .../BridgeJSLinkTests/ArrayTypes.js | 171 +++- .../__Snapshots__/BridgeJSLinkTests/Async.js | 183 +++- .../AsyncAssociatedValueEnum.js | 171 +++- .../BridgeJSLinkTests/AsyncImport.js | 181 +++- .../BridgeJSLinkTests/AsyncStaticImport.js | 173 +++- .../BridgeJSLinkTests/ClassWithNestedTypes.js | 171 +++- .../BridgeJSLinkTests/DefaultParameters.js | 171 +++- .../BridgeJSLinkTests/DictionaryTypes.js | 171 +++- .../BridgeJSLinkTests/DocComments.js | 171 +++- .../BridgeJSLinkTests/EnumAlias.js | 171 +++- .../BridgeJSLinkTests/EnumAssociatedValue.js | 171 +++- .../EnumAssociatedValueImport.js | 171 +++- .../BridgeJSLinkTests/EnumCase.js | 171 +++- .../BridgeJSLinkTests/EnumCaseImport.js | 171 +++- .../BridgeJSLinkTests/EnumNamespace.Global.js | 171 +++- .../BridgeJSLinkTests/EnumNamespace.js | 171 +++- .../BridgeJSLinkTests/EnumRawType.js | 175 +++- .../BridgeJSLinkTests/ExtensionNestedTypes.js | 171 +++- .../ExtensionOrderIndependence.js | 171 +++- .../BridgeJSLinkTests/ExtensionScopeParity.js | 171 +++- .../BridgeJSLinkTests/FixedWidthIntegers.js | 171 +++- .../BridgeJSLinkTests/GenericImports.js | 179 +++- .../BridgeJSLinkTests/GlobalGetter.js | 175 +++- .../BridgeJSLinkTests/GlobalThisImports.js | 183 +++- .../IdentityModeClass.ConfigPointer.js | 171 +++- .../IdentityModeClass.PerClass.js | 171 +++- .../BridgeJSLinkTests/IdentityModeClass.js | 171 +++- .../BridgeJSLinkTests/ImportArray.js | 175 +++- .../ImportedTypeInExportedInterface.js | 171 +++- .../BridgeJSLinkTests/InvalidPropertyNames.js | 191 +++- .../BridgeJSLinkTests/JSClass.js | 183 +++- .../JSClassStaticFunctions.js | 171 +++- .../BridgeJSLinkTests/JSImportBareModule.js | 179 +++- .../JSImportBareModuleFallback.js | 177 +++- .../BridgeJSLinkTests/JSImportModule.js | 171 +++- .../BridgeJSLinkTests/JSNameOverride.js | 171 +++- .../BridgeJSLinkTests/JSNameTypes.js | 171 +++- .../BridgeJSLinkTests/JSTypedArrayTypes.js | 171 +++- .../BridgeJSLinkTests/JSValue.js | 171 +++- .../BridgeJSLinkTests/MixedGlobal.js | 171 +++- .../BridgeJSLinkTests/MixedModules.js | 171 +++- .../BridgeJSLinkTests/MixedPrivate.js | 171 +++- .../NamespacedClassSignature.js | 173 +++- .../BridgeJSLinkTests/Namespaces.Global.js | 171 +++- .../BridgeJSLinkTests/Namespaces.js | 171 +++- .../BridgeJSLinkTests/NestedType.js | 171 +++- .../NestedTypeNameCollision.js | 171 +++- .../BridgeJSLinkTests/Optionals.js | 193 +++- .../BridgeJSLinkTests/PrimitiveParameters.js | 171 +++- .../BridgeJSLinkTests/PrimitiveReturn.js | 171 +++- .../BridgeJSLinkTests/PropertyTypes.js | 171 +++- .../BridgeJSLinkTests/Protocol.js | 193 +++- .../BridgeJSLinkTests/ProtocolInClosure.js | 173 +++- .../RelativeQualifiedTypes.js | 171 +++- .../StaticFunctions.Global.js | 171 +++- .../BridgeJSLinkTests/StaticFunctions.js | 171 +++- .../StaticProperties.Global.js | 171 +++- .../BridgeJSLinkTests/StaticProperties.js | 171 +++- .../BridgeJSLinkTests/StringParameter.js | 179 +++- .../BridgeJSLinkTests/StringReturn.js | 171 +++- .../StructWithNestedTypes.js | 171 +++- .../BridgeJSLinkTests/SwiftClass.js | 171 +++- .../BridgeJSLinkTests/SwiftClosure.js | 217 ++++- .../BridgeJSLinkTests/SwiftClosureImports.js | 189 +++- .../BridgeJSLinkTests/SwiftStruct.js | 171 +++- .../BridgeJSLinkTests/SwiftStructImports.js | 171 +++- .../SwiftTypedClosureAccess.js | 173 +++- .../__Snapshots__/BridgeJSLinkTests/Throws.js | 171 +++- .../BridgeJSLinkTests/UnsafePointer.js | 171 +++- .../VoidParameterVoidReturn.js | 171 +++- .../JavaScriptKit/BridgeJSIntrinsics.swift | 97 +- .../Generated/BridgeJS.swift | 836 ++++++++++++------ .../Generated/JavaScript/BridgeJS.json | 570 ++++++++++++ .../JavaScript/StringABITests.mjs | 53 ++ .../BridgeJSRuntimeTests/StringABITests.swift | 81 ++ Tests/prelude.mjs | 8 + 104 files changed, 13775 insertions(+), 1458 deletions(-) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringDecoderTests.mjs create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/StringDecoderTests.swift create mode 100644 Tests/BridgeJSRuntimeTests/JavaScript/StringABITests.mjs create mode 100644 Tests/BridgeJSRuntimeTests/StringABITests.swift diff --git a/Benchmarks/Sources/Generated/BridgeJS.swift b/Benchmarks/Sources/Generated/BridgeJS.swift index 86f2516e6..fc46623f2 100644 --- a/Benchmarks/Sources/Generated/BridgeJS.swift +++ b/Benchmarks/Sources/Generated/BridgeJS.swift @@ -2429,20 +2429,20 @@ func _$benchmarkHelperNoopWithNumber(_ n: Double) throws(JSException) -> Void { #if arch(wasm32) @_extern(wasm, module: "Benchmarks", name: "bjs_benchmarkRunner") -fileprivate func bjs_benchmarkRunner_extern(_ nameBytes: Int32, _ nameLength: Int32, _ body: Int32) -> Void +fileprivate func bjs_benchmarkRunner_extern(_ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32, _ body: Int32) -> Void #else -fileprivate func bjs_benchmarkRunner_extern(_ nameBytes: Int32, _ nameLength: Int32, _ body: Int32) -> Void { +fileprivate func bjs_benchmarkRunner_extern(_ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32, _ body: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_benchmarkRunner(_ nameBytes: Int32, _ nameLength: Int32, _ body: Int32) -> Void { - return bjs_benchmarkRunner_extern(nameBytes, nameLength, body) +@inline(never) fileprivate func bjs_benchmarkRunner(_ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32, _ body: Int32) -> Void { + return bjs_benchmarkRunner_extern(nameWord0, nameWord1, nameWord2, body) } func _$benchmarkRunner(_ name: String, _ body: JSObject) throws(JSException) -> Void { - name.bridgeJSWithLoweredParameter { (nameBytes, nameLength) in + name.bridgeJSWithLoweredParameter { (nameWord0, nameWord1, nameWord2) in let bodyValue = body.bridgeJSLowerParameter() - bjs_benchmarkRunner(nameBytes, nameLength, bodyValue) + bjs_benchmarkRunner(nameWord0, nameWord1, nameWord2, bodyValue) } if let error = _swift_js_take_exception() { throw error diff --git a/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.swift b/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.swift index eed55bdea..ee8b1f436 100644 --- a/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.swift +++ b/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.swift @@ -268,20 +268,20 @@ func _$createTS2Swift() throws(JSException) -> TS2Swift { #if arch(wasm32) @_extern(wasm, module: "PlayBridgeJS", name: "bjs_TS2Swift_convert") -fileprivate func bjs_TS2Swift_convert_extern(_ self: Int32, _ tsBytes: Int32, _ tsLength: Int32) -> Int32 +fileprivate func bjs_TS2Swift_convert_extern(_ self: Int32, _ tsWord0: Int32, _ tsWord1: Int32, _ tsWord2: Int32) -> Int32 #else -fileprivate func bjs_TS2Swift_convert_extern(_ self: Int32, _ tsBytes: Int32, _ tsLength: Int32) -> Int32 { +fileprivate func bjs_TS2Swift_convert_extern(_ self: Int32, _ tsWord0: Int32, _ tsWord1: Int32, _ tsWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_TS2Swift_convert(_ self: Int32, _ tsBytes: Int32, _ tsLength: Int32) -> Int32 { - return bjs_TS2Swift_convert_extern(self, tsBytes, tsLength) +@inline(never) fileprivate func bjs_TS2Swift_convert(_ self: Int32, _ tsWord0: Int32, _ tsWord1: Int32, _ tsWord2: Int32) -> Int32 { + return bjs_TS2Swift_convert_extern(self, tsWord0, tsWord1, tsWord2) } func _$TS2Swift_convert(_ self: JSObject, _ ts: String) throws(JSException) -> String { - let ret0 = ts.bridgeJSWithLoweredParameter { (tsBytes, tsLength) in + let ret0 = ts.bridgeJSWithLoweredParameter { (tsWord0, tsWord1, tsWord2) in let selfValue = self.bridgeJSLowerParameter() - let ret = bjs_TS2Swift_convert(selfValue, tsBytes, tsLength) + let ret = bjs_TS2Swift_convert(selfValue, tsWord0, tsWord1, tsWord2) return ret } let ret = ret0 diff --git a/Plugins/BridgeJS/README.md b/Plugins/BridgeJS/README.md index 0905695c5..4d93dc875 100644 --- a/Plugins/BridgeJS/README.md +++ b/Plugins/BridgeJS/README.md @@ -139,7 +139,8 @@ The ABI will not be stable, and not meant to be interposed by other tools. Parameter passing follows Wasm calling conventions, with custom handling for complex types: - **Primitives**: Passed directly as Wasm arguments (`i32`, `i64`, `f32`, `f64`) -- **Strings**: UTF-8 bytes stored in `swift.memory`, ID + length passed as Wasm arguments +- **Strings (JS → Swift)**: UTF-8 bytes stored in `swift.memory`, ID + length passed as Wasm arguments +- **Strings (Swift → JS)**: the wasm32 12-byte `String` layout passed as three `i32` words. JS fast-decodes small strings, caches large immortals by a 53-bit `ptr + len` pack when `len < 2**21`, and otherwise reads UTF-8 at `word1 + 20` (`nativeBias`). This layout is a Swift stdlib implementation detail and can change with the toolchain. - **Swift Classes**: Raw Swift heap pointer passed as `i32` - **JSObjects**: Object stored in `swift.memory.heap`, object ID passed as `i32` - **Structs/Arrays**: Fields/elements pushed to type-specific stacks, Swift pops in reverse order @@ -150,7 +151,7 @@ Parameter passing follows Wasm calling conventions, with custom handling for com Return values use direct Wasm returns for primitives, and imported intrinsic functions for complex types: - **Primitives**: Returned directly via Wasm return value -- **Strings**: Swift writes UTF-8 bytes to shared memory, JS decodes +- **Strings**: Swift passes the 12-byte `String` layout; JS decodes (small / immortal-cached / UTF-8) - **Swift Classes**: Pointer returned directly, JS wraps in `SwiftHeapObject` with `FinalizationRegistry` - **Structs/Arrays**: Swift pushes fields/elements to type-specific stacks, JS reconstructs diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index 6b5d3ef76..df8c589ea 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -744,9 +744,7 @@ public class ExportSwift { /// public func _bjs_Greeter_greet(pointer: UnsafeMutableRawPointer) -> Void { /// let _self = Unmanaged.fromOpaque(pointer).takeUnretainedValue() /// var ret = _self.greet() - /// return ret.withUTF8 { ptr in - /// _swift_js_return_string(ptr.baseAddress, Int32(ptr.count)) - /// } + /// return ret.bridgeJSLowerReturn() /// } /// @_expose(wasm, "bjs_Greeter_deinit") /// @_cdecl("bjs_Greeter_deinit") diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift index 378fe2012..841c0409c 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift @@ -927,7 +927,7 @@ extension BridgeType { static let float = LoweringParameterInfo(loweredParameters: [("value", .f32)]) static let double = LoweringParameterInfo(loweredParameters: [("value", .f64)]) static let string = LoweringParameterInfo( - loweredParameters: [("bytes", .i32), ("length", .i32)], + loweredParameters: [("word0", .i32), ("word1", .i32), ("word2", .i32)], useBorrowing: true ) static let jsObject = LoweringParameterInfo(loweredParameters: [("value", .i32)]) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 40b1c13c3..7f4ecab03 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -313,12 +313,180 @@ public struct BridgeJSLink { return data } + /// Emits `decodeString`, including small-string helpers used only by it. + /// + /// The wasm32 12-byte Swift `String` layout is a standard-library + /// implementation detail, not a stable ABI. Small strings (`word2 & 0x2000`) + /// store up to 8 UTF-8 bytes inline. Large strings store the UTF-8 count in + /// `word0` and a variant/object pointer in `word1`; UTF-8 starts at + /// `word1 + nativeBias` (20 on 32-bit). Immortal large strings + /// (`word2 & 0x8000`) are cached by a 53-bit `ptr + len * 2**32` key when + /// `len < 2**21`; longer immortals skip the cache. + private func emitDecodeString(_ printer: CodeFragmentPrinter) { + printer.write( + multilineString: """ + \(JSGlueVariableScope.reservedDecodeString) = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return \(JSGlueVariableScope.reservedDecodeUTF8)(ptr, len); + const key = ptr + len * 0x100000000; + const cached = \(JSGlueVariableScope.reservedImmortalStrings).get(key); + if (cached !== undefined) return cached; + const value = \(JSGlueVariableScope.reservedDecodeUTF8)(ptr, len); + \(JSGlueVariableScope.reservedImmortalStrings).set(key, value); + return value; + }; + })(); + """ + ) + } + private func generateVariableDeclarations() -> [String] { var declarations: [String] = [ "let \(JSGlueVariableScope.reservedInstance);", "let \(JSGlueVariableScope.reservedMemory);", "let \(JSGlueVariableScope.reservedSetException);", "let \(JSGlueVariableScope.reservedDecodeString);", + "let \(JSGlueVariableScope.reservedDecodeUTF8);", + "const \(JSGlueVariableScope.reservedImmortalStrings) = new Map();", "const \(JSGlueVariableScope.reservedTextDecoder) = new TextDecoder(\"utf-8\");", "const \(JSGlueVariableScope.reservedTextEncoder) = new TextEncoder(\"utf-8\");", "let \(JSGlueVariableScope.reservedStorageToReturnString);", @@ -495,10 +663,10 @@ public struct BridgeJSLink { "const imports = options.getImports(importsContext);" ]) } - printer.write("bjs[\"swift_js_return_string\"] = function(ptr, len) {") + printer.write("bjs[\"swift_js_return_string\"] = function(word0, word1, word2) {") printer.indent { printer.write( - "\(JSGlueVariableScope.reservedStorageToReturnString) = \(JSGlueVariableScope.reservedDecodeString)(ptr, len);" + "\(JSGlueVariableScope.reservedStorageToReturnString) = \(JSGlueVariableScope.reservedDecodeString)(word0, word1, word2);" ) } printer.write("}") @@ -516,10 +684,10 @@ public struct BridgeJSLink { printer.write("bytes.set(source);") } printer.write("}") - printer.write("bjs[\"swift_js_make_js_string\"] = function(ptr, len) {") + printer.write("bjs[\"swift_js_make_js_string\"] = function(word0, word1, word2) {") printer.indent { printer.write( - "return \(JSGlueVariableScope.reservedSwift).\(JSGlueVariableScope.reservedMemory).retain(\(JSGlueVariableScope.reservedDecodeString)(ptr, len));" + "return \(JSGlueVariableScope.reservedSwift).\(JSGlueVariableScope.reservedMemory).retain(\(JSGlueVariableScope.reservedDecodeString)(word0, word1, word2));" ) } printer.write("}") @@ -566,9 +734,11 @@ public struct BridgeJSLink { printer.write("\(JSGlueVariableScope.reservedF64Stack).push(v);") } printer.write("}") - printer.write("bjs[\"swift_js_push_string\"] = function(ptr, len) {") + printer.write("bjs[\"swift_js_push_string\"] = function(word0, word1, word2) {") printer.indent { - printer.write("const value = \(JSGlueVariableScope.reservedDecodeString)(ptr, len);") + printer.write( + "const value = \(JSGlueVariableScope.reservedDecodeString)(word0, word1, word2);" + ) printer.write("\(JSGlueVariableScope.reservedStringStack).push(value);") } printer.write("}") @@ -732,7 +902,7 @@ public struct BridgeJSLink { printer.write("}") } printer.write("}") - printer.write("bjs[\"swift_js_return_optional_string\"] = function(isSome, ptr, len) {") + printer.write("bjs[\"swift_js_return_optional_string\"] = function(isSome, word0, word1, word2) {") printer.indent { printer.write("if (isSome === 0) {") printer.indent { @@ -741,7 +911,7 @@ public struct BridgeJSLink { printer.write("} else {") printer.indent { printer.write(lines: [ - "\(JSGlueVariableScope.reservedStorageToReturnString) = \(JSGlueVariableScope.reservedDecodeString)(ptr, len);" + "\(JSGlueVariableScope.reservedStorageToReturnString) = \(JSGlueVariableScope.reservedDecodeString)(word0, word1, word2);" ]) } printer.write("}") @@ -879,7 +1049,7 @@ public struct BridgeJSLink { helperPrinter.write("let length = 0;") helperPrinter.write("while (bytes[length] !== 0) { length += 1; }") helperPrinter.write( - "const fileID = \(JSGlueVariableScope.reservedDecodeString)(state.file, length);" + "const fileID = \(JSGlueVariableScope.reservedDecodeUTF8)(state.file, length);" ) helperPrinter.write( "throw new Error(`Attempted to call a released JSTypedClosure created at ${fileID}:${state.line}`);" @@ -1289,19 +1459,21 @@ public struct BridgeJSLink { printer.write("setInstance: (i) => {") printer.indent { printer.write(lines: [ + "if (\(JSGlueVariableScope.reservedMemory) !== i.exports.memory) \(JSGlueVariableScope.reservedImmortalStrings).clear();", "\(JSGlueVariableScope.reservedInstance) = i;", "\(JSGlueVariableScope.reservedMemory) = \(JSGlueVariableScope.reservedInstance).exports.memory;", ]) printer.nextLine() if sharedMemory { printer.write( - "\(JSGlueVariableScope.reservedDecodeString) = (ptr, len) => { const bytes = new Uint8Array(\(JSGlueVariableScope.reservedMemory).buffer, ptr >>> 0, len >>> 0).slice(); return \(JSGlueVariableScope.reservedTextDecoder).decode(bytes); }" + "\(JSGlueVariableScope.reservedDecodeUTF8) = (ptr, len) => { const bytes = new Uint8Array(\(JSGlueVariableScope.reservedMemory).buffer, ptr >>> 0, len >>> 0).slice(); return \(JSGlueVariableScope.reservedTextDecoder).decode(bytes); }" ) } else { printer.write( - "\(JSGlueVariableScope.reservedDecodeString) = (ptr, len) => { const bytes = new Uint8Array(\(JSGlueVariableScope.reservedMemory).buffer, ptr >>> 0, len >>> 0); return \(JSGlueVariableScope.reservedTextDecoder).decode(bytes); }" + "\(JSGlueVariableScope.reservedDecodeUTF8) = (ptr, len) => { const bytes = new Uint8Array(\(JSGlueVariableScope.reservedMemory).buffer, ptr >>> 0, len >>> 0); return \(JSGlueVariableScope.reservedTextDecoder).decode(bytes); }" ) } + emitDecodeString(printer) printer.nextLine() // Error handling printer.write("\(JSGlueVariableScope.reservedSetException) = (error) => {") diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index 747c9f532..2da07f2be 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -14,6 +14,8 @@ final class JSGlueVariableScope { static let reservedMemory = "memory" static let reservedSetException = "setException" static let reservedDecodeString = "decodeString" + static let reservedDecodeUTF8 = "decodeUTF8" + static let reservedImmortalStrings = "immortalStrings" static let reservedStorageToReturnString = "tmpRetString" static let reservedStorageToReturnBytes = "tmpRetBytes" static let reservedStorageToReturnException = "tmpRetException" @@ -49,6 +51,8 @@ final class JSGlueVariableScope { reservedMemory, reservedSetException, reservedDecodeString, + reservedDecodeUTF8, + reservedImmortalStrings, reservedStorageToReturnString, reservedStorageToReturnBytes, reservedStorageToReturnException, @@ -678,14 +682,15 @@ struct IntrinsicJSFragment: Sendable { } ) static let stringLiftParameter = IntrinsicJSFragment( - parameters: ["bytes", "count"], + parameters: ["word0", "word1", "word2"], printCode: { arguments, context in let (scope, printer) = (context.scope, context.printer) - let bytesExpr = arguments[0] - let countExpr = arguments[1] + let word0Expr = arguments[0] + let word1Expr = arguments[1] + let word2Expr = arguments[2] let stringLabel = scope.variable("string") printer.write( - "const \(stringLabel) = \(JSGlueVariableScope.reservedDecodeString)(\(bytesExpr), \(countExpr));" + "const \(stringLabel) = \(JSGlueVariableScope.reservedDecodeString)(\(word0Expr), \(word1Expr), \(word2Expr));" ) return [stringLabel] } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringDecoderTests.mjs b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringDecoderTests.mjs new file mode 100644 index 000000000..2aa88cf5d --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringDecoderTests.mjs @@ -0,0 +1,98 @@ +import assert from 'node:assert/strict'; +import { readFile } from 'node:fs/promises'; + +// Execute generated glue rather than a duplicate of the decoder implementation. +const source = await readFile(process.argv[2] ?? new URL('../__Snapshots__/BridgeJSLinkTests/StringReturn.js', import.meta.url), 'utf8'); +const shared = process.argv[3] === 'shared'; +const { createInstantiator } = await import(`data:text/javascript;base64,${Buffer.from(source).toString('base64')}`); +const encoder = new TextEncoder(); +const decoder = new TextDecoder(); +const swift = { memory: { heap: [], retain: (value) => value } }; +const bridge = await createInstantiator({ getImports: () => ({}) }, swift); +const imports = {}; +bridge.addImports(imports, {}); +let words; +function instance(memory) { + return { exports: { memory, bjs_checkString: () => imports.bjs.swift_js_return_string(...words) } }; +} +let memory = new WebAssembly.Memory({ initial: 40, maximum: 41, shared }); +let wasm = instance(memory); +bridge.setInstance(wasm); +let exports = bridge.createExports(wasm); +function small(value) { + const bytes = encoder.encode(value); + assert.ok(bytes.length <= 8); + const storage = new Uint8Array(12); + storage.set(bytes.subarray(0, 8)); + storage[9] = (bytes.every((b) => b < 128) ? 0xe0 : 0xa0) | bytes.length; + const view = new DataView(storage.buffer); + return [0, 4, 8].map((offset) => view.getInt32(offset, true)); +} +function large(value, immortal = false, ptr = 64) { + const bytes = encoder.encode(value); + new Uint8Array(memory.buffer, ptr, bytes.length).set(bytes); + return [bytes.length, ptr - 20, immortal ? 0x8000 : 0]; +} +const values = ['', 'div', 'abcdefgh', 'abcdefghi', 'abcdefghij', 'abcdefé', 'abcdefgé', + 'abcdefghé', 'abcdefghié', 'abc€', 'abcdefg€', 'abc😄', 'abcdef😄', 'abcdefg😄', + 'a\0b', '\ufeff', '\ufeffx', 'x\ufeff', '\ufeff\ufeffx', '\ufeffabcdefghijk', + 'abc\ufeffdefghijk', '\ufeff\ufeffabcdefghijk']; +for (const value of values) { + const expected = decoder.decode(encoder.encode(value)); + if (encoder.encode(value).length <= 8) { + words = small(value); + assert.equal(exports.checkString(), expected); + } + words = large(value); + assert.equal(exports.checkString(), expected); +} +// Alternate full and short inputs: bytes outside count must never leak into the result. +for (const value of ['abcd😄', 'é', 'abcde€', '\ufeff', 'abcdefgh', '', 'x\0', '€', '\ufeff\ufeff']) { + words = small(value); + assert.equal(exports.checkString(), decoder.decode(encoder.encode(value))); +} +// Every ASCII byte, including NUL, at every small-string length. +for (let byte = 0; byte < 128; byte++) { + for (let count = 0; count <= 8; count++) { + const value = String.fromCharCode(byte).repeat(count); + words = small(value); + assert.equal(exports.checkString(), value); + } +} +// Unexpected inline lengths must fail for both ASCII and Unicode discriminators. +for (const count of [9, 10]) { + for (const discriminator of [0xe0, 0xa0]) { + words = [0, 0, (discriminator | count) << 8]; + assert.throws(() => exports.checkString(), { + name: 'Error', + message: `Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`, + }); + } +} +words = large('first literal', true); +assert.equal(exports.checkString(), 'first literal'); +// A new instance using the same memory must preserve valid cache entries. +wasm = instance(memory); +bridge.setInstance(wasm); +exports = bridge.createExports(wasm); +assert.equal(exports.checkString(), 'first literal'); +// A different memory may reuse the same pointer/length for different contents. +memory = new WebAssembly.Memory({ initial: 40, maximum: 41, shared }); +wasm = instance(memory); +bridge.setInstance(wasm); +exports = bridge.createExports(wasm); +words = large('other literal', true); +assert.equal(exports.checkString(), 'other literal'); +// Same pointer with a different length must have a distinct key. +words = large('other', true); +assert.equal(exports.checkString(), 'other'); +// Values at the numeric-key cutoff bypass the cache. +const huge = 'x'.repeat(2 ** 21); +words = large(huge, true); +assert.equal(exports.checkString(), huge); +new Uint8Array(memory.buffer)[64] = 121; +assert.equal(exports.checkString(), 'y' + huge.slice(1)); +memory.grow(1); +words = large('after memory growth'); +assert.equal(exports.checkString(), 'after memory growth'); +console.log('String decoder regressions passed'); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/StringDecoderTests.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/StringDecoderTests.swift new file mode 100644 index 000000000..96449b4de --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/StringDecoderTests.swift @@ -0,0 +1,44 @@ +import Foundation +import SwiftParser +import Testing +@testable import BridgeJSCore +@testable import BridgeJSLink +@testable import TS2Swift + +@Suite struct StringDecoderTests { + @Test(arguments: [false, true]) + func generatedStringDecoder(sharedMemory: Bool) throws { + let directory = URL(fileURLWithPath: #filePath).deletingLastPathComponent() + let fixture = directory.appendingPathComponent("Inputs/MacroSwift/StringReturn.swift") + let collector = SwiftToSkeleton( + progress: .silent, + moduleName: "TestModule", + exposeToGlobal: false, + externalModuleIndex: .empty + ) + collector.addSourceFile( + Parser.parse(source: try String(contentsOf: fixture, encoding: .utf8)), + inputFilePath: fixture.path + ) + var linker = BridgeJSLink() + try linker.addSkeletonFile(data: JSONEncoder().encode(collector.finalize())) + let output = try linker.link(sharedMemory: sharedMemory) + guard let node = which("node") else { + Issue.record("Node.js is required for string decoder regression tests") + return + } + try withTemporaryDirectory { temporaryDirectory, _ in + let glue = temporaryDirectory.appendingPathComponent("bridge.js") + try output.outputJs.write(to: glue, atomically: true, encoding: .utf8) + let process = Process() + process.executableURL = node + process.arguments = [ + directory.appendingPathComponent("Inputs/StringDecoderTests.mjs").path, + glue.path, sharedMemory ? "shared" : "unshared", + ] + try process.run() + process.waitUntilExit() + #expect(process.terminationStatus == 0) + } + } +} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Alias.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Alias.swift index 2529f22d3..7f8b3750d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Alias.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Alias.swift @@ -297,19 +297,19 @@ extension UserId: _BridgedSwiftAlias, _BridgedSwiftStackType {} #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_acceptTagged") -fileprivate func bjs_acceptTagged_extern(_ taggedBytes: Int32, _ taggedLength: Int32) -> Void +fileprivate func bjs_acceptTagged_extern(_ taggedWord0: Int32, _ taggedWord1: Int32, _ taggedWord2: Int32) -> Void #else -fileprivate func bjs_acceptTagged_extern(_ taggedBytes: Int32, _ taggedLength: Int32) -> Void { +fileprivate func bjs_acceptTagged_extern(_ taggedWord0: Int32, _ taggedWord1: Int32, _ taggedWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_acceptTagged(_ taggedBytes: Int32, _ taggedLength: Int32) -> Void { - return bjs_acceptTagged_extern(taggedBytes, taggedLength) +@inline(never) fileprivate func bjs_acceptTagged(_ taggedWord0: Int32, _ taggedWord1: Int32, _ taggedWord2: Int32) -> Void { + return bjs_acceptTagged_extern(taggedWord0, taggedWord1, taggedWord2) } func _$acceptTagged(_ tagged: Tagged) throws(JSException) -> Void { - tagged.bridgeJSWithLoweredParameter { (taggedBytes, taggedLength) in - bjs_acceptTagged(taggedBytes, taggedLength) + tagged.bridgeJSWithLoweredParameter { (taggedWord0, taggedWord1, taggedWord2) in + bjs_acceptTagged(taggedWord0, taggedWord1, taggedWord2) } if let error = _swift_js_take_exception() { throw error @@ -318,19 +318,19 @@ func _$acceptTagged(_ tagged: Tagged) throws(JSException) -> Void { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_acceptOptionalTagged") -fileprivate func bjs_acceptOptionalTagged_extern(_ taggedIsSome: Int32, _ taggedBytes: Int32, _ taggedLength: Int32) -> Void +fileprivate func bjs_acceptOptionalTagged_extern(_ taggedIsSome: Int32, _ taggedWord0: Int32, _ taggedWord1: Int32, _ taggedWord2: Int32) -> Void #else -fileprivate func bjs_acceptOptionalTagged_extern(_ taggedIsSome: Int32, _ taggedBytes: Int32, _ taggedLength: Int32) -> Void { +fileprivate func bjs_acceptOptionalTagged_extern(_ taggedIsSome: Int32, _ taggedWord0: Int32, _ taggedWord1: Int32, _ taggedWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_acceptOptionalTagged(_ taggedIsSome: Int32, _ taggedBytes: Int32, _ taggedLength: Int32) -> Void { - return bjs_acceptOptionalTagged_extern(taggedIsSome, taggedBytes, taggedLength) +@inline(never) fileprivate func bjs_acceptOptionalTagged(_ taggedIsSome: Int32, _ taggedWord0: Int32, _ taggedWord1: Int32, _ taggedWord2: Int32) -> Void { + return bjs_acceptOptionalTagged_extern(taggedIsSome, taggedWord0, taggedWord1, taggedWord2) } func _$acceptOptionalTagged(_ tagged: Optional) throws(JSException) -> Void { - tagged.bridgeJSWithLoweredParameter { (taggedIsSome, taggedBytes, taggedLength) in - bjs_acceptOptionalTagged(taggedIsSome, taggedBytes, taggedLength) + tagged.bridgeJSWithLoweredParameter { (taggedIsSome, taggedWord0, taggedWord1, taggedWord2) in + bjs_acceptOptionalTagged(taggedIsSome, taggedWord0, taggedWord1, taggedWord2) } if let error = _swift_js_take_exception() { throw error @@ -339,19 +339,19 @@ func _$acceptOptionalTagged(_ tagged: Optional) throws(JSException) -> V #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_roundtripTagged") -fileprivate func bjs_roundtripTagged_extern(_ taggedBytes: Int32, _ taggedLength: Int32) -> Int32 +fileprivate func bjs_roundtripTagged_extern(_ taggedWord0: Int32, _ taggedWord1: Int32, _ taggedWord2: Int32) -> Int32 #else -fileprivate func bjs_roundtripTagged_extern(_ taggedBytes: Int32, _ taggedLength: Int32) -> Int32 { +fileprivate func bjs_roundtripTagged_extern(_ taggedWord0: Int32, _ taggedWord1: Int32, _ taggedWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_roundtripTagged(_ taggedBytes: Int32, _ taggedLength: Int32) -> Int32 { - return bjs_roundtripTagged_extern(taggedBytes, taggedLength) +@inline(never) fileprivate func bjs_roundtripTagged(_ taggedWord0: Int32, _ taggedWord1: Int32, _ taggedWord2: Int32) -> Int32 { + return bjs_roundtripTagged_extern(taggedWord0, taggedWord1, taggedWord2) } func _$roundtripTagged(_ tagged: Tagged) throws(JSException) -> Tagged { - let ret0 = tagged.bridgeJSWithLoweredParameter { (taggedBytes, taggedLength) in - let ret = bjs_roundtripTagged(taggedBytes, taggedLength) + let ret0 = tagged.bridgeJSWithLoweredParameter { (taggedWord0, taggedWord1, taggedWord2) in + let ret = bjs_roundtripTagged(taggedWord0, taggedWord1, taggedWord2) return ret } let ret = ret0 diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Async.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Async.swift index ae03fc475..2d0143ea9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Async.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Async.swift @@ -423,20 +423,20 @@ func _$Promise_resolve_Si(_ promise: JSObject, _ value: Int) throws(JSException) #if arch(wasm32) @_extern(wasm, module: "bjs", name: "promise_resolve_TestModule_SS") -fileprivate func promise_resolve_TestModule_SS_extern(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void +fileprivate func promise_resolve_TestModule_SS_extern(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void #else -fileprivate func promise_resolve_TestModule_SS_extern(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { +fileprivate func promise_resolve_TestModule_SS_extern(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func promise_resolve_TestModule_SS(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - return promise_resolve_TestModule_SS_extern(promise, valueBytes, valueLength) +@inline(never) fileprivate func promise_resolve_TestModule_SS(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { + return promise_resolve_TestModule_SS_extern(promise, valueWord0, valueWord1, valueWord2) } func _$Promise_resolve_SS(_ promise: JSObject, _ value: String) throws(JSException) -> Void { - value.bridgeJSWithLoweredParameter { (valueBytes, valueLength) in + value.bridgeJSWithLoweredParameter { (valueWord0, valueWord1, valueWord2) in let promiseValue = promise.bridgeJSLowerParameter() - promise_resolve_TestModule_SS(promiseValue, valueBytes, valueLength) + promise_resolve_TestModule_SS(promiseValue, valueWord0, valueWord1, valueWord2) } if let error = _swift_js_take_exception() { throw error } } @@ -571,20 +571,20 @@ func _$Promise_resolve_14AsyncDirectionO(_ promise: JSObject, _ value: AsyncDire #if arch(wasm32) @_extern(wasm, module: "bjs", name: "promise_resolve_TestModule_10AsyncThemeO") -fileprivate func promise_resolve_TestModule_10AsyncThemeO_extern(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void +fileprivate func promise_resolve_TestModule_10AsyncThemeO_extern(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void #else -fileprivate func promise_resolve_TestModule_10AsyncThemeO_extern(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { +fileprivate func promise_resolve_TestModule_10AsyncThemeO_extern(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func promise_resolve_TestModule_10AsyncThemeO(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - return promise_resolve_TestModule_10AsyncThemeO_extern(promise, valueBytes, valueLength) +@inline(never) fileprivate func promise_resolve_TestModule_10AsyncThemeO(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { + return promise_resolve_TestModule_10AsyncThemeO_extern(promise, valueWord0, valueWord1, valueWord2) } func _$Promise_resolve_10AsyncThemeO(_ promise: JSObject, _ value: AsyncTheme) throws(JSException) -> Void { - value.bridgeJSWithLoweredParameter { (valueBytes, valueLength) in + value.bridgeJSWithLoweredParameter { (valueWord0, valueWord1, valueWord2) in let promiseValue = promise.bridgeJSLowerParameter() - promise_resolve_TestModule_10AsyncThemeO(promiseValue, valueBytes, valueLength) + promise_resolve_TestModule_10AsyncThemeO(promiseValue, valueWord0, valueWord1, valueWord2) } if let error = _swift_js_take_exception() { throw error } } @@ -614,20 +614,20 @@ func _$Promise_resolve_Sq14AsyncDirectionO(_ promise: JSObject, _ value: Optiona #if arch(wasm32) @_extern(wasm, module: "bjs", name: "promise_resolve_TestModule_Sq10AsyncThemeO") -fileprivate func promise_resolve_TestModule_Sq10AsyncThemeO_extern(_ promise: Int32, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void +fileprivate func promise_resolve_TestModule_Sq10AsyncThemeO_extern(_ promise: Int32, _ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void #else -fileprivate func promise_resolve_TestModule_Sq10AsyncThemeO_extern(_ promise: Int32, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { +fileprivate func promise_resolve_TestModule_Sq10AsyncThemeO_extern(_ promise: Int32, _ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func promise_resolve_TestModule_Sq10AsyncThemeO(_ promise: Int32, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - return promise_resolve_TestModule_Sq10AsyncThemeO_extern(promise, valueIsSome, valueBytes, valueLength) +@inline(never) fileprivate func promise_resolve_TestModule_Sq10AsyncThemeO(_ promise: Int32, _ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { + return promise_resolve_TestModule_Sq10AsyncThemeO_extern(promise, valueIsSome, valueWord0, valueWord1, valueWord2) } func _$Promise_resolve_Sq10AsyncThemeO(_ promise: JSObject, _ value: Optional) throws(JSException) -> Void { - value.bridgeJSWithLoweredParameter { (valueIsSome, valueBytes, valueLength) in + value.bridgeJSWithLoweredParameter { (valueIsSome, valueWord0, valueWord1, valueWord2) in let promiseValue = promise.bridgeJSLowerParameter() - promise_resolve_TestModule_Sq10AsyncThemeO(promiseValue, valueIsSome, valueBytes, valueLength) + promise_resolve_TestModule_Sq10AsyncThemeO(promiseValue, valueIsSome, valueWord0, valueWord1, valueWord2) } if let error = _swift_js_take_exception() { throw error } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/AsyncImport.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/AsyncImport.swift index 509f79578..42cb4f52b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/AsyncImport.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/AsyncImport.swift @@ -124,14 +124,14 @@ public func _invoke_swift_closure_TestModule_10TestModules8JSObjectC_y(_ boxPtr: #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModulesSS_y") -fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void +fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void #else -fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { +fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { - return invoke_js_callback_TestModule_10TestModulesSS_y_extern(callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + return invoke_js_callback_TestModule_10TestModulesSS_y_extern(callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -151,9 +151,9 @@ private enum _BJS_Closure_10TestModulesSS_y { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] param0 in #if arch(wasm32) - param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - invoke_js_callback_TestModule_10TestModulesSS_y(callbackValue, param0Bytes, param0Length) + invoke_js_callback_TestModule_10TestModulesSS_y(callbackValue, param0Word0, param0Word1, param0Word2) } #else fatalError("Only available on WebAssembly") @@ -479,14 +479,14 @@ func _$asyncRoundTripInt(_ v: Int) async throws(JSException) -> Int { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_asyncRoundTripString") -fileprivate func bjs_asyncRoundTripString_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ vBytes: Int32, _ vLength: Int32) -> Void +fileprivate func bjs_asyncRoundTripString_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ vWord0: Int32, _ vWord1: Int32, _ vWord2: Int32) -> Void #else -fileprivate func bjs_asyncRoundTripString_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ vBytes: Int32, _ vLength: Int32) -> Void { +fileprivate func bjs_asyncRoundTripString_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ vWord0: Int32, _ vWord1: Int32, _ vWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_asyncRoundTripString(_ resolveRef: Int32, _ rejectRef: Int32, _ vBytes: Int32, _ vLength: Int32) -> Void { - return bjs_asyncRoundTripString_extern(resolveRef, rejectRef, vBytes, vLength) +@inline(never) fileprivate func bjs_asyncRoundTripString(_ resolveRef: Int32, _ rejectRef: Int32, _ vWord0: Int32, _ vWord1: Int32, _ vWord2: Int32) -> Void { + return bjs_asyncRoundTripString_extern(resolveRef, rejectRef, vWord0, vWord1, vWord2) } func _$asyncRoundTripString(_ v: String) async throws(JSException) -> String { @@ -495,8 +495,8 @@ func _$asyncRoundTripString(_ v: String) async throws(JSException) -> String { }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in - v.bridgeJSWithLoweredParameter { (vBytes, vLength) in - bjs_asyncRoundTripString(resolveRef, rejectRef, vBytes, vLength) + v.bridgeJSWithLoweredParameter { (vWord0, vWord1, vWord2) in + bjs_asyncRoundTripString(resolveRef, rejectRef, vWord0, vWord1, vWord2) } } return resolved diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.swift index 2cee26721..da2e3916f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.swift @@ -528,19 +528,19 @@ extension Ratio: BridgedSwiftGenericBridgeable { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_takesFeatureFlag") -fileprivate func bjs_takesFeatureFlag_extern(_ flagBytes: Int32, _ flagLength: Int32) -> Void +fileprivate func bjs_takesFeatureFlag_extern(_ flagWord0: Int32, _ flagWord1: Int32, _ flagWord2: Int32) -> Void #else -fileprivate func bjs_takesFeatureFlag_extern(_ flagBytes: Int32, _ flagLength: Int32) -> Void { +fileprivate func bjs_takesFeatureFlag_extern(_ flagWord0: Int32, _ flagWord1: Int32, _ flagWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_takesFeatureFlag(_ flagBytes: Int32, _ flagLength: Int32) -> Void { - return bjs_takesFeatureFlag_extern(flagBytes, flagLength) +@inline(never) fileprivate func bjs_takesFeatureFlag(_ flagWord0: Int32, _ flagWord1: Int32, _ flagWord2: Int32) -> Void { + return bjs_takesFeatureFlag_extern(flagWord0, flagWord1, flagWord2) } func _$takesFeatureFlag(_ flag: FeatureFlag) throws(JSException) -> Void { - flag.bridgeJSWithLoweredParameter { (flagBytes, flagLength) in - bjs_takesFeatureFlag(flagBytes, flagLength) + flag.bridgeJSWithLoweredParameter { (flagWord0, flagWord1, flagWord2) in + bjs_takesFeatureFlag(flagWord0, flagWord1, flagWord2) } if let error = _swift_js_take_exception() { throw error diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GenericImports.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GenericImports.swift index ecb1512cf..8a9a11197 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GenericImports.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GenericImports.swift @@ -321,19 +321,19 @@ func _$genericRoundTrip(_ value: T) throws(JSE #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_genericParse") -fileprivate func bjs_genericParse_extern(_ jsonBytes: Int32, _ jsonLength: Int32, _ _generic0TypeId: Int32) -> Void +fileprivate func bjs_genericParse_extern(_ jsonWord0: Int32, _ jsonWord1: Int32, _ jsonWord2: Int32, _ _generic0TypeId: Int32) -> Void #else -fileprivate func bjs_genericParse_extern(_ jsonBytes: Int32, _ jsonLength: Int32, _ _generic0TypeId: Int32) -> Void { +fileprivate func bjs_genericParse_extern(_ jsonWord0: Int32, _ jsonWord1: Int32, _ jsonWord2: Int32, _ _generic0TypeId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_genericParse(_ jsonBytes: Int32, _ jsonLength: Int32, _ _generic0TypeId: Int32) -> Void { - return bjs_genericParse_extern(jsonBytes, jsonLength, _generic0TypeId) +@inline(never) fileprivate func bjs_genericParse(_ jsonWord0: Int32, _ jsonWord1: Int32, _ jsonWord2: Int32, _ _generic0TypeId: Int32) -> Void { + return bjs_genericParse_extern(jsonWord0, jsonWord1, jsonWord2, _generic0TypeId) } func _$genericParse(_ json: String) throws(JSException) -> T { - json.bridgeJSWithLoweredParameter { (jsonBytes, jsonLength) in - bjs_genericParse(jsonBytes, jsonLength, T.bridgeJSTypeID) + json.bridgeJSWithLoweredParameter { (jsonWord0, jsonWord1, jsonWord2) in + bjs_genericParse(jsonWord0, jsonWord1, jsonWord2, T.bridgeJSTypeID) } if let error = _swift_js_take_exception() { throw error @@ -514,21 +514,21 @@ func _$constrainedComposition Int32 +fileprivate func bjs_GenericPairFactory_init_extern(_ tagWord0: Int32, _ tagWord1: Int32, _ tagWord2: Int32, _ _generic0TypeId: Int32, _ _generic1TypeId: Int32) -> Int32 #else -fileprivate func bjs_GenericPairFactory_init_extern(_ tagBytes: Int32, _ tagLength: Int32, _ _generic0TypeId: Int32, _ _generic1TypeId: Int32) -> Int32 { +fileprivate func bjs_GenericPairFactory_init_extern(_ tagWord0: Int32, _ tagWord1: Int32, _ tagWord2: Int32, _ _generic0TypeId: Int32, _ _generic1TypeId: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_GenericPairFactory_init(_ tagBytes: Int32, _ tagLength: Int32, _ _generic0TypeId: Int32, _ _generic1TypeId: Int32) -> Int32 { - return bjs_GenericPairFactory_init_extern(tagBytes, tagLength, _generic0TypeId, _generic1TypeId) +@inline(never) fileprivate func bjs_GenericPairFactory_init(_ tagWord0: Int32, _ tagWord1: Int32, _ tagWord2: Int32, _ _generic0TypeId: Int32, _ _generic1TypeId: Int32) -> Int32 { + return bjs_GenericPairFactory_init_extern(tagWord0, tagWord1, tagWord2, _generic0TypeId, _generic1TypeId) } func _$GenericPairFactory_init(_ tag: String, _ first: T, _ second: U) throws(JSException) -> JSObject { - let ret0 = tag.bridgeJSWithLoweredParameter { (tagBytes, tagLength) in + let ret0 = tag.bridgeJSWithLoweredParameter { (tagWord0, tagWord1, tagWord2) in second.bridgeJSStackPush() first.bridgeJSStackPush() - let ret = bjs_GenericPairFactory_init(tagBytes, tagLength, T.bridgeJSTypeID, U.bridgeJSTypeID) + let ret = bjs_GenericPairFactory_init(tagWord0, tagWord1, tagWord2, T.bridgeJSTypeID, U.bridgeJSTypeID) return ret } let ret = ret0 diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.swift index 68afce080..14d4b1907 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.swift @@ -20,20 +20,20 @@ func _$console_get() throws(JSException) -> JSConsole { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_JSConsole_log") -fileprivate func bjs_JSConsole_log_extern(_ self: Int32, _ messageBytes: Int32, _ messageLength: Int32) -> Void +fileprivate func bjs_JSConsole_log_extern(_ self: Int32, _ messageWord0: Int32, _ messageWord1: Int32, _ messageWord2: Int32) -> Void #else -fileprivate func bjs_JSConsole_log_extern(_ self: Int32, _ messageBytes: Int32, _ messageLength: Int32) -> Void { +fileprivate func bjs_JSConsole_log_extern(_ self: Int32, _ messageWord0: Int32, _ messageWord1: Int32, _ messageWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_JSConsole_log(_ self: Int32, _ messageBytes: Int32, _ messageLength: Int32) -> Void { - return bjs_JSConsole_log_extern(self, messageBytes, messageLength) +@inline(never) fileprivate func bjs_JSConsole_log(_ self: Int32, _ messageWord0: Int32, _ messageWord1: Int32, _ messageWord2: Int32) -> Void { + return bjs_JSConsole_log_extern(self, messageWord0, messageWord1, messageWord2) } func _$JSConsole_log(_ self: JSObject, _ message: String) throws(JSException) -> Void { - message.bridgeJSWithLoweredParameter { (messageBytes, messageLength) in + message.bridgeJSWithLoweredParameter { (messageWord0, messageWord1, messageWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_JSConsole_log(selfValue, messageBytes, messageLength) + bjs_JSConsole_log(selfValue, messageWord0, messageWord1, messageWord2) } if let error = _swift_js_take_exception() { throw error diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.swift index 4ba7a26fe..896c4e36d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.swift @@ -20,19 +20,19 @@ func _$console_get() throws(JSException) -> JSConsole { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_parseInt") -fileprivate func bjs_parseInt_extern(_ stringBytes: Int32, _ stringLength: Int32) -> Float64 +fileprivate func bjs_parseInt_extern(_ stringWord0: Int32, _ stringWord1: Int32, _ stringWord2: Int32) -> Float64 #else -fileprivate func bjs_parseInt_extern(_ stringBytes: Int32, _ stringLength: Int32) -> Float64 { +fileprivate func bjs_parseInt_extern(_ stringWord0: Int32, _ stringWord1: Int32, _ stringWord2: Int32) -> Float64 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_parseInt(_ stringBytes: Int32, _ stringLength: Int32) -> Float64 { - return bjs_parseInt_extern(stringBytes, stringLength) +@inline(never) fileprivate func bjs_parseInt(_ stringWord0: Int32, _ stringWord1: Int32, _ stringWord2: Int32) -> Float64 { + return bjs_parseInt_extern(stringWord0, stringWord1, stringWord2) } func _$parseInt(_ string: String) throws(JSException) -> Double { - let ret0 = string.bridgeJSWithLoweredParameter { (stringBytes, stringLength) in - let ret = bjs_parseInt(stringBytes, stringLength) + let ret0 = string.bridgeJSWithLoweredParameter { (stringWord0, stringWord1, stringWord2) in + let ret = bjs_parseInt(stringWord0, stringWord1, stringWord2) return ret } let ret = ret0 @@ -44,20 +44,20 @@ func _$parseInt(_ string: String) throws(JSException) -> Double { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_JSConsole_log") -fileprivate func bjs_JSConsole_log_extern(_ self: Int32, _ messageBytes: Int32, _ messageLength: Int32) -> Void +fileprivate func bjs_JSConsole_log_extern(_ self: Int32, _ messageWord0: Int32, _ messageWord1: Int32, _ messageWord2: Int32) -> Void #else -fileprivate func bjs_JSConsole_log_extern(_ self: Int32, _ messageBytes: Int32, _ messageLength: Int32) -> Void { +fileprivate func bjs_JSConsole_log_extern(_ self: Int32, _ messageWord0: Int32, _ messageWord1: Int32, _ messageWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_JSConsole_log(_ self: Int32, _ messageBytes: Int32, _ messageLength: Int32) -> Void { - return bjs_JSConsole_log_extern(self, messageBytes, messageLength) +@inline(never) fileprivate func bjs_JSConsole_log(_ self: Int32, _ messageWord0: Int32, _ messageWord1: Int32, _ messageWord2: Int32) -> Void { + return bjs_JSConsole_log_extern(self, messageWord0, messageWord1, messageWord2) } func _$JSConsole_log(_ self: JSObject, _ message: String) throws(JSException) -> Void { - message.bridgeJSWithLoweredParameter { (messageBytes, messageLength) in + message.bridgeJSWithLoweredParameter { (messageWord0, messageWord1, messageWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_JSConsole_log(selfValue, messageBytes, messageLength) + bjs_JSConsole_log(selfValue, messageWord0, messageWord1, messageWord2) } if let error = _swift_js_take_exception() { throw error @@ -66,14 +66,14 @@ func _$JSConsole_log(_ self: JSObject, _ message: String) throws(JSException) -> #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_WebSocket_init") -fileprivate func bjs_WebSocket_init_extern(_ urlBytes: Int32, _ urlLength: Int32) -> Int32 +fileprivate func bjs_WebSocket_init_extern(_ urlWord0: Int32, _ urlWord1: Int32, _ urlWord2: Int32) -> Int32 #else -fileprivate func bjs_WebSocket_init_extern(_ urlBytes: Int32, _ urlLength: Int32) -> Int32 { +fileprivate func bjs_WebSocket_init_extern(_ urlWord0: Int32, _ urlWord1: Int32, _ urlWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_WebSocket_init(_ urlBytes: Int32, _ urlLength: Int32) -> Int32 { - return bjs_WebSocket_init_extern(urlBytes, urlLength) +@inline(never) fileprivate func bjs_WebSocket_init(_ urlWord0: Int32, _ urlWord1: Int32, _ urlWord2: Int32) -> Int32 { + return bjs_WebSocket_init_extern(urlWord0, urlWord1, urlWord2) } #if arch(wasm32) @@ -89,8 +89,8 @@ fileprivate func bjs_WebSocket_close_extern(_ self: Int32) -> Void { } func _$WebSocket_init(_ url: String) throws(JSException) -> JSObject { - let ret0 = url.bridgeJSWithLoweredParameter { (urlBytes, urlLength) in - let ret = bjs_WebSocket_init(urlBytes, urlLength) + let ret0 = url.bridgeJSWithLoweredParameter { (urlWord0, urlWord1, urlWord2) in + let ret = bjs_WebSocket_init(urlWord0, urlWord1, urlWord2) return ret } let ret = ret0 diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportArray.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportArray.swift index 12abbd1e6..a501dd2f5 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportArray.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportArray.swift @@ -63,21 +63,21 @@ func _$optionalArrayThenArray(_ a: Optional<[Int]>, _ b: [Int]) throws(JSExcepti #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_borrowedStringAroundStackParams") -fileprivate func bjs_borrowedStringAroundStackParams_extern(_ sBytes: Int32, _ sLength: Int32) -> Int32 +fileprivate func bjs_borrowedStringAroundStackParams_extern(_ sWord0: Int32, _ sWord1: Int32, _ sWord2: Int32) -> Int32 #else -fileprivate func bjs_borrowedStringAroundStackParams_extern(_ sBytes: Int32, _ sLength: Int32) -> Int32 { +fileprivate func bjs_borrowedStringAroundStackParams_extern(_ sWord0: Int32, _ sWord1: Int32, _ sWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_borrowedStringAroundStackParams(_ sBytes: Int32, _ sLength: Int32) -> Int32 { - return bjs_borrowedStringAroundStackParams_extern(sBytes, sLength) +@inline(never) fileprivate func bjs_borrowedStringAroundStackParams(_ sWord0: Int32, _ sWord1: Int32, _ sWord2: Int32) -> Int32 { + return bjs_borrowedStringAroundStackParams_extern(sWord0, sWord1, sWord2) } func _$borrowedStringAroundStackParams(_ s: String, _ a: Optional<[Int]>, _ b: [Int]) throws(JSException) -> Int { - let ret0 = s.bridgeJSWithLoweredParameter { (sBytes, sLength) in + let ret0 = s.bridgeJSWithLoweredParameter { (sWord0, sWord1, sWord2) in let _ = b.bridgeJSLowerParameter() let _ = a.bridgeJSLowerParameter() - let ret = bjs_borrowedStringAroundStackParams(sBytes, sLength) + let ret = bjs_borrowedStringAroundStackParams(sWord0, sWord1, sWord2) return ret } let ret = ret0 diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.swift index f82632737..3adaeb88f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.swift @@ -136,14 +136,14 @@ fileprivate func bjs_WeirdNaming_Any_get_extern(_ self: Int32) -> Int32 { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_normalProperty_set") -fileprivate func bjs_WeirdNaming_normalProperty_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void +fileprivate func bjs_WeirdNaming_normalProperty_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void #else -fileprivate func bjs_WeirdNaming_normalProperty_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { +fileprivate func bjs_WeirdNaming_normalProperty_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_WeirdNaming_normalProperty_set(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { - return bjs_WeirdNaming_normalProperty_set_extern(self, newValueBytes, newValueLength) +@inline(never) fileprivate func bjs_WeirdNaming_normalProperty_set(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { + return bjs_WeirdNaming_normalProperty_set_extern(self, newValueWord0, newValueWord1, newValueWord2) } #if arch(wasm32) @@ -172,14 +172,14 @@ fileprivate func bjs_WeirdNaming__123invalidStart_set_extern(_ self: Int32, _ ne #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_property_with_spaces_set") -fileprivate func bjs_WeirdNaming_property_with_spaces_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void +fileprivate func bjs_WeirdNaming_property_with_spaces_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void #else -fileprivate func bjs_WeirdNaming_property_with_spaces_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { +fileprivate func bjs_WeirdNaming_property_with_spaces_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_WeirdNaming_property_with_spaces_set(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { - return bjs_WeirdNaming_property_with_spaces_set_extern(self, newValueBytes, newValueLength) +@inline(never) fileprivate func bjs_WeirdNaming_property_with_spaces_set(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { + return bjs_WeirdNaming_property_with_spaces_set_extern(self, newValueWord0, newValueWord1, newValueWord2) } #if arch(wasm32) @@ -196,38 +196,38 @@ fileprivate func bjs_WeirdNaming__specialChar_set_extern(_ self: Int32, _ newVal #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_constructor_set") -fileprivate func bjs_WeirdNaming_constructor_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void +fileprivate func bjs_WeirdNaming_constructor_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void #else -fileprivate func bjs_WeirdNaming_constructor_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { +fileprivate func bjs_WeirdNaming_constructor_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_WeirdNaming_constructor_set(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { - return bjs_WeirdNaming_constructor_set_extern(self, newValueBytes, newValueLength) +@inline(never) fileprivate func bjs_WeirdNaming_constructor_set(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { + return bjs_WeirdNaming_constructor_set_extern(self, newValueWord0, newValueWord1, newValueWord2) } #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_for_set") -fileprivate func bjs_WeirdNaming_for_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void +fileprivate func bjs_WeirdNaming_for_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void #else -fileprivate func bjs_WeirdNaming_for_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { +fileprivate func bjs_WeirdNaming_for_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_WeirdNaming_for_set(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { - return bjs_WeirdNaming_for_set_extern(self, newValueBytes, newValueLength) +@inline(never) fileprivate func bjs_WeirdNaming_for_set(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { + return bjs_WeirdNaming_for_set_extern(self, newValueWord0, newValueWord1, newValueWord2) } #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_any_set") -fileprivate func bjs_WeirdNaming_any_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void +fileprivate func bjs_WeirdNaming_any_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void #else -fileprivate func bjs_WeirdNaming_any_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { +fileprivate func bjs_WeirdNaming_any_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_WeirdNaming_any_set(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { - return bjs_WeirdNaming_any_set_extern(self, newValueBytes, newValueLength) +@inline(never) fileprivate func bjs_WeirdNaming_any_set(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { + return bjs_WeirdNaming_any_set_extern(self, newValueWord0, newValueWord1, newValueWord2) } #if arch(wasm32) @@ -327,9 +327,9 @@ func _$WeirdNaming_Any_get(_ self: JSObject) throws(JSException) -> String { } func _$WeirdNaming_normalProperty_set(_ self: JSObject, _ newValue: String) throws(JSException) -> Void { - newValue.bridgeJSWithLoweredParameter { (newValueBytes, newValueLength) in + newValue.bridgeJSWithLoweredParameter { (newValueWord0, newValueWord1, newValueWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_WeirdNaming_normalProperty_set(selfValue, newValueBytes, newValueLength) + bjs_WeirdNaming_normalProperty_set(selfValue, newValueWord0, newValueWord1, newValueWord2) } if let error = _swift_js_take_exception() { throw error @@ -355,9 +355,9 @@ func _$WeirdNaming__123invalidStart_set(_ self: JSObject, _ newValue: Bool) thro } func _$WeirdNaming_property_with_spaces_set(_ self: JSObject, _ newValue: String) throws(JSException) -> Void { - newValue.bridgeJSWithLoweredParameter { (newValueBytes, newValueLength) in + newValue.bridgeJSWithLoweredParameter { (newValueWord0, newValueWord1, newValueWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_WeirdNaming_property_with_spaces_set(selfValue, newValueBytes, newValueLength) + bjs_WeirdNaming_property_with_spaces_set(selfValue, newValueWord0, newValueWord1, newValueWord2) } if let error = _swift_js_take_exception() { throw error @@ -374,9 +374,9 @@ func _$WeirdNaming__specialChar_set(_ self: JSObject, _ newValue: Double) throws } func _$WeirdNaming_constructor_set(_ self: JSObject, _ newValue: String) throws(JSException) -> Void { - newValue.bridgeJSWithLoweredParameter { (newValueBytes, newValueLength) in + newValue.bridgeJSWithLoweredParameter { (newValueWord0, newValueWord1, newValueWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_WeirdNaming_constructor_set(selfValue, newValueBytes, newValueLength) + bjs_WeirdNaming_constructor_set(selfValue, newValueWord0, newValueWord1, newValueWord2) } if let error = _swift_js_take_exception() { throw error @@ -384,9 +384,9 @@ func _$WeirdNaming_constructor_set(_ self: JSObject, _ newValue: String) throws( } func _$WeirdNaming_for_set(_ self: JSObject, _ newValue: String) throws(JSException) -> Void { - newValue.bridgeJSWithLoweredParameter { (newValueBytes, newValueLength) in + newValue.bridgeJSWithLoweredParameter { (newValueWord0, newValueWord1, newValueWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_WeirdNaming_for_set(selfValue, newValueBytes, newValueLength) + bjs_WeirdNaming_for_set(selfValue, newValueWord0, newValueWord1, newValueWord2) } if let error = _swift_js_take_exception() { throw error @@ -394,9 +394,9 @@ func _$WeirdNaming_for_set(_ self: JSObject, _ newValue: String) throws(JSExcept } func _$WeirdNaming_any_set(_ self: JSObject, _ newValue: String) throws(JSException) -> Void { - newValue.bridgeJSWithLoweredParameter { (newValueBytes, newValueLength) in + newValue.bridgeJSWithLoweredParameter { (newValueWord0, newValueWord1, newValueWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_WeirdNaming_any_set(selfValue, newValueBytes, newValueLength) + bjs_WeirdNaming_any_set(selfValue, newValueWord0, newValueWord1, newValueWord2) } if let error = _swift_js_take_exception() { throw error diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.swift index 37009f318..95e020b23 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.swift @@ -20,14 +20,14 @@ func _$returnAnimatable() throws(JSException) -> Animatable { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_Greeter_init") -fileprivate func bjs_Greeter_init_extern(_ nameBytes: Int32, _ nameLength: Int32) -> Int32 +fileprivate func bjs_Greeter_init_extern(_ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32) -> Int32 #else -fileprivate func bjs_Greeter_init_extern(_ nameBytes: Int32, _ nameLength: Int32) -> Int32 { +fileprivate func bjs_Greeter_init_extern(_ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_Greeter_init(_ nameBytes: Int32, _ nameLength: Int32) -> Int32 { - return bjs_Greeter_init_extern(nameBytes, nameLength) +@inline(never) fileprivate func bjs_Greeter_init(_ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32) -> Int32 { + return bjs_Greeter_init_extern(nameWord0, nameWord1, nameWord2) } #if arch(wasm32) @@ -56,14 +56,14 @@ fileprivate func bjs_Greeter_age_get_extern(_ self: Int32) -> Float64 { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_Greeter_name_set") -fileprivate func bjs_Greeter_name_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void +fileprivate func bjs_Greeter_name_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void #else -fileprivate func bjs_Greeter_name_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { +fileprivate func bjs_Greeter_name_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_Greeter_name_set(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { - return bjs_Greeter_name_set_extern(self, newValueBytes, newValueLength) +@inline(never) fileprivate func bjs_Greeter_name_set(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { + return bjs_Greeter_name_set_extern(self, newValueWord0, newValueWord1, newValueWord2) } #if arch(wasm32) @@ -80,19 +80,19 @@ fileprivate func bjs_Greeter_greet_extern(_ self: Int32) -> Int32 { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_Greeter_changeName") -fileprivate func bjs_Greeter_changeName_extern(_ self: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void +fileprivate func bjs_Greeter_changeName_extern(_ self: Int32, _ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32) -> Void #else -fileprivate func bjs_Greeter_changeName_extern(_ self: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { +fileprivate func bjs_Greeter_changeName_extern(_ self: Int32, _ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_Greeter_changeName(_ self: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { - return bjs_Greeter_changeName_extern(self, nameBytes, nameLength) +@inline(never) fileprivate func bjs_Greeter_changeName(_ self: Int32, _ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32) -> Void { + return bjs_Greeter_changeName_extern(self, nameWord0, nameWord1, nameWord2) } func _$Greeter_init(_ name: String) throws(JSException) -> JSObject { - let ret0 = name.bridgeJSWithLoweredParameter { (nameBytes, nameLength) in - let ret = bjs_Greeter_init(nameBytes, nameLength) + let ret0 = name.bridgeJSWithLoweredParameter { (nameWord0, nameWord1, nameWord2) in + let ret = bjs_Greeter_init(nameWord0, nameWord1, nameWord2) return ret } let ret = ret0 @@ -121,9 +121,9 @@ func _$Greeter_age_get(_ self: JSObject) throws(JSException) -> Double { } func _$Greeter_name_set(_ self: JSObject, _ newValue: String) throws(JSException) -> Void { - newValue.bridgeJSWithLoweredParameter { (newValueBytes, newValueLength) in + newValue.bridgeJSWithLoweredParameter { (newValueWord0, newValueWord1, newValueWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_Greeter_name_set(selfValue, newValueBytes, newValueLength) + bjs_Greeter_name_set(selfValue, newValueWord0, newValueWord1, newValueWord2) } if let error = _swift_js_take_exception() { throw error @@ -140,9 +140,9 @@ func _$Greeter_greet(_ self: JSObject) throws(JSException) -> String { } func _$Greeter_changeName(_ self: JSObject, _ name: String) throws(JSException) -> Void { - name.bridgeJSWithLoweredParameter { (nameBytes, nameLength) in + name.bridgeJSWithLoweredParameter { (nameWord0, nameWord1, nameWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_Greeter_changeName(selfValue, nameBytes, nameLength) + bjs_Greeter_changeName(selfValue, nameWord0, nameWord1, nameWord2) } if let error = _swift_js_take_exception() { throw error diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSImportBareModule.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSImportBareModule.swift index 4baf8d0f0..69de3b2ff 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSImportBareModule.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSImportBareModule.swift @@ -40,19 +40,19 @@ func _$localDefaultExport_get() throws(JSException) -> JSObject { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_nodeBasename") -fileprivate func bjs_nodeBasename_extern(_ pathBytes: Int32, _ pathLength: Int32) -> Int32 +fileprivate func bjs_nodeBasename_extern(_ pathWord0: Int32, _ pathWord1: Int32, _ pathWord2: Int32) -> Int32 #else -fileprivate func bjs_nodeBasename_extern(_ pathBytes: Int32, _ pathLength: Int32) -> Int32 { +fileprivate func bjs_nodeBasename_extern(_ pathWord0: Int32, _ pathWord1: Int32, _ pathWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_nodeBasename(_ pathBytes: Int32, _ pathLength: Int32) -> Int32 { - return bjs_nodeBasename_extern(pathBytes, pathLength) +@inline(never) fileprivate func bjs_nodeBasename(_ pathWord0: Int32, _ pathWord1: Int32, _ pathWord2: Int32) -> Int32 { + return bjs_nodeBasename_extern(pathWord0, pathWord1, pathWord2) } func _$nodeBasename(_ path: String) throws(JSException) -> String { - let ret0 = path.bridgeJSWithLoweredParameter { (pathBytes, pathLength) in - let ret = bjs_nodeBasename(pathBytes, pathLength) + let ret0 = path.bridgeJSWithLoweredParameter { (pathWord0, pathWord1, pathWord2) in + let ret = bjs_nodeBasename(pathWord0, pathWord1, pathWord2) return ret } let ret = ret0 @@ -64,19 +64,19 @@ func _$nodeBasename(_ path: String) throws(JSException) -> String { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_nodeDirname") -fileprivate func bjs_nodeDirname_extern(_ pathBytes: Int32, _ pathLength: Int32) -> Int32 +fileprivate func bjs_nodeDirname_extern(_ pathWord0: Int32, _ pathWord1: Int32, _ pathWord2: Int32) -> Int32 #else -fileprivate func bjs_nodeDirname_extern(_ pathBytes: Int32, _ pathLength: Int32) -> Int32 { +fileprivate func bjs_nodeDirname_extern(_ pathWord0: Int32, _ pathWord1: Int32, _ pathWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_nodeDirname(_ pathBytes: Int32, _ pathLength: Int32) -> Int32 { - return bjs_nodeDirname_extern(pathBytes, pathLength) +@inline(never) fileprivate func bjs_nodeDirname(_ pathWord0: Int32, _ pathWord1: Int32, _ pathWord2: Int32) -> Int32 { + return bjs_nodeDirname_extern(pathWord0, pathWord1, pathWord2) } func _$nodeDirname(_ path: String) throws(JSException) -> String { - let ret0 = path.bridgeJSWithLoweredParameter { (pathBytes, pathLength) in - let ret = bjs_nodeDirname(pathBytes, pathLength) + let ret0 = path.bridgeJSWithLoweredParameter { (pathWord0, pathWord1, pathWord2) in + let ret = bjs_nodeDirname(pathWord0, pathWord1, pathWord2) return ret } let ret = ret0 diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSImportBareModuleFallback.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSImportBareModuleFallback.swift index 7780b5eb0..459130153 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSImportBareModuleFallback.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSImportBareModuleFallback.swift @@ -40,20 +40,20 @@ func _$kebabCaseFunction() throws(JSException) -> Int { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_joinPaths") -fileprivate func bjs_joinPaths_extern(_ lhsBytes: Int32, _ lhsLength: Int32, _ rhsBytes: Int32, _ rhsLength: Int32) -> Int32 +fileprivate func bjs_joinPaths_extern(_ lhsWord0: Int32, _ lhsWord1: Int32, _ lhsWord2: Int32, _ rhsWord0: Int32, _ rhsWord1: Int32, _ rhsWord2: Int32) -> Int32 #else -fileprivate func bjs_joinPaths_extern(_ lhsBytes: Int32, _ lhsLength: Int32, _ rhsBytes: Int32, _ rhsLength: Int32) -> Int32 { +fileprivate func bjs_joinPaths_extern(_ lhsWord0: Int32, _ lhsWord1: Int32, _ lhsWord2: Int32, _ rhsWord0: Int32, _ rhsWord1: Int32, _ rhsWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_joinPaths(_ lhsBytes: Int32, _ lhsLength: Int32, _ rhsBytes: Int32, _ rhsLength: Int32) -> Int32 { - return bjs_joinPaths_extern(lhsBytes, lhsLength, rhsBytes, rhsLength) +@inline(never) fileprivate func bjs_joinPaths(_ lhsWord0: Int32, _ lhsWord1: Int32, _ lhsWord2: Int32, _ rhsWord0: Int32, _ rhsWord1: Int32, _ rhsWord2: Int32) -> Int32 { + return bjs_joinPaths_extern(lhsWord0, lhsWord1, lhsWord2, rhsWord0, rhsWord1, rhsWord2) } func _$joinPaths(_ lhs: String, _ rhs: String) throws(JSException) -> String { - let ret0 = lhs.bridgeJSWithLoweredParameter { (lhsBytes, lhsLength) in - let ret1 = rhs.bridgeJSWithLoweredParameter { (rhsBytes, rhsLength) in - let ret = bjs_joinPaths(lhsBytes, lhsLength, rhsBytes, rhsLength) + let ret0 = lhs.bridgeJSWithLoweredParameter { (lhsWord0, lhsWord1, lhsWord2) in + let ret1 = rhs.bridgeJSWithLoweredParameter { (rhsWord0, rhsWord1, rhsWord2) in + let ret = bjs_joinPaths(lhsWord0, lhsWord1, lhsWord2, rhsWord0, rhsWord1, rhsWord2) return ret } return ret1 diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.swift index f45a0bb1e..c35ea24e6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.swift @@ -484,14 +484,14 @@ fileprivate func _bjs_OptionalPropertyHolder_wrap_extern(_ pointer: UnsafeMutabl #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_init") -fileprivate func bjs_WithOptionalJSClass_init_extern(_ valueOrNullIsSome: Int32, _ valueOrNullBytes: Int32, _ valueOrNullLength: Int32, _ valueOrUndefinedIsSome: Int32, _ valueOrUndefinedBytes: Int32, _ valueOrUndefinedLength: Int32) -> Int32 +fileprivate func bjs_WithOptionalJSClass_init_extern(_ valueOrNullIsSome: Int32, _ valueOrNullWord0: Int32, _ valueOrNullWord1: Int32, _ valueOrNullWord2: Int32, _ valueOrUndefinedIsSome: Int32, _ valueOrUndefinedWord0: Int32, _ valueOrUndefinedWord1: Int32, _ valueOrUndefinedWord2: Int32) -> Int32 #else -fileprivate func bjs_WithOptionalJSClass_init_extern(_ valueOrNullIsSome: Int32, _ valueOrNullBytes: Int32, _ valueOrNullLength: Int32, _ valueOrUndefinedIsSome: Int32, _ valueOrUndefinedBytes: Int32, _ valueOrUndefinedLength: Int32) -> Int32 { +fileprivate func bjs_WithOptionalJSClass_init_extern(_ valueOrNullIsSome: Int32, _ valueOrNullWord0: Int32, _ valueOrNullWord1: Int32, _ valueOrNullWord2: Int32, _ valueOrUndefinedIsSome: Int32, _ valueOrUndefinedWord0: Int32, _ valueOrUndefinedWord1: Int32, _ valueOrUndefinedWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_WithOptionalJSClass_init(_ valueOrNullIsSome: Int32, _ valueOrNullBytes: Int32, _ valueOrNullLength: Int32, _ valueOrUndefinedIsSome: Int32, _ valueOrUndefinedBytes: Int32, _ valueOrUndefinedLength: Int32) -> Int32 { - return bjs_WithOptionalJSClass_init_extern(valueOrNullIsSome, valueOrNullBytes, valueOrNullLength, valueOrUndefinedIsSome, valueOrUndefinedBytes, valueOrUndefinedLength) +@inline(never) fileprivate func bjs_WithOptionalJSClass_init(_ valueOrNullIsSome: Int32, _ valueOrNullWord0: Int32, _ valueOrNullWord1: Int32, _ valueOrNullWord2: Int32, _ valueOrUndefinedIsSome: Int32, _ valueOrUndefinedWord0: Int32, _ valueOrUndefinedWord1: Int32, _ valueOrUndefinedWord2: Int32) -> Int32 { + return bjs_WithOptionalJSClass_init_extern(valueOrNullIsSome, valueOrNullWord0, valueOrNullWord1, valueOrNullWord2, valueOrUndefinedIsSome, valueOrUndefinedWord0, valueOrUndefinedWord1, valueOrUndefinedWord2) } #if arch(wasm32) @@ -604,26 +604,26 @@ fileprivate func bjs_WithOptionalJSClass_childOrNull_get_extern(_ self: Int32) - #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_stringOrNull_set") -fileprivate func bjs_WithOptionalJSClass_stringOrNull_set_extern(_ self: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void +fileprivate func bjs_WithOptionalJSClass_stringOrNull_set_extern(_ self: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void #else -fileprivate func bjs_WithOptionalJSClass_stringOrNull_set_extern(_ self: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { +fileprivate func bjs_WithOptionalJSClass_stringOrNull_set_extern(_ self: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_WithOptionalJSClass_stringOrNull_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { - return bjs_WithOptionalJSClass_stringOrNull_set_extern(self, newValueIsSome, newValueBytes, newValueLength) +@inline(never) fileprivate func bjs_WithOptionalJSClass_stringOrNull_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { + return bjs_WithOptionalJSClass_stringOrNull_set_extern(self, newValueIsSome, newValueWord0, newValueWord1, newValueWord2) } #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_stringOrUndefined_set") -fileprivate func bjs_WithOptionalJSClass_stringOrUndefined_set_extern(_ self: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void +fileprivate func bjs_WithOptionalJSClass_stringOrUndefined_set_extern(_ self: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void #else -fileprivate func bjs_WithOptionalJSClass_stringOrUndefined_set_extern(_ self: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { +fileprivate func bjs_WithOptionalJSClass_stringOrUndefined_set_extern(_ self: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_WithOptionalJSClass_stringOrUndefined_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { - return bjs_WithOptionalJSClass_stringOrUndefined_set_extern(self, newValueIsSome, newValueBytes, newValueLength) +@inline(never) fileprivate func bjs_WithOptionalJSClass_stringOrUndefined_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { + return bjs_WithOptionalJSClass_stringOrUndefined_set_extern(self, newValueIsSome, newValueWord0, newValueWord1, newValueWord2) } #if arch(wasm32) @@ -712,26 +712,26 @@ fileprivate func bjs_WithOptionalJSClass_childOrNull_set_extern(_ self: Int32, _ #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_roundTripStringOrNull") -fileprivate func bjs_WithOptionalJSClass_roundTripStringOrNull_extern(_ self: Int32, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void +fileprivate func bjs_WithOptionalJSClass_roundTripStringOrNull_extern(_ self: Int32, _ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void #else -fileprivate func bjs_WithOptionalJSClass_roundTripStringOrNull_extern(_ self: Int32, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { +fileprivate func bjs_WithOptionalJSClass_roundTripStringOrNull_extern(_ self: Int32, _ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_WithOptionalJSClass_roundTripStringOrNull(_ self: Int32, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - return bjs_WithOptionalJSClass_roundTripStringOrNull_extern(self, valueIsSome, valueBytes, valueLength) +@inline(never) fileprivate func bjs_WithOptionalJSClass_roundTripStringOrNull(_ self: Int32, _ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { + return bjs_WithOptionalJSClass_roundTripStringOrNull_extern(self, valueIsSome, valueWord0, valueWord1, valueWord2) } #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_roundTripStringOrUndefined") -fileprivate func bjs_WithOptionalJSClass_roundTripStringOrUndefined_extern(_ self: Int32, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void +fileprivate func bjs_WithOptionalJSClass_roundTripStringOrUndefined_extern(_ self: Int32, _ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void #else -fileprivate func bjs_WithOptionalJSClass_roundTripStringOrUndefined_extern(_ self: Int32, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { +fileprivate func bjs_WithOptionalJSClass_roundTripStringOrUndefined_extern(_ self: Int32, _ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_WithOptionalJSClass_roundTripStringOrUndefined(_ self: Int32, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - return bjs_WithOptionalJSClass_roundTripStringOrUndefined_extern(self, valueIsSome, valueBytes, valueLength) +@inline(never) fileprivate func bjs_WithOptionalJSClass_roundTripStringOrUndefined(_ self: Int32, _ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { + return bjs_WithOptionalJSClass_roundTripStringOrUndefined_extern(self, valueIsSome, valueWord0, valueWord1, valueWord2) } #if arch(wasm32) @@ -819,9 +819,9 @@ fileprivate func bjs_WithOptionalJSClass_roundTripChildOrNull_extern(_ self: Int } func _$WithOptionalJSClass_init(_ valueOrNull: Optional, _ valueOrUndefined: JSUndefinedOr) throws(JSException) -> JSObject { - let ret0 = valueOrNull.bridgeJSWithLoweredParameter { (valueOrNullIsSome, valueOrNullBytes, valueOrNullLength) in - let ret1 = valueOrUndefined.bridgeJSWithLoweredParameter { (valueOrUndefinedIsSome, valueOrUndefinedBytes, valueOrUndefinedLength) in - let ret = bjs_WithOptionalJSClass_init(valueOrNullIsSome, valueOrNullBytes, valueOrNullLength, valueOrUndefinedIsSome, valueOrUndefinedBytes, valueOrUndefinedLength) + let ret0 = valueOrNull.bridgeJSWithLoweredParameter { (valueOrNullIsSome, valueOrNullWord0, valueOrNullWord1, valueOrNullWord2) in + let ret1 = valueOrUndefined.bridgeJSWithLoweredParameter { (valueOrUndefinedIsSome, valueOrUndefinedWord0, valueOrUndefinedWord1, valueOrUndefinedWord2) in + let ret = bjs_WithOptionalJSClass_init(valueOrNullIsSome, valueOrNullWord0, valueOrNullWord1, valueOrNullWord2, valueOrUndefinedIsSome, valueOrUndefinedWord0, valueOrUndefinedWord1, valueOrUndefinedWord2) return ret } return ret1 @@ -915,9 +915,9 @@ func _$WithOptionalJSClass_childOrNull_get(_ self: JSObject) throws(JSException) } func _$WithOptionalJSClass_stringOrNull_set(_ self: JSObject, _ newValue: Optional) throws(JSException) -> Void { - newValue.bridgeJSWithLoweredParameter { (newValueIsSome, newValueBytes, newValueLength) in + newValue.bridgeJSWithLoweredParameter { (newValueIsSome, newValueWord0, newValueWord1, newValueWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_WithOptionalJSClass_stringOrNull_set(selfValue, newValueIsSome, newValueBytes, newValueLength) + bjs_WithOptionalJSClass_stringOrNull_set(selfValue, newValueIsSome, newValueWord0, newValueWord1, newValueWord2) } if let error = _swift_js_take_exception() { throw error @@ -925,9 +925,9 @@ func _$WithOptionalJSClass_stringOrNull_set(_ self: JSObject, _ newValue: Option } func _$WithOptionalJSClass_stringOrUndefined_set(_ self: JSObject, _ newValue: JSUndefinedOr) throws(JSException) -> Void { - newValue.bridgeJSWithLoweredParameter { (newValueIsSome, newValueBytes, newValueLength) in + newValue.bridgeJSWithLoweredParameter { (newValueIsSome, newValueWord0, newValueWord1, newValueWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_WithOptionalJSClass_stringOrUndefined_set(selfValue, newValueIsSome, newValueBytes, newValueLength) + bjs_WithOptionalJSClass_stringOrUndefined_set(selfValue, newValueIsSome, newValueWord0, newValueWord1, newValueWord2) } if let error = _swift_js_take_exception() { throw error @@ -998,9 +998,9 @@ func _$WithOptionalJSClass_childOrNull_set(_ self: JSObject, _ newValue: Optiona } func _$WithOptionalJSClass_roundTripStringOrNull(_ self: JSObject, _ value: Optional) throws(JSException) -> Optional { - value.bridgeJSWithLoweredParameter { (valueIsSome, valueBytes, valueLength) in + value.bridgeJSWithLoweredParameter { (valueIsSome, valueWord0, valueWord1, valueWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_WithOptionalJSClass_roundTripStringOrNull(selfValue, valueIsSome, valueBytes, valueLength) + bjs_WithOptionalJSClass_roundTripStringOrNull(selfValue, valueIsSome, valueWord0, valueWord1, valueWord2) } if let error = _swift_js_take_exception() { throw error @@ -1009,9 +1009,9 @@ func _$WithOptionalJSClass_roundTripStringOrNull(_ self: JSObject, _ value: Opti } func _$WithOptionalJSClass_roundTripStringOrUndefined(_ self: JSObject, _ value: JSUndefinedOr) throws(JSException) -> JSUndefinedOr { - value.bridgeJSWithLoweredParameter { (valueIsSome, valueBytes, valueLength) in + value.bridgeJSWithLoweredParameter { (valueIsSome, valueWord0, valueWord1, valueWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_WithOptionalJSClass_roundTripStringOrUndefined(selfValue, valueIsSome, valueBytes, valueLength) + bjs_WithOptionalJSClass_roundTripStringOrUndefined(selfValue, valueIsSome, valueWord0, valueWord1, valueWord2) } if let error = _swift_js_take_exception() { throw error diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift index ec3d2f65a..a91524da5 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift @@ -5,9 +5,9 @@ extension MyViewControllerDelegate where Self: _BridgedSwiftProtocolWrapper { } func onValueChanged(_ value: String) -> Void { - value.bridgeJSWithLoweredParameter { (valueBytes, valueLength) in + value.bridgeJSWithLoweredParameter { (valueWord0, valueWord1, valueWord2) in let jsObjectValue = jsObject.bridgeJSLowerParameter() - bjs_MyViewControllerDelegate_onValueChanged(jsObjectValue, valueBytes, valueLength) + bjs_MyViewControllerDelegate_onValueChanged(jsObjectValue, valueWord0, valueWord1, valueWord2) } } @@ -19,10 +19,10 @@ extension MyViewControllerDelegate where Self: _BridgedSwiftProtocolWrapper { } func onLabelUpdated(_ prefix: String, _ suffix: String) -> Void { - prefix.bridgeJSWithLoweredParameter { (prefixBytes, prefixLength) in - suffix.bridgeJSWithLoweredParameter { (suffixBytes, suffixLength) in + prefix.bridgeJSWithLoweredParameter { (prefixWord0, prefixWord1, prefixWord2) in + suffix.bridgeJSWithLoweredParameter { (suffixWord0, suffixWord1, suffixWord2) in let jsObjectValue = jsObject.bridgeJSLowerParameter() - bjs_MyViewControllerDelegate_onLabelUpdated(jsObjectValue, prefixBytes, prefixLength, suffixBytes, suffixLength) + bjs_MyViewControllerDelegate_onLabelUpdated(jsObjectValue, prefixWord0, prefixWord1, prefixWord2, suffixWord0, suffixWord1, suffixWord2) } } } @@ -103,9 +103,9 @@ extension MyViewControllerDelegate where Self: _BridgedSwiftProtocolWrapper { return Optional.bridgeJSLiftReturnFromSideChannel() } set { - newValue.bridgeJSWithLoweredParameter { (newValueIsSome, newValueBytes, newValueLength) in + newValue.bridgeJSWithLoweredParameter { (newValueIsSome, newValueWord0, newValueWord1, newValueWord2) in let jsObjectValue = jsObject.bridgeJSLowerParameter() - bjs_MyViewControllerDelegate_optionalName_set(jsObjectValue, newValueIsSome, newValueBytes, newValueLength) + bjs_MyViewControllerDelegate_optionalName_set(jsObjectValue, newValueIsSome, newValueWord0, newValueWord1, newValueWord2) } } } @@ -117,9 +117,9 @@ extension MyViewControllerDelegate where Self: _BridgedSwiftProtocolWrapper { return Optional.bridgeJSLiftReturnFromSideChannel() } set { - newValue.bridgeJSWithLoweredParameter { (newValueIsSome, newValueBytes, newValueLength) in + newValue.bridgeJSWithLoweredParameter { (newValueIsSome, newValueWord0, newValueWord1, newValueWord2) in let jsObjectValue = jsObject.bridgeJSLowerParameter() - bjs_MyViewControllerDelegate_optionalRawEnum_set(jsObjectValue, newValueIsSome, newValueBytes, newValueLength) + bjs_MyViewControllerDelegate_optionalRawEnum_set(jsObjectValue, newValueIsSome, newValueWord0, newValueWord1, newValueWord2) } } } @@ -131,9 +131,9 @@ extension MyViewControllerDelegate where Self: _BridgedSwiftProtocolWrapper { return ExampleEnum.bridgeJSLiftReturn(ret) } set { - newValue.bridgeJSWithLoweredParameter { (newValueBytes, newValueLength) in + newValue.bridgeJSWithLoweredParameter { (newValueWord0, newValueWord1, newValueWord2) in let jsObjectValue = jsObject.bridgeJSLowerParameter() - bjs_MyViewControllerDelegate_rawStringEnum_set(jsObjectValue, newValueBytes, newValueLength) + bjs_MyViewControllerDelegate_rawStringEnum_set(jsObjectValue, newValueWord0, newValueWord1, newValueWord2) } } } @@ -239,14 +239,14 @@ fileprivate func bjs_MyViewControllerDelegate_onSomethingHappened_extern(_ jsObj #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_onValueChanged") -fileprivate func bjs_MyViewControllerDelegate_onValueChanged_extern(_ jsObject: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void +fileprivate func bjs_MyViewControllerDelegate_onValueChanged_extern(_ jsObject: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void #else -fileprivate func bjs_MyViewControllerDelegate_onValueChanged_extern(_ jsObject: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { +fileprivate func bjs_MyViewControllerDelegate_onValueChanged_extern(_ jsObject: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_MyViewControllerDelegate_onValueChanged(_ jsObject: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - return bjs_MyViewControllerDelegate_onValueChanged_extern(jsObject, valueBytes, valueLength) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_onValueChanged(_ jsObject: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { + return bjs_MyViewControllerDelegate_onValueChanged_extern(jsObject, valueWord0, valueWord1, valueWord2) } #if arch(wasm32) @@ -263,14 +263,14 @@ fileprivate func bjs_MyViewControllerDelegate_onCountUpdated_extern(_ jsObject: #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_onLabelUpdated") -fileprivate func bjs_MyViewControllerDelegate_onLabelUpdated_extern(_ jsObject: Int32, _ prefixBytes: Int32, _ prefixLength: Int32, _ suffixBytes: Int32, _ suffixLength: Int32) -> Void +fileprivate func bjs_MyViewControllerDelegate_onLabelUpdated_extern(_ jsObject: Int32, _ prefixWord0: Int32, _ prefixWord1: Int32, _ prefixWord2: Int32, _ suffixWord0: Int32, _ suffixWord1: Int32, _ suffixWord2: Int32) -> Void #else -fileprivate func bjs_MyViewControllerDelegate_onLabelUpdated_extern(_ jsObject: Int32, _ prefixBytes: Int32, _ prefixLength: Int32, _ suffixBytes: Int32, _ suffixLength: Int32) -> Void { +fileprivate func bjs_MyViewControllerDelegate_onLabelUpdated_extern(_ jsObject: Int32, _ prefixWord0: Int32, _ prefixWord1: Int32, _ prefixWord2: Int32, _ suffixWord0: Int32, _ suffixWord1: Int32, _ suffixWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_MyViewControllerDelegate_onLabelUpdated(_ jsObject: Int32, _ prefixBytes: Int32, _ prefixLength: Int32, _ suffixBytes: Int32, _ suffixLength: Int32) -> Void { - return bjs_MyViewControllerDelegate_onLabelUpdated_extern(jsObject, prefixBytes, prefixLength, suffixBytes, suffixLength) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_onLabelUpdated(_ jsObject: Int32, _ prefixWord0: Int32, _ prefixWord1: Int32, _ prefixWord2: Int32, _ suffixWord0: Int32, _ suffixWord1: Int32, _ suffixWord2: Int32) -> Void { + return bjs_MyViewControllerDelegate_onLabelUpdated_extern(jsObject, prefixWord0, prefixWord1, prefixWord2, suffixWord0, suffixWord1, suffixWord2) } #if arch(wasm32) @@ -419,14 +419,14 @@ fileprivate func bjs_MyViewControllerDelegate_optionalName_get_extern(_ jsObject #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_optionalName_set") -fileprivate func bjs_MyViewControllerDelegate_optionalName_set_extern(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void +fileprivate func bjs_MyViewControllerDelegate_optionalName_set_extern(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void #else -fileprivate func bjs_MyViewControllerDelegate_optionalName_set_extern(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { +fileprivate func bjs_MyViewControllerDelegate_optionalName_set_extern(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_MyViewControllerDelegate_optionalName_set(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { - return bjs_MyViewControllerDelegate_optionalName_set_extern(jsObject, newValueIsSome, newValueBytes, newValueLength) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_optionalName_set(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { + return bjs_MyViewControllerDelegate_optionalName_set_extern(jsObject, newValueIsSome, newValueWord0, newValueWord1, newValueWord2) } #if arch(wasm32) @@ -443,14 +443,14 @@ fileprivate func bjs_MyViewControllerDelegate_optionalRawEnum_get_extern(_ jsObj #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_optionalRawEnum_set") -fileprivate func bjs_MyViewControllerDelegate_optionalRawEnum_set_extern(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void +fileprivate func bjs_MyViewControllerDelegate_optionalRawEnum_set_extern(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void #else -fileprivate func bjs_MyViewControllerDelegate_optionalRawEnum_set_extern(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { +fileprivate func bjs_MyViewControllerDelegate_optionalRawEnum_set_extern(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_MyViewControllerDelegate_optionalRawEnum_set(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { - return bjs_MyViewControllerDelegate_optionalRawEnum_set_extern(jsObject, newValueIsSome, newValueBytes, newValueLength) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_optionalRawEnum_set(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { + return bjs_MyViewControllerDelegate_optionalRawEnum_set_extern(jsObject, newValueIsSome, newValueWord0, newValueWord1, newValueWord2) } #if arch(wasm32) @@ -467,14 +467,14 @@ fileprivate func bjs_MyViewControllerDelegate_rawStringEnum_get_extern(_ jsObjec #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_rawStringEnum_set") -fileprivate func bjs_MyViewControllerDelegate_rawStringEnum_set_extern(_ jsObject: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void +fileprivate func bjs_MyViewControllerDelegate_rawStringEnum_set_extern(_ jsObject: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void #else -fileprivate func bjs_MyViewControllerDelegate_rawStringEnum_set_extern(_ jsObject: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { +fileprivate func bjs_MyViewControllerDelegate_rawStringEnum_set_extern(_ jsObject: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_MyViewControllerDelegate_rawStringEnum_set(_ jsObject: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { - return bjs_MyViewControllerDelegate_rawStringEnum_set_extern(jsObject, newValueBytes, newValueLength) +@inline(never) fileprivate func bjs_MyViewControllerDelegate_rawStringEnum_set(_ jsObject: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { + return bjs_MyViewControllerDelegate_rawStringEnum_set_extern(jsObject, newValueWord0, newValueWord1, newValueWord2) } #if arch(wasm32) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringParameter.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringParameter.swift index f519c3306..f00cbd49c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringParameter.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringParameter.swift @@ -23,19 +23,19 @@ public func _bjs_roundtripString(_ aBytes: Int32, _ aLength: Int32) -> Void { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_checkString") -fileprivate func bjs_checkString_extern(_ aBytes: Int32, _ aLength: Int32) -> Void +fileprivate func bjs_checkString_extern(_ aWord0: Int32, _ aWord1: Int32, _ aWord2: Int32) -> Void #else -fileprivate func bjs_checkString_extern(_ aBytes: Int32, _ aLength: Int32) -> Void { +fileprivate func bjs_checkString_extern(_ aWord0: Int32, _ aWord1: Int32, _ aWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_checkString(_ aBytes: Int32, _ aLength: Int32) -> Void { - return bjs_checkString_extern(aBytes, aLength) +@inline(never) fileprivate func bjs_checkString(_ aWord0: Int32, _ aWord1: Int32, _ aWord2: Int32) -> Void { + return bjs_checkString_extern(aWord0, aWord1, aWord2) } func _$checkString(_ a: String) throws(JSException) -> Void { - a.bridgeJSWithLoweredParameter { (aBytes, aLength) in - bjs_checkString(aBytes, aLength) + a.bridgeJSWithLoweredParameter { (aWord0, aWord1, aWord2) in + bjs_checkString(aWord0, aWord1, aWord2) } if let error = _swift_js_take_exception() { throw error @@ -44,20 +44,20 @@ func _$checkString(_ a: String) throws(JSException) -> Void { #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_checkStringWithLength") -fileprivate func bjs_checkStringWithLength_extern(_ aBytes: Int32, _ aLength: Int32, _ b: Float64) -> Void +fileprivate func bjs_checkStringWithLength_extern(_ aWord0: Int32, _ aWord1: Int32, _ aWord2: Int32, _ b: Float64) -> Void #else -fileprivate func bjs_checkStringWithLength_extern(_ aBytes: Int32, _ aLength: Int32, _ b: Float64) -> Void { +fileprivate func bjs_checkStringWithLength_extern(_ aWord0: Int32, _ aWord1: Int32, _ aWord2: Int32, _ b: Float64) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_checkStringWithLength(_ aBytes: Int32, _ aLength: Int32, _ b: Float64) -> Void { - return bjs_checkStringWithLength_extern(aBytes, aLength, b) +@inline(never) fileprivate func bjs_checkStringWithLength(_ aWord0: Int32, _ aWord1: Int32, _ aWord2: Int32, _ b: Float64) -> Void { + return bjs_checkStringWithLength_extern(aWord0, aWord1, aWord2, b) } func _$checkStringWithLength(_ a: String, _ b: Double) throws(JSException) -> Void { - a.bridgeJSWithLoweredParameter { (aBytes, aLength) in + a.bridgeJSWithLoweredParameter { (aWord0, aWord1, aWord2) in let bValue = b.bridgeJSLowerParameter() - bjs_checkStringWithLength(aBytes, aLength, bValue) + bjs_checkStringWithLength(aWord0, aWord1, aWord2, bValue) } if let error = _swift_js_take_exception() { throw error diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.swift index af740495c..152b41102 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.swift @@ -64,14 +64,14 @@ public func _invoke_swift_closure_TestModule_10TestModule10HttpStatusO_10HttpSta #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModule5ThemeO_5ThemeO") -fileprivate func invoke_js_callback_TestModule_10TestModule5ThemeO_5ThemeO_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 +fileprivate func invoke_js_callback_TestModule_10TestModule5ThemeO_5ThemeO_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 #else -fileprivate func invoke_js_callback_TestModule_10TestModule5ThemeO_5ThemeO_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { +fileprivate func invoke_js_callback_TestModule_10TestModule5ThemeO_5ThemeO_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModule5ThemeO_5ThemeO(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { - return invoke_js_callback_TestModule_10TestModule5ThemeO_5ThemeO_extern(callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModule5ThemeO_5ThemeO(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { + return invoke_js_callback_TestModule_10TestModule5ThemeO_5ThemeO_extern(callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -91,9 +91,9 @@ private enum _BJS_Closure_10TestModule5ThemeO_5ThemeO { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] param0 in #if arch(wasm32) - let ret0 = param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + let ret0 = param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - let ret = invoke_js_callback_TestModule_10TestModule5ThemeO_5ThemeO(callbackValue, param0Bytes, param0Length) + let ret = invoke_js_callback_TestModule_10TestModule5ThemeO_5ThemeO(callbackValue, param0Word0, param0Word1, param0Word2) return ret } let ret = ret0 @@ -387,14 +387,14 @@ public func _invoke_swift_closure_TestModule_10TestModule9DirectionO_9DirectionO #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModuleKSS_Sb") -fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Sb_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 +fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Sb_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 #else -fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Sb_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { +fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Sb_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Sb(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { - return invoke_js_callback_TestModule_10TestModuleKSS_Sb_extern(callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Sb(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { + return invoke_js_callback_TestModule_10TestModuleKSS_Sb_extern(callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -414,9 +414,9 @@ private enum _BJS_Closure_10TestModuleKSS_Sb { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] (param0: String) throws(JSException) -> Bool in #if arch(wasm32) - let ret0 = param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + let ret0 = param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - let ret = invoke_js_callback_TestModule_10TestModuleKSS_Sb(callbackValue, param0Bytes, param0Length) + let ret = invoke_js_callback_TestModule_10TestModuleKSS_Sb(callbackValue, param0Word0, param0Word1, param0Word2) return ret } let ret = ret0 @@ -471,14 +471,14 @@ public func _invoke_swift_closure_TestModule_10TestModuleKSS_Sb(_ boxPtr: Unsafe #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModuleKSS_Si") -fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Si_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 +fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Si_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 #else -fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Si_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { +fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Si_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Si(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { - return invoke_js_callback_TestModule_10TestModuleKSS_Si_extern(callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Si(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { + return invoke_js_callback_TestModule_10TestModuleKSS_Si_extern(callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -498,9 +498,9 @@ private enum _BJS_Closure_10TestModuleKSS_Si { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] (param0: String) throws(JSException) -> Int in #if arch(wasm32) - let ret0 = param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + let ret0 = param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - let ret = invoke_js_callback_TestModule_10TestModuleKSS_Si(callbackValue, param0Bytes, param0Length) + let ret = invoke_js_callback_TestModule_10TestModuleKSS_Si(callbackValue, param0Word0, param0Word1, param0Word2) return ret } let ret = ret0 @@ -555,14 +555,14 @@ public func _invoke_swift_closure_TestModule_10TestModuleKSS_Si(_ boxPtr: Unsafe #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModuleSS_SS") -fileprivate func invoke_js_callback_TestModule_10TestModuleSS_SS_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 +fileprivate func invoke_js_callback_TestModule_10TestModuleSS_SS_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 #else -fileprivate func invoke_js_callback_TestModule_10TestModuleSS_SS_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { +fileprivate func invoke_js_callback_TestModule_10TestModuleSS_SS_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleSS_SS(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { - return invoke_js_callback_TestModule_10TestModuleSS_SS_extern(callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleSS_SS(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { + return invoke_js_callback_TestModule_10TestModuleSS_SS_extern(callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -582,9 +582,9 @@ private enum _BJS_Closure_10TestModuleSS_SS { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] param0 in #if arch(wasm32) - let ret0 = param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + let ret0 = param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - let ret = invoke_js_callback_TestModule_10TestModuleSS_SS(callbackValue, param0Bytes, param0Length) + let ret = invoke_js_callback_TestModule_10TestModuleSS_SS(callbackValue, param0Word0, param0Word1, param0Word2) return ret } let ret = ret0 @@ -942,14 +942,14 @@ public func _invoke_swift_closure_TestModule_10TestModuleSq10HttpStatusO_Sq10Htt #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO") -fileprivate func invoke_js_callback_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void +fileprivate func invoke_js_callback_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void #else -fileprivate func invoke_js_callback_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { +fileprivate func invoke_js_callback_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO(_ callback: Int32, _ param0IsSome: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { - return invoke_js_callback_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO_extern(callback, param0IsSome, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO(_ callback: Int32, _ param0IsSome: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + return invoke_js_callback_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO_extern(callback, param0IsSome, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -969,9 +969,9 @@ private enum _BJS_Closure_10TestModuleSq5ThemeO_Sq5ThemeO { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] param0 in #if arch(wasm32) - param0.bridgeJSWithLoweredParameter { (param0IsSome, param0Bytes, param0Length) in + param0.bridgeJSWithLoweredParameter { (param0IsSome, param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - invoke_js_callback_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO(callbackValue, param0IsSome, param0Bytes, param0Length) + invoke_js_callback_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO(callbackValue, param0IsSome, param0Word0, param0Word1, param0Word2) } return Optional.bridgeJSLiftReturnFromSideChannel() #else @@ -1263,14 +1263,14 @@ public func _invoke_swift_closure_TestModule_10TestModuleSq9DirectionO_Sq9Direct #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModuleSqSS_SqSS") -fileprivate func invoke_js_callback_TestModule_10TestModuleSqSS_SqSS_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void +fileprivate func invoke_js_callback_TestModule_10TestModuleSqSS_SqSS_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void #else -fileprivate func invoke_js_callback_TestModule_10TestModuleSqSS_SqSS_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { +fileprivate func invoke_js_callback_TestModule_10TestModuleSqSS_SqSS_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleSqSS_SqSS(_ callback: Int32, _ param0IsSome: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { - return invoke_js_callback_TestModule_10TestModuleSqSS_SqSS_extern(callback, param0IsSome, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleSqSS_SqSS(_ callback: Int32, _ param0IsSome: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + return invoke_js_callback_TestModule_10TestModuleSqSS_SqSS_extern(callback, param0IsSome, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -1290,9 +1290,9 @@ private enum _BJS_Closure_10TestModuleSqSS_SqSS { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] param0 in #if arch(wasm32) - param0.bridgeJSWithLoweredParameter { (param0IsSome, param0Bytes, param0Length) in + param0.bridgeJSWithLoweredParameter { (param0IsSome, param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - invoke_js_callback_TestModule_10TestModuleSqSS_SqSS(callbackValue, param0IsSome, param0Bytes, param0Length) + invoke_js_callback_TestModule_10TestModuleSqSS_SqSS(callbackValue, param0IsSome, param0Word0, param0Word1, param0Word2) } return Optional.bridgeJSLiftReturnFromSideChannel() #else @@ -1584,14 +1584,14 @@ public func _invoke_swift_closure_TestModule_10TestModuleSqSi_SqSi(_ boxPtr: Uns #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModuleYaKSS_SS") -fileprivate func invoke_js_callback_TestModule_10TestModuleYaKSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void +fileprivate func invoke_js_callback_TestModule_10TestModuleYaKSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void #else -fileprivate func invoke_js_callback_TestModule_10TestModuleYaKSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { +fileprivate func invoke_js_callback_TestModule_10TestModuleYaKSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleYaKSS_SS(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { - return invoke_js_callback_TestModule_10TestModuleYaKSS_SS_extern(resolveRef, rejectRef, callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleYaKSS_SS(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + return invoke_js_callback_TestModule_10TestModuleYaKSS_SS_extern(resolveRef, rejectRef, callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -1616,9 +1616,9 @@ private enum _BJS_Closure_10TestModuleYaKSS_SS { }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in - param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - invoke_js_callback_TestModule_10TestModuleYaKSS_SS(resolveRef, rejectRef, callbackValue, param0Bytes, param0Length) + invoke_js_callback_TestModule_10TestModuleYaKSS_SS(resolveRef, rejectRef, callbackValue, param0Word0, param0Word1, param0Word2) } } return resolved @@ -1727,14 +1727,14 @@ public func _invoke_swift_closure_TestModule_10TestModuleYaKSb_9APIResultO(_ box #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModuleYaSS_6AnimalV") -fileprivate func invoke_js_callback_TestModule_10TestModuleYaSS_6AnimalV_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void +fileprivate func invoke_js_callback_TestModule_10TestModuleYaSS_6AnimalV_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void #else -fileprivate func invoke_js_callback_TestModule_10TestModuleYaSS_6AnimalV_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { +fileprivate func invoke_js_callback_TestModule_10TestModuleYaSS_6AnimalV_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleYaSS_6AnimalV(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { - return invoke_js_callback_TestModule_10TestModuleYaSS_6AnimalV_extern(resolveRef, rejectRef, callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleYaSS_6AnimalV(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + return invoke_js_callback_TestModule_10TestModuleYaSS_6AnimalV_extern(resolveRef, rejectRef, callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -1759,9 +1759,9 @@ private enum _BJS_Closure_10TestModuleYaSS_6AnimalV { }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in - param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - invoke_js_callback_TestModule_10TestModuleYaSS_6AnimalV(resolveRef, rejectRef, callbackValue, param0Bytes, param0Length) + invoke_js_callback_TestModule_10TestModuleYaSS_6AnimalV(resolveRef, rejectRef, callbackValue, param0Word0, param0Word1, param0Word2) } } return resolved @@ -1799,14 +1799,14 @@ public func _invoke_swift_closure_TestModule_10TestModuleYaSS_6AnimalV(_ boxPtr: #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModuleYaSS_SS") -fileprivate func invoke_js_callback_TestModule_10TestModuleYaSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void +fileprivate func invoke_js_callback_TestModule_10TestModuleYaSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void #else -fileprivate func invoke_js_callback_TestModule_10TestModuleYaSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { +fileprivate func invoke_js_callback_TestModule_10TestModuleYaSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleYaSS_SS(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { - return invoke_js_callback_TestModule_10TestModuleYaSS_SS_extern(resolveRef, rejectRef, callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleYaSS_SS(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + return invoke_js_callback_TestModule_10TestModuleYaSS_SS_extern(resolveRef, rejectRef, callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -1831,9 +1831,9 @@ private enum _BJS_Closure_10TestModuleYaSS_SS { }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in - param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - invoke_js_callback_TestModule_10TestModuleYaSS_SS(resolveRef, rejectRef, callbackValue, param0Bytes, param0Length) + invoke_js_callback_TestModule_10TestModuleYaSS_SS(resolveRef, rejectRef, callbackValue, param0Word0, param0Word1, param0Word2) } } return resolved @@ -2057,14 +2057,14 @@ public func _invoke_swift_closure_TestModule_10TestModules9APIResultO_y(_ boxPtr #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModulesSS_y") -fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void +fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void #else -fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { +fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { - return invoke_js_callback_TestModule_10TestModulesSS_y_extern(callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + return invoke_js_callback_TestModule_10TestModulesSS_y_extern(callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -2084,9 +2084,9 @@ private enum _BJS_Closure_10TestModulesSS_y { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] param0 in #if arch(wasm32) - param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - invoke_js_callback_TestModule_10TestModulesSS_y(callbackValue, param0Bytes, param0Length) + invoke_js_callback_TestModule_10TestModulesSS_y(callbackValue, param0Word0, param0Word1, param0Word2) } #else fatalError("Only available on WebAssembly") @@ -2741,20 +2741,20 @@ func _$Promise_reject(_ promise: JSObject, _ value: JSValue) throws(JSException) #if arch(wasm32) @_extern(wasm, module: "bjs", name: "promise_resolve_TestModule_SS") -fileprivate func promise_resolve_TestModule_SS_extern(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void +fileprivate func promise_resolve_TestModule_SS_extern(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void #else -fileprivate func promise_resolve_TestModule_SS_extern(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { +fileprivate func promise_resolve_TestModule_SS_extern(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func promise_resolve_TestModule_SS(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - return promise_resolve_TestModule_SS_extern(promise, valueBytes, valueLength) +@inline(never) fileprivate func promise_resolve_TestModule_SS(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { + return promise_resolve_TestModule_SS_extern(promise, valueWord0, valueWord1, valueWord2) } func _$Promise_resolve_SS(_ promise: JSObject, _ value: String) throws(JSException) -> Void { - value.bridgeJSWithLoweredParameter { (valueBytes, valueLength) in + value.bridgeJSWithLoweredParameter { (valueWord0, valueWord1, valueWord2) in let promiseValue = promise.bridgeJSLowerParameter() - promise_resolve_TestModule_SS(promiseValue, valueBytes, valueLength) + promise_resolve_TestModule_SS(promiseValue, valueWord0, valueWord1, valueWord2) } if let error = _swift_js_take_exception() { throw error } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosureImports.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosureImports.swift index 3634ad491..5c22db7f2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosureImports.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosureImports.swift @@ -1,13 +1,13 @@ #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModuleKSS_Sb") -fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Sb_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 +fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Sb_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 #else -fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Sb_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { +fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Sb_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Sb(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { - return invoke_js_callback_TestModule_10TestModuleKSS_Sb_extern(callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleKSS_Sb(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { + return invoke_js_callback_TestModule_10TestModuleKSS_Sb_extern(callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -27,9 +27,9 @@ private enum _BJS_Closure_10TestModuleKSS_Sb { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] (param0: String) throws(JSException) -> Bool in #if arch(wasm32) - let ret0 = param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + let ret0 = param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - let ret = invoke_js_callback_TestModule_10TestModuleKSS_Sb(callbackValue, param0Bytes, param0Length) + let ret = invoke_js_callback_TestModule_10TestModuleKSS_Sb(callbackValue, param0Word0, param0Word1, param0Word2) return ret } let ret = ret0 @@ -148,14 +148,14 @@ public func _invoke_swift_closure_TestModule_10TestModuleSi_Si(_ boxPtr: UnsafeM #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModuleYaKSS_SS") -fileprivate func invoke_js_callback_TestModule_10TestModuleYaKSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void +fileprivate func invoke_js_callback_TestModule_10TestModuleYaKSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void #else -fileprivate func invoke_js_callback_TestModule_10TestModuleYaKSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { +fileprivate func invoke_js_callback_TestModule_10TestModuleYaKSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleYaKSS_SS(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { - return invoke_js_callback_TestModule_10TestModuleYaKSS_SS_extern(resolveRef, rejectRef, callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleYaKSS_SS(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + return invoke_js_callback_TestModule_10TestModuleYaKSS_SS_extern(resolveRef, rejectRef, callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -180,9 +180,9 @@ private enum _BJS_Closure_10TestModuleYaKSS_SS { }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in - param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - invoke_js_callback_TestModule_10TestModuleYaKSS_SS(resolveRef, rejectRef, callbackValue, param0Bytes, param0Length) + invoke_js_callback_TestModule_10TestModuleYaKSS_SS(resolveRef, rejectRef, callbackValue, param0Word0, param0Word1, param0Word2) } } return resolved @@ -282,14 +282,14 @@ public func _invoke_swift_closure_TestModule_10TestModules7JSValueV_y(_ boxPtr: #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModulesSS_y") -fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void +fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void #else -fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { +fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { - return invoke_js_callback_TestModule_10TestModulesSS_y_extern(callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + return invoke_js_callback_TestModule_10TestModulesSS_y_extern(callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -309,9 +309,9 @@ private enum _BJS_Closure_10TestModulesSS_y { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] param0 in #if arch(wasm32) - param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - invoke_js_callback_TestModule_10TestModulesSS_y(callbackValue, param0Bytes, param0Length) + invoke_js_callback_TestModule_10TestModulesSS_y(callbackValue, param0Word0, param0Word1, param0Word2) } #else fatalError("Only available on WebAssembly") @@ -390,20 +390,20 @@ func _$Promise_reject(_ promise: JSObject, _ value: JSValue) throws(JSException) #if arch(wasm32) @_extern(wasm, module: "bjs", name: "promise_resolve_TestModule_SS") -fileprivate func promise_resolve_TestModule_SS_extern(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void +fileprivate func promise_resolve_TestModule_SS_extern(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void #else -fileprivate func promise_resolve_TestModule_SS_extern(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { +fileprivate func promise_resolve_TestModule_SS_extern(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func promise_resolve_TestModule_SS(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - return promise_resolve_TestModule_SS_extern(promise, valueBytes, valueLength) +@inline(never) fileprivate func promise_resolve_TestModule_SS(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { + return promise_resolve_TestModule_SS_extern(promise, valueWord0, valueWord1, valueWord2) } func _$Promise_resolve_SS(_ promise: JSObject, _ value: String) throws(JSException) -> Void { - value.bridgeJSWithLoweredParameter { (valueBytes, valueLength) in + value.bridgeJSWithLoweredParameter { (valueWord0, valueWord1, valueWord2) in let promiseValue = promise.bridgeJSLowerParameter() - promise_resolve_TestModule_SS(promiseValue, valueBytes, valueLength) + promise_resolve_TestModule_SS(promiseValue, valueWord0, valueWord1, valueWord2) } if let error = _swift_js_take_exception() { throw error } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js index b1cfb68aa..422e26dd9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js @@ -15,6 +15,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -432,8 +434,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -441,8 +443,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -467,8 +469,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -536,11 +538,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -611,19 +613,19 @@ export async function createInstantiator(options, swift) { return swift.memory.retain(obj); }; const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; - TestModule["bjs_acceptTagged"] = function bjs_acceptTagged(taggedBytes, taggedCount) { + TestModule["bjs_acceptTagged"] = function bjs_acceptTagged(taggedWord0, taggedWord1, taggedWord2) { try { - const string = decodeString(taggedBytes, taggedCount); + const string = decodeString(taggedWord0, taggedWord1, taggedWord2); imports.acceptTagged(string); } catch (error) { setException(error); } } - TestModule["bjs_acceptOptionalTagged"] = function bjs_acceptOptionalTagged(taggedIsSome, taggedBytes, taggedCount) { + TestModule["bjs_acceptOptionalTagged"] = function bjs_acceptOptionalTagged(taggedIsSome, taggedWord0, taggedWord1, taggedWord2) { try { let optResult; if (taggedIsSome) { - const string = decodeString(taggedBytes, taggedCount); + const string = decodeString(taggedWord0, taggedWord1, taggedWord2); optResult = string; } else { optResult = null; @@ -633,9 +635,9 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_roundtripTagged"] = function bjs_roundtripTagged(taggedBytes, taggedCount) { + TestModule["bjs_roundtripTagged"] = function bjs_roundtripTagged(taggedWord0, taggedWord1, taggedWord2) { try { - const string = decodeString(taggedBytes, taggedCount); + const string = decodeString(taggedWord0, taggedWord1, taggedWord2); let ret = imports.roundtripTagged(string); tmpRetBytes = textEncoder.encode(ret); return tmpRetBytes.length; @@ -678,10 +680,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AliasInClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AliasInClosure.js index fa9095cd8..5a7dc255e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AliasInClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AliasInClosure.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -42,7 +44,7 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, state.file >>> 0); let length = 0; while (bytes[length] !== 0) { length += 1; } - const fileID = decodeString(state.file, length); + const fileID = decodeUTF8(state.file, length); throw new Error(`Attempted to call a released JSTypedClosure created at ${fileID}:${state.line}`); } return func(...args); @@ -64,8 +66,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -73,8 +75,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -99,8 +101,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -168,11 +170,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -290,10 +292,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js index 6d3992ce5..bb61c4fb5 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js @@ -22,6 +22,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -495,8 +497,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -504,8 +506,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -530,8 +532,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -606,11 +608,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -740,10 +742,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js index c025cf4f0..b657a2188 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js @@ -19,6 +19,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -407,8 +409,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -416,8 +418,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -442,8 +444,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -504,9 +506,9 @@ export async function createInstantiator(options, swift) { setException(error); } } - bjs["promise_resolve_TestModule_SS"] = function(promise, valueBytes, valueCount) { + bjs["promise_resolve_TestModule_SS"] = function(promise, valueWord0, valueWord1, valueWord2) { try { - const string = decodeString(valueBytes, valueCount); + const string = decodeString(valueWord0, valueWord1, valueWord2); swift.memory.getObject(promise)[__bjs_promiseSettlers].resolve(string); } catch (error) { setException(error); @@ -555,9 +557,9 @@ export async function createInstantiator(options, swift) { setException(error); } } - bjs["promise_resolve_TestModule_10AsyncThemeO"] = function(promise, valueBytes, valueCount) { + bjs["promise_resolve_TestModule_10AsyncThemeO"] = function(promise, valueWord0, valueWord1, valueWord2) { try { - const string = decodeString(valueBytes, valueCount); + const string = decodeString(valueWord0, valueWord1, valueWord2); swift.memory.getObject(promise)[__bjs_promiseSettlers].resolve(string); } catch (error) { setException(error); @@ -570,11 +572,11 @@ export async function createInstantiator(options, swift) { setException(error); } } - bjs["promise_resolve_TestModule_Sq10AsyncThemeO"] = function(promise, valueIsSome, valueBytes, valueCount) { + bjs["promise_resolve_TestModule_Sq10AsyncThemeO"] = function(promise, valueIsSome, valueWord0, valueWord1, valueWord2) { try { let optResult; if (valueIsSome) { - const string = decodeString(valueBytes, valueCount); + const string = decodeString(valueWord0, valueWord1, valueWord2); optResult = string; } else { optResult = null; @@ -660,11 +662,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -724,10 +726,161 @@ export async function createInstantiator(options, swift) { bjs["swift_js_closure_unregister"] = function(funcRef) {} }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncAssociatedValueEnum.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncAssociatedValueEnum.js index 49b2ff88b..d16d071b7 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncAssociatedValueEnum.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncAssociatedValueEnum.js @@ -16,6 +16,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -172,8 +174,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -181,8 +183,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -207,8 +209,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -306,11 +308,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -370,10 +372,161 @@ export async function createInstantiator(options, swift) { bjs["swift_js_closure_unregister"] = function(funcRef) {} }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js index 96c0d11e8..cc7b29f42 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -131,7 +133,7 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, state.file >>> 0); let length = 0; while (bytes[length] !== 0) { length += 1; } - const fileID = decodeString(state.file, length); + const fileID = decodeUTF8(state.file, length); throw new Error(`Attempted to call a released JSTypedClosure created at ${fileID}:${state.line}`); } return func(...args); @@ -154,8 +156,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -163,8 +165,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -189,8 +191,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -257,11 +259,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -365,10 +367,10 @@ export async function createInstantiator(options, swift) { }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModules8JSObjectC_y); } - bjs["invoke_js_callback_TestModule_10TestModulesSS_y"] = function(callbackId, param0Bytes, param0Count) { + bjs["invoke_js_callback_TestModule_10TestModulesSS_y"] = function(callbackId, param0Word0, param0Word1, param0Word2) { try { const callback = swift.memory.getObject(callbackId); - const string = decodeString(param0Bytes, param0Count); + const string = decodeString(param0Word0, param0Word1, param0Word2); callback(string); } catch (error) { setException(error); @@ -479,10 +481,10 @@ export async function createInstantiator(options, swift) { const reject = swift.memory.getObject(rejectRef); imports.asyncRoundTripInt(v).then(resolve, reject); } - TestModule["bjs_asyncRoundTripString"] = function bjs_asyncRoundTripString(resolveRef, rejectRef, vBytes, vCount) { + TestModule["bjs_asyncRoundTripString"] = function bjs_asyncRoundTripString(resolveRef, rejectRef, vWord0, vWord1, vWord2) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); - const string = decodeString(vBytes, vCount); + const string = decodeString(vWord0, vWord1, vWord2); imports.asyncRoundTripString(string).then(resolve, reject); } TestModule["bjs_asyncRoundTripBool"] = function bjs_asyncRoundTripBool(resolveRef, rejectRef, v) { @@ -502,10 +504,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js index eea340c35..406c5da24 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -131,7 +133,7 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, state.file >>> 0); let length = 0; while (bytes[length] !== 0) { length += 1; } - const fileID = decodeString(state.file, length); + const fileID = decodeUTF8(state.file, length); throw new Error(`Attempted to call a released JSTypedClosure created at ${fileID}:${state.line}`); } return func(...args); @@ -154,8 +156,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -163,8 +165,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -189,8 +191,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -257,11 +259,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -398,10 +400,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ClassWithNestedTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ClassWithNestedTypes.js index ecdb0b059..3d0a66cc3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ClassWithNestedTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ClassWithNestedTypes.js @@ -14,6 +14,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -56,8 +58,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -65,8 +67,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -91,8 +93,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -167,11 +169,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -239,10 +241,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js index 9fda637df..35417c66b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js @@ -15,6 +15,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -419,8 +421,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -428,8 +430,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -454,8 +456,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -537,11 +539,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -617,10 +619,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js index 8ccda3c19..1b796f0de 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -399,8 +401,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -408,8 +410,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -434,8 +436,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -510,11 +512,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -592,10 +594,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DocComments.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DocComments.js index 6d23d394f..0dae550a8 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DocComments.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DocComments.js @@ -15,6 +15,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -56,8 +58,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -65,8 +67,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -91,8 +93,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -167,11 +169,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -256,10 +258,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAlias.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAlias.js index d8bc06fcf..897f9e772 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAlias.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAlias.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -39,8 +41,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -48,8 +50,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -74,8 +76,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -143,11 +145,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -215,10 +217,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js index 66f85760c..afe2e8ac7 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js @@ -90,6 +90,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -994,8 +996,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -1003,8 +1005,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -1029,8 +1031,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -1105,11 +1107,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -1177,10 +1179,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValueImport.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValueImport.js index 2b36953bb..4b71ac219 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValueImport.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValueImport.js @@ -16,6 +16,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -84,8 +86,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -93,8 +95,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -119,8 +121,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -188,11 +190,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -301,10 +303,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js index 838e3062b..e87881f55 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js @@ -33,6 +33,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -63,8 +65,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -72,8 +74,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -98,8 +100,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -167,11 +169,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -231,10 +233,161 @@ export async function createInstantiator(options, swift) { bjs["swift_js_closure_unregister"] = function(funcRef) {} }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCaseImport.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCaseImport.js index bde5fc31f..c816b3bf0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCaseImport.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCaseImport.js @@ -14,6 +14,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -45,8 +47,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -54,8 +56,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -80,8 +82,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -149,11 +151,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -239,10 +241,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js index 0a691374b..f744a43f3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js @@ -53,6 +53,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -83,8 +85,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -92,8 +94,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -118,8 +120,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -187,11 +189,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -271,10 +273,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js index 03f0a8d9a..e43b2bcb9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js @@ -34,6 +34,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -64,8 +66,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -73,8 +75,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -99,8 +101,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -168,11 +170,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -252,10 +254,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js index 09e03e44a..fd3640162 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js @@ -84,6 +84,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -459,8 +461,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -468,8 +470,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -494,8 +496,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -563,11 +565,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -626,9 +628,9 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_closure_unregister"] = function(funcRef) {} const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; - TestModule["bjs_takesFeatureFlag"] = function bjs_takesFeatureFlag(flagBytes, flagCount) { + TestModule["bjs_takesFeatureFlag"] = function bjs_takesFeatureFlag(flagWord0, flagWord1, flagWord2) { try { - const string = decodeString(flagBytes, flagCount); + const string = decodeString(flagWord0, flagWord1, flagWord2); imports.takesFeatureFlag(string); } catch (error) { setException(error); @@ -645,10 +647,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionNestedTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionNestedTypes.js index 85cdb44d4..53690ed6a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionNestedTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionNestedTypes.js @@ -25,6 +25,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -110,8 +112,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -119,8 +121,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -145,8 +147,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -228,11 +230,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -300,10 +302,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionOrderIndependence.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionOrderIndependence.js index a9091e925..e5a43fdc2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionOrderIndependence.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionOrderIndependence.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -59,8 +61,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -68,8 +70,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -94,8 +96,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -170,11 +172,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -242,10 +244,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionScopeParity.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionScopeParity.js index 6b8ae44b1..5312f0fbd 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionScopeParity.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionScopeParity.js @@ -13,6 +13,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -55,8 +57,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -64,8 +66,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -90,8 +92,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -166,11 +168,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -242,10 +244,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/FixedWidthIntegers.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/FixedWidthIntegers.js index 56a31b784..af7fa150c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/FixedWidthIntegers.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/FixedWidthIntegers.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -40,8 +42,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -49,8 +51,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -75,8 +77,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -143,11 +145,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -280,10 +282,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js index 529f1772e..e2f71f878 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js @@ -25,6 +25,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -506,8 +508,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -515,8 +517,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -541,8 +543,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -653,11 +655,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -734,10 +736,10 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_genericParse"] = function bjs_genericParse(jsonBytes, jsonCount, tTypeId) { + TestModule["bjs_genericParse"] = function bjs_genericParse(jsonWord0, jsonWord1, jsonWord2, tTypeId) { try { const codecT = __bjs_codecForTypeId(tTypeId); - const string = decodeString(jsonBytes, jsonCount); + const string = decodeString(jsonWord0, jsonWord1, jsonWord2); let ret = imports.genericParse(string); codecT.lower(ret); } catch (error) { @@ -829,11 +831,11 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_GenericPairFactory_init"] = function bjs_GenericPairFactory_init(tagBytes, tagCount, tTypeId, uTypeId) { + TestModule["bjs_GenericPairFactory_init"] = function bjs_GenericPairFactory_init(tagWord0, tagWord1, tagWord2, tTypeId, uTypeId) { try { const codecT = __bjs_codecForTypeId(tTypeId); const codecU = __bjs_codecForTypeId(uTypeId); - const string = decodeString(tagBytes, tagCount); + const string = decodeString(tagWord0, tagWord1, tagWord2); const first = codecT.lift(); const second = codecU.lift(); return swift.memory.retain(new imports.GenericPairFactory(string, first, second)); @@ -938,10 +940,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js index adb70913c..77dcf0f7a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -40,8 +42,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -49,8 +51,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -75,8 +77,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -143,11 +145,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -215,9 +217,9 @@ export async function createInstantiator(options, swift) { return 0 } } - TestModule["bjs_JSConsole_log"] = function bjs_JSConsole_log(self, messageBytes, messageCount) { + TestModule["bjs_JSConsole_log"] = function bjs_JSConsole_log(self, messageWord0, messageWord1, messageWord2) { try { - const string = decodeString(messageBytes, messageCount); + const string = decodeString(messageWord0, messageWord1, messageWord2); swift.memory.getObject(self).log(string); } catch (error) { setException(error); @@ -225,10 +227,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js index 760a6b50c..c5c7221d0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -39,8 +41,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -48,8 +50,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -74,8 +76,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -142,11 +144,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -214,9 +216,9 @@ export async function createInstantiator(options, swift) { return 0 } } - TestModule["bjs_parseInt"] = function bjs_parseInt(stringBytes, stringCount) { + TestModule["bjs_parseInt"] = function bjs_parseInt(stringWord0, stringWord1, stringWord2) { try { - const string = decodeString(stringBytes, stringCount); + const string = decodeString(stringWord0, stringWord1, stringWord2); let ret = globalThis.parseInt(string); return ret; } catch (error) { @@ -224,17 +226,17 @@ export async function createInstantiator(options, swift) { return 0 } } - TestModule["bjs_JSConsole_log"] = function bjs_JSConsole_log(self, messageBytes, messageCount) { + TestModule["bjs_JSConsole_log"] = function bjs_JSConsole_log(self, messageWord0, messageWord1, messageWord2) { try { - const string = decodeString(messageBytes, messageCount); + const string = decodeString(messageWord0, messageWord1, messageWord2); swift.memory.getObject(self).log(string); } catch (error) { setException(error); } } - TestModule["bjs_WebSocket_init"] = function bjs_WebSocket_init(urlBytes, urlCount) { + TestModule["bjs_WebSocket_init"] = function bjs_WebSocket_init(urlWord0, urlWord1, urlWord2) { try { - const string = decodeString(urlBytes, urlCount); + const string = decodeString(urlWord0, urlWord1, urlWord2); return swift.memory.retain(new globalThis.WebSocket(string)); } catch (error) { setException(error); @@ -250,10 +252,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.ConfigPointer.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.ConfigPointer.js index 1e1d14696..f33437e89 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.ConfigPointer.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.ConfigPointer.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -39,8 +41,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -48,8 +50,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -74,8 +76,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -142,11 +144,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -222,10 +224,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.PerClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.PerClass.js index c85aee3af..43901d4a2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.PerClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.PerClass.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -39,8 +41,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -48,8 +50,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -74,8 +76,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -142,11 +144,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -222,10 +224,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.js index c85aee3af..43901d4a2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -39,8 +41,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -48,8 +50,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -74,8 +76,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -142,11 +144,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -222,10 +224,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js index c92ea6ad3..893402b07 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -367,8 +369,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -376,8 +378,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -402,8 +404,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -470,11 +472,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -561,9 +563,9 @@ export async function createInstantiator(options, swift) { return 0 } } - TestModule["bjs_borrowedStringAroundStackParams"] = function bjs_borrowedStringAroundStackParams(sBytes, sCount) { + TestModule["bjs_borrowedStringAroundStackParams"] = function bjs_borrowedStringAroundStackParams(sWord0, sWord1, sWord2) { try { - const string = decodeString(sBytes, sCount); + const string = decodeString(sWord0, sWord1, sWord2); const optValue = __bjs_codec_Optional_Array_Int.lift(); const arrayResult = __bjs_codec_Array_Int.lift(); let ret = imports.borrowedStringAroundStackParams(string, optValue, arrayResult); @@ -575,10 +577,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js index 363f6c595..69a851251 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -403,8 +405,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -412,8 +414,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -438,8 +440,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -514,11 +516,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -587,10 +589,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js index e8fe5ec10..8909352ce 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -40,8 +42,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -49,8 +51,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -75,8 +77,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -143,11 +145,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -296,9 +298,9 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_WeirdNaming_normalProperty_set"] = function bjs_WeirdNaming_normalProperty_set(self, newValueBytes, newValueCount) { + TestModule["bjs_WeirdNaming_normalProperty_set"] = function bjs_WeirdNaming_normalProperty_set(self, newValueWord0, newValueWord1, newValueWord2) { try { - const string = decodeString(newValueBytes, newValueCount); + const string = decodeString(newValueWord0, newValueWord1, newValueWord2); swift.memory.getObject(self).normalProperty = string; } catch (error) { setException(error); @@ -318,9 +320,9 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_WeirdNaming_property_with_spaces_set"] = function bjs_WeirdNaming_property_with_spaces_set(self, newValueBytes, newValueCount) { + TestModule["bjs_WeirdNaming_property_with_spaces_set"] = function bjs_WeirdNaming_property_with_spaces_set(self, newValueWord0, newValueWord1, newValueWord2) { try { - const string = decodeString(newValueBytes, newValueCount); + const string = decodeString(newValueWord0, newValueWord1, newValueWord2); swift.memory.getObject(self)["property with spaces"] = string; } catch (error) { setException(error); @@ -333,25 +335,25 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_WeirdNaming_constructor_set"] = function bjs_WeirdNaming_constructor_set(self, newValueBytes, newValueCount) { + TestModule["bjs_WeirdNaming_constructor_set"] = function bjs_WeirdNaming_constructor_set(self, newValueWord0, newValueWord1, newValueWord2) { try { - const string = decodeString(newValueBytes, newValueCount); + const string = decodeString(newValueWord0, newValueWord1, newValueWord2); swift.memory.getObject(self).constructor = string; } catch (error) { setException(error); } } - TestModule["bjs_WeirdNaming_for_set"] = function bjs_WeirdNaming_for_set(self, newValueBytes, newValueCount) { + TestModule["bjs_WeirdNaming_for_set"] = function bjs_WeirdNaming_for_set(self, newValueWord0, newValueWord1, newValueWord2) { try { - const string = decodeString(newValueBytes, newValueCount); + const string = decodeString(newValueWord0, newValueWord1, newValueWord2); swift.memory.getObject(self).for = string; } catch (error) { setException(error); } } - TestModule["bjs_WeirdNaming_any_set"] = function bjs_WeirdNaming_any_set(self, newValueBytes, newValueCount) { + TestModule["bjs_WeirdNaming_any_set"] = function bjs_WeirdNaming_any_set(self, newValueWord0, newValueWord1, newValueWord2) { try { - const string = decodeString(newValueBytes, newValueCount); + const string = decodeString(newValueWord0, newValueWord1, newValueWord2); swift.memory.getObject(self).Any = string; } catch (error) { setException(error); @@ -388,10 +390,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js index 15b48d4b9..0c0f030f7 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -40,8 +42,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -49,8 +51,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -75,8 +77,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -143,11 +145,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -215,9 +217,9 @@ export async function createInstantiator(options, swift) { return 0 } } - TestModule["bjs_Greeter_init"] = function bjs_Greeter_init(nameBytes, nameCount) { + TestModule["bjs_Greeter_init"] = function bjs_Greeter_init(nameWord0, nameWord1, nameWord2) { try { - const string = decodeString(nameBytes, nameCount); + const string = decodeString(nameWord0, nameWord1, nameWord2); return swift.memory.retain(new imports.Greeter(string)); } catch (error) { setException(error); @@ -242,9 +244,9 @@ export async function createInstantiator(options, swift) { return 0 } } - TestModule["bjs_Greeter_name_set"] = function bjs_Greeter_name_set(self, newValueBytes, newValueCount) { + TestModule["bjs_Greeter_name_set"] = function bjs_Greeter_name_set(self, newValueWord0, newValueWord1, newValueWord2) { try { - const string = decodeString(newValueBytes, newValueCount); + const string = decodeString(newValueWord0, newValueWord1, newValueWord2); swift.memory.getObject(self).name = string; } catch (error) { setException(error); @@ -259,9 +261,9 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_Greeter_changeName"] = function bjs_Greeter_changeName(self, nameBytes, nameCount) { + TestModule["bjs_Greeter_changeName"] = function bjs_Greeter_changeName(self, nameWord0, nameWord1, nameWord2) { try { - const string = decodeString(nameBytes, nameCount); + const string = decodeString(nameWord0, nameWord1, nameWord2); swift.memory.getObject(self).changeName(string); } catch (error) { setException(error); @@ -287,10 +289,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js index 5eaba3c8f..f730efb98 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -40,8 +42,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -49,8 +51,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -75,8 +77,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -143,11 +145,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -270,10 +272,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModule.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModule.js index 6d1b1b6fb..23a5b1635 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModule.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModule.js @@ -15,6 +15,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -45,8 +47,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -54,8 +56,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -80,8 +82,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -148,11 +150,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -229,9 +231,9 @@ export async function createInstantiator(options, swift) { return 0 } } - TestModule["bjs_nodeBasename"] = function bjs_nodeBasename(pathBytes, pathCount) { + TestModule["bjs_nodeBasename"] = function bjs_nodeBasename(pathWord0, pathWord1, pathWord2) { try { - const string = decodeString(pathBytes, pathCount); + const string = decodeString(pathWord0, pathWord1, pathWord2); let ret = __bjs_import_3_basename(string); tmpRetBytes = textEncoder.encode(ret); return tmpRetBytes.length; @@ -239,9 +241,9 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_nodeDirname"] = function bjs_nodeDirname(pathBytes, pathCount) { + TestModule["bjs_nodeDirname"] = function bjs_nodeDirname(pathWord0, pathWord1, pathWord2) { try { - const string = decodeString(pathBytes, pathCount); + const string = decodeString(pathWord0, pathWord1, pathWord2); let ret = __bjs_import_3_dirname(string); tmpRetBytes = textEncoder.encode(ret); return tmpRetBytes.length; @@ -295,10 +297,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModuleFallback.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModuleFallback.js index 9428698be..55ef14aa6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModuleFallback.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModuleFallback.js @@ -12,6 +12,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -42,8 +44,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -51,8 +53,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -77,8 +79,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -145,11 +147,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -226,10 +228,10 @@ export async function createInstantiator(options, swift) { return 0 } } - TestModule["bjs_joinPaths"] = function bjs_joinPaths(lhsBytes, lhsCount, rhsBytes, rhsCount) { + TestModule["bjs_joinPaths"] = function bjs_joinPaths(lhsWord0, lhsWord1, lhsWord2, rhsWord0, rhsWord1, rhsWord2) { try { - const string = decodeString(lhsBytes, lhsCount); - const string1 = decodeString(rhsBytes, rhsCount); + const string = decodeString(lhsWord0, lhsWord1, lhsWord2); + const string1 = decodeString(rhsWord0, rhsWord1, rhsWord2); let ret = __bjs_import_0_join(string, string1); tmpRetBytes = textEncoder.encode(ret); return tmpRetBytes.length; @@ -239,10 +241,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportModule.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportModule.js index aacf5e61a..589f570cf 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportModule.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportModule.js @@ -12,6 +12,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -42,8 +44,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -51,8 +53,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -77,8 +79,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -145,11 +147,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -279,10 +281,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameOverride.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameOverride.js index 68ac11976..16219c83c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameOverride.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameOverride.js @@ -14,6 +14,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -61,8 +63,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -70,8 +72,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -96,8 +98,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -172,11 +174,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -244,10 +246,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameTypes.js index fb061d342..ad3e9096e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameTypes.js @@ -14,6 +14,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -44,8 +46,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -53,8 +55,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -79,8 +81,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -148,11 +150,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -220,10 +222,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSTypedArrayTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSTypedArrayTypes.js index f02f6bcf2..f1ffa766f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSTypedArrayTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSTypedArrayTypes.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -39,8 +41,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -48,8 +50,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -74,8 +76,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -142,11 +144,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -206,10 +208,161 @@ export async function createInstantiator(options, swift) { bjs["swift_js_closure_unregister"] = function(funcRef) {} }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js index 9fe12ff47..99742f97b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -366,8 +368,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -375,8 +377,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -401,8 +403,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -469,11 +471,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -563,10 +565,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js index 5db38dde5..bed72152c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -39,8 +41,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -48,8 +50,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -74,8 +76,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -142,11 +144,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -214,10 +216,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js index 66818952b..75697b834 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -39,8 +41,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -48,8 +50,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -74,8 +76,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -142,11 +144,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -222,10 +224,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js index a732808a6..c6f2fdffa 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -39,8 +41,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -48,8 +50,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -74,8 +76,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -142,11 +144,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -214,10 +216,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NamespacedClassSignature.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NamespacedClassSignature.js index 082d85f65..79519e8f1 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NamespacedClassSignature.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NamespacedClassSignature.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -42,7 +44,7 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, state.file >>> 0); let length = 0; while (bytes[length] !== 0) { length += 1; } - const fileID = decodeString(state.file, length); + const fileID = decodeUTF8(state.file, length); throw new Error(`Attempted to call a released JSTypedClosure created at ${fileID}:${state.line}`); } return func(...args); @@ -64,8 +66,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -73,8 +75,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -99,8 +101,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -167,11 +169,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -266,10 +268,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js index ea49220de..2e2667caa 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -374,8 +376,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -383,8 +385,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -409,8 +411,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -477,11 +479,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -561,10 +563,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js index 25bd44d05..33d18909a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -374,8 +376,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -383,8 +385,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -409,8 +411,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -477,11 +479,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -561,10 +563,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedType.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedType.js index f57c4007b..f46e610cd 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedType.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedType.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -64,8 +66,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -73,8 +75,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -99,8 +101,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -182,11 +184,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -258,10 +260,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedTypeNameCollision.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedTypeNameCollision.js index 1f4400ce9..332fc4e42 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedTypeNameCollision.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedTypeNameCollision.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -60,8 +62,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -69,8 +71,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -95,8 +97,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -178,11 +180,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -242,10 +244,161 @@ export async function createInstantiator(options, swift) { bjs["swift_js_closure_unregister"] = function(funcRef) {} }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js index b63f360e9..57c49fd4c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -390,8 +392,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -399,8 +401,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -425,8 +427,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -493,11 +495,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -568,18 +570,18 @@ export async function createInstantiator(options, swift) { return swift.memory.retain(obj); }; const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; - TestModule["bjs_WithOptionalJSClass_init"] = function bjs_WithOptionalJSClass_init(valueOrNullIsSome, valueOrNullBytes, valueOrNullCount, valueOrUndefinedIsSome, valueOrUndefinedBytes, valueOrUndefinedCount) { + TestModule["bjs_WithOptionalJSClass_init"] = function bjs_WithOptionalJSClass_init(valueOrNullIsSome, valueOrNullWord0, valueOrNullWord1, valueOrNullWord2, valueOrUndefinedIsSome, valueOrUndefinedWord0, valueOrUndefinedWord1, valueOrUndefinedWord2) { try { let optResult; if (valueOrNullIsSome) { - const string = decodeString(valueOrNullBytes, valueOrNullCount); + const string = decodeString(valueOrNullWord0, valueOrNullWord1, valueOrNullWord2); optResult = string; } else { optResult = null; } let optResult1; if (valueOrUndefinedIsSome) { - const string1 = decodeString(valueOrUndefinedBytes, valueOrUndefinedCount); + const string1 = decodeString(valueOrUndefinedWord0, valueOrUndefinedWord1, valueOrUndefinedWord2); optResult1 = string1; } else { optResult1 = undefined; @@ -670,11 +672,11 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_WithOptionalJSClass_stringOrNull_set"] = function bjs_WithOptionalJSClass_stringOrNull_set(self, newValueIsSome, newValueBytes, newValueCount) { + TestModule["bjs_WithOptionalJSClass_stringOrNull_set"] = function bjs_WithOptionalJSClass_stringOrNull_set(self, newValueIsSome, newValueWord0, newValueWord1, newValueWord2) { try { let optResult; if (newValueIsSome) { - const string = decodeString(newValueBytes, newValueCount); + const string = decodeString(newValueWord0, newValueWord1, newValueWord2); optResult = string; } else { optResult = null; @@ -684,11 +686,11 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_WithOptionalJSClass_stringOrUndefined_set"] = function bjs_WithOptionalJSClass_stringOrUndefined_set(self, newValueIsSome, newValueBytes, newValueCount) { + TestModule["bjs_WithOptionalJSClass_stringOrUndefined_set"] = function bjs_WithOptionalJSClass_stringOrUndefined_set(self, newValueIsSome, newValueWord0, newValueWord1, newValueWord2) { try { let optResult; if (newValueIsSome) { - const string = decodeString(newValueBytes, newValueCount); + const string = decodeString(newValueWord0, newValueWord1, newValueWord2); optResult = string; } else { optResult = undefined; @@ -747,11 +749,11 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_WithOptionalJSClass_roundTripStringOrNull"] = function bjs_WithOptionalJSClass_roundTripStringOrNull(self, valueIsSome, valueBytes, valueCount) { + TestModule["bjs_WithOptionalJSClass_roundTripStringOrNull"] = function bjs_WithOptionalJSClass_roundTripStringOrNull(self, valueIsSome, valueWord0, valueWord1, valueWord2) { try { let optResult; if (valueIsSome) { - const string = decodeString(valueBytes, valueCount); + const string = decodeString(valueWord0, valueWord1, valueWord2); optResult = string; } else { optResult = null; @@ -763,11 +765,11 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_WithOptionalJSClass_roundTripStringOrUndefined"] = function bjs_WithOptionalJSClass_roundTripStringOrUndefined(self, valueIsSome, valueBytes, valueCount) { + TestModule["bjs_WithOptionalJSClass_roundTripStringOrUndefined"] = function bjs_WithOptionalJSClass_roundTripStringOrUndefined(self, valueIsSome, valueWord0, valueWord1, valueWord2) { try { let optResult; if (valueIsSome) { - const string = decodeString(valueBytes, valueCount); + const string = decodeString(valueWord0, valueWord1, valueWord2); optResult = string; } else { optResult = undefined; @@ -843,10 +845,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js index d4480a65c..a25de5e29 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -40,8 +42,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -49,8 +51,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -75,8 +77,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -143,11 +145,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -215,10 +217,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js index e9b298fb2..2a92af613 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -40,8 +42,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -49,8 +51,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -75,8 +77,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -143,11 +145,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -226,10 +228,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js index beb9417df..39677e821 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -39,8 +41,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -48,8 +50,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -74,8 +76,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -142,11 +144,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -214,10 +216,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js index f0c2d3fae..192e93d8e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js @@ -33,6 +33,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -434,8 +436,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -443,8 +445,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -469,8 +471,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -538,11 +540,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -650,11 +652,11 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_MyViewControllerDelegate_optionalName_set"] = function bjs_MyViewControllerDelegate_optionalName_set(self, valueIsSome, valueBytes, valueCount) { + TestModule["bjs_MyViewControllerDelegate_optionalName_set"] = function bjs_MyViewControllerDelegate_optionalName_set(self, valueIsSome, valueWord0, valueWord1, valueWord2) { try { let optResult; if (valueIsSome) { - const string = decodeString(valueBytes, valueCount); + const string = decodeString(valueWord0, valueWord1, valueWord2); optResult = string; } else { optResult = null; @@ -672,11 +674,11 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_MyViewControllerDelegate_optionalRawEnum_set"] = function bjs_MyViewControllerDelegate_optionalRawEnum_set(self, valueIsSome, valueBytes, valueCount) { + TestModule["bjs_MyViewControllerDelegate_optionalRawEnum_set"] = function bjs_MyViewControllerDelegate_optionalRawEnum_set(self, valueIsSome, valueWord0, valueWord1, valueWord2) { try { let optResult; if (valueIsSome) { - const string = decodeString(valueBytes, valueCount); + const string = decodeString(valueWord0, valueWord1, valueWord2); optResult = string; } else { optResult = null; @@ -695,9 +697,9 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_MyViewControllerDelegate_rawStringEnum_set"] = function bjs_MyViewControllerDelegate_rawStringEnum_set(self, valueBytes, valueCount) { + TestModule["bjs_MyViewControllerDelegate_rawStringEnum_set"] = function bjs_MyViewControllerDelegate_rawStringEnum_set(self, valueWord0, valueWord1, valueWord2) { try { - const string = decodeString(valueBytes, valueCount); + const string = decodeString(valueWord0, valueWord1, valueWord2); swift.memory.getObject(self).rawStringEnum = string; } catch (error) { setException(error); @@ -818,9 +820,9 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_MyViewControllerDelegate_onValueChanged"] = function bjs_MyViewControllerDelegate_onValueChanged(self, valueBytes, valueCount) { + TestModule["bjs_MyViewControllerDelegate_onValueChanged"] = function bjs_MyViewControllerDelegate_onValueChanged(self, valueWord0, valueWord1, valueWord2) { try { - const string = decodeString(valueBytes, valueCount); + const string = decodeString(valueWord0, valueWord1, valueWord2); swift.memory.getObject(self).onValueChanged(string); } catch (error) { setException(error); @@ -835,10 +837,10 @@ export async function createInstantiator(options, swift) { return 0 } } - TestModule["bjs_MyViewControllerDelegate_onLabelUpdated"] = function bjs_MyViewControllerDelegate_onLabelUpdated(self, prefixBytes, prefixCount, suffixBytes, suffixCount) { + TestModule["bjs_MyViewControllerDelegate_onLabelUpdated"] = function bjs_MyViewControllerDelegate_onLabelUpdated(self, prefixWord0, prefixWord1, prefixWord2, suffixWord0, suffixWord1, suffixWord2) { try { - const string = decodeString(prefixBytes, prefixCount); - const string1 = decodeString(suffixBytes, suffixCount); + const string = decodeString(prefixWord0, prefixWord1, prefixWord2); + const string1 = decodeString(suffixWord0, suffixWord1, suffixWord2); swift.memory.getObject(self).onLabelUpdated(string, string1); } catch (error) { setException(error); @@ -913,10 +915,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js index eed26c581..aab8103f5 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -42,7 +44,7 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, state.file >>> 0); let length = 0; while (bytes[length] !== 0) { length += 1; } - const fileID = decodeString(state.file, length); + const fileID = decodeUTF8(state.file, length); throw new Error(`Attempted to call a released JSTypedClosure created at ${fileID}:${state.line}`); } return func(...args); @@ -64,8 +66,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -73,8 +75,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -99,8 +101,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -167,11 +169,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -360,10 +362,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/RelativeQualifiedTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/RelativeQualifiedTypes.js index 2765d709f..a1b8f290c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/RelativeQualifiedTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/RelativeQualifiedTypes.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -82,8 +84,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -91,8 +93,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -117,8 +119,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -221,11 +223,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -297,10 +299,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js index f46f42d10..338cf237d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js @@ -20,6 +20,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -83,8 +85,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -92,8 +94,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -118,8 +120,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -187,11 +189,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -259,10 +261,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js index 37d3415a4..e474c82a6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js @@ -20,6 +20,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -83,8 +85,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -92,8 +94,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -118,8 +120,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -187,11 +189,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -259,10 +261,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js index e2a9093b6..eb1b2d2ef 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js @@ -14,6 +14,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -44,8 +46,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -53,8 +55,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -79,8 +81,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -148,11 +150,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -220,10 +222,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js index f442745e5..95470ed56 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js @@ -14,6 +14,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -44,8 +46,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -53,8 +55,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -79,8 +81,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -148,11 +150,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -220,10 +222,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js index ebddbefd2..c76381468 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -40,8 +42,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -49,8 +51,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -75,8 +77,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -143,11 +145,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -206,17 +208,17 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_closure_unregister"] = function(funcRef) {} const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; - TestModule["bjs_checkString"] = function bjs_checkString(aBytes, aCount) { + TestModule["bjs_checkString"] = function bjs_checkString(aWord0, aWord1, aWord2) { try { - const string = decodeString(aBytes, aCount); + const string = decodeString(aWord0, aWord1, aWord2); imports.checkString(string); } catch (error) { setException(error); } } - TestModule["bjs_checkStringWithLength"] = function bjs_checkStringWithLength(aBytes, aCount, b) { + TestModule["bjs_checkStringWithLength"] = function bjs_checkStringWithLength(aWord0, aWord1, aWord2, b) { try { - const string = decodeString(aBytes, aCount); + const string = decodeString(aWord0, aWord1, aWord2); imports.checkStringWithLength(string, b); } catch (error) { setException(error); @@ -224,10 +226,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js index d2dfa204f..0a0fc1650 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -40,8 +42,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -49,8 +51,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -75,8 +77,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -143,11 +145,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -217,10 +219,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StructWithNestedTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StructWithNestedTypes.js index 9104e2084..7c189df7e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StructWithNestedTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StructWithNestedTypes.js @@ -24,6 +24,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -98,8 +100,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -107,8 +109,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -133,8 +135,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -230,11 +232,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -294,10 +296,161 @@ export async function createInstantiator(options, swift) { bjs["swift_js_closure_unregister"] = function(funcRef) {} }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js index 92ef435fb..293ea56da 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -40,8 +42,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -49,8 +51,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -75,8 +77,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -143,11 +145,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -242,10 +244,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js index 279a9d3c6..dabb7595f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js @@ -39,6 +39,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -395,7 +397,7 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, state.file >>> 0); let length = 0; while (bytes[length] !== 0) { length += 1; } - const fileID = decodeString(state.file, length); + const fileID = decodeUTF8(state.file, length); throw new Error(`Attempted to call a released JSTypedClosure created at ${fileID}:${state.line}`); } return func(...args); @@ -501,8 +503,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -510,8 +512,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -536,8 +538,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -584,9 +586,9 @@ export async function createInstantiator(options, swift) { promise[__bjs_promiseSettlers] = { resolve, reject }; return swift.memory.retain(promise); } - bjs["promise_resolve_TestModule_SS"] = function(promise, valueBytes, valueCount) { + bjs["promise_resolve_TestModule_SS"] = function(promise, valueWord0, valueWord1, valueWord2) { try { - const string = decodeString(valueBytes, valueCount); + const string = decodeString(valueWord0, valueWord1, valueWord2); swift.memory.getObject(promise)[__bjs_promiseSettlers].resolve(string); } catch (error) { setException(error); @@ -644,11 +646,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -733,10 +735,10 @@ export async function createInstantiator(options, swift) { }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModule10HttpStatusO_10HttpStatusO); } - bjs["invoke_js_callback_TestModule_10TestModule5ThemeO_5ThemeO"] = function(callbackId, param0Bytes, param0Count) { + bjs["invoke_js_callback_TestModule_10TestModule5ThemeO_5ThemeO"] = function(callbackId, param0Word0, param0Word1, param0Word2) { try { const callback = swift.memory.getObject(callbackId); - const string = decodeString(param0Bytes, param0Count); + const string = decodeString(param0Word0, param0Word1, param0Word2); let ret = callback(string); tmpRetBytes = textEncoder.encode(ret); return tmpRetBytes.length; @@ -858,10 +860,10 @@ export async function createInstantiator(options, swift) { }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModule9DirectionO_9DirectionO); } - bjs["invoke_js_callback_TestModule_10TestModuleKSS_Sb"] = function(callbackId, param0Bytes, param0Count) { + bjs["invoke_js_callback_TestModule_10TestModuleKSS_Sb"] = function(callbackId, param0Word0, param0Word1, param0Word2) { try { const callback = swift.memory.getObject(callbackId); - const string = decodeString(param0Bytes, param0Count); + const string = decodeString(param0Word0, param0Word1, param0Word2); let ret = callback(string); return ret ? 1 : 0; } catch (error) { @@ -884,10 +886,10 @@ export async function createInstantiator(options, swift) { }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleKSS_Sb); } - bjs["invoke_js_callback_TestModule_10TestModuleKSS_Si"] = function(callbackId, param0Bytes, param0Count) { + bjs["invoke_js_callback_TestModule_10TestModuleKSS_Si"] = function(callbackId, param0Word0, param0Word1, param0Word2) { try { const callback = swift.memory.getObject(callbackId); - const string = decodeString(param0Bytes, param0Count); + const string = decodeString(param0Word0, param0Word1, param0Word2); let ret = callback(string); return ret; } catch (error) { @@ -910,10 +912,10 @@ export async function createInstantiator(options, swift) { }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleKSS_Si); } - bjs["invoke_js_callback_TestModule_10TestModuleSS_SS"] = function(callbackId, param0Bytes, param0Count) { + bjs["invoke_js_callback_TestModule_10TestModuleSS_SS"] = function(callbackId, param0Word0, param0Word1, param0Word2) { try { const callback = swift.memory.getObject(callbackId); - const string = decodeString(param0Bytes, param0Count); + const string = decodeString(param0Word0, param0Word1, param0Word2); let ret = callback(string); tmpRetBytes = textEncoder.encode(ret); return tmpRetBytes.length; @@ -1056,12 +1058,12 @@ export async function createInstantiator(options, swift) { }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSq10HttpStatusO_Sq10HttpStatusO); } - bjs["invoke_js_callback_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO"] = function(callbackId, param0IsSome, param0Bytes, param0Count) { + bjs["invoke_js_callback_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO"] = function(callbackId, param0IsSome, param0Word0, param0Word1, param0Word2) { try { const callback = swift.memory.getObject(callbackId); let optResult; if (param0IsSome) { - const string = decodeString(param0Bytes, param0Count); + const string = decodeString(param0Word0, param0Word1, param0Word2); optResult = string; } else { optResult = null; @@ -1228,12 +1230,12 @@ export async function createInstantiator(options, swift) { }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSq9DirectionO_Sq9DirectionO); } - bjs["invoke_js_callback_TestModule_10TestModuleSqSS_SqSS"] = function(callbackId, param0IsSome, param0Bytes, param0Count) { + bjs["invoke_js_callback_TestModule_10TestModuleSqSS_SqSS"] = function(callbackId, param0IsSome, param0Word0, param0Word1, param0Word2) { try { const callback = swift.memory.getObject(callbackId); let optResult; if (param0IsSome) { - const string = decodeString(param0Bytes, param0Count); + const string = decodeString(param0Word0, param0Word1, param0Word2); optResult = string; } else { optResult = null; @@ -1375,11 +1377,11 @@ export async function createInstantiator(options, swift) { }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSqSi_SqSi); } - bjs["invoke_js_callback_TestModule_10TestModuleYaKSS_SS"] = function(resolveRef, rejectRef, callbackId, param0Bytes, param0Count) { + bjs["invoke_js_callback_TestModule_10TestModuleYaKSS_SS"] = function(resolveRef, rejectRef, callbackId, param0Word0, param0Word1, param0Word2) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); const callback = swift.memory.getObject(callbackId); - const string = decodeString(param0Bytes, param0Count); + const string = decodeString(param0Word0, param0Word1, param0Word2); callback(string).then(resolve, reject); } bjs["make_swift_closure_TestModule_10TestModuleYaKSS_SS"] = function(boxPtr, file, line) { @@ -1420,11 +1422,11 @@ export async function createInstantiator(options, swift) { }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleYaKSb_9APIResultO); } - bjs["invoke_js_callback_TestModule_10TestModuleYaSS_6AnimalV"] = function(resolveRef, rejectRef, callbackId, param0Bytes, param0Count) { + bjs["invoke_js_callback_TestModule_10TestModuleYaSS_6AnimalV"] = function(resolveRef, rejectRef, callbackId, param0Word0, param0Word1, param0Word2) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); const callback = swift.memory.getObject(callbackId); - const string = decodeString(param0Bytes, param0Count); + const string = decodeString(param0Word0, param0Word1, param0Word2); callback(string).then(resolve, reject); } bjs["make_swift_closure_TestModule_10TestModuleYaSS_6AnimalV"] = function(boxPtr, file, line) { @@ -1438,11 +1440,11 @@ export async function createInstantiator(options, swift) { }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleYaSS_6AnimalV); } - bjs["invoke_js_callback_TestModule_10TestModuleYaSS_SS"] = function(resolveRef, rejectRef, callbackId, param0Bytes, param0Count) { + bjs["invoke_js_callback_TestModule_10TestModuleYaSS_SS"] = function(resolveRef, rejectRef, callbackId, param0Word0, param0Word1, param0Word2) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); const callback = swift.memory.getObject(callbackId); - const string = decodeString(param0Bytes, param0Count); + const string = decodeString(param0Word0, param0Word1, param0Word2); callback(string).then(resolve, reject); } bjs["make_swift_closure_TestModule_10TestModuleYaSS_SS"] = function(boxPtr, file, line) { @@ -1522,10 +1524,10 @@ export async function createInstantiator(options, swift) { }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModules9APIResultO_y); } - bjs["invoke_js_callback_TestModule_10TestModulesSS_y"] = function(callbackId, param0Bytes, param0Count) { + bjs["invoke_js_callback_TestModule_10TestModulesSS_y"] = function(callbackId, param0Word0, param0Word1, param0Word2) { try { const callback = swift.memory.getObject(callbackId); - const string = decodeString(param0Bytes, param0Count); + const string = decodeString(param0Word0, param0Word1, param0Word2); callback(string); } catch (error) { setException(error); @@ -1559,10 +1561,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js index 96c78dd22..0a6690be9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -131,7 +133,7 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, state.file >>> 0); let length = 0; while (bytes[length] !== 0) { length += 1; } - const fileID = decodeString(state.file, length); + const fileID = decodeUTF8(state.file, length); throw new Error(`Attempted to call a released JSTypedClosure created at ${fileID}:${state.line}`); } return func(...args); @@ -154,8 +156,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -163,8 +165,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -189,8 +191,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -229,9 +231,9 @@ export async function createInstantiator(options, swift) { promise[__bjs_promiseSettlers] = { resolve, reject }; return swift.memory.retain(promise); } - bjs["promise_resolve_TestModule_SS"] = function(promise, valueBytes, valueCount) { + bjs["promise_resolve_TestModule_SS"] = function(promise, valueWord0, valueWord1, valueWord2) { try { - const string = decodeString(valueBytes, valueCount); + const string = decodeString(valueWord0, valueWord1, valueWord2); swift.memory.getObject(promise)[__bjs_promiseSettlers].resolve(string); } catch (error) { setException(error); @@ -273,11 +275,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -339,10 +341,10 @@ export async function createInstantiator(options, swift) { const func = swift.memory.getObject(funcRef); func.__unregister(); } - bjs["invoke_js_callback_TestModule_10TestModuleKSS_Sb"] = function(callbackId, param0Bytes, param0Count) { + bjs["invoke_js_callback_TestModule_10TestModuleKSS_Sb"] = function(callbackId, param0Word0, param0Word1, param0Word2) { try { const callback = swift.memory.getObject(callbackId); - const string = decodeString(param0Bytes, param0Count); + const string = decodeString(param0Word0, param0Word1, param0Word2); let ret = callback(string); return ret ? 1 : 0; } catch (error) { @@ -388,11 +390,11 @@ export async function createInstantiator(options, swift) { }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSi_Si); } - bjs["invoke_js_callback_TestModule_10TestModuleYaKSS_SS"] = function(resolveRef, rejectRef, callbackId, param0Bytes, param0Count) { + bjs["invoke_js_callback_TestModule_10TestModuleYaKSS_SS"] = function(resolveRef, rejectRef, callbackId, param0Word0, param0Word1, param0Word2) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); const callback = swift.memory.getObject(callbackId); - const string = decodeString(param0Bytes, param0Count); + const string = decodeString(param0Word0, param0Word1, param0Word2); callback(string).then(resolve, reject); } bjs["make_swift_closure_TestModule_10TestModuleYaKSS_SS"] = function(boxPtr, file, line) { @@ -434,10 +436,10 @@ export async function createInstantiator(options, swift) { }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModules7JSValueV_y); } - bjs["invoke_js_callback_TestModule_10TestModulesSS_y"] = function(callbackId, param0Bytes, param0Count) { + bjs["invoke_js_callback_TestModule_10TestModulesSS_y"] = function(callbackId, param0Word0, param0Word1, param0Word2) { try { const callback = swift.memory.getObject(callbackId); - const string = decodeString(param0Bytes, param0Count); + const string = decodeString(param0Word0, param0Word1, param0Word2); callback(string); } catch (error) { setException(error); @@ -481,10 +483,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js index 0bfd7c2e2..e336f8911 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js @@ -14,6 +14,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -544,8 +546,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -553,8 +555,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -579,8 +581,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -704,11 +706,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -776,10 +778,161 @@ export async function createInstantiator(options, swift) { }; }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js index 134d7c28e..ff953c9a3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -385,8 +387,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -394,8 +396,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -420,8 +422,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -496,11 +498,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -579,10 +581,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftTypedClosureAccess.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftTypedClosureAccess.js index 500a005a3..8cec87d6e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftTypedClosureAccess.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftTypedClosureAccess.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -42,7 +44,7 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, state.file >>> 0); let length = 0; while (bytes[length] !== 0) { length += 1; } - const fileID = decodeString(state.file, length); + const fileID = decodeUTF8(state.file, length); throw new Error(`Attempted to call a released JSTypedClosure created at ${fileID}:${state.line}`); } return func(...args); @@ -64,8 +66,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -73,8 +75,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -99,8 +101,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -167,11 +169,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -324,10 +326,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js index 58ff6a85a..40bf7e8c2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -39,8 +41,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -48,8 +50,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -74,8 +76,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -142,11 +144,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -206,10 +208,161 @@ export async function createInstantiator(options, swift) { bjs["swift_js_closure_unregister"] = function(funcRef) {} }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js index 416e5c281..435415b0f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -56,8 +58,8 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -65,8 +67,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -91,8 +93,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -167,11 +169,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -231,10 +233,161 @@ export async function createInstantiator(options, swift) { bjs["swift_js_closure_unregister"] = function(funcRef) {} }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js index 81b09eaf4..ce27ff522 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js @@ -9,6 +9,8 @@ export async function createInstantiator(options, swift) { let memory; let setException; let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); const textDecoder = new TextDecoder("utf-8"); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; @@ -40,8 +42,8 @@ export async function createInstantiator(options, swift) { bjs = {}; importObject["bjs"] = bjs; const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - tmpRetString = decodeString(ptr, len); + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); @@ -49,8 +51,8 @@ export async function createInstantiator(options, swift) { const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); bytes.set(source); } - bjs["swift_js_make_js_string"] = function(ptr, len) { - return swift.memory.retain(decodeString(ptr, len)); + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); } bjs["swift_js_init_memory_with_result"] = function(ptr, len) { const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); @@ -75,8 +77,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_f64"] = function(v) { f64Stack.push(v); } - bjs["swift_js_push_string"] = function(ptr, len) { - const value = decodeString(ptr, len); + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); strStack.push(value); } bjs["swift_js_pop_i32"] = function() { @@ -143,11 +145,11 @@ export async function createInstantiator(options, swift) { tmpRetOptionalDouble = value; } } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { if (isSome === 0) { tmpRetString = null; } else { - tmpRetString = decodeString(ptr, len); + tmpRetString = decodeString(word0, word1, word2); } } bjs["swift_js_return_optional_object"] = function(isSome, objectId) { @@ -215,10 +217,161 @@ export async function createInstantiator(options, swift) { } }, setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); instance = i; memory = instance.exports.memory; - decodeString = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const start = byteIndex; + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + // Match TextDecoder: consume exactly one leading UTF-8 BOM. + if (start === 0 && codePoint === 0xfeff) continue; + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) diff --git a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift index 6946d6a59..dd5e1e970 100644 --- a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift +++ b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift @@ -452,7 +452,7 @@ extension _BridgedSwiftAlias where JSRepresentation: _BridgedSwiftAssociatedValu extension _BridgedSwiftAlias where JSRepresentation == String { // MARK: ImportTS - @_spi(BridgeJS) public consuming func bridgeJSWithLoweredParameter(_ body: (Int32, Int32) -> T) -> T { + @_spi(BridgeJS) public consuming func bridgeJSWithLoweredParameter(_ body: (Int32, Int32, Int32) -> T) -> T { bridgeToJS().bridgeJSWithLoweredParameter(body) } @_spi(BridgeJS) public static func bridgeJSLiftReturn(_ bytesCount: Int32) -> Self { @@ -476,7 +476,7 @@ extension _BridgedSwiftAlias where JSRepresentation == String { extension _BridgedAsOptional where Wrapped: _BridgedSwiftAlias, Wrapped.JSRepresentation == String { @_spi(BridgeJS) public consuming func bridgeJSWithLoweredParameter( - _ body: (Int32, Int32, Int32) -> T + _ body: (Int32, Int32, Int32, Int32) -> T ) -> T { asOptional.map { $0.bridgeToJS() }.bridgeJSWithLoweredParameter(body) } @@ -798,12 +798,29 @@ extension Double: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType, _BridgedSwiftS extension String: _BridgedSwiftStackType { public typealias StackLiftResult = String + /// Lends the three wasm32 `String` words to `body` for the duration of a synchronous JS call. + /// + /// The 12-byte layout is a Swift stdlib implementation detail. JS interprets small-string + /// flags in `word2` and, for large strings, UTF-8 at `word1 + 20` (`nativeBias` on 32-bit). + @inline(__always) + fileprivate consuming func withBridgeJSRawWords(_ body: (Int32, Int32, Int32) -> Result) -> Result { + #if arch(wasm32) + return withUnsafeBytes(of: self) { bytes in + precondition(bytes.count == 12, "BridgeJS expects the 12-byte wasm32 String layout") + let word0 = bytes.load(fromByteOffset: 0, as: Int32.self) + let word1 = bytes.load(fromByteOffset: 4, as: Int32.self) + let word2 = bytes.load(fromByteOffset: 8, as: Int32.self) + return body(word0, word1, word2) + } + #else + _onlyAvailableOnWasm() + #endif + } + // MARK: ImportTS - @_spi(BridgeJS) public consuming func bridgeJSWithLoweredParameter(_ body: (Int32, Int32) -> T) -> T { - return self.withUTF8 { b in - body(Int32(bitPattern: UInt32(UInt(bitPattern: b.baseAddress))), Int32(b.count)) - } + @_spi(BridgeJS) public consuming func bridgeJSWithLoweredParameter(_ body: (Int32, Int32, Int32) -> T) -> T { + withBridgeJSRawWords(body) } @_spi(BridgeJS) public static func bridgeJSLiftReturn(_ bytesCount: Int32) -> String { @@ -835,14 +852,14 @@ extension String: _BridgedSwiftStackType { } @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { - return self.withUTF8 { ptr in - _swift_js_return_string(ptr.baseAddress, Int32(ptr.count)) + withBridgeJSRawWords { word0, word1, word2 in + _swift_js_return_string(word0, word1, word2) } } @_spi(BridgeJS) public consuming func bridgeJSStackPush() { - self.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) + withBridgeJSRawWords { word0, word1, word2 in + _swift_js_push_string(word0, word1, word2) } } } @@ -1290,7 +1307,7 @@ extension _BridgedSwiftStruct { extension _BridgedSwiftEnumNoPayload where Self: RawRepresentable, RawValue == String { // MARK: ImportTS - @_spi(BridgeJS) public consuming func bridgeJSWithLoweredParameter(_ body: (Int32, Int32) -> T) -> T { + @_spi(BridgeJS) public consuming func bridgeJSWithLoweredParameter(_ body: (Int32, Int32, Int32) -> T) -> T { rawValue.bridgeJSWithLoweredParameter(body) } @@ -1348,15 +1365,15 @@ private func _swift_js_init_memory_extern(_ sourceId: Int32, _ ptr: UnsafeMutabl #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_push_string") -private func _swift_js_push_string_extern(_ ptr: UnsafePointer?, _ len: Int32) +private func _swift_js_push_string_extern(_ word0: Int32, _ word1: Int32, _ word2: Int32) #else -private func _swift_js_push_string_extern(_ ptr: UnsafePointer?, _ len: Int32) { +private func _swift_js_push_string_extern(_ word0: Int32, _ word1: Int32, _ word2: Int32) { _onlyAvailableOnWasm() } #endif -@_spi(BridgeJS) @inline(never) public func _swift_js_push_string(_ ptr: UnsafePointer?, _ len: Int32) { - _swift_js_push_string_extern(ptr, len) +@_spi(BridgeJS) @inline(never) public func _swift_js_push_string(_ word0: Int32, _ word1: Int32, _ word2: Int32) { + _swift_js_push_string_extern(word0, word1, word2) } #if arch(wasm32) @@ -1542,15 +1559,15 @@ extension UInt: _BridgedNumericArray { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_make_js_string") -private func _swift_js_make_js_string_extern(_ ptr: UnsafePointer?, _ len: Int32) -> Int32 +private func _swift_js_make_js_string_extern(_ word0: Int32, _ word1: Int32, _ word2: Int32) -> Int32 #else -/// Creates a JavaScript string from UTF-8 data in WebAssembly memory -private func _swift_js_make_js_string_extern(_ ptr: UnsafePointer?, _ len: Int32) -> Int32 { +/// Creates a JavaScript string from the wasm32 Swift `String` layout words +private func _swift_js_make_js_string_extern(_ word0: Int32, _ word1: Int32, _ word2: Int32) -> Int32 { _onlyAvailableOnWasm() } #endif -@inline(never) func _swift_js_make_js_string(_ ptr: UnsafePointer?, _ len: Int32) -> Int32 { - _swift_js_make_js_string_extern(ptr, len) +@inline(never) func _swift_js_make_js_string(_ word0: Int32, _ word1: Int32, _ word2: Int32) -> Int32 { + _swift_js_make_js_string_extern(word0, word1, word2) } #if arch(wasm32) @@ -1568,15 +1585,15 @@ private func _swift_js_init_memory_with_result_extern(_ ptr: UnsafePointer?, _ len: Int32) +private func _swift_js_return_string_extern(_ word0: Int32, _ word1: Int32, _ word2: Int32) #else /// Write a string to reserved string storage to be returned to JavaScript -private func _swift_js_return_string_extern(_ ptr: UnsafePointer?, _ len: Int32) { +private func _swift_js_return_string_extern(_ word0: Int32, _ word1: Int32, _ word2: Int32) { _onlyAvailableOnWasm() } #endif -@inline(never) func _swift_js_return_string(_ ptr: UnsafePointer?, _ len: Int32) { - _swift_js_return_string_extern(ptr, len) +@inline(never) func _swift_js_return_string(_ word0: Int32, _ word1: Int32, _ word2: Int32) { + _swift_js_return_string_extern(word0, word1, word2) } #if arch(wasm32) @@ -1657,15 +1674,15 @@ private func _swift_js_get_optional_string_extern() -> Int32 { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_return_optional_string") -private func _swift_js_return_optional_string_extern(_ isSome: Int32, _ ptr: UnsafePointer?, _ len: Int32) +private func _swift_js_return_optional_string_extern(_ isSome: Int32, _ word0: Int32, _ word1: Int32, _ word2: Int32) #else /// Write an optional string to reserved string storage to be returned to JavaScript -private func _swift_js_return_optional_string_extern(_ isSome: Int32, _ ptr: UnsafePointer?, _ len: Int32) { +private func _swift_js_return_optional_string_extern(_ isSome: Int32, _ word0: Int32, _ word1: Int32, _ word2: Int32) { _onlyAvailableOnWasm() } #endif -@inline(never) func _swift_js_return_optional_string(_ isSome: Int32, _ ptr: UnsafePointer?, _ len: Int32) { - _swift_js_return_optional_string_extern(isSome, ptr, len) +@inline(never) func _swift_js_return_optional_string(_ isSome: Int32, _ word0: Int32, _ word1: Int32, _ word2: Int32) { + _swift_js_return_optional_string_extern(isSome, word0, word1, word2) } #if arch(wasm32) @@ -2156,14 +2173,14 @@ extension _BridgedAsOptional where Wrapped == Bool { extension _BridgedAsOptional where Wrapped == String { @_spi(BridgeJS) @_transparent public consuming func bridgeJSWithLoweredParameter( - _ body: (Int32, Int32, Int32) -> T + _ body: (Int32, Int32, Int32, Int32) -> T ) -> T { switch asOptional { case .none: - return body(0, 0, 0) + return body(0, 0, 0, 0) case .some(let value): - return value.bridgeJSWithLoweredParameter { bytes, count in - return body(1, bytes, count) + return value.bridgeJSWithLoweredParameter { word0, word1, word2 in + return body(1, word0, word1, word2) } } } @@ -2194,10 +2211,10 @@ extension _BridgedAsOptional where Wrapped == String { @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { switch asOptional { case .none: - _swift_js_return_optional_string(0, nil, 0) - case .some(var value): - value.withUTF8 { ptr in - _swift_js_return_optional_string(1, ptr.baseAddress, Int32(ptr.count)) + _swift_js_return_optional_string(0, 0, 0, 0) + case .some(let value): + value.withBridgeJSRawWords { word0, word1, word2 in + _swift_js_return_optional_string(1, word0, word1, word2) } } } @@ -2358,14 +2375,14 @@ extension _BridgedAsOptional where Wrapped: _BridgedSwiftCaseEnum { extension _BridgedAsOptional where Wrapped: _BridgedSwiftEnumNoPayload, Wrapped: RawRepresentable, Wrapped.RawValue == String { @_spi(BridgeJS) @_transparent public consuming func bridgeJSWithLoweredParameter( - _ body: (Int32, Int32, Int32) -> T + _ body: (Int32, Int32, Int32, Int32) -> T ) -> T { switch asOptional { case .none: - return body(0, 0, 0) + return body(0, 0, 0, 0) case .some(let wrapped): - return wrapped.bridgeJSWithLoweredParameter { bytes, count in - return body(1, bytes, count) + return wrapped.bridgeJSWithLoweredParameter { word0, word1, word2 in + return body(1, word0, word1, word2) } } } diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index acb3e23f1..52799fa7c 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -202,14 +202,14 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTests13D #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_SS") -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_SS_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_SS_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 #else -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_SS_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_SS_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_SS(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { - return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_SS_extern(callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_SS(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { + return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_SS_extern(callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -229,9 +229,9 @@ private enum _BJS_Closure_20BridgeJSRuntimeTests5ThemeO_SS { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] param0 in #if arch(wasm32) - let ret0 = param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + let ret0 = param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_SS(callbackValue, param0Bytes, param0Length) + let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_SS(callbackValue, param0Word0, param0Word1, param0Word2) return ret } let ret = ret0 @@ -269,14 +269,14 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5Th #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_Sb") -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_Sb_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_Sb_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 #else -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_Sb_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_Sb_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_Sb(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { - return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_Sb_extern(callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_Sb(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { + return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_Sb_extern(callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -296,9 +296,9 @@ private enum _BJS_Closure_20BridgeJSRuntimeTests5ThemeO_Sb { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] param0 in #if arch(wasm32) - let ret0 = param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + let ret0 = param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_Sb(callbackValue, param0Bytes, param0Length) + let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTests5ThemeO_Sb(callbackValue, param0Word0, param0Word1, param0Word2) return ret } let ret = ret0 @@ -846,14 +846,14 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsAl7 #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Sb") -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Sb_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Sb_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 #else -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Sb_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Sb_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Sb(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { - return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Sb_extern(callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Sb(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { + return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Sb_extern(callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -873,9 +873,9 @@ private enum _BJS_Closure_20BridgeJSRuntimeTestsKSS_Sb { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] (param0: String) throws(JSException) -> Bool in #if arch(wasm32) - let ret0 = param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + let ret0 = param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Sb(callbackValue, param0Bytes, param0Length) + let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Sb(callbackValue, param0Word0, param0Word1, param0Word2) return ret } let ret = ret0 @@ -930,14 +930,14 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Si") -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Si_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Si_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 #else -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Si_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Si_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Si(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { - return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Si_extern(callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Si(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { + return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Si_extern(callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -957,9 +957,9 @@ private enum _BJS_Closure_20BridgeJSRuntimeTestsKSS_Si { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] (param0: String) throws(JSException) -> Int in #if arch(wasm32) - let ret0 = param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + let ret0 = param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Si(callbackValue, param0Bytes, param0Length) + let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS_Si(callbackValue, param0Word0, param0Word1, param0Word2) return ret } let ret = ret0 @@ -1014,14 +1014,14 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsKSS #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_7GreeterC") -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_7GreeterC_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> UnsafeMutableRawPointer +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_7GreeterC_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> UnsafeMutableRawPointer #else -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_7GreeterC_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> UnsafeMutableRawPointer { +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_7GreeterC_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> UnsafeMutableRawPointer { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_7GreeterC(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> UnsafeMutableRawPointer { - return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_7GreeterC_extern(callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_7GreeterC(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> UnsafeMutableRawPointer { + return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_7GreeterC_extern(callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -1041,9 +1041,9 @@ private enum _BJS_Closure_20BridgeJSRuntimeTestsSS_7GreeterC { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] param0 in #if arch(wasm32) - let ret0 = param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + let ret0 = param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_7GreeterC(callbackValue, param0Bytes, param0Length) + let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_7GreeterC(callbackValue, param0Word0, param0Word1, param0Word2) return ret } let ret = ret0 @@ -1081,14 +1081,14 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_ #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_SS") -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_SS_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_SS_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 #else -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_SS_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_SS_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_SS(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { - return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_SS_extern(callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_SS(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { + return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_SS_extern(callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -1108,9 +1108,9 @@ private enum _BJS_Closure_20BridgeJSRuntimeTestsSS_SS { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] param0 in #if arch(wasm32) - let ret0 = param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + let ret0 = param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_SS(callbackValue, param0Bytes, param0Length) + let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSS_SS(callbackValue, param0Word0, param0Word1, param0Word2) return ret } let ret = ret0 @@ -1726,14 +1726,14 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSd_ #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSiSSSd_SS") -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSiSSSd_SS_extern(_ callback: Int32, _ param0: Int32, _ param1Bytes: Int32, _ param1Length: Int32, _ param2: Float64) -> Int32 +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSiSSSd_SS_extern(_ callback: Int32, _ param0: Int32, _ param1Word0: Int32, _ param1Word1: Int32, _ param1Word2: Int32, _ param2: Float64) -> Int32 #else -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSiSSSd_SS_extern(_ callback: Int32, _ param0: Int32, _ param1Bytes: Int32, _ param1Length: Int32, _ param2: Float64) -> Int32 { +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSiSSSd_SS_extern(_ callback: Int32, _ param0: Int32, _ param1Word0: Int32, _ param1Word1: Int32, _ param1Word2: Int32, _ param2: Float64) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSiSSSd_SS(_ callback: Int32, _ param0: Int32, _ param1Bytes: Int32, _ param1Length: Int32, _ param2: Float64) -> Int32 { - return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSiSSSd_SS_extern(callback, param0, param1Bytes, param1Length, param2) +@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSiSSSd_SS(_ callback: Int32, _ param0: Int32, _ param1Word0: Int32, _ param1Word1: Int32, _ param1Word2: Int32, _ param2: Float64) -> Int32 { + return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSiSSSd_SS_extern(callback, param0, param1Word0, param1Word1, param1Word2, param2) } #if arch(wasm32) @@ -1753,11 +1753,11 @@ private enum _BJS_Closure_20BridgeJSRuntimeTestsSiSSSd_SS { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] (param0, param1, param2) in #if arch(wasm32) - let ret0 = param1.bridgeJSWithLoweredParameter { (param1Bytes, param1Length) in + let ret0 = param1.bridgeJSWithLoweredParameter { (param1Word0, param1Word1, param1Word2) in let param2Value = param2.bridgeJSLowerParameter() let param0Value = param0.bridgeJSLowerParameter() let callbackValue = callback.bridgeJSLowerParameter() - let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSiSSSd_SS(callbackValue, param0Value, param1Bytes, param1Length, param2Value) + let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSiSSSd_SS(callbackValue, param0Value, param1Word0, param1Word1, param1Word2, param2Value) return ret } let ret = ret0 @@ -2126,14 +2126,14 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq1 #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq5ThemeO_SS") -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq5ThemeO_SS_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq5ThemeO_SS_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 #else -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq5ThemeO_SS_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq5ThemeO_SS_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq5ThemeO_SS(_ callback: Int32, _ param0IsSome: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { - return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq5ThemeO_SS_extern(callback, param0IsSome, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq5ThemeO_SS(_ callback: Int32, _ param0IsSome: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { + return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq5ThemeO_SS_extern(callback, param0IsSome, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -2153,9 +2153,9 @@ private enum _BJS_Closure_20BridgeJSRuntimeTestsSq5ThemeO_SS { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] param0 in #if arch(wasm32) - let ret0 = param0.bridgeJSWithLoweredParameter { (param0IsSome, param0Bytes, param0Length) in + let ret0 = param0.bridgeJSWithLoweredParameter { (param0IsSome, param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq5ThemeO_SS(callbackValue, param0IsSome, param0Bytes, param0Length) + let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq5ThemeO_SS(callbackValue, param0IsSome, param0Word0, param0Word1, param0Word2) return ret } let ret = ret0 @@ -2449,14 +2449,14 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq9 #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSqSS_SS") -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSqSS_SS_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSqSS_SS_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 #else -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSqSS_SS_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSqSS_SS_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSqSS_SS(_ callback: Int32, _ param0IsSome: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Int32 { - return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSqSS_SS_extern(callback, param0IsSome, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSqSS_SS(_ callback: Int32, _ param0IsSome: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Int32 { + return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSqSS_SS_extern(callback, param0IsSome, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -2476,9 +2476,9 @@ private enum _BJS_Closure_20BridgeJSRuntimeTestsSqSS_SS { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] param0 in #if arch(wasm32) - let ret0 = param0.bridgeJSWithLoweredParameter { (param0IsSome, param0Bytes, param0Length) in + let ret0 = param0.bridgeJSWithLoweredParameter { (param0IsSome, param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSqSS_SS(callbackValue, param0IsSome, param0Bytes, param0Length) + let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSqSS_SS(callbackValue, param0IsSome, param0Word0, param0Word1, param0Word2) return ret } let ret = ret0 @@ -2580,14 +2580,14 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSqS #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_SS") -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void #else -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_SS(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { - return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_SS_extern(resolveRef, rejectRef, callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_SS(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_SS_extern(resolveRef, rejectRef, callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -2612,9 +2612,9 @@ private enum _BJS_Closure_20BridgeJSRuntimeTestsYaKSS_SS { }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in - param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_SS(resolveRef, rejectRef, callbackValue, param0Bytes, param0Length) + invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_SS(resolveRef, rejectRef, callbackValue, param0Word0, param0Word1, param0Word2) } } return resolved @@ -2652,14 +2652,14 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaK #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_y") -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_y_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_y_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void #else -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_y_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_y_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_y(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { - return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_y_extern(resolveRef, rejectRef, callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_y(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_y_extern(resolveRef, rejectRef, callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -2684,9 +2684,9 @@ private enum _BJS_Closure_20BridgeJSRuntimeTestsYaKSS_y { }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in - param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_y(resolveRef, rejectRef, callbackValue, param0Bytes, param0Length) + invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaKSS_y(resolveRef, rejectRef, callbackValue, param0Word0, param0Word1, param0Word2) } } #else @@ -2794,14 +2794,14 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaK #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaSS_SS") -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void #else -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaSS_SS_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaSS_SS(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { - return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaSS_SS_extern(resolveRef, rejectRef, callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaSS_SS(_ resolveRef: Int32, _ rejectRef: Int32, _ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaSS_SS_extern(resolveRef, rejectRef, callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -2826,9 +2826,9 @@ private enum _BJS_Closure_20BridgeJSRuntimeTestsYaSS_SS { }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in - param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaSS_SS(resolveRef, rejectRef, callbackValue, param0Bytes, param0Length) + invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaSS_SS(resolveRef, rejectRef, callbackValue, param0Word0, param0Word1, param0Word2) } } return resolved @@ -3008,14 +3008,14 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsYaS #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestss11FeatureFlagO_y") -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestss11FeatureFlagO_y_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestss11FeatureFlagO_y_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void #else -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestss11FeatureFlagO_y_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestss11FeatureFlagO_y_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestss11FeatureFlagO_y(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { - return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestss11FeatureFlagO_y_extern(callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestss11FeatureFlagO_y(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestss11FeatureFlagO_y_extern(callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -3035,9 +3035,9 @@ private enum _BJS_Closure_20BridgeJSRuntimeTestss11FeatureFlagO_y { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] param0 in #if arch(wasm32) - param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestss11FeatureFlagO_y(callbackValue, param0Bytes, param0Length) + invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestss11FeatureFlagO_y(callbackValue, param0Word0, param0Word1, param0Word2) } #else fatalError("Only available on WebAssembly") @@ -3381,14 +3381,14 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestss9D #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSS_y") -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSS_y_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSS_y_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void #else -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSS_y_extern(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSS_y_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSS_y(_ callback: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { - return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSS_y_extern(callback, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSS_y(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSS_y_extern(callback, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -3408,9 +3408,9 @@ private enum _BJS_Closure_20BridgeJSRuntimeTestssSS_y { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] param0 in #if arch(wasm32) - param0.bridgeJSWithLoweredParameter { (param0Bytes, param0Length) in + param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSS_y(callbackValue, param0Bytes, param0Length) + invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSS_y(callbackValue, param0Word0, param0Word1, param0Word2) } #else fatalError("Only available on WebAssembly") @@ -3878,14 +3878,14 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSq #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSqSS_y") -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSqSS_y_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSqSS_y_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void #else -fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSqSS_y_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSqSS_y_extern(_ callback: Int32, _ param0IsSome: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSqSS_y(_ callback: Int32, _ param0IsSome: Int32, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { - return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSqSS_y_extern(callback, param0IsSome, param0Bytes, param0Length) +@inline(never) fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSqSS_y(_ callback: Int32, _ param0IsSome: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + return invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSqSS_y_extern(callback, param0IsSome, param0Word0, param0Word1, param0Word2) } #if arch(wasm32) @@ -3905,9 +3905,9 @@ private enum _BJS_Closure_20BridgeJSRuntimeTestssSqSS_y { let callback = JSObject.bridgeJSLiftParameter(callbackId) return { [callback] param0 in #if arch(wasm32) - param0.bridgeJSWithLoweredParameter { (param0IsSome, param0Bytes, param0Length) in + param0.bridgeJSWithLoweredParameter { (param0IsSome, param0Word0, param0Word1, param0Word2) in let callbackValue = callback.bridgeJSLowerParameter() - invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSqSS_y(callbackValue, param0IsSome, param0Bytes, param0Length) + invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestssSqSS_y(callbackValue, param0IsSome, param0Word0, param0Word1, param0Word2) } #else fatalError("Only available on WebAssembly") @@ -4308,10 +4308,10 @@ extension DataProcessor where Self: _BridgedSwiftProtocolWrapper { } func setLabelElements(_ labelPrefix: String, _ labelSuffix: String) -> Void { - labelPrefix.bridgeJSWithLoweredParameter { (labelPrefixBytes, labelPrefixLength) in - labelSuffix.bridgeJSWithLoweredParameter { (labelSuffixBytes, labelSuffixLength) in + labelPrefix.bridgeJSWithLoweredParameter { (labelPrefixWord0, labelPrefixWord1, labelPrefixWord2) in + labelSuffix.bridgeJSWithLoweredParameter { (labelSuffixWord0, labelSuffixWord1, labelSuffixWord2) in let jsObjectValue = jsObject.bridgeJSLowerParameter() - bjs_DataProcessor_setLabelElements(jsObjectValue, labelPrefixBytes, labelPrefixLength, labelSuffixBytes, labelSuffixLength) + bjs_DataProcessor_setLabelElements(jsObjectValue, labelPrefixWord0, labelPrefixWord1, labelPrefixWord2, labelSuffixWord0, labelSuffixWord1, labelSuffixWord2) } } } @@ -4394,9 +4394,9 @@ extension DataProcessor where Self: _BridgedSwiftProtocolWrapper { return Optional.bridgeJSLiftReturnFromSideChannel() } set { - newValue.bridgeJSWithLoweredParameter { (newValueIsSome, newValueBytes, newValueLength) in + newValue.bridgeJSWithLoweredParameter { (newValueIsSome, newValueWord0, newValueWord1, newValueWord2) in let jsObjectValue = jsObject.bridgeJSLowerParameter() - bjs_DataProcessor_optionalTag_set(jsObjectValue, newValueIsSome, newValueBytes, newValueLength) + bjs_DataProcessor_optionalTag_set(jsObjectValue, newValueIsSome, newValueWord0, newValueWord1, newValueWord2) } } } @@ -4434,9 +4434,9 @@ extension DataProcessor where Self: _BridgedSwiftProtocolWrapper { return Optional.bridgeJSLiftReturnFromSideChannel() } set { - newValue.bridgeJSWithLoweredParameter { (newValueIsSome, newValueBytes, newValueLength) in + newValue.bridgeJSWithLoweredParameter { (newValueIsSome, newValueWord0, newValueWord1, newValueWord2) in let jsObjectValue = jsObject.bridgeJSLowerParameter() - bjs_DataProcessor_optionalTheme_set(jsObjectValue, newValueIsSome, newValueBytes, newValueLength) + bjs_DataProcessor_optionalTheme_set(jsObjectValue, newValueIsSome, newValueWord0, newValueWord1, newValueWord2) } } } @@ -4528,14 +4528,14 @@ fileprivate func bjs_DataProcessor_getValue_extern(_ jsObject: Int32) -> Int32 { #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_setLabelElements") -fileprivate func bjs_DataProcessor_setLabelElements_extern(_ jsObject: Int32, _ labelPrefixBytes: Int32, _ labelPrefixLength: Int32, _ labelSuffixBytes: Int32, _ labelSuffixLength: Int32) -> Void +fileprivate func bjs_DataProcessor_setLabelElements_extern(_ jsObject: Int32, _ labelPrefixWord0: Int32, _ labelPrefixWord1: Int32, _ labelPrefixWord2: Int32, _ labelSuffixWord0: Int32, _ labelSuffixWord1: Int32, _ labelSuffixWord2: Int32) -> Void #else -fileprivate func bjs_DataProcessor_setLabelElements_extern(_ jsObject: Int32, _ labelPrefixBytes: Int32, _ labelPrefixLength: Int32, _ labelSuffixBytes: Int32, _ labelSuffixLength: Int32) -> Void { +fileprivate func bjs_DataProcessor_setLabelElements_extern(_ jsObject: Int32, _ labelPrefixWord0: Int32, _ labelPrefixWord1: Int32, _ labelPrefixWord2: Int32, _ labelSuffixWord0: Int32, _ labelSuffixWord1: Int32, _ labelSuffixWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_DataProcessor_setLabelElements(_ jsObject: Int32, _ labelPrefixBytes: Int32, _ labelPrefixLength: Int32, _ labelSuffixBytes: Int32, _ labelSuffixLength: Int32) -> Void { - return bjs_DataProcessor_setLabelElements_extern(jsObject, labelPrefixBytes, labelPrefixLength, labelSuffixBytes, labelSuffixLength) +@inline(never) fileprivate func bjs_DataProcessor_setLabelElements(_ jsObject: Int32, _ labelPrefixWord0: Int32, _ labelPrefixWord1: Int32, _ labelPrefixWord2: Int32, _ labelSuffixWord0: Int32, _ labelSuffixWord1: Int32, _ labelSuffixWord2: Int32) -> Void { + return bjs_DataProcessor_setLabelElements_extern(jsObject, labelPrefixWord0, labelPrefixWord1, labelPrefixWord2, labelSuffixWord0, labelSuffixWord1, labelSuffixWord2) } #if arch(wasm32) @@ -4684,14 +4684,14 @@ fileprivate func bjs_DataProcessor_optionalTag_get_extern(_ jsObject: Int32) -> #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_optionalTag_set") -fileprivate func bjs_DataProcessor_optionalTag_set_extern(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void +fileprivate func bjs_DataProcessor_optionalTag_set_extern(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void #else -fileprivate func bjs_DataProcessor_optionalTag_set_extern(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { +fileprivate func bjs_DataProcessor_optionalTag_set_extern(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_DataProcessor_optionalTag_set(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { - return bjs_DataProcessor_optionalTag_set_extern(jsObject, newValueIsSome, newValueBytes, newValueLength) +@inline(never) fileprivate func bjs_DataProcessor_optionalTag_set(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { + return bjs_DataProcessor_optionalTag_set_extern(jsObject, newValueIsSome, newValueWord0, newValueWord1, newValueWord2) } #if arch(wasm32) @@ -4756,14 +4756,14 @@ fileprivate func bjs_DataProcessor_optionalTheme_get_extern(_ jsObject: Int32) - #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_optionalTheme_set") -fileprivate func bjs_DataProcessor_optionalTheme_set_extern(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void +fileprivate func bjs_DataProcessor_optionalTheme_set_extern(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void #else -fileprivate func bjs_DataProcessor_optionalTheme_set_extern(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { +fileprivate func bjs_DataProcessor_optionalTheme_set_extern(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_DataProcessor_optionalTheme_set(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { - return bjs_DataProcessor_optionalTheme_set_extern(jsObject, newValueIsSome, newValueBytes, newValueLength) +@inline(never) fileprivate func bjs_DataProcessor_optionalTheme_set(_ jsObject: Int32, _ newValueIsSome: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { + return bjs_DataProcessor_optionalTheme_set_extern(jsObject, newValueIsSome, newValueWord0, newValueWord1, newValueWord2) } #if arch(wasm32) @@ -7672,6 +7672,174 @@ extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { } } +@_expose(wasm, "bjs_StringABIExports_static_echo") +@_cdecl("bjs_StringABIExports_static_echo") +public func _bjs_StringABIExports_static_echo(_ valueBytes: Int32, _ valueLength: Int32) -> Void { + #if arch(wasm32) + let value = String.bridgeJSLiftParameter(valueBytes, valueLength) + let ret = StringABIExports.echo(_: value) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_StringABIExports_static_echoOptional") +@_cdecl("bjs_StringABIExports_static_echoOptional") +public func _bjs_StringABIExports_static_echoOptional(_ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { + #if arch(wasm32) + let value = Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength) + let ret = StringABIExports.echoOptional(_: value) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_StringABIExports_static_echoArray") +@_cdecl("bjs_StringABIExports_static_echoArray") +public func _bjs_StringABIExports_static_echoArray() -> Void { + #if arch(wasm32) + let value = [String].bridgeJSStackPop() + let ret = StringABIExports.echoArray(_: value) + ret.bridgeJSStackPush() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_StringABIExports_static_smallEmpty") +@_cdecl("bjs_StringABIExports_static_smallEmpty") +public func _bjs_StringABIExports_static_smallEmpty() -> Void { + #if arch(wasm32) + let ret = StringABIExports.smallEmpty() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_StringABIExports_static_smallASCII") +@_cdecl("bjs_StringABIExports_static_smallASCII") +public func _bjs_StringABIExports_static_smallASCII() -> Void { + #if arch(wasm32) + let ret = StringABIExports.smallASCII() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_StringABIExports_static_smallEight") +@_cdecl("bjs_StringABIExports_static_smallEight") +public func _bjs_StringABIExports_static_smallEight() -> Void { + #if arch(wasm32) + let ret = StringABIExports.smallEight() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_StringABIExports_static_smallNine") +@_cdecl("bjs_StringABIExports_static_smallNine") +public func _bjs_StringABIExports_static_smallNine() -> Void { + #if arch(wasm32) + let ret = StringABIExports.smallNine() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_StringABIExports_static_smallTen") +@_cdecl("bjs_StringABIExports_static_smallTen") +public func _bjs_StringABIExports_static_smallTen() -> Void { + #if arch(wasm32) + let ret = StringABIExports.smallTen() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_StringABIExports_static_smallUTF8") +@_cdecl("bjs_StringABIExports_static_smallUTF8") +public func _bjs_StringABIExports_static_smallUTF8() -> Void { + #if arch(wasm32) + let ret = StringABIExports.smallUTF8() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_StringABIExports_static_largeImmortal") +@_cdecl("bjs_StringABIExports_static_largeImmortal") +public func _bjs_StringABIExports_static_largeImmortal() -> Void { + #if arch(wasm32) + let ret = StringABIExports.largeImmortal() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_StringABIExports_static_largeImmortalAgain") +@_cdecl("bjs_StringABIExports_static_largeImmortalAgain") +public func _bjs_StringABIExports_static_largeImmortalAgain() -> Void { + #if arch(wasm32) + let ret = StringABIExports.largeImmortalAgain() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_StringABIExports_static_largeDynamic") +@_cdecl("bjs_StringABIExports_static_largeDynamic") +public func _bjs_StringABIExports_static_largeDynamic() -> Void { + #if arch(wasm32) + let ret = StringABIExports.largeDynamic() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_StringABIExports_static_immortalSubstring") +@_cdecl("bjs_StringABIExports_static_immortalSubstring") +public func _bjs_StringABIExports_static_immortalSubstring() -> Void { + #if arch(wasm32) + let ret = StringABIExports.immortalSubstring() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_StringABIExports_static_optionalNone") +@_cdecl("bjs_StringABIExports_static_optionalNone") +public func _bjs_StringABIExports_static_optionalNone() -> Void { + #if arch(wasm32) + let ret = StringABIExports.optionalNone() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_StringABIExports_static_optionalSome") +@_cdecl("bjs_StringABIExports_static_optionalSome") +public func _bjs_StringABIExports_static_optionalSome() -> Void { + #if arch(wasm32) + let ret = StringABIExports.optionalSome() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + extension JSCoordinate: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSStackPop() -> JSCoordinate { let longitude = Double.bridgeJSStackPop() @@ -16234,20 +16402,20 @@ func _$Promise_reject(_ promise: JSObject, _ value: JSValue) throws(JSException) #if arch(wasm32) @_extern(wasm, module: "bjs", name: "promise_resolve_BridgeJSRuntimeTests_SS") -fileprivate func promise_resolve_BridgeJSRuntimeTests_SS_extern(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void +fileprivate func promise_resolve_BridgeJSRuntimeTests_SS_extern(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void #else -fileprivate func promise_resolve_BridgeJSRuntimeTests_SS_extern(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { +fileprivate func promise_resolve_BridgeJSRuntimeTests_SS_extern(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func promise_resolve_BridgeJSRuntimeTests_SS(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - return promise_resolve_BridgeJSRuntimeTests_SS_extern(promise, valueBytes, valueLength) +@inline(never) fileprivate func promise_resolve_BridgeJSRuntimeTests_SS(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { + return promise_resolve_BridgeJSRuntimeTests_SS_extern(promise, valueWord0, valueWord1, valueWord2) } func _$Promise_resolve_SS(_ promise: JSObject, _ value: String) throws(JSException) -> Void { - value.bridgeJSWithLoweredParameter { (valueBytes, valueLength) in + value.bridgeJSWithLoweredParameter { (valueWord0, valueWord1, valueWord2) in let promiseValue = promise.bridgeJSLowerParameter() - promise_resolve_BridgeJSRuntimeTests_SS(promiseValue, valueBytes, valueLength) + promise_resolve_BridgeJSRuntimeTests_SS(promiseValue, valueWord0, valueWord1, valueWord2) } if let error = _swift_js_take_exception() { throw error } } @@ -16402,20 +16570,20 @@ func _$Promise_resolve_8JSObjectC(_ promise: JSObject, _ value: JSObject) throws #if arch(wasm32) @_extern(wasm, module: "bjs", name: "promise_resolve_BridgeJSRuntimeTests_5ThemeO") -fileprivate func promise_resolve_BridgeJSRuntimeTests_5ThemeO_extern(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void +fileprivate func promise_resolve_BridgeJSRuntimeTests_5ThemeO_extern(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void #else -fileprivate func promise_resolve_BridgeJSRuntimeTests_5ThemeO_extern(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { +fileprivate func promise_resolve_BridgeJSRuntimeTests_5ThemeO_extern(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func promise_resolve_BridgeJSRuntimeTests_5ThemeO(_ promise: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - return promise_resolve_BridgeJSRuntimeTests_5ThemeO_extern(promise, valueBytes, valueLength) +@inline(never) fileprivate func promise_resolve_BridgeJSRuntimeTests_5ThemeO(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { + return promise_resolve_BridgeJSRuntimeTests_5ThemeO_extern(promise, valueWord0, valueWord1, valueWord2) } func _$Promise_resolve_5ThemeO(_ promise: JSObject, _ value: Theme) throws(JSException) -> Void { - value.bridgeJSWithLoweredParameter { (valueBytes, valueLength) in + value.bridgeJSWithLoweredParameter { (valueWord0, valueWord1, valueWord2) in let promiseValue = promise.bridgeJSLowerParameter() - promise_resolve_BridgeJSRuntimeTests_5ThemeO(promiseValue, valueBytes, valueLength) + promise_resolve_BridgeJSRuntimeTests_5ThemeO(promiseValue, valueWord0, valueWord1, valueWord2) } if let error = _swift_js_take_exception() { throw error } } @@ -16445,20 +16613,20 @@ func _$Promise_resolve_9DirectionO(_ promise: JSObject, _ value: Direction) thro #if arch(wasm32) @_extern(wasm, module: "bjs", name: "promise_resolve_BridgeJSRuntimeTests_Sq5ThemeO") -fileprivate func promise_resolve_BridgeJSRuntimeTests_Sq5ThemeO_extern(_ promise: Int32, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void +fileprivate func promise_resolve_BridgeJSRuntimeTests_Sq5ThemeO_extern(_ promise: Int32, _ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void #else -fileprivate func promise_resolve_BridgeJSRuntimeTests_Sq5ThemeO_extern(_ promise: Int32, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { +fileprivate func promise_resolve_BridgeJSRuntimeTests_Sq5ThemeO_extern(_ promise: Int32, _ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func promise_resolve_BridgeJSRuntimeTests_Sq5ThemeO(_ promise: Int32, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - return promise_resolve_BridgeJSRuntimeTests_Sq5ThemeO_extern(promise, valueIsSome, valueBytes, valueLength) +@inline(never) fileprivate func promise_resolve_BridgeJSRuntimeTests_Sq5ThemeO(_ promise: Int32, _ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { + return promise_resolve_BridgeJSRuntimeTests_Sq5ThemeO_extern(promise, valueIsSome, valueWord0, valueWord1, valueWord2) } func _$Promise_resolve_Sq5ThemeO(_ promise: JSObject, _ value: Optional) throws(JSException) -> Void { - value.bridgeJSWithLoweredParameter { (valueIsSome, valueBytes, valueLength) in + value.bridgeJSWithLoweredParameter { (valueIsSome, valueWord0, valueWord1, valueWord2) in let promiseValue = promise.bridgeJSLowerParameter() - promise_resolve_BridgeJSRuntimeTests_Sq5ThemeO(promiseValue, valueIsSome, valueBytes, valueLength) + promise_resolve_BridgeJSRuntimeTests_Sq5ThemeO(promiseValue, valueIsSome, valueWord0, valueWord1, valueWord2) } if let error = _swift_js_take_exception() { throw error } } @@ -16802,14 +16970,14 @@ extension Boxed: _BridgedSwiftAlias, _BridgedSwiftStackType {} #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_Surface_init") -fileprivate func bjs_Surface_init_extern(_ labelBytes: Int32, _ labelLength: Int32) -> Int32 +fileprivate func bjs_Surface_init_extern(_ labelWord0: Int32, _ labelWord1: Int32, _ labelWord2: Int32) -> Int32 #else -fileprivate func bjs_Surface_init_extern(_ labelBytes: Int32, _ labelLength: Int32) -> Int32 { +fileprivate func bjs_Surface_init_extern(_ labelWord0: Int32, _ labelWord1: Int32, _ labelWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_Surface_init(_ labelBytes: Int32, _ labelLength: Int32) -> Int32 { - return bjs_Surface_init_extern(labelBytes, labelLength) +@inline(never) fileprivate func bjs_Surface_init(_ labelWord0: Int32, _ labelWord1: Int32, _ labelWord2: Int32) -> Int32 { + return bjs_Surface_init_extern(labelWord0, labelWord1, labelWord2) } #if arch(wasm32) @@ -16825,8 +16993,8 @@ fileprivate func bjs_Surface_label_get_extern(_ self: Int32) -> Int32 { } func _$Surface_init(_ label: String) throws(JSException) -> JSObject { - let ret0 = label.bridgeJSWithLoweredParameter { (labelBytes, labelLength) in - let ret = bjs_Surface_init(labelBytes, labelLength) + let ret0 = label.bridgeJSWithLoweredParameter { (labelWord0, labelWord1, labelWord2) in + let ret = bjs_Surface_init(labelWord0, labelWord1, labelWord2) return ret } let ret = ret0 @@ -16847,38 +17015,38 @@ func _$Surface_label_get(_ self: JSObject) throws(JSException) -> String { #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_AliasImports_jsRoundTripTagged_static") -fileprivate func bjs_AliasImports_jsRoundTripTagged_static_extern(_ valueBytes: Int32, _ valueLength: Int32) -> Int32 +fileprivate func bjs_AliasImports_jsRoundTripTagged_static_extern(_ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Int32 #else -fileprivate func bjs_AliasImports_jsRoundTripTagged_static_extern(_ valueBytes: Int32, _ valueLength: Int32) -> Int32 { +fileprivate func bjs_AliasImports_jsRoundTripTagged_static_extern(_ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_AliasImports_jsRoundTripTagged_static(_ valueBytes: Int32, _ valueLength: Int32) -> Int32 { - return bjs_AliasImports_jsRoundTripTagged_static_extern(valueBytes, valueLength) +@inline(never) fileprivate func bjs_AliasImports_jsRoundTripTagged_static(_ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Int32 { + return bjs_AliasImports_jsRoundTripTagged_static_extern(valueWord0, valueWord1, valueWord2) } #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_AliasImports_jsRoundTripOptionalTagged_static") -fileprivate func bjs_AliasImports_jsRoundTripOptionalTagged_static_extern(_ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void +fileprivate func bjs_AliasImports_jsRoundTripOptionalTagged_static_extern(_ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void #else -fileprivate func bjs_AliasImports_jsRoundTripOptionalTagged_static_extern(_ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { +fileprivate func bjs_AliasImports_jsRoundTripOptionalTagged_static_extern(_ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_AliasImports_jsRoundTripOptionalTagged_static(_ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - return bjs_AliasImports_jsRoundTripOptionalTagged_static_extern(valueIsSome, valueBytes, valueLength) +@inline(never) fileprivate func bjs_AliasImports_jsRoundTripOptionalTagged_static(_ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { + return bjs_AliasImports_jsRoundTripOptionalTagged_static_extern(valueIsSome, valueWord0, valueWord1, valueWord2) } #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_AliasImports_jsProduceOptionalCanvas_static") -fileprivate func bjs_AliasImports_jsProduceOptionalCanvas_static_extern(_ labelIsSome: Int32, _ labelBytes: Int32, _ labelLength: Int32) -> Void +fileprivate func bjs_AliasImports_jsProduceOptionalCanvas_static_extern(_ labelIsSome: Int32, _ labelWord0: Int32, _ labelWord1: Int32, _ labelWord2: Int32) -> Void #else -fileprivate func bjs_AliasImports_jsProduceOptionalCanvas_static_extern(_ labelIsSome: Int32, _ labelBytes: Int32, _ labelLength: Int32) -> Void { +fileprivate func bjs_AliasImports_jsProduceOptionalCanvas_static_extern(_ labelIsSome: Int32, _ labelWord0: Int32, _ labelWord1: Int32, _ labelWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_AliasImports_jsProduceOptionalCanvas_static(_ labelIsSome: Int32, _ labelBytes: Int32, _ labelLength: Int32) -> Void { - return bjs_AliasImports_jsProduceOptionalCanvas_static_extern(labelIsSome, labelBytes, labelLength) +@inline(never) fileprivate func bjs_AliasImports_jsProduceOptionalCanvas_static(_ labelIsSome: Int32, _ labelWord0: Int32, _ labelWord1: Int32, _ labelWord2: Int32) -> Void { + return bjs_AliasImports_jsProduceOptionalCanvas_static_extern(labelIsSome, labelWord0, labelWord1, labelWord2) } #if arch(wasm32) @@ -16942,8 +17110,8 @@ fileprivate func bjs_AliasImports_jsRoundTripOptionalUserId_static_extern(_ valu } func _$AliasImports_jsRoundTripTagged(_ value: Tagged) throws(JSException) -> Tagged { - let ret0 = value.bridgeJSWithLoweredParameter { (valueBytes, valueLength) in - let ret = bjs_AliasImports_jsRoundTripTagged_static(valueBytes, valueLength) + let ret0 = value.bridgeJSWithLoweredParameter { (valueWord0, valueWord1, valueWord2) in + let ret = bjs_AliasImports_jsRoundTripTagged_static(valueWord0, valueWord1, valueWord2) return ret } let ret = ret0 @@ -16954,8 +17122,8 @@ func _$AliasImports_jsRoundTripTagged(_ value: Tagged) throws(JSException) -> Ta } func _$AliasImports_jsRoundTripOptionalTagged(_ value: Optional) throws(JSException) -> Optional { - value.bridgeJSWithLoweredParameter { (valueIsSome, valueBytes, valueLength) in - bjs_AliasImports_jsRoundTripOptionalTagged_static(valueIsSome, valueBytes, valueLength) + value.bridgeJSWithLoweredParameter { (valueIsSome, valueWord0, valueWord1, valueWord2) in + bjs_AliasImports_jsRoundTripOptionalTagged_static(valueIsSome, valueWord0, valueWord1, valueWord2) } if let error = _swift_js_take_exception() { throw error @@ -16964,8 +17132,8 @@ func _$AliasImports_jsRoundTripOptionalTagged(_ value: Optional) throws( } func _$AliasImports_jsProduceOptionalCanvas(_ label: Optional) throws(JSException) -> Optional { - label.bridgeJSWithLoweredParameter { (labelIsSome, labelBytes, labelLength) in - bjs_AliasImports_jsProduceOptionalCanvas_static(labelIsSome, labelBytes, labelLength) + label.bridgeJSWithLoweredParameter { (labelIsSome, labelWord0, labelWord1, labelWord2) in + bjs_AliasImports_jsProduceOptionalCanvas_static(labelIsSome, labelWord0, labelWord1, labelWord2) } if let error = _swift_js_take_exception() { throw error @@ -17020,14 +17188,14 @@ func _$AliasImports_jsRoundTripOptionalUserId(_ value: Optional) throws( #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayElementObject_init") -fileprivate func bjs_ArrayElementObject_init_extern(_ idBytes: Int32, _ idLength: Int32) -> Int32 +fileprivate func bjs_ArrayElementObject_init_extern(_ idWord0: Int32, _ idWord1: Int32, _ idWord2: Int32) -> Int32 #else -fileprivate func bjs_ArrayElementObject_init_extern(_ idBytes: Int32, _ idLength: Int32) -> Int32 { +fileprivate func bjs_ArrayElementObject_init_extern(_ idWord0: Int32, _ idWord1: Int32, _ idWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_ArrayElementObject_init(_ idBytes: Int32, _ idLength: Int32) -> Int32 { - return bjs_ArrayElementObject_init_extern(idBytes, idLength) +@inline(never) fileprivate func bjs_ArrayElementObject_init(_ idWord0: Int32, _ idWord1: Int32, _ idWord2: Int32) -> Int32 { + return bjs_ArrayElementObject_init_extern(idWord0, idWord1, idWord2) } #if arch(wasm32) @@ -17043,8 +17211,8 @@ fileprivate func bjs_ArrayElementObject_id_get_extern(_ self: Int32) -> Int32 { } func _$ArrayElementObject_init(_ id: String) throws(JSException) -> JSObject { - let ret0 = id.bridgeJSWithLoweredParameter { (idBytes, idLength) in - let ret = bjs_ArrayElementObject_init(idBytes, idLength) + let ret0 = id.bridgeJSWithLoweredParameter { (idWord0, idWord1, idWord2) in + let ret = bjs_ArrayElementObject_init(idWord0, idWord1, idWord2) return ret } let ret = ret0 @@ -17455,26 +17623,26 @@ fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripBool_static_extern(_ res #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_AsyncImportImports_jsAsyncRoundTripString_static") -fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripString_static_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ vBytes: Int32, _ vLength: Int32) -> Void +fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripString_static_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ vWord0: Int32, _ vWord1: Int32, _ vWord2: Int32) -> Void #else -fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripString_static_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ vBytes: Int32, _ vLength: Int32) -> Void { +fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripString_static_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ vWord0: Int32, _ vWord1: Int32, _ vWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripString_static(_ resolveRef: Int32, _ rejectRef: Int32, _ vBytes: Int32, _ vLength: Int32) -> Void { - return bjs_AsyncImportImports_jsAsyncRoundTripString_static_extern(resolveRef, rejectRef, vBytes, vLength) +@inline(never) fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripString_static(_ resolveRef: Int32, _ rejectRef: Int32, _ vWord0: Int32, _ vWord1: Int32, _ vWord2: Int32) -> Void { + return bjs_AsyncImportImports_jsAsyncRoundTripString_static_extern(resolveRef, rejectRef, vWord0, vWord1, vWord2) } #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_AsyncImportImports_jsAsyncRoundTripOptionalString_static") -fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripOptionalString_static_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ vIsSome: Int32, _ vBytes: Int32, _ vLength: Int32) -> Void +fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripOptionalString_static_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ vIsSome: Int32, _ vWord0: Int32, _ vWord1: Int32, _ vWord2: Int32) -> Void #else -fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripOptionalString_static_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ vIsSome: Int32, _ vBytes: Int32, _ vLength: Int32) -> Void { +fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripOptionalString_static_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ vIsSome: Int32, _ vWord0: Int32, _ vWord1: Int32, _ vWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripOptionalString_static(_ resolveRef: Int32, _ rejectRef: Int32, _ vIsSome: Int32, _ vBytes: Int32, _ vLength: Int32) -> Void { - return bjs_AsyncImportImports_jsAsyncRoundTripOptionalString_static_extern(resolveRef, rejectRef, vIsSome, vBytes, vLength) +@inline(never) fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripOptionalString_static(_ resolveRef: Int32, _ rejectRef: Int32, _ vIsSome: Int32, _ vWord0: Int32, _ vWord1: Int32, _ vWord2: Int32) -> Void { + return bjs_AsyncImportImports_jsAsyncRoundTripOptionalString_static_extern(resolveRef, rejectRef, vIsSome, vWord0, vWord1, vWord2) } #if arch(wasm32) @@ -17527,14 +17695,14 @@ fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripStringArray_static_exter #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_AsyncImportImports_jsAsyncRoundTripFeatureFlag_static") -fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripFeatureFlag_static_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ vBytes: Int32, _ vLength: Int32) -> Void +fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripFeatureFlag_static_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ vWord0: Int32, _ vWord1: Int32, _ vWord2: Int32) -> Void #else -fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripFeatureFlag_static_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ vBytes: Int32, _ vLength: Int32) -> Void { +fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripFeatureFlag_static_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ vWord0: Int32, _ vWord1: Int32, _ vWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripFeatureFlag_static(_ resolveRef: Int32, _ rejectRef: Int32, _ vBytes: Int32, _ vLength: Int32) -> Void { - return bjs_AsyncImportImports_jsAsyncRoundTripFeatureFlag_static_extern(resolveRef, rejectRef, vBytes, vLength) +@inline(never) fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripFeatureFlag_static(_ resolveRef: Int32, _ rejectRef: Int32, _ vWord0: Int32, _ vWord1: Int32, _ vWord2: Int32) -> Void { + return bjs_AsyncImportImports_jsAsyncRoundTripFeatureFlag_static_extern(resolveRef, rejectRef, vWord0, vWord1, vWord2) } #if arch(wasm32) @@ -17601,8 +17769,8 @@ func _$AsyncImportImports_jsAsyncRoundTripString(_ v: String) async throws(JSExc }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in - v.bridgeJSWithLoweredParameter { (vBytes, vLength) in - bjs_AsyncImportImports_jsAsyncRoundTripString_static(resolveRef, rejectRef, vBytes, vLength) + v.bridgeJSWithLoweredParameter { (vWord0, vWord1, vWord2) in + bjs_AsyncImportImports_jsAsyncRoundTripString_static(resolveRef, rejectRef, vWord0, vWord1, vWord2) } } return resolved @@ -17614,8 +17782,8 @@ func _$AsyncImportImports_jsAsyncRoundTripOptionalString(_ v: Optional) }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in - v.bridgeJSWithLoweredParameter { (vIsSome, vBytes, vLength) in - bjs_AsyncImportImports_jsAsyncRoundTripOptionalString_static(resolveRef, rejectRef, vIsSome, vBytes, vLength) + v.bridgeJSWithLoweredParameter { (vIsSome, vWord0, vWord1, vWord2) in + bjs_AsyncImportImports_jsAsyncRoundTripOptionalString_static(resolveRef, rejectRef, vIsSome, vWord0, vWord1, vWord2) } } return resolved @@ -17675,8 +17843,8 @@ func _$AsyncImportImports_jsAsyncRoundTripFeatureFlag(_ v: FeatureFlag) async th }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in - v.bridgeJSWithLoweredParameter { (vBytes, vLength) in - bjs_AsyncImportImports_jsAsyncRoundTripFeatureFlag_static(resolveRef, rejectRef, vBytes, vLength) + v.bridgeJSWithLoweredParameter { (vWord0, vWord1, vWord2) in + bjs_AsyncImportImports_jsAsyncRoundTripFeatureFlag_static(resolveRef, rejectRef, vWord0, vWord1, vWord2) } } return resolved @@ -17778,14 +17946,14 @@ fileprivate func bjs_ClosureSupportImports_jsApplyDouble_static_extern(_ value: #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ClosureSupportImports_jsApplyString_static") -fileprivate func bjs_ClosureSupportImports_jsApplyString_static_extern(_ valueBytes: Int32, _ valueLength: Int32, _ transform: Int32) -> Int32 +fileprivate func bjs_ClosureSupportImports_jsApplyString_static_extern(_ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32, _ transform: Int32) -> Int32 #else -fileprivate func bjs_ClosureSupportImports_jsApplyString_static_extern(_ valueBytes: Int32, _ valueLength: Int32, _ transform: Int32) -> Int32 { +fileprivate func bjs_ClosureSupportImports_jsApplyString_static_extern(_ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32, _ transform: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_ClosureSupportImports_jsApplyString_static(_ valueBytes: Int32, _ valueLength: Int32, _ transform: Int32) -> Int32 { - return bjs_ClosureSupportImports_jsApplyString_static_extern(valueBytes, valueLength, transform) +@inline(never) fileprivate func bjs_ClosureSupportImports_jsApplyString_static(_ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32, _ transform: Int32) -> Int32 { + return bjs_ClosureSupportImports_jsApplyString_static_extern(valueWord0, valueWord1, valueWord2, transform) } #if arch(wasm32) @@ -17886,14 +18054,14 @@ fileprivate func bjs_ClosureSupportImports_jsMakeDoubleToDouble_static_extern(_ #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ClosureSupportImports_jsMakeStringToString_static") -fileprivate func bjs_ClosureSupportImports_jsMakeStringToString_static_extern(_ prefixBytes: Int32, _ prefixLength: Int32) -> Int32 +fileprivate func bjs_ClosureSupportImports_jsMakeStringToString_static_extern(_ prefixWord0: Int32, _ prefixWord1: Int32, _ prefixWord2: Int32) -> Int32 #else -fileprivate func bjs_ClosureSupportImports_jsMakeStringToString_static_extern(_ prefixBytes: Int32, _ prefixLength: Int32) -> Int32 { +fileprivate func bjs_ClosureSupportImports_jsMakeStringToString_static_extern(_ prefixWord0: Int32, _ prefixWord1: Int32, _ prefixWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_ClosureSupportImports_jsMakeStringToString_static(_ prefixBytes: Int32, _ prefixLength: Int32) -> Int32 { - return bjs_ClosureSupportImports_jsMakeStringToString_static_extern(prefixBytes, prefixLength) +@inline(never) fileprivate func bjs_ClosureSupportImports_jsMakeStringToString_static(_ prefixWord0: Int32, _ prefixWord1: Int32, _ prefixWord2: Int32) -> Int32 { + return bjs_ClosureSupportImports_jsMakeStringToString_static_extern(prefixWord0, prefixWord1, prefixWord2) } #if arch(wasm32) @@ -18042,9 +18210,9 @@ func _$ClosureSupportImports_jsApplyDouble(_ value: Double, _ transform: JSTyped } func _$ClosureSupportImports_jsApplyString(_ value: String, _ transform: JSTypedClosure<(String) -> String>) throws(JSException) -> String { - let ret0 = value.bridgeJSWithLoweredParameter { (valueBytes, valueLength) in + let ret0 = value.bridgeJSWithLoweredParameter { (valueWord0, valueWord1, valueWord2) in let transformFuncRef = transform.bridgeJSLowerParameter() - let ret = bjs_ClosureSupportImports_jsApplyString_static(valueBytes, valueLength, transformFuncRef) + let ret = bjs_ClosureSupportImports_jsApplyString_static(valueWord0, valueWord1, valueWord2, transformFuncRef) return ret } let ret = ret0 @@ -18133,8 +18301,8 @@ func _$ClosureSupportImports_jsMakeDoubleToDouble(_ base: Double) throws(JSExcep } func _$ClosureSupportImports_jsMakeStringToString(_ prefix: String) throws(JSException) -> (String) -> String { - let ret0 = prefix.bridgeJSWithLoweredParameter { (prefixBytes, prefixLength) in - let ret = bjs_ClosureSupportImports_jsMakeStringToString_static(prefixBytes, prefixLength) + let ret0 = prefix.bridgeJSWithLoweredParameter { (prefixWord0, prefixWord1, prefixWord2) in + let ret = bjs_ClosureSupportImports_jsMakeStringToString_static(prefixWord0, prefixWord1, prefixWord2) return ret } let ret = ret0 @@ -18386,14 +18554,14 @@ func _$DictionarySupportImports_jsRoundTripDictionaryDoubleArray(_ values: [Stri #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_Foo_init") -fileprivate func bjs_Foo_init_extern(_ valueBytes: Int32, _ valueLength: Int32) -> Int32 +fileprivate func bjs_Foo_init_extern(_ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Int32 #else -fileprivate func bjs_Foo_init_extern(_ valueBytes: Int32, _ valueLength: Int32) -> Int32 { +fileprivate func bjs_Foo_init_extern(_ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_Foo_init(_ valueBytes: Int32, _ valueLength: Int32) -> Int32 { - return bjs_Foo_init_extern(valueBytes, valueLength) +@inline(never) fileprivate func bjs_Foo_init(_ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Int32 { + return bjs_Foo_init_extern(valueWord0, valueWord1, valueWord2) } #if arch(wasm32) @@ -18409,8 +18577,8 @@ fileprivate func bjs_Foo_value_get_extern(_ self: Int32) -> Int32 { } func _$Foo_init(_ value: String) throws(JSException) -> JSObject { - let ret0 = value.bridgeJSWithLoweredParameter { (valueBytes, valueLength) in - let ret = bjs_Foo_init(valueBytes, valueLength) + let ret0 = value.bridgeJSWithLoweredParameter { (valueWord0, valueWord1, valueWord2) in + let ret = bjs_Foo_init(valueWord0, valueWord1, valueWord2) return ret } let ret = ret0 @@ -18512,19 +18680,19 @@ func _$jsRoundTripBool(_ v: Bool) throws(JSException) -> Bool { #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripString") -fileprivate func bjs_jsRoundTripString_extern(_ vBytes: Int32, _ vLength: Int32) -> Int32 +fileprivate func bjs_jsRoundTripString_extern(_ vWord0: Int32, _ vWord1: Int32, _ vWord2: Int32) -> Int32 #else -fileprivate func bjs_jsRoundTripString_extern(_ vBytes: Int32, _ vLength: Int32) -> Int32 { +fileprivate func bjs_jsRoundTripString_extern(_ vWord0: Int32, _ vWord1: Int32, _ vWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_jsRoundTripString(_ vBytes: Int32, _ vLength: Int32) -> Int32 { - return bjs_jsRoundTripString_extern(vBytes, vLength) +@inline(never) fileprivate func bjs_jsRoundTripString(_ vWord0: Int32, _ vWord1: Int32, _ vWord2: Int32) -> Int32 { + return bjs_jsRoundTripString_extern(vWord0, vWord1, vWord2) } func _$jsRoundTripString(_ v: String) throws(JSException) -> String { - let ret0 = v.bridgeJSWithLoweredParameter { (vBytes, vLength) in - let ret = bjs_jsRoundTripString(vBytes, vLength) + let ret0 = v.bridgeJSWithLoweredParameter { (vWord0, vWord1, vWord2) in + let ret = bjs_jsRoundTripString(vWord0, vWord1, vWord2) return ret } let ret = ret0 @@ -18640,19 +18808,19 @@ func _$jsThrowOrString(_ shouldThrow: Bool) throws(JSException) -> String { #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripFeatureFlag") -fileprivate func bjs_jsRoundTripFeatureFlag_extern(_ flagBytes: Int32, _ flagLength: Int32) -> Int32 +fileprivate func bjs_jsRoundTripFeatureFlag_extern(_ flagWord0: Int32, _ flagWord1: Int32, _ flagWord2: Int32) -> Int32 #else -fileprivate func bjs_jsRoundTripFeatureFlag_extern(_ flagBytes: Int32, _ flagLength: Int32) -> Int32 { +fileprivate func bjs_jsRoundTripFeatureFlag_extern(_ flagWord0: Int32, _ flagWord1: Int32, _ flagWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_jsRoundTripFeatureFlag(_ flagBytes: Int32, _ flagLength: Int32) -> Int32 { - return bjs_jsRoundTripFeatureFlag_extern(flagBytes, flagLength) +@inline(never) fileprivate func bjs_jsRoundTripFeatureFlag(_ flagWord0: Int32, _ flagWord1: Int32, _ flagWord2: Int32) -> Int32 { + return bjs_jsRoundTripFeatureFlag_extern(flagWord0, flagWord1, flagWord2) } func _$jsRoundTripFeatureFlag(_ flag: FeatureFlag) throws(JSException) -> FeatureFlag { - let ret0 = flag.bridgeJSWithLoweredParameter { (flagBytes, flagLength) in - let ret = bjs_jsRoundTripFeatureFlag(flagBytes, flagLength) + let ret0 = flag.bridgeJSWithLoweredParameter { (flagWord0, flagWord1, flagWord2) in + let ret = bjs_jsRoundTripFeatureFlag(flagWord0, flagWord1, flagWord2) return ret } let ret = ret0 @@ -18686,14 +18854,14 @@ func _$runAsyncWorks() async throws(JSException) -> Void { #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_fetchWeatherData") -fileprivate func bjs_fetchWeatherData_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ cityBytes: Int32, _ cityLength: Int32) -> Void +fileprivate func bjs_fetchWeatherData_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ cityWord0: Int32, _ cityWord1: Int32, _ cityWord2: Int32) -> Void #else -fileprivate func bjs_fetchWeatherData_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ cityBytes: Int32, _ cityLength: Int32) -> Void { +fileprivate func bjs_fetchWeatherData_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ cityWord0: Int32, _ cityWord1: Int32, _ cityWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_fetchWeatherData(_ resolveRef: Int32, _ rejectRef: Int32, _ cityBytes: Int32, _ cityLength: Int32) -> Void { - return bjs_fetchWeatherData_extern(resolveRef, rejectRef, cityBytes, cityLength) +@inline(never) fileprivate func bjs_fetchWeatherData(_ resolveRef: Int32, _ rejectRef: Int32, _ cityWord0: Int32, _ cityWord1: Int32, _ cityWord2: Int32) -> Void { + return bjs_fetchWeatherData_extern(resolveRef, rejectRef, cityWord0, cityWord1, cityWord2) } func _$fetchWeatherData(_ city: String) async throws(JSException) -> WeatherData { @@ -18702,8 +18870,8 @@ func _$fetchWeatherData(_ city: String) async throws(JSException) -> WeatherData }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in - city.bridgeJSWithLoweredParameter { (cityBytes, cityLength) in - bjs_fetchWeatherData(resolveRef, rejectRef, cityBytes, cityLength) + city.bridgeJSWithLoweredParameter { (cityWord0, cityWord1, cityWord2) in + bjs_fetchWeatherData(resolveRef, rejectRef, cityWord0, cityWord1, cityWord2) } } return resolved @@ -18731,19 +18899,19 @@ func _$_jsWeirdFunction() throws(JSException) -> Double { #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_parseInt") -fileprivate func bjs_parseInt_extern(_ stringBytes: Int32, _ stringLength: Int32) -> Float64 +fileprivate func bjs_parseInt_extern(_ stringWord0: Int32, _ stringWord1: Int32, _ stringWord2: Int32) -> Float64 #else -fileprivate func bjs_parseInt_extern(_ stringBytes: Int32, _ stringLength: Int32) -> Float64 { +fileprivate func bjs_parseInt_extern(_ stringWord0: Int32, _ stringWord1: Int32, _ stringWord2: Int32) -> Float64 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_parseInt(_ stringBytes: Int32, _ stringLength: Int32) -> Float64 { - return bjs_parseInt_extern(stringBytes, stringLength) +@inline(never) fileprivate func bjs_parseInt(_ stringWord0: Int32, _ stringWord1: Int32, _ stringWord2: Int32) -> Float64 { + return bjs_parseInt_extern(stringWord0, stringWord1, stringWord2) } func _$parseInt(_ string: String) throws(JSException) -> Double { - let ret0 = string.bridgeJSWithLoweredParameter { (stringBytes, stringLength) in - let ret = bjs_parseInt(stringBytes, stringLength) + let ret0 = string.bridgeJSWithLoweredParameter { (stringWord0, stringWord1, stringWord2) in + let ret = bjs_parseInt(stringWord0, stringWord1, stringWord2) return ret } let ret = ret0 @@ -18755,14 +18923,14 @@ func _$parseInt(_ string: String) throws(JSException) -> Double { #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JsGreeter_init") -fileprivate func bjs_JsGreeter_init_extern(_ nameBytes: Int32, _ nameLength: Int32, _ prefixBytes: Int32, _ prefixLength: Int32) -> Int32 +fileprivate func bjs_JsGreeter_init_extern(_ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32, _ prefixWord0: Int32, _ prefixWord1: Int32, _ prefixWord2: Int32) -> Int32 #else -fileprivate func bjs_JsGreeter_init_extern(_ nameBytes: Int32, _ nameLength: Int32, _ prefixBytes: Int32, _ prefixLength: Int32) -> Int32 { +fileprivate func bjs_JsGreeter_init_extern(_ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32, _ prefixWord0: Int32, _ prefixWord1: Int32, _ prefixWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_JsGreeter_init(_ nameBytes: Int32, _ nameLength: Int32, _ prefixBytes: Int32, _ prefixLength: Int32) -> Int32 { - return bjs_JsGreeter_init_extern(nameBytes, nameLength, prefixBytes, prefixLength) +@inline(never) fileprivate func bjs_JsGreeter_init(_ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32, _ prefixWord0: Int32, _ prefixWord1: Int32, _ prefixWord2: Int32) -> Int32 { + return bjs_JsGreeter_init_extern(nameWord0, nameWord1, nameWord2, prefixWord0, prefixWord1, prefixWord2) } #if arch(wasm32) @@ -18791,14 +18959,14 @@ fileprivate func bjs_JsGreeter_prefix_get_extern(_ self: Int32) -> Int32 { #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JsGreeter_name_set") -fileprivate func bjs_JsGreeter_name_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void +fileprivate func bjs_JsGreeter_name_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void #else -fileprivate func bjs_JsGreeter_name_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { +fileprivate func bjs_JsGreeter_name_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_JsGreeter_name_set(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { - return bjs_JsGreeter_name_set_extern(self, newValueBytes, newValueLength) +@inline(never) fileprivate func bjs_JsGreeter_name_set(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { + return bjs_JsGreeter_name_set_extern(self, newValueWord0, newValueWord1, newValueWord2) } #if arch(wasm32) @@ -18815,20 +18983,20 @@ fileprivate func bjs_JsGreeter_greet_extern(_ self: Int32) -> Int32 { #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JsGreeter_changeName") -fileprivate func bjs_JsGreeter_changeName_extern(_ self: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void +fileprivate func bjs_JsGreeter_changeName_extern(_ self: Int32, _ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32) -> Void #else -fileprivate func bjs_JsGreeter_changeName_extern(_ self: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { +fileprivate func bjs_JsGreeter_changeName_extern(_ self: Int32, _ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_JsGreeter_changeName(_ self: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { - return bjs_JsGreeter_changeName_extern(self, nameBytes, nameLength) +@inline(never) fileprivate func bjs_JsGreeter_changeName(_ self: Int32, _ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32) -> Void { + return bjs_JsGreeter_changeName_extern(self, nameWord0, nameWord1, nameWord2) } func _$JsGreeter_init(_ name: String, _ prefix: String) throws(JSException) -> JSObject { - let ret0 = name.bridgeJSWithLoweredParameter { (nameBytes, nameLength) in - let ret1 = prefix.bridgeJSWithLoweredParameter { (prefixBytes, prefixLength) in - let ret = bjs_JsGreeter_init(nameBytes, nameLength, prefixBytes, prefixLength) + let ret0 = name.bridgeJSWithLoweredParameter { (nameWord0, nameWord1, nameWord2) in + let ret1 = prefix.bridgeJSWithLoweredParameter { (prefixWord0, prefixWord1, prefixWord2) in + let ret = bjs_JsGreeter_init(nameWord0, nameWord1, nameWord2, prefixWord0, prefixWord1, prefixWord2) return ret } return ret1 @@ -18859,9 +19027,9 @@ func _$JsGreeter_prefix_get(_ self: JSObject) throws(JSException) -> String { } func _$JsGreeter_name_set(_ self: JSObject, _ newValue: String) throws(JSException) -> Void { - newValue.bridgeJSWithLoweredParameter { (newValueBytes, newValueLength) in + newValue.bridgeJSWithLoweredParameter { (newValueWord0, newValueWord1, newValueWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_JsGreeter_name_set(selfValue, newValueBytes, newValueLength) + bjs_JsGreeter_name_set(selfValue, newValueWord0, newValueWord1, newValueWord2) } if let error = _swift_js_take_exception() { throw error @@ -18878,9 +19046,9 @@ func _$JsGreeter_greet(_ self: JSObject) throws(JSException) -> String { } func _$JsGreeter_changeName(_ self: JSObject, _ name: String) throws(JSException) -> Void { - name.bridgeJSWithLoweredParameter { (nameBytes, nameLength) in + name.bridgeJSWithLoweredParameter { (nameWord0, nameWord1, nameWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_JsGreeter_changeName(selfValue, nameBytes, nameLength) + bjs_JsGreeter_changeName(selfValue, nameWord0, nameWord1, nameWord2) } if let error = _swift_js_take_exception() { throw error @@ -18937,14 +19105,14 @@ fileprivate func bjs_WeatherData_temperature_set_extern(_ self: Int32, _ newValu #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_WeatherData_description_set") -fileprivate func bjs_WeatherData_description_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void +fileprivate func bjs_WeatherData_description_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void #else -fileprivate func bjs_WeatherData_description_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { +fileprivate func bjs_WeatherData_description_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_WeatherData_description_set(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { - return bjs_WeatherData_description_set_extern(self, newValueBytes, newValueLength) +@inline(never) fileprivate func bjs_WeatherData_description_set(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { + return bjs_WeatherData_description_set_extern(self, newValueWord0, newValueWord1, newValueWord2) } #if arch(wasm32) @@ -18996,9 +19164,9 @@ func _$WeatherData_temperature_set(_ self: JSObject, _ newValue: Double) throws( } func _$WeatherData_description_set(_ self: JSObject, _ newValue: String) throws(JSException) -> Void { - newValue.bridgeJSWithLoweredParameter { (newValueBytes, newValueLength) in + newValue.bridgeJSWithLoweredParameter { (newValueWord0, newValueWord1, newValueWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_WeatherData_description_set(selfValue, newValueBytes, newValueLength) + bjs_WeatherData_description_set(selfValue, newValueWord0, newValueWord1, newValueWord2) } if let error = _swift_js_take_exception() { throw error @@ -19180,14 +19348,14 @@ func _$StaticBox_value(_ self: JSObject) throws(JSException) -> Double { #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_Animal_init") -fileprivate func bjs_Animal_init_extern(_ nameBytes: Int32, _ nameLength: Int32, _ age: Float64, _ isCat: Int32) -> Int32 +fileprivate func bjs_Animal_init_extern(_ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32, _ age: Float64, _ isCat: Int32) -> Int32 #else -fileprivate func bjs_Animal_init_extern(_ nameBytes: Int32, _ nameLength: Int32, _ age: Float64, _ isCat: Int32) -> Int32 { +fileprivate func bjs_Animal_init_extern(_ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32, _ age: Float64, _ isCat: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_Animal_init(_ nameBytes: Int32, _ nameLength: Int32, _ age: Float64, _ isCat: Int32) -> Int32 { - return bjs_Animal_init_extern(nameBytes, nameLength, age, isCat) +@inline(never) fileprivate func bjs_Animal_init(_ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32, _ age: Float64, _ isCat: Int32) -> Int32 { + return bjs_Animal_init_extern(nameWord0, nameWord1, nameWord2, age, isCat) } #if arch(wasm32) @@ -19228,14 +19396,14 @@ fileprivate func bjs_Animal_isCat_get_extern(_ self: Int32) -> Int32 { #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_Animal_name_set") -fileprivate func bjs_Animal_name_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void +fileprivate func bjs_Animal_name_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void #else -fileprivate func bjs_Animal_name_set_extern(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { +fileprivate func bjs_Animal_name_set_extern(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_Animal_name_set(_ self: Int32, _ newValueBytes: Int32, _ newValueLength: Int32) -> Void { - return bjs_Animal_name_set_extern(self, newValueBytes, newValueLength) +@inline(never) fileprivate func bjs_Animal_name_set(_ self: Int32, _ newValueWord0: Int32, _ newValueWord1: Int32, _ newValueWord2: Int32) -> Void { + return bjs_Animal_name_set_extern(self, newValueWord0, newValueWord1, newValueWord2) } #if arch(wasm32) @@ -19287,10 +19455,10 @@ fileprivate func bjs_Animal_getIsCat_extern(_ self: Int32) -> Int32 { } func _$Animal_init(_ name: String, _ age: Double, _ isCat: Bool) throws(JSException) -> JSObject { - let ret0 = name.bridgeJSWithLoweredParameter { (nameBytes, nameLength) in + let ret0 = name.bridgeJSWithLoweredParameter { (nameWord0, nameWord1, nameWord2) in let isCatValue = isCat.bridgeJSLowerParameter() let ageValue = age.bridgeJSLowerParameter() - let ret = bjs_Animal_init(nameBytes, nameLength, ageValue, isCatValue) + let ret = bjs_Animal_init(nameWord0, nameWord1, nameWord2, ageValue, isCatValue) return ret } let ret = ret0 @@ -19328,9 +19496,9 @@ func _$Animal_isCat_get(_ self: JSObject) throws(JSException) -> Bool { } func _$Animal_name_set(_ self: JSObject, _ newValue: String) throws(JSException) -> Void { - newValue.bridgeJSWithLoweredParameter { (newValueBytes, newValueLength) in + newValue.bridgeJSWithLoweredParameter { (newValueWord0, newValueWord1, newValueWord2) in let selfValue = self.bridgeJSLowerParameter() - bjs_Animal_name_set(selfValue, newValueBytes, newValueLength) + bjs_Animal_name_set(selfValue, newValueWord0, newValueWord1, newValueWord2) } if let error = _swift_js_take_exception() { throw error @@ -19504,21 +19672,21 @@ func _$jsJoinEnumThenArray(_ a: ImportedPayloadSignal, _ b: [Int]) throws(JSExce #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsJoinStringThenStackParams") -fileprivate func bjs_jsJoinStringThenStackParams_extern(_ sBytes: Int32, _ sLength: Int32) -> Int32 +fileprivate func bjs_jsJoinStringThenStackParams_extern(_ sWord0: Int32, _ sWord1: Int32, _ sWord2: Int32) -> Int32 #else -fileprivate func bjs_jsJoinStringThenStackParams_extern(_ sBytes: Int32, _ sLength: Int32) -> Int32 { +fileprivate func bjs_jsJoinStringThenStackParams_extern(_ sWord0: Int32, _ sWord1: Int32, _ sWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_jsJoinStringThenStackParams(_ sBytes: Int32, _ sLength: Int32) -> Int32 { - return bjs_jsJoinStringThenStackParams_extern(sBytes, sLength) +@inline(never) fileprivate func bjs_jsJoinStringThenStackParams(_ sWord0: Int32, _ sWord1: Int32, _ sWord2: Int32) -> Int32 { + return bjs_jsJoinStringThenStackParams_extern(sWord0, sWord1, sWord2) } func _$jsJoinStringThenStackParams(_ s: String, _ a: Optional<[Int]>, _ b: [Int]) throws(JSException) -> String { - let ret0 = s.bridgeJSWithLoweredParameter { (sBytes, sLength) in + let ret0 = s.bridgeJSWithLoweredParameter { (sWord0, sWord1, sWord2) in let _ = b.bridgeJSLowerParameter() let _ = a.bridgeJSLowerParameter() - let ret = bjs_jsJoinStringThenStackParams(sBytes, sLength) + let ret = bjs_jsJoinStringThenStackParams(sWord0, sWord1, sWord2) return ret } let ret = ret0 @@ -19572,19 +19740,19 @@ func _$jsGenericRoundTripClass(_ value: T) thr #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsGenericParsePoint") -fileprivate func bjs_jsGenericParsePoint_extern(_ jsonBytes: Int32, _ jsonLength: Int32, _ _generic0TypeId: Int32) -> Void +fileprivate func bjs_jsGenericParsePoint_extern(_ jsonWord0: Int32, _ jsonWord1: Int32, _ jsonWord2: Int32, _ _generic0TypeId: Int32) -> Void #else -fileprivate func bjs_jsGenericParsePoint_extern(_ jsonBytes: Int32, _ jsonLength: Int32, _ _generic0TypeId: Int32) -> Void { +fileprivate func bjs_jsGenericParsePoint_extern(_ jsonWord0: Int32, _ jsonWord1: Int32, _ jsonWord2: Int32, _ _generic0TypeId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_jsGenericParsePoint(_ jsonBytes: Int32, _ jsonLength: Int32, _ _generic0TypeId: Int32) -> Void { - return bjs_jsGenericParsePoint_extern(jsonBytes, jsonLength, _generic0TypeId) +@inline(never) fileprivate func bjs_jsGenericParsePoint(_ jsonWord0: Int32, _ jsonWord1: Int32, _ jsonWord2: Int32, _ _generic0TypeId: Int32) -> Void { + return bjs_jsGenericParsePoint_extern(jsonWord0, jsonWord1, jsonWord2, _generic0TypeId) } func _$jsGenericParsePoint(_ json: String) throws(JSException) -> T { - json.bridgeJSWithLoweredParameter { (jsonBytes, jsonLength) in - bjs_jsGenericParsePoint(jsonBytes, jsonLength, T.bridgeJSTypeID) + json.bridgeJSWithLoweredParameter { (jsonWord0, jsonWord1, jsonWord2) in + bjs_jsGenericParsePoint(jsonWord0, jsonWord1, jsonWord2, T.bridgeJSTypeID) } if let error = _swift_js_take_exception() { throw error @@ -20398,19 +20566,19 @@ func _$defaultExport_get() throws(JSException) -> JSObject { #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_nodeBasename") -fileprivate func bjs_nodeBasename_extern(_ pathBytes: Int32, _ pathLength: Int32) -> Int32 +fileprivate func bjs_nodeBasename_extern(_ pathWord0: Int32, _ pathWord1: Int32, _ pathWord2: Int32) -> Int32 #else -fileprivate func bjs_nodeBasename_extern(_ pathBytes: Int32, _ pathLength: Int32) -> Int32 { +fileprivate func bjs_nodeBasename_extern(_ pathWord0: Int32, _ pathWord1: Int32, _ pathWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_nodeBasename(_ pathBytes: Int32, _ pathLength: Int32) -> Int32 { - return bjs_nodeBasename_extern(pathBytes, pathLength) +@inline(never) fileprivate func bjs_nodeBasename(_ pathWord0: Int32, _ pathWord1: Int32, _ pathWord2: Int32) -> Int32 { + return bjs_nodeBasename_extern(pathWord0, pathWord1, pathWord2) } func _$nodeBasename(_ path: String) throws(JSException) -> String { - let ret0 = path.bridgeJSWithLoweredParameter { (pathBytes, pathLength) in - let ret = bjs_nodeBasename(pathBytes, pathLength) + let ret0 = path.bridgeJSWithLoweredParameter { (pathWord0, pathWord1, pathWord2) in + let ret = bjs_nodeBasename(pathWord0, pathWord1, pathWord2) return ret } let ret = ret0 @@ -20422,20 +20590,20 @@ func _$nodeBasename(_ path: String) throws(JSException) -> String { #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_nodeJoin") -fileprivate func bjs_nodeJoin_extern(_ lhsBytes: Int32, _ lhsLength: Int32, _ rhsBytes: Int32, _ rhsLength: Int32) -> Int32 +fileprivate func bjs_nodeJoin_extern(_ lhsWord0: Int32, _ lhsWord1: Int32, _ lhsWord2: Int32, _ rhsWord0: Int32, _ rhsWord1: Int32, _ rhsWord2: Int32) -> Int32 #else -fileprivate func bjs_nodeJoin_extern(_ lhsBytes: Int32, _ lhsLength: Int32, _ rhsBytes: Int32, _ rhsLength: Int32) -> Int32 { +fileprivate func bjs_nodeJoin_extern(_ lhsWord0: Int32, _ lhsWord1: Int32, _ lhsWord2: Int32, _ rhsWord0: Int32, _ rhsWord1: Int32, _ rhsWord2: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_nodeJoin(_ lhsBytes: Int32, _ lhsLength: Int32, _ rhsBytes: Int32, _ rhsLength: Int32) -> Int32 { - return bjs_nodeJoin_extern(lhsBytes, lhsLength, rhsBytes, rhsLength) +@inline(never) fileprivate func bjs_nodeJoin(_ lhsWord0: Int32, _ lhsWord1: Int32, _ lhsWord2: Int32, _ rhsWord0: Int32, _ rhsWord1: Int32, _ rhsWord2: Int32) -> Int32 { + return bjs_nodeJoin_extern(lhsWord0, lhsWord1, lhsWord2, rhsWord0, rhsWord1, rhsWord2) } func _$nodeJoin(_ lhs: String, _ rhs: String) throws(JSException) -> String { - let ret0 = lhs.bridgeJSWithLoweredParameter { (lhsBytes, lhsLength) in - let ret1 = rhs.bridgeJSWithLoweredParameter { (rhsBytes, rhsLength) in - let ret = bjs_nodeJoin(lhsBytes, lhsLength, rhsBytes, rhsLength) + let ret0 = lhs.bridgeJSWithLoweredParameter { (lhsWord0, lhsWord1, lhsWord2) in + let ret1 = rhs.bridgeJSWithLoweredParameter { (rhsWord0, rhsWord1, rhsWord2) in + let ret = bjs_nodeJoin(lhsWord0, lhsWord1, lhsWord2, rhsWord0, rhsWord1, rhsWord2) return ret } return ret1 @@ -20979,26 +21147,26 @@ fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalNumberUndefined_s #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_OptionalSupportImports_jsRoundTripOptionalStringNull_static") -fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalStringNull_static_extern(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void +fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalStringNull_static_extern(_ nameIsSome: Int32, _ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32) -> Void #else -fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalStringNull_static_extern(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { +fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalStringNull_static_extern(_ nameIsSome: Int32, _ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalStringNull_static(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { - return bjs_OptionalSupportImports_jsRoundTripOptionalStringNull_static_extern(nameIsSome, nameBytes, nameLength) +@inline(never) fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalStringNull_static(_ nameIsSome: Int32, _ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32) -> Void { + return bjs_OptionalSupportImports_jsRoundTripOptionalStringNull_static_extern(nameIsSome, nameWord0, nameWord1, nameWord2) } #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_OptionalSupportImports_jsRoundTripOptionalStringUndefined_static") -fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalStringUndefined_static_extern(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void +fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalStringUndefined_static_extern(_ nameIsSome: Int32, _ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32) -> Void #else -fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalStringUndefined_static_extern(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { +fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalStringUndefined_static_extern(_ nameIsSome: Int32, _ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalStringUndefined_static(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { - return bjs_OptionalSupportImports_jsRoundTripOptionalStringUndefined_static_extern(nameIsSome, nameBytes, nameLength) +@inline(never) fileprivate func bjs_OptionalSupportImports_jsRoundTripOptionalStringUndefined_static(_ nameIsSome: Int32, _ nameWord0: Int32, _ nameWord1: Int32, _ nameWord2: Int32) -> Void { + return bjs_OptionalSupportImports_jsRoundTripOptionalStringUndefined_static_extern(nameIsSome, nameWord0, nameWord1, nameWord2) } #if arch(wasm32) @@ -21092,8 +21260,8 @@ func _$OptionalSupportImports_jsRoundTripOptionalNumberUndefined(_ value: JSUnde } func _$OptionalSupportImports_jsRoundTripOptionalStringNull(_ name: Optional) throws(JSException) -> Optional { - name.bridgeJSWithLoweredParameter { (nameIsSome, nameBytes, nameLength) in - bjs_OptionalSupportImports_jsRoundTripOptionalStringNull_static(nameIsSome, nameBytes, nameLength) + name.bridgeJSWithLoweredParameter { (nameIsSome, nameWord0, nameWord1, nameWord2) in + bjs_OptionalSupportImports_jsRoundTripOptionalStringNull_static(nameIsSome, nameWord0, nameWord1, nameWord2) } if let error = _swift_js_take_exception() { throw error @@ -21102,8 +21270,8 @@ func _$OptionalSupportImports_jsRoundTripOptionalStringNull(_ name: Optional) throws(JSException) -> JSUndefinedOr { - name.bridgeJSWithLoweredParameter { (nameIsSome, nameBytes, nameLength) in - bjs_OptionalSupportImports_jsRoundTripOptionalStringUndefined_static(nameIsSome, nameBytes, nameLength) + name.bridgeJSWithLoweredParameter { (nameIsSome, nameWord0, nameWord1, nameWord2) in + bjs_OptionalSupportImports_jsRoundTripOptionalStringUndefined_static(nameIsSome, nameWord0, nameWord1, nameWord2) } if let error = _swift_js_take_exception() { throw error @@ -21163,6 +21331,92 @@ func _$OptionalSupportImports_runJsOptionalSupportTests() throws(JSException) -> } } +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_StringABIImports_jsEcho_static") +fileprivate func bjs_StringABIImports_jsEcho_static_extern(_ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Int32 +#else +fileprivate func bjs_StringABIImports_jsEcho_static_extern(_ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_StringABIImports_jsEcho_static(_ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Int32 { + return bjs_StringABIImports_jsEcho_static_extern(valueWord0, valueWord1, valueWord2) +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_StringABIImports_jsEchoOptional_static") +fileprivate func bjs_StringABIImports_jsEchoOptional_static_extern(_ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void +#else +fileprivate func bjs_StringABIImports_jsEchoOptional_static_extern(_ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_StringABIImports_jsEchoOptional_static(_ valueIsSome: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { + return bjs_StringABIImports_jsEchoOptional_static_extern(valueIsSome, valueWord0, valueWord1, valueWord2) +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_StringABIImports_jsEchoArray_static") +fileprivate func bjs_StringABIImports_jsEchoArray_static_extern() -> Void +#else +fileprivate func bjs_StringABIImports_jsEchoArray_static_extern() -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_StringABIImports_jsEchoArray_static() -> Void { + return bjs_StringABIImports_jsEchoArray_static_extern() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_StringABIImports_runJsStringABITests_static") +fileprivate func bjs_StringABIImports_runJsStringABITests_static_extern() -> Void +#else +fileprivate func bjs_StringABIImports_runJsStringABITests_static_extern() -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_StringABIImports_runJsStringABITests_static() -> Void { + return bjs_StringABIImports_runJsStringABITests_static_extern() +} + +func _$StringABIImports_jsEcho(_ value: String) throws(JSException) -> String { + let ret0 = value.bridgeJSWithLoweredParameter { (valueWord0, valueWord1, valueWord2) in + let ret = bjs_StringABIImports_jsEcho_static(valueWord0, valueWord1, valueWord2) + return ret + } + let ret = ret0 + if let error = _swift_js_take_exception() { + throw error + } + return String.bridgeJSLiftReturn(ret) +} + +func _$StringABIImports_jsEchoOptional(_ value: Optional) throws(JSException) -> Optional { + value.bridgeJSWithLoweredParameter { (valueIsSome, valueWord0, valueWord1, valueWord2) in + bjs_StringABIImports_jsEchoOptional_static(valueIsSome, valueWord0, valueWord1, valueWord2) + } + if let error = _swift_js_take_exception() { + throw error + } + return Optional.bridgeJSLiftReturnFromSideChannel() +} + +func _$StringABIImports_jsEchoArray(_ value: [String]) throws(JSException) -> [String] { + let _ = value.bridgeJSLowerParameter() + bjs_StringABIImports_jsEchoArray_static() + if let error = _swift_js_take_exception() { + throw error + } + return [String].bridgeJSLiftReturn() +} + +func _$StringABIImports_runJsStringABITests() throws(JSException) -> Void { + bjs_StringABIImports_runJsStringABITests_static() + if let error = _swift_js_take_exception() { + throw error + } +} + #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_gc") fileprivate func bjs_gc_extern() -> Void diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index 4749c6eb3..d649d4e76 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -13085,6 +13085,447 @@ ], "swiftCallName" : "APIOptionalResult", "tsFullPath" : "APIOptionalResult" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "StringABIExports", + "staticMethods" : [ + { + "abiName" : "bjs_StringABIExports_static_echo", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "echo", + "namespace" : [ + "StringABIExports" + ], + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "StringABIExports" + } + } + }, + { + "abiName" : "bjs_StringABIExports_static_echoOptional", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "echoOptional", + "namespace" : [ + "StringABIExports" + ], + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "StringABIExports" + } + } + }, + { + "abiName" : "bjs_StringABIExports_static_echoArray", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "echoArray", + "namespace" : [ + "StringABIExports" + ], + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "StringABIExports" + } + } + }, + { + "abiName" : "bjs_StringABIExports_static_smallEmpty", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "smallEmpty", + "namespace" : [ + "StringABIExports" + ], + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "StringABIExports" + } + } + }, + { + "abiName" : "bjs_StringABIExports_static_smallASCII", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "smallASCII", + "namespace" : [ + "StringABIExports" + ], + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "StringABIExports" + } + } + }, + { + "abiName" : "bjs_StringABIExports_static_smallEight", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "smallEight", + "namespace" : [ + "StringABIExports" + ], + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "StringABIExports" + } + } + }, + { + "abiName" : "bjs_StringABIExports_static_smallNine", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "smallNine", + "namespace" : [ + "StringABIExports" + ], + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "StringABIExports" + } + } + }, + { + "abiName" : "bjs_StringABIExports_static_smallTen", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "smallTen", + "namespace" : [ + "StringABIExports" + ], + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "StringABIExports" + } + } + }, + { + "abiName" : "bjs_StringABIExports_static_smallUTF8", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "smallUTF8", + "namespace" : [ + "StringABIExports" + ], + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "StringABIExports" + } + } + }, + { + "abiName" : "bjs_StringABIExports_static_largeImmortal", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "largeImmortal", + "namespace" : [ + "StringABIExports" + ], + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "StringABIExports" + } + } + }, + { + "abiName" : "bjs_StringABIExports_static_largeImmortalAgain", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "largeImmortalAgain", + "namespace" : [ + "StringABIExports" + ], + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "StringABIExports" + } + } + }, + { + "abiName" : "bjs_StringABIExports_static_largeDynamic", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "largeDynamic", + "namespace" : [ + "StringABIExports" + ], + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "StringABIExports" + } + } + }, + { + "abiName" : "bjs_StringABIExports_static_immortalSubstring", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "immortalSubstring", + "namespace" : [ + "StringABIExports" + ], + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "StringABIExports" + } + } + }, + { + "abiName" : "bjs_StringABIExports_static_optionalNone", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "optionalNone", + "namespace" : [ + "StringABIExports" + ], + "parameters" : [ + + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "StringABIExports" + } + } + }, + { + "abiName" : "bjs_StringABIExports_static_optionalSome", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "optionalSome", + "namespace" : [ + "StringABIExports" + ], + "parameters" : [ + + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "StringABIExports" + } + } + } + ], + "staticProperties" : [ + + ], + "swiftCallName" : "StringABIExports", + "tsFullPath" : "StringABIExports" } ], "exposeToGlobal" : false, @@ -27823,6 +28264,135 @@ } ] }, + { + "functions" : [ + + ], + "types" : [ + { + "accessLevel" : "internal", + "getters" : [ + + ], + "methods" : [ + + ], + "name" : "StringABIImports", + "setters" : [ + + ], + "staticMethods" : [ + { + "accessLevel" : "internal", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "jsEcho", + "parameters" : [ + { + "name" : "value", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "accessLevel" : "internal", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "jsEchoOptional", + "parameters" : [ + { + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "accessLevel" : "internal", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "jsEchoArray", + "parameters" : [ + { + "name" : "value", + "type" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + }, + { + "accessLevel" : "internal", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "runJsStringABITests", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + } + ] + } + ] + }, { "functions" : [ { diff --git a/Tests/BridgeJSRuntimeTests/JavaScript/StringABITests.mjs b/Tests/BridgeJSRuntimeTests/JavaScript/StringABITests.mjs new file mode 100644 index 000000000..8468e1faf --- /dev/null +++ b/Tests/BridgeJSRuntimeTests/JavaScript/StringABITests.mjs @@ -0,0 +1,53 @@ +// @ts-check + +import assert from 'node:assert'; + +/** + * @returns {import('../../../.build/plugins/PackageToJS/outputs/PackageTests/bridge-js.d.ts').Imports["StringABIImports"]} + */ +export function getImports(importsContext) { + return { + jsEcho: (value) => value, + jsEchoArray: (value) => value, + jsEchoOptional: (value) => value ?? null, + runJsStringABITests: () => { + const exports = importsContext.getExports(); + if (!exports) { throw new Error("No exports!?"); } + runJsStringABITests(exports); + }, + }; +} + +/** + * Swift→JS string layout coverage: small, immortal, dynamic, substring, optional. + * @param {import('../../../.build/plugins/PackageToJS/outputs/PackageTests/bridge-js.d.ts').Exports} rootExports + */ +export function runJsStringABITests(rootExports) { + const exports = rootExports.StringABIExports; + const immortal = "this is a long immortal literal string"; + + assert.equal(exports.smallEmpty(), ""); + assert.equal(exports.smallASCII(), "div"); + assert.equal(exports.smallEight(), "abcdefgh"); + assert.equal(exports.smallNine(), "abcdefghi"); + assert.equal(exports.smallTen(), "abcdefghij"); + assert.equal(exports.smallUTF8(), "é"); + assert.equal(exports.largeImmortal(), immortal); + assert.equal(exports.largeImmortalAgain(), immortal); + assert.equal(exports.largeDynamic(), immortal); + assert.equal(exports.immortalSubstring(), immortal.slice(10)); + assert.equal(exports.optionalNone(), null); + assert.equal(exports.optionalSome(), immortal); + const expected = samples.map((s) => s.startsWith("\ufeff") ? s.slice(1) : s); + for (let i = 0; i < samples.length; i++) { + assert.equal(exports.echo(samples[i]), expected[i]); + assert.equal(exports.echoOptional(samples[i]), expected[i]); + } + assert.deepEqual(exports.echoArray(samples), expected); +} + +const samples = [ + "abcdefé", "abcdefgé", "abcdefghé", "abcdefghié", "abc€", "abcdefg€", + "abc😄", "abcdef😄", "abcdefg😄", "a\0b", "\ufeffx", "x\ufeff", + "\ufeff\ufeffx", "\ufeffabcdefghijk", "abc\ufeffdefghijk", "\ufeff\ufeffabcdefghijk", +]; diff --git a/Tests/BridgeJSRuntimeTests/StringABITests.swift b/Tests/BridgeJSRuntimeTests/StringABITests.swift new file mode 100644 index 000000000..c3f424011 --- /dev/null +++ b/Tests/BridgeJSRuntimeTests/StringABITests.swift @@ -0,0 +1,81 @@ +import XCTest +import JavaScriptKit +import JavaScriptEventLoop + +private let largeImmortalLiteral = "this is a long immortal literal string" + +@inline(never) +private func runtimeCopy(_ string: String) -> String { + String(decoding: Array(string.utf8), as: UTF8.self) +} + +@JSClass struct StringABIImports { + @JSFunction static func jsEcho(_ value: String) throws(JSException) -> String + @JSFunction static func jsEchoOptional(_ value: String?) throws(JSException) -> String? + @JSFunction static func jsEchoArray(_ value: [String]) throws(JSException) -> [String] + @JSFunction static func runJsStringABITests() throws(JSException) +} + +@JS enum StringABIExports { + @JS static func echo(_ value: String) -> String { value } + @JS static func echoOptional(_ value: String?) -> String? { value } + @JS static func echoArray(_ value: [String]) -> [String] { value } + @JS static func smallEmpty() -> String { "" } + @JS static func smallASCII() -> String { "div" } + @JS static func smallEight() -> String { "abcdefgh" } + @JS static func smallNine() -> String { "abcdefghi" } + @JS static func smallTen() -> String { "abcdefghij" } + @JS static func smallUTF8() -> String { "é" } + @JS static func largeImmortal() -> String { largeImmortalLiteral } + @JS static func largeImmortalAgain() -> String { largeImmortalLiteral } + @JS static func largeDynamic() -> String { runtimeCopy(largeImmortalLiteral) } + @JS static func immortalSubstring() -> String { String(largeImmortalLiteral.dropFirst(10)) } + @JS static func optionalNone() -> String? { nil } + @JS static func optionalSome() -> String? { largeImmortalLiteral } +} + +final class StringABITests: XCTestCase { + func testRunJsStringABITests() throws { + try StringABIImports.runJsStringABITests() + } + + func testUnicodeAndBOMParametersAndStacks() throws { + let samples = [ + "abcdefé", "abcdefgé", "abcdefghé", "abcdefghié", + "abc€", "abcdefg€", "abc😄", "abcdef😄", "abcdefg😄", "a\0b", + "\u{FEFF}x", "x\u{FEFF}", "\u{FEFF}\u{FEFF}x", + "\u{FEFF}abcdefghijk", "abc\u{FEFF}defghijk", "\u{FEFF}\u{FEFF}abcdefghijk", + ] + let expected = samples.map { $0.first == "\u{FEFF}" ? String($0.dropFirst()) : $0 } + for (input, output) in zip(samples, expected) { + try XCTAssertEqual(StringABIImports.jsEcho(input), output) + try XCTAssertEqual(StringABIImports.jsEchoOptional(input), output) + } + try XCTAssertEqual(StringABIImports.jsEchoArray(samples), expected) + } + + func testImportEchoesSmallStrings() throws { + try XCTAssertEqual(StringABIImports.jsEcho(""), "") + try XCTAssertEqual(StringABIImports.jsEcho("div"), "div") + try XCTAssertEqual(StringABIImports.jsEcho("abcdefgh"), "abcdefgh") + try XCTAssertEqual(StringABIImports.jsEcho("abcdefghi"), "abcdefghi") + try XCTAssertEqual(StringABIImports.jsEcho("abcdefghij"), "abcdefghij") + try XCTAssertEqual(StringABIImports.jsEcho("é"), "é") + } + + func testImportEchoesLargeImmortalAndDynamicStrings() throws { + try XCTAssertEqual(StringABIImports.jsEcho(largeImmortalLiteral), largeImmortalLiteral) + try XCTAssertEqual(StringABIImports.jsEcho(largeImmortalLiteral), largeImmortalLiteral) + try XCTAssertEqual(StringABIImports.jsEcho(runtimeCopy(largeImmortalLiteral)), largeImmortalLiteral) + try XCTAssertEqual( + StringABIImports.jsEcho(String(largeImmortalLiteral.dropFirst(10))), + String(largeImmortalLiteral.dropFirst(10)) + ) + } + + func testImportEchoesOptionalStrings() throws { + try XCTAssertNil(StringABIImports.jsEchoOptional(nil)) + try XCTAssertEqual(StringABIImports.jsEchoOptional("div"), "div") + try XCTAssertEqual(StringABIImports.jsEchoOptional(largeImmortalLiteral), largeImmortalLiteral) + } +} diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index 5287df791..8a109bcb5 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -11,6 +11,7 @@ import { getImports as getClosureThrowsImports } from './BridgeJSRuntimeTests/Ja import { getImports as getClosureAsyncImports } from './BridgeJSRuntimeTests/JavaScript/ClosureAsyncTests.mjs'; import { getImports as getSwiftClassSupportImports } from './BridgeJSRuntimeTests/JavaScript/SwiftClassSupportTests.mjs'; import { getImports as getOptionalSupportImports } from './BridgeJSRuntimeTests/JavaScript/OptionalSupportTests.mjs'; +import { getImports as getStringABIImports } from './BridgeJSRuntimeTests/JavaScript/StringABITests.mjs'; import { getImports as getArraySupportImports, ArrayElementObject } from './BridgeJSRuntimeTests/JavaScript/ArraySupportTests.mjs'; import { getImports as getDictionarySupportImports } from './BridgeJSRuntimeTests/JavaScript/DictionarySupportTests.mjs'; import { getImports as getDefaultArgumentImports } from './BridgeJSRuntimeTests/JavaScript/DefaultArgumentTests.mjs'; @@ -212,6 +213,7 @@ export async function setupOptions(options, context) { ClosureAsyncImports: getClosureAsyncImports(importsContext), SwiftClassSupportImports: getSwiftClassSupportImports(importsContext), OptionalSupportImports: getOptionalSupportImports(importsContext), + StringABIImports: getStringABIImports(importsContext), ArraySupportImports: getArraySupportImports(importsContext), DictionarySupportImports: getDictionarySupportImports(importsContext), DefaultArgumentImports: getDefaultArgumentImports(importsContext), @@ -289,6 +291,12 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { assert.equal(exports.roundTripBool(v), v); } for (const v of [ + "", + "div", + "abcdefgh", + "abcdefghi", + "abcdefghij", + "é", "Hello, world!", "😄", "こんにちは", From c68ee9bdebfa28176ebd648d3b51c1cfa1a92a99 Mon Sep 17 00:00:00 2001 From: Simon Leeb <52261246+sliemeobn@users.noreply.github.com> Date: Fri, 9 Oct 2026 01:45:23 +0200 Subject: [PATCH 03/18] Preserve BOMs in decoded strings (#817) --- .../Sources/BridgeJSLink/BridgeJSLink.swift | 5 +--- .../Inputs/StringDecoderTests.mjs | 23 +++++++++++-------- .../__Snapshots__/BridgeJSLinkTests/Alias.js | 5 +--- .../BridgeJSLinkTests/AliasInClosure.js | 5 +--- .../BridgeJSLinkTests/ArrayTypes.js | 5 +--- .../__Snapshots__/BridgeJSLinkTests/Async.js | 5 +--- .../AsyncAssociatedValueEnum.js | 5 +--- .../BridgeJSLinkTests/AsyncImport.js | 5 +--- .../BridgeJSLinkTests/AsyncStaticImport.js | 5 +--- .../BridgeJSLinkTests/ClassWithNestedTypes.js | 5 +--- .../BridgeJSLinkTests/DefaultParameters.js | 5 +--- .../BridgeJSLinkTests/DictionaryTypes.js | 5 +--- .../BridgeJSLinkTests/DocComments.js | 5 +--- .../BridgeJSLinkTests/EnumAlias.js | 5 +--- .../BridgeJSLinkTests/EnumAssociatedValue.js | 5 +--- .../EnumAssociatedValueImport.js | 5 +--- .../BridgeJSLinkTests/EnumCase.js | 5 +--- .../BridgeJSLinkTests/EnumCaseImport.js | 5 +--- .../BridgeJSLinkTests/EnumNamespace.Global.js | 5 +--- .../BridgeJSLinkTests/EnumNamespace.js | 5 +--- .../BridgeJSLinkTests/EnumRawType.js | 5 +--- .../BridgeJSLinkTests/ExtensionNestedTypes.js | 5 +--- .../ExtensionOrderIndependence.js | 5 +--- .../BridgeJSLinkTests/ExtensionScopeParity.js | 5 +--- .../BridgeJSLinkTests/FixedWidthIntegers.js | 5 +--- .../BridgeJSLinkTests/GenericImports.js | 5 +--- .../BridgeJSLinkTests/GlobalGetter.js | 5 +--- .../BridgeJSLinkTests/GlobalThisImports.js | 5 +--- .../IdentityModeClass.ConfigPointer.js | 5 +--- .../IdentityModeClass.PerClass.js | 5 +--- .../BridgeJSLinkTests/IdentityModeClass.js | 5 +--- .../BridgeJSLinkTests/ImportArray.js | 5 +--- .../ImportedTypeInExportedInterface.js | 5 +--- .../BridgeJSLinkTests/InvalidPropertyNames.js | 5 +--- .../BridgeJSLinkTests/JSClass.js | 5 +--- .../JSClassStaticFunctions.js | 5 +--- .../BridgeJSLinkTests/JSImportBareModule.js | 5 +--- .../JSImportBareModuleFallback.js | 5 +--- .../BridgeJSLinkTests/JSImportModule.js | 5 +--- .../BridgeJSLinkTests/JSNameOverride.js | 5 +--- .../BridgeJSLinkTests/JSNameTypes.js | 5 +--- .../BridgeJSLinkTests/JSTypedArrayTypes.js | 5 +--- .../BridgeJSLinkTests/JSValue.js | 5 +--- .../BridgeJSLinkTests/MixedGlobal.js | 5 +--- .../BridgeJSLinkTests/MixedModules.js | 5 +--- .../BridgeJSLinkTests/MixedPrivate.js | 5 +--- .../NamespacedClassSignature.js | 5 +--- .../BridgeJSLinkTests/Namespaces.Global.js | 5 +--- .../BridgeJSLinkTests/Namespaces.js | 5 +--- .../BridgeJSLinkTests/NestedType.js | 5 +--- .../NestedTypeNameCollision.js | 5 +--- .../BridgeJSLinkTests/Optionals.js | 5 +--- .../BridgeJSLinkTests/PrimitiveParameters.js | 5 +--- .../BridgeJSLinkTests/PrimitiveReturn.js | 5 +--- .../BridgeJSLinkTests/PropertyTypes.js | 5 +--- .../BridgeJSLinkTests/Protocol.js | 5 +--- .../BridgeJSLinkTests/ProtocolInClosure.js | 5 +--- .../RelativeQualifiedTypes.js | 5 +--- .../StaticFunctions.Global.js | 5 +--- .../BridgeJSLinkTests/StaticFunctions.js | 5 +--- .../StaticProperties.Global.js | 5 +--- .../BridgeJSLinkTests/StaticProperties.js | 5 +--- .../BridgeJSLinkTests/StringParameter.js | 5 +--- .../BridgeJSLinkTests/StringReturn.js | 5 +--- .../StructWithNestedTypes.js | 5 +--- .../BridgeJSLinkTests/SwiftClass.js | 5 +--- .../BridgeJSLinkTests/SwiftClosure.js | 5 +--- .../BridgeJSLinkTests/SwiftClosureImports.js | 5 +--- .../BridgeJSLinkTests/SwiftStruct.js | 5 +--- .../BridgeJSLinkTests/SwiftStructImports.js | 5 +--- .../SwiftTypedClosureAccess.js | 5 +--- .../__Snapshots__/BridgeJSLinkTests/Throws.js | 5 +--- .../BridgeJSLinkTests/UnsafePointer.js | 5 +--- .../VoidParameterVoidReturn.js | 5 +--- .../JavaScript/StringABITests.mjs | 9 ++++---- .../BridgeJSRuntimeTests/StringABITests.swift | 11 ++++----- 76 files changed, 96 insertions(+), 312 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 7f4ecab03..8f1c84622 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -346,7 +346,6 @@ public struct BridgeJSLink { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -361,8 +360,6 @@ public struct BridgeJSLink { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) @@ -487,7 +484,7 @@ public struct BridgeJSLink { "let \(JSGlueVariableScope.reservedDecodeString);", "let \(JSGlueVariableScope.reservedDecodeUTF8);", "const \(JSGlueVariableScope.reservedImmortalStrings) = new Map();", - "const \(JSGlueVariableScope.reservedTextDecoder) = new TextDecoder(\"utf-8\");", + "const \(JSGlueVariableScope.reservedTextDecoder) = new TextDecoder(\"utf-8\", { ignoreBOM: true });", "const \(JSGlueVariableScope.reservedTextEncoder) = new TextEncoder(\"utf-8\");", "let \(JSGlueVariableScope.reservedStorageToReturnString);", "let \(JSGlueVariableScope.reservedStorageToReturnBytes);", diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringDecoderTests.mjs b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringDecoderTests.mjs index 2aa88cf5d..73299ddc0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringDecoderTests.mjs +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringDecoderTests.mjs @@ -6,7 +6,6 @@ const source = await readFile(process.argv[2] ?? new URL('../__Snapshots__/Bridg const shared = process.argv[3] === 'shared'; const { createInstantiator } = await import(`data:text/javascript;base64,${Buffer.from(source).toString('base64')}`); const encoder = new TextEncoder(); -const decoder = new TextDecoder(); const swift = { memory: { heap: [], retain: (value) => value } }; const bridge = await createInstantiator({ getImports: () => ({}) }, swift); const imports = {}; @@ -35,21 +34,27 @@ function large(value, immortal = false, ptr = 64) { } const values = ['', 'div', 'abcdefgh', 'abcdefghi', 'abcdefghij', 'abcdefé', 'abcdefgé', 'abcdefghé', 'abcdefghié', 'abc€', 'abcdefg€', 'abc😄', 'abcdef😄', 'abcdefg😄', - 'a\0b', '\ufeff', '\ufeffx', 'x\ufeff', '\ufeff\ufeffx', '\ufeffabcdefghijk', - 'abc\ufeffdefghijk', '\ufeff\ufeffabcdefghijk']; -for (const value of values) { - const expected = decoder.decode(encoder.encode(value)); + '😄😄', 'éééé', 'a\0b', '\ufeff', '\ufeffx', '\ufeffabcde', '\ufeffabcdef', + 'x\ufeff', '\ufeff\ufeffx', '\ufeffabcdefghijk', + 'abc\ufeffdefghijk', '\ufeff\ufeffabcdefghijk', + // UTF-8 widths, the surrogate gap, and supplementary-plane boundaries. + '\u0080', '\u07ff', '\u0800', '\ud7ff', '\ue000', '\uffff', '\u{10000}', '\u{10ffff}']; +for (const [index, value] of values.entries()) { if (encoder.encode(value).length <= 8) { words = small(value); - assert.equal(exports.checkString(), expected); + assert.equal(exports.checkString(), value); + } + for (const immortal of [false, true]) { + // Distinct locations keep immortal cache entries faithful to Swift literals. + words = large(value, immortal, 64 + index * 64); + assert.equal(exports.checkString(), value); + assert.equal(exports.checkString(), value); } - words = large(value); - assert.equal(exports.checkString(), expected); } // Alternate full and short inputs: bytes outside count must never leak into the result. for (const value of ['abcd😄', 'é', 'abcde€', '\ufeff', 'abcdefgh', '', 'x\0', '€', '\ufeff\ufeff']) { words = small(value); - assert.equal(exports.checkString(), decoder.decode(encoder.encode(value))); + assert.equal(exports.checkString(), value); } // Every ASCII byte, including NUL, at every small-string length. for (let byte = 0; byte < 128; byte++) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js index 422e26dd9..b434d4e5e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js @@ -17,7 +17,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -706,7 +706,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -721,8 +720,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AliasInClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AliasInClosure.js index 5a7dc255e..d4174627e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AliasInClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AliasInClosure.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -318,7 +318,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -333,8 +332,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js index bb61c4fb5..f4c519fe9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js @@ -24,7 +24,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -768,7 +768,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -783,8 +782,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js index b657a2188..33c4ff195 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js @@ -21,7 +21,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -752,7 +752,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -767,8 +766,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncAssociatedValueEnum.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncAssociatedValueEnum.js index d16d071b7..099a0756e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncAssociatedValueEnum.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncAssociatedValueEnum.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -398,7 +398,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -413,8 +412,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js index cc7b29f42..5b2a085ac 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -530,7 +530,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -545,8 +544,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js index 406c5da24..7a265486b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -426,7 +426,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -441,8 +440,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ClassWithNestedTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ClassWithNestedTypes.js index 3d0a66cc3..1d7ebeabf 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ClassWithNestedTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ClassWithNestedTypes.js @@ -16,7 +16,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -267,7 +267,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -282,8 +281,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js index 35417c66b..03afa8031 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js @@ -17,7 +17,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -645,7 +645,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -660,8 +659,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js index 1b796f0de..10f84209a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -620,7 +620,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -635,8 +634,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DocComments.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DocComments.js index 0dae550a8..902f06ff9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DocComments.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DocComments.js @@ -17,7 +17,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -284,7 +284,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -299,8 +298,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAlias.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAlias.js index 897f9e772..3ff888129 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAlias.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAlias.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -243,7 +243,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -258,8 +257,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js index afe2e8ac7..3f0c005f2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js @@ -92,7 +92,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -1205,7 +1205,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -1220,8 +1219,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValueImport.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValueImport.js index 4b71ac219..0d770ed41 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValueImport.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValueImport.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -329,7 +329,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -344,8 +343,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js index e87881f55..999d1847f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js @@ -35,7 +35,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -259,7 +259,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -274,8 +273,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCaseImport.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCaseImport.js index c816b3bf0..3a78dd143 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCaseImport.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCaseImport.js @@ -16,7 +16,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -267,7 +267,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -282,8 +281,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js index f744a43f3..b838f4c96 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js @@ -55,7 +55,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -299,7 +299,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -314,8 +313,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js index e43b2bcb9..929f55c86 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js @@ -36,7 +36,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -280,7 +280,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -295,8 +294,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js index fd3640162..ce8d4ed42 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js @@ -86,7 +86,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -673,7 +673,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -688,8 +687,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionNestedTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionNestedTypes.js index 53690ed6a..1b54d416e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionNestedTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionNestedTypes.js @@ -27,7 +27,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -328,7 +328,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -343,8 +342,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionOrderIndependence.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionOrderIndependence.js index e5a43fdc2..cda13ba4c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionOrderIndependence.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionOrderIndependence.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -270,7 +270,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -285,8 +284,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionScopeParity.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionScopeParity.js index 5312f0fbd..d0d1ea8bd 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionScopeParity.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionScopeParity.js @@ -15,7 +15,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -270,7 +270,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -285,8 +284,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/FixedWidthIntegers.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/FixedWidthIntegers.js index af7fa150c..50d25d09b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/FixedWidthIntegers.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/FixedWidthIntegers.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -308,7 +308,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -323,8 +322,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js index e2f71f878..49aaa5798 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js @@ -27,7 +27,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -966,7 +966,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -981,8 +980,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js index 77dcf0f7a..1d299cab4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -253,7 +253,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -268,8 +267,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js index c5c7221d0..8c3f0b5b4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -278,7 +278,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -293,8 +292,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.ConfigPointer.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.ConfigPointer.js index f33437e89..cc70a978a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.ConfigPointer.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.ConfigPointer.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -250,7 +250,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -265,8 +264,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.PerClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.PerClass.js index 43901d4a2..b9b854e52 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.PerClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.PerClass.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -250,7 +250,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -265,8 +264,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.js index 43901d4a2..b9b854e52 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -250,7 +250,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -265,8 +264,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js index 893402b07..a3e0fd6d3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -603,7 +603,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -618,8 +617,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js index 69a851251..4bfce3e14 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -615,7 +615,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -630,8 +629,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js index 8909352ce..edcedc1b7 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -416,7 +416,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -431,8 +430,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js index 0c0f030f7..cbec50c8f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -315,7 +315,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -330,8 +329,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js index f730efb98..9cbaf2a3e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -298,7 +298,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -313,8 +312,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModule.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModule.js index 23a5b1635..50ed98d9a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModule.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModule.js @@ -17,7 +17,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -323,7 +323,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -338,8 +337,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModuleFallback.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModuleFallback.js index 55ef14aa6..ca94e5a13 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModuleFallback.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModuleFallback.js @@ -14,7 +14,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -267,7 +267,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -282,8 +281,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportModule.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportModule.js index 589f570cf..af4273cc3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportModule.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportModule.js @@ -14,7 +14,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -307,7 +307,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -322,8 +321,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameOverride.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameOverride.js index 16219c83c..0190b9c65 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameOverride.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameOverride.js @@ -16,7 +16,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -272,7 +272,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -287,8 +286,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameTypes.js index ad3e9096e..107f497fc 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameTypes.js @@ -16,7 +16,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -248,7 +248,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -263,8 +262,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSTypedArrayTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSTypedArrayTypes.js index f1ffa766f..9d03440f5 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSTypedArrayTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSTypedArrayTypes.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -234,7 +234,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -249,8 +248,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js index 99742f97b..07d7ba167 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -591,7 +591,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -606,8 +605,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js index bed72152c..964b97e3a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -242,7 +242,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -257,8 +256,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js index 75697b834..d8eee50de 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -250,7 +250,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -265,8 +264,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js index c6f2fdffa..359f5ddd9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -242,7 +242,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -257,8 +256,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NamespacedClassSignature.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NamespacedClassSignature.js index 79519e8f1..1d6b6c343 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NamespacedClassSignature.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NamespacedClassSignature.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -294,7 +294,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -309,8 +308,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js index 2e2667caa..a5f6d34f4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -589,7 +589,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -604,8 +603,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js index 33d18909a..b13010601 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -589,7 +589,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -604,8 +603,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedType.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedType.js index f46e610cd..82710d04b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedType.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedType.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -286,7 +286,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -301,8 +300,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedTypeNameCollision.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedTypeNameCollision.js index 332fc4e42..541ad55df 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedTypeNameCollision.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedTypeNameCollision.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -270,7 +270,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -285,8 +284,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js index 57c49fd4c..fb8018c44 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -871,7 +871,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -886,8 +885,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js index a25de5e29..3b8c9adbc 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -243,7 +243,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -258,8 +257,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js index 2a92af613..1177dc82b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -254,7 +254,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -269,8 +268,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js index 39677e821..44eab0d15 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -242,7 +242,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -257,8 +256,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js index 192e93d8e..96f132fda 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js @@ -35,7 +35,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -941,7 +941,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -956,8 +955,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js index aab8103f5..d6fa6f143 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -388,7 +388,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -403,8 +402,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/RelativeQualifiedTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/RelativeQualifiedTypes.js index a1b8f290c..06af75757 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/RelativeQualifiedTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/RelativeQualifiedTypes.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -325,7 +325,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -340,8 +339,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js index 338cf237d..4cc10e4b9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js @@ -22,7 +22,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -287,7 +287,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -302,8 +301,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js index e474c82a6..b9c8414b0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js @@ -22,7 +22,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -287,7 +287,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -302,8 +301,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js index eb1b2d2ef..7eff82661 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js @@ -16,7 +16,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -248,7 +248,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -263,8 +262,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js index 95470ed56..f8aa35927 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js @@ -16,7 +16,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -248,7 +248,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -263,8 +262,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js index c76381468..6dc173b63 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -252,7 +252,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -267,8 +266,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js index 0a0fc1650..eb4e4c37b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -245,7 +245,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -260,8 +259,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StructWithNestedTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StructWithNestedTypes.js index 7c189df7e..f9b50f9f8 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StructWithNestedTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StructWithNestedTypes.js @@ -26,7 +26,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -322,7 +322,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -337,8 +336,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js index 293ea56da..e171064a6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -270,7 +270,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -285,8 +284,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js index dabb7595f..928cc44a0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js @@ -41,7 +41,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -1587,7 +1587,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -1602,8 +1601,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js index 0a6690be9..c47a65b6b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -509,7 +509,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -524,8 +523,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js index e336f8911..54aa63d69 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js @@ -16,7 +16,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -804,7 +804,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -819,8 +818,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js index ff953c9a3..2ebef1501 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -607,7 +607,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -622,8 +621,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftTypedClosureAccess.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftTypedClosureAccess.js index 8cec87d6e..80e2a1984 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftTypedClosureAccess.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftTypedClosureAccess.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -352,7 +352,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -367,8 +366,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js index 40bf7e8c2..5a575ffed 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -234,7 +234,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -249,8 +248,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js index 435415b0f..ef00d53a6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -259,7 +259,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -274,8 +273,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js index ce27ff522..5abfccc3f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js @@ -11,7 +11,7 @@ export async function createInstantiator(options, swift) { let decodeString; let decodeUTF8; const immortalStrings = new Map(); - const textDecoder = new TextDecoder("utf-8"); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); const textEncoder = new TextEncoder("utf-8"); let tmpRetString; let tmpRetBytes; @@ -243,7 +243,6 @@ export async function createInstantiator(options, swift) { u6 = 0, u7 = 0; while (byteIndex < count) { - const start = byteIndex; const b0 = byteAt(word0, word1, byteIndex++); let codePoint; if (b0 < 128) codePoint = b0; @@ -258,8 +257,6 @@ export async function createInstantiator(options, swift) { b3 = byteAt(word0, word1, byteIndex++); codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); } - // Match TextDecoder: consume exactly one leading UTF-8 BOM. - if (start === 0 && codePoint === 0xfeff) continue; const supplementary = codePoint > 0xffff; const codeUnit = supplementary ? 0xd800 + ((codePoint - 0x10000) >>> 10) diff --git a/Tests/BridgeJSRuntimeTests/JavaScript/StringABITests.mjs b/Tests/BridgeJSRuntimeTests/JavaScript/StringABITests.mjs index 8468e1faf..1ff321261 100644 --- a/Tests/BridgeJSRuntimeTests/JavaScript/StringABITests.mjs +++ b/Tests/BridgeJSRuntimeTests/JavaScript/StringABITests.mjs @@ -38,16 +38,15 @@ export function runJsStringABITests(rootExports) { assert.equal(exports.immortalSubstring(), immortal.slice(10)); assert.equal(exports.optionalNone(), null); assert.equal(exports.optionalSome(), immortal); - const expected = samples.map((s) => s.startsWith("\ufeff") ? s.slice(1) : s); for (let i = 0; i < samples.length; i++) { - assert.equal(exports.echo(samples[i]), expected[i]); - assert.equal(exports.echoOptional(samples[i]), expected[i]); + assert.equal(exports.echo(samples[i]), samples[i]); + assert.equal(exports.echoOptional(samples[i]), samples[i]); } - assert.deepEqual(exports.echoArray(samples), expected); + assert.deepEqual(exports.echoArray(samples), samples); } const samples = [ "abcdefé", "abcdefgé", "abcdefghé", "abcdefghié", "abc€", "abcdefg€", - "abc😄", "abcdef😄", "abcdefg😄", "a\0b", "\ufeffx", "x\ufeff", + "abc😄", "abcdef😄", "abcdefg😄", "a\0b", "\ufeff", "\ufeffx", "\ufeffabcde", "\ufeffabcdef", "x\ufeff", "\ufeff\ufeffx", "\ufeffabcdefghijk", "abc\ufeffdefghijk", "\ufeff\ufeffabcdefghijk", ]; diff --git a/Tests/BridgeJSRuntimeTests/StringABITests.swift b/Tests/BridgeJSRuntimeTests/StringABITests.swift index c3f424011..5d2cae9b0 100644 --- a/Tests/BridgeJSRuntimeTests/StringABITests.swift +++ b/Tests/BridgeJSRuntimeTests/StringABITests.swift @@ -43,15 +43,14 @@ final class StringABITests: XCTestCase { let samples = [ "abcdefé", "abcdefgé", "abcdefghé", "abcdefghié", "abc€", "abcdefg€", "abc😄", "abcdef😄", "abcdefg😄", "a\0b", - "\u{FEFF}x", "x\u{FEFF}", "\u{FEFF}\u{FEFF}x", + "\u{FEFF}", "\u{FEFF}x", "\u{FEFF}abcde", "\u{FEFF}abcdef", "x\u{FEFF}", "\u{FEFF}\u{FEFF}x", "\u{FEFF}abcdefghijk", "abc\u{FEFF}defghijk", "\u{FEFF}\u{FEFF}abcdefghijk", ] - let expected = samples.map { $0.first == "\u{FEFF}" ? String($0.dropFirst()) : $0 } - for (input, output) in zip(samples, expected) { - try XCTAssertEqual(StringABIImports.jsEcho(input), output) - try XCTAssertEqual(StringABIImports.jsEchoOptional(input), output) + for input in samples { + try XCTAssertEqual(StringABIImports.jsEcho(input), input) + try XCTAssertEqual(StringABIImports.jsEchoOptional(input), input) } - try XCTAssertEqual(StringABIImports.jsEchoArray(samples), expected) + try XCTAssertEqual(StringABIImports.jsEchoArray(samples), samples) } func testImportEchoesSmallStrings() throws { From 67f3be5cc54fa8134cbccafd9c1a3026dd6b5750 Mon Sep 17 00:00:00 2001 From: William Taylor Date: Wed, 14 Oct 2026 15:29:39 +1100 Subject: [PATCH 04/18] BridgeJS: Support `any T` and `(T)` (#819) --- .../Sources/BridgeJSCore/SwiftToSkeleton.swift | 15 +++++++++++++++ .../Inputs/MacroSwift/Protocol.swift | 8 ++++---- .../Inputs/MacroSwift/ProtocolInClosure.swift | 4 ++-- .../BridgeJSRuntimeTests/ArraySupportTests.swift | 2 +- Tests/BridgeJSRuntimeTests/ExportAPITests.swift | 16 ++++++++-------- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index 0f9f79c06..ad3722dac 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -436,6 +436,21 @@ public final class SwiftToSkeleton { return lookupType(for: attributedType.baseType, errors: &errors) } + // any P + if let existentialType = type.as(SomeOrAnyTypeSyntax.self), + existentialType.someOrAnySpecifier.tokenKind == .keyword(.any) + { + return lookupType(for: existentialType.constraint, errors: &errors) + } + + // (T) + if let tupleType = type.as(TupleTypeSyntax.self), + tupleType.elements.count == 1, + let element = tupleType.elements.first + { + return lookupType(for: element.type, errors: &errors) + } + // JSTypedArray if let identifierType = type.as(IdentifierTypeSyntax.self), identifierType.name.text == "JSTypedArray", diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift index bdb700d69..0f65a4dcf 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift @@ -66,9 +66,9 @@ import JavaScriptKit var delegate: MyViewControllerDelegate @JS - var secondDelegate: MyViewControllerDelegate? + var secondDelegate: (any MyViewControllerDelegate)? - @JS init(delegate: MyViewControllerDelegate) { + @JS init(delegate: any MyViewControllerDelegate) { self.delegate = delegate } @@ -103,7 +103,7 @@ import JavaScriptKit var delegates: [MyViewControllerDelegate] @JS - var delegatesByName: [String: MyViewControllerDelegate] + var delegatesByName: [String: any MyViewControllerDelegate] @JS init(delegates: [MyViewControllerDelegate]) { self.delegates = delegates @@ -117,7 +117,7 @@ import JavaScriptKit } } -@JS func processDelegates(_ delegates: [MyViewControllerDelegate]) -> [MyViewControllerDelegate] +@JS func processDelegates(_ delegates: [any MyViewControllerDelegate]) -> [any MyViewControllerDelegate] @JS func processDelegatesByName( _ delegates: [String: MyViewControllerDelegate] diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ProtocolInClosure.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ProtocolInClosure.swift index cb814adf2..660d1a834 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ProtocolInClosure.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ProtocolInClosure.swift @@ -14,5 +14,5 @@ import JavaScriptKit @JS func processRenderable(_ item: Renderable, transform: (Renderable) -> String) -> String @JS func makeRenderableFactory(defaultName: String) -> () -> Renderable -@JS func roundtripRenderable(_ callback: (Renderable) -> Renderable) -> (Renderable) -> Renderable -@JS func processOptionalRenderable(_ callback: (Renderable?) -> String) -> String +@JS func roundtripRenderable(_ callback: (any Renderable) -> any Renderable) -> (any Renderable) -> any Renderable +@JS func processOptionalRenderable(_ callback: ((any Renderable)?) -> String) -> String diff --git a/Tests/BridgeJSRuntimeTests/ArraySupportTests.swift b/Tests/BridgeJSRuntimeTests/ArraySupportTests.swift index 90c4b138e..3ff17cbfa 100644 --- a/Tests/BridgeJSRuntimeTests/ArraySupportTests.swift +++ b/Tests/BridgeJSRuntimeTests/ArraySupportTests.swift @@ -195,7 +195,7 @@ final class ArraySupportTests: XCTestCase { @JS static func roundTripStructArray(_ v: [DataPoint]) -> [DataPoint] { v } @JS static func roundTripSwiftClassArray(_ v: [Greeter]) -> [Greeter] { v } @JS static func roundTripNamespacedSwiftClassArray(_ v: [Utils.Converter]) -> [Utils.Converter] { v } - @JS static func roundTripProtocolArray(_ v: [ArrayElementProtocol]) -> [ArrayElementProtocol] { v } + @JS static func roundTripProtocolArray(_ v: [any ArrayElementProtocol]) -> [any ArrayElementProtocol] { v } @JS static func roundTripJSClassArray(_ v: [ArrayElementObject]) -> [ArrayElementObject] { v } @JS static func roundTripOptionalIntArray(_ v: [Int?]) -> [Int?] { v } diff --git a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift index 8778c2c8e..142b2ae9b 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -966,9 +966,9 @@ enum GraphOperations { @JS class DataProcessorManager { @JS var processor: DataProcessor - @JS var backupProcessor: DataProcessor? + @JS var backupProcessor: (any DataProcessor)? - @JS init(processor: DataProcessor) { + @JS init(processor: any DataProcessor) { self.processor = processor self.backupProcessor = nil } @@ -1124,7 +1124,7 @@ enum GraphOperations { return SwiftDataProcessor() } - @JS static func createNativeProcessorOptional() -> DataProcessor? { + @JS static func createNativeProcessorOptional() -> (any DataProcessor)? { return SwiftDataProcessor() } @@ -1132,7 +1132,7 @@ enum GraphOperations { return nil } - @JS static func createNativeProcessorArray() -> [DataProcessor] { + @JS static func createNativeProcessorArray() -> [any DataProcessor] { let p1 = SwiftDataProcessor() p1.count = 10 let p2 = SwiftDataProcessor() @@ -1140,7 +1140,7 @@ enum GraphOperations { return [p1, p2] } - @JS static func createNativeProcessorDictionary() -> [String: DataProcessor] { + @JS static func createNativeProcessorDictionary() -> [String: any DataProcessor] { let p1 = SwiftDataProcessor() p1.count = 10 let p2 = SwiftDataProcessor() @@ -1317,12 +1317,12 @@ enum GraphOperations { } @JS func roundtripDataProcessor( - _ callback: @escaping (DataProcessor) -> DataProcessor - ) -> (DataProcessor) -> DataProcessor { + _ callback: @escaping (any DataProcessor) -> any DataProcessor + ) -> (any DataProcessor) -> any DataProcessor { return callback } - @JS func processOptionalDataProcessor(_ callback: (DataProcessor?) -> String) -> String { + @JS func processOptionalDataProcessor(_ callback: ((any DataProcessor)?) -> String) -> String { let processor = SwiftDataProcessor() processor.increment(by: 7) return callback(processor) + " | " + callback(nil) From 14c1336e758f7cc1567f353563f60d1d72a6834a Mon Sep 17 00:00:00 2001 From: William Taylor Date: Wed, 14 Oct 2026 15:49:47 +1100 Subject: [PATCH 05/18] BridgeJS: Support exporting protocol methods with async and throws --- .../Sources/BridgeJSCore/ExportSwift.swift | 2 +- .../Sources/BridgeJSLink/BridgeJSLink.swift | 22 +- .../BridgeJSSkeleton/BridgeJSSkeleton.swift | 9 + .../Inputs/MacroSwift/Protocol.swift | 12 + .../BridgeJSCodegenTests/Protocol.json | 149 +++++++ .../BridgeJSCodegenTests/Protocol.swift | 412 ++++++++++++++++++ .../BridgeJSLinkTests/AsyncImport.js | 38 +- .../BridgeJSLinkTests/AsyncStaticImport.js | 12 +- .../BridgeJSLinkTests/Protocol.d.ts | 6 + .../BridgeJSLinkTests/Protocol.js | 191 ++++++++ .../BridgeJSLinkTests/SwiftClosure.js | 38 +- .../BridgeJSLinkTests/SwiftClosureImports.js | 10 +- .../Exporting-Swift-Protocols.md | 2 + .../AsyncImportTests.swift | 15 + .../BridgeJSRuntimeTests/ExportAPITests.swift | 39 ++ .../Generated/BridgeJS.swift | 264 +++++++++++ .../Generated/JavaScript/BridgeJS.json | 327 ++++++++++++++ .../JavaScript/AsyncImportTests.mjs | 6 + .../JavaScript/ClosureAsyncTests.mjs | 8 + Tests/prelude.mjs | 130 +++++- 20 files changed, 1654 insertions(+), 38 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index df8c589ea..7d402aa9c 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -1439,7 +1439,7 @@ struct ProtocolCodegen { let signature = SwiftSignatureBuilder.buildFunctionSignature( parameters: method.parameters, returnType: method.returnType, - effects: nil + effects: method.effects ) // Build extern declaration using helper function diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 8f1c84622..c97bdf293 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -2908,7 +2908,15 @@ extension BridgeJSLink { let s = JSGlueVariableScope.reservedSwift printer.write("const resolve = \(s).memory.getObject(resolveRef);") printer.write("const reject = \(s).memory.getObject(rejectRef);") - printer.write(contentsOf: body) + printer.write("try {") + printer.indent { + printer.write(contentsOf: body) + } + printer.write("} catch (error) {") + printer.indent { + printer.write("reject(error);") + } + printer.write("}") } printer.write("}") return printer.lines @@ -2930,7 +2938,7 @@ extension BridgeJSLink { private func call(callExpr: String) throws { if effects.isAsync { - body.write("\(callExpr).then(resolve, reject);") + body.write("Promise.resolve(\(callExpr)).then(resolve, reject);") return } if let name = returnType.referencedGenericName { @@ -2997,14 +3005,6 @@ extension BridgeJSLink { return try call(calleeExpr: calleeExpr) } - /// Generates an async method call with resolve/reject closure refs. - func callAsyncMethod(name: String) { - let objectExpr = "\(JSGlueVariableScope.reservedSwift).memory.getObject(self)" - let calleeExpr = Self.propertyAccessExpr(objectExpr: objectExpr, propertyName: name) - let callExpr = "\(calleeExpr)(\(parameterForwardings.joined(separator: ", ")))" - body.write("\(callExpr).then(resolve, reject);") - } - func callStaticMethod(on objectExpr: String, name: String) throws { let calleeExpr = Self.propertyAccessExpr(objectExpr: objectExpr, propertyName: name) return try call(calleeExpr: calleeExpr) @@ -4235,7 +4235,7 @@ extension BridgeJSLink { method: ExportedFunction ) throws { let thunkBuilder = ImportedThunkBuilder( - effects: Effects(isAsync: false, isThrows: false), + effects: method.effects, returnType: method.returnType, context: .exportSwift, intrinsicRegistry: intrinsicRegistry diff --git a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift index 8da9f2e4e..d52e9122d 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift @@ -607,6 +607,7 @@ public protocol BridgeSkeletonVisitor { accessLevel: BridgeJSAccessLevel ) mutating func visitImportedFunction(_ function: ImportedFunctionSkeleton) + mutating func visitProtocolMethod(_ method: ExportedFunction, accessLevel: BridgeJSAccessLevel) } public extension BridgeSkeletonVisitor { @@ -616,6 +617,7 @@ public extension BridgeSkeletonVisitor { accessLevel: BridgeJSAccessLevel ) {} mutating func visitImportedFunction(_ function: ImportedFunctionSkeleton) {} + mutating func visitProtocolMethod(_ method: ExportedFunction, accessLevel: BridgeJSAccessLevel) {} } public struct BridgeSkeletonWalker { @@ -681,6 +683,7 @@ public struct BridgeSkeletonWalker { } for proto in skeleton.protocols { for method in proto.methods { + visitor.visitProtocolMethod(method, accessLevel: currentAccessLevel) walk(method) } for property in proto.properties { @@ -1870,6 +1873,12 @@ public struct ClosureSignatureCollectorVisitor: BridgeSkeletonVisitor { ) } + public mutating func visitProtocolMethod(_ method: ExportedFunction, accessLevel: BridgeJSAccessLevel) { + guard method.effects.isAsync else { return } + + recordInjectedSignatures(forReturnType: method.returnType, accessLevel: accessLevel) + } + private mutating func recordInjectedSignatures( forReturnType returnType: BridgeType, accessLevel: BridgeJSAccessLevel diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift index bdb700d69..8ddb3dfbd 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift @@ -59,6 +59,10 @@ import JavaScriptKit func createEnum() -> ExampleEnum func handleResult(_ result: Result) func getResult() -> Result + func validate(_ value: Int) throws(JSException) -> Int + func loadLabel(_ key: String) async throws(JSException) -> String + func reset() async throws(JSException) + func fetchCount() async -> Int } @JS class MyViewController { @@ -95,6 +99,14 @@ import JavaScriptKit @JS func sendHelper(_ helper: Helper) { delegate.onHelperUpdated(helper) } + + @JS func validateValue(_ value: Int) throws(JSException) -> Int { + return try delegate.validate(value) + } + + @JS func loadLabel(_ key: String) async throws(JSException) -> String { + return try await delegate.loadLabel(key) + } } // Protocol array support diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json index bc443c6c0..4fbec6b49 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json @@ -228,6 +228,62 @@ "returnType" : { "void" : { + } + } + }, + { + "abiName" : "bjs_MyViewController_validateValue", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "validateValue", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } + ], + "returnType" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + }, + { + "abiName" : "bjs_MyViewController_loadLabel", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : true + }, + "name" : "loadLabel", + "parameters" : [ + { + "label" : "_", + "name" : "key", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + } } } @@ -831,6 +887,99 @@ "_0" : "Result" } } + }, + { + "abiName" : "bjs_MyViewControllerDelegate_validate", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "validate", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } + ], + "returnType" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + }, + { + "abiName" : "bjs_MyViewControllerDelegate_loadLabel", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : true + }, + "name" : "loadLabel", + "parameters" : [ + { + "label" : "_", + "name" : "key", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_MyViewControllerDelegate_reset", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : true + }, + "name" : "reset", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_MyViewControllerDelegate_fetchCount", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : false + }, + "name" : "fetchCount", + "parameters" : [ + + ], + "returnType" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } } ], "name" : "MyViewControllerDelegate", diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift index a91524da5..3c4ba2a78 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift @@ -1,3 +1,250 @@ +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModules7JSValueV_y") +fileprivate func invoke_js_callback_TestModule_10TestModules7JSValueV_y_extern(_ callback: Int32, _ param0Kind: Int32, _ param0Payload1: Int32, _ param0Payload2: Float64) -> Void +#else +fileprivate func invoke_js_callback_TestModule_10TestModules7JSValueV_y_extern(_ callback: Int32, _ param0Kind: Int32, _ param0Payload1: Int32, _ param0Payload2: Float64) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModules7JSValueV_y(_ callback: Int32, _ param0Kind: Int32, _ param0Payload1: Int32, _ param0Payload2: Float64) -> Void { + return invoke_js_callback_TestModule_10TestModules7JSValueV_y_extern(callback, param0Kind, param0Payload1, param0Payload2) +} + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "make_swift_closure_TestModule_10TestModules7JSValueV_y") +fileprivate func make_swift_closure_TestModule_10TestModules7JSValueV_y_extern(_ boxPtr: UnsafeMutableRawPointer, _ file: UnsafePointer, _ line: UInt32) -> Int32 +#else +fileprivate func make_swift_closure_TestModule_10TestModules7JSValueV_y_extern(_ boxPtr: UnsafeMutableRawPointer, _ file: UnsafePointer, _ line: UInt32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func make_swift_closure_TestModule_10TestModules7JSValueV_y(_ boxPtr: UnsafeMutableRawPointer, _ file: UnsafePointer, _ line: UInt32) -> Int32 { + return make_swift_closure_TestModule_10TestModules7JSValueV_y_extern(boxPtr, file, line) +} + +private enum _BJS_Closure_10TestModules7JSValueV_y { + static func bridgeJSLift(_ callbackId: Int32) -> (sending JSValue) -> Void { + let callback = JSObject.bridgeJSLiftParameter(callbackId) + return { [callback] param0 in + #if arch(wasm32) + let (param0Kind, param0Payload1, param0Payload2) = param0.bridgeJSLowerParameter() + let callbackValue = callback.bridgeJSLowerParameter() + invoke_js_callback_TestModule_10TestModules7JSValueV_y(callbackValue, param0Kind, param0Payload1, param0Payload2) + #else + fatalError("Only available on WebAssembly") + #endif + } + } +} + +extension JSTypedClosure where Signature == (sending JSValue) -> Void { + static func sending(fileID: StaticString = #fileID, line: UInt32 = #line, _ body: @escaping (sending JSValue) -> Void) -> Self { + Self( + makeClosure: make_swift_closure_TestModule_10TestModules7JSValueV_y, + body: body, + fileID: fileID, + line: line + ) + } +} + +@_expose(wasm, "invoke_swift_closure_TestModule_10TestModules7JSValueV_y") +@_cdecl("invoke_swift_closure_TestModule_10TestModules7JSValueV_y") +public func _invoke_swift_closure_TestModule_10TestModules7JSValueV_y(_ boxPtr: UnsafeMutableRawPointer, _ param0Kind: Int32, _ param0Payload1: Int32, _ param0Payload2: Float64) -> Void { + #if arch(wasm32) + let param0 = JSValue.bridgeJSLiftParameter(param0Kind, param0Payload1, param0Payload2) + let closure = Unmanaged<_BridgeJSTypedClosureBox<(sending JSValue) -> Void>>.fromOpaque(boxPtr).takeUnretainedValue().closure + closure(param0) + #else + fatalError("Only available on WebAssembly") + #endif +} + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModulesSS_y") +fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void +#else +fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y_extern(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModulesSS_y(_ callback: Int32, _ param0Word0: Int32, _ param0Word1: Int32, _ param0Word2: Int32) -> Void { + return invoke_js_callback_TestModule_10TestModulesSS_y_extern(callback, param0Word0, param0Word1, param0Word2) +} + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "make_swift_closure_TestModule_10TestModulesSS_y") +fileprivate func make_swift_closure_TestModule_10TestModulesSS_y_extern(_ boxPtr: UnsafeMutableRawPointer, _ file: UnsafePointer, _ line: UInt32) -> Int32 +#else +fileprivate func make_swift_closure_TestModule_10TestModulesSS_y_extern(_ boxPtr: UnsafeMutableRawPointer, _ file: UnsafePointer, _ line: UInt32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func make_swift_closure_TestModule_10TestModulesSS_y(_ boxPtr: UnsafeMutableRawPointer, _ file: UnsafePointer, _ line: UInt32) -> Int32 { + return make_swift_closure_TestModule_10TestModulesSS_y_extern(boxPtr, file, line) +} + +private enum _BJS_Closure_10TestModulesSS_y { + static func bridgeJSLift(_ callbackId: Int32) -> (sending String) -> Void { + let callback = JSObject.bridgeJSLiftParameter(callbackId) + return { [callback] param0 in + #if arch(wasm32) + param0.bridgeJSWithLoweredParameter { (param0Word0, param0Word1, param0Word2) in + let callbackValue = callback.bridgeJSLowerParameter() + invoke_js_callback_TestModule_10TestModulesSS_y(callbackValue, param0Word0, param0Word1, param0Word2) + } + #else + fatalError("Only available on WebAssembly") + #endif + } + } +} + +extension JSTypedClosure where Signature == (sending String) -> Void { + static func sending(fileID: StaticString = #fileID, line: UInt32 = #line, _ body: @escaping (sending String) -> Void) -> Self { + Self( + makeClosure: make_swift_closure_TestModule_10TestModulesSS_y, + body: body, + fileID: fileID, + line: line + ) + } +} + +@_expose(wasm, "invoke_swift_closure_TestModule_10TestModulesSS_y") +@_cdecl("invoke_swift_closure_TestModule_10TestModulesSS_y") +public func _invoke_swift_closure_TestModule_10TestModulesSS_y(_ boxPtr: UnsafeMutableRawPointer, _ param0Bytes: Int32, _ param0Length: Int32) -> Void { + #if arch(wasm32) + let param0 = String.bridgeJSLiftParameter(param0Bytes, param0Length) + let closure = Unmanaged<_BridgeJSTypedClosureBox<(sending String) -> Void>>.fromOpaque(boxPtr).takeUnretainedValue().closure + closure(param0) + #else + fatalError("Only available on WebAssembly") + #endif +} + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModulesSi_y") +fileprivate func invoke_js_callback_TestModule_10TestModulesSi_y_extern(_ callback: Int32, _ param0: Int32) -> Void +#else +fileprivate func invoke_js_callback_TestModule_10TestModulesSi_y_extern(_ callback: Int32, _ param0: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModulesSi_y(_ callback: Int32, _ param0: Int32) -> Void { + return invoke_js_callback_TestModule_10TestModulesSi_y_extern(callback, param0) +} + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "make_swift_closure_TestModule_10TestModulesSi_y") +fileprivate func make_swift_closure_TestModule_10TestModulesSi_y_extern(_ boxPtr: UnsafeMutableRawPointer, _ file: UnsafePointer, _ line: UInt32) -> Int32 +#else +fileprivate func make_swift_closure_TestModule_10TestModulesSi_y_extern(_ boxPtr: UnsafeMutableRawPointer, _ file: UnsafePointer, _ line: UInt32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func make_swift_closure_TestModule_10TestModulesSi_y(_ boxPtr: UnsafeMutableRawPointer, _ file: UnsafePointer, _ line: UInt32) -> Int32 { + return make_swift_closure_TestModule_10TestModulesSi_y_extern(boxPtr, file, line) +} + +private enum _BJS_Closure_10TestModulesSi_y { + static func bridgeJSLift(_ callbackId: Int32) -> (sending Int) -> Void { + let callback = JSObject.bridgeJSLiftParameter(callbackId) + return { [callback] param0 in + #if arch(wasm32) + let param0Value = param0.bridgeJSLowerParameter() + let callbackValue = callback.bridgeJSLowerParameter() + invoke_js_callback_TestModule_10TestModulesSi_y(callbackValue, param0Value) + #else + fatalError("Only available on WebAssembly") + #endif + } + } +} + +extension JSTypedClosure where Signature == (sending Int) -> Void { + static func sending(fileID: StaticString = #fileID, line: UInt32 = #line, _ body: @escaping (sending Int) -> Void) -> Self { + Self( + makeClosure: make_swift_closure_TestModule_10TestModulesSi_y, + body: body, + fileID: fileID, + line: line + ) + } +} + +@_expose(wasm, "invoke_swift_closure_TestModule_10TestModulesSi_y") +@_cdecl("invoke_swift_closure_TestModule_10TestModulesSi_y") +public func _invoke_swift_closure_TestModule_10TestModulesSi_y(_ boxPtr: UnsafeMutableRawPointer, _ param0: Int32) -> Void { + #if arch(wasm32) + let param0 = Int.bridgeJSLiftParameter(param0) + let closure = Unmanaged<_BridgeJSTypedClosureBox<(sending Int) -> Void>>.fromOpaque(boxPtr).takeUnretainedValue().closure + closure(param0) + #else + fatalError("Only available on WebAssembly") + #endif +} + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModuley_y") +fileprivate func invoke_js_callback_TestModule_10TestModuley_y_extern(_ callback: Int32) -> Void +#else +fileprivate func invoke_js_callback_TestModule_10TestModuley_y_extern(_ callback: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuley_y(_ callback: Int32) -> Void { + return invoke_js_callback_TestModule_10TestModuley_y_extern(callback) +} + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "make_swift_closure_TestModule_10TestModuley_y") +fileprivate func make_swift_closure_TestModule_10TestModuley_y_extern(_ boxPtr: UnsafeMutableRawPointer, _ file: UnsafePointer, _ line: UInt32) -> Int32 +#else +fileprivate func make_swift_closure_TestModule_10TestModuley_y_extern(_ boxPtr: UnsafeMutableRawPointer, _ file: UnsafePointer, _ line: UInt32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func make_swift_closure_TestModule_10TestModuley_y(_ boxPtr: UnsafeMutableRawPointer, _ file: UnsafePointer, _ line: UInt32) -> Int32 { + return make_swift_closure_TestModule_10TestModuley_y_extern(boxPtr, file, line) +} + +private enum _BJS_Closure_10TestModuley_y { + static func bridgeJSLift(_ callbackId: Int32) -> () -> Void { + let callback = JSObject.bridgeJSLiftParameter(callbackId) + return { [callback] in + #if arch(wasm32) + let callbackValue = callback.bridgeJSLowerParameter() + invoke_js_callback_TestModule_10TestModuley_y(callbackValue) + #else + fatalError("Only available on WebAssembly") + #endif + } + } +} + +extension JSTypedClosure where Signature == () -> Void { + init(fileID: StaticString = #fileID, line: UInt32 = #line, _ body: @escaping () -> Void) { + self.init( + makeClosure: make_swift_closure_TestModule_10TestModuley_y, + body: body, + fileID: fileID, + line: line + ) + } +} + +@_expose(wasm, "invoke_swift_closure_TestModule_10TestModuley_y") +@_cdecl("invoke_swift_closure_TestModule_10TestModuley_y") +public func _invoke_swift_closure_TestModule_10TestModuley_y(_ boxPtr: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let closure = Unmanaged<_BridgeJSTypedClosureBox<() -> Void>>.fromOpaque(boxPtr).takeUnretainedValue().closure + closure() + #else + fatalError("Only available on WebAssembly") + #endif +} + extension MyViewControllerDelegate where Self: _BridgedSwiftProtocolWrapper { func onSomethingHappened() -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() @@ -75,6 +322,39 @@ extension MyViewControllerDelegate where Self: _BridgedSwiftProtocolWrapper { return Result.bridgeJSLiftReturn(ret) } + func validate(_ value: Int) throws(JSException) -> Int { + let valueValue = value.bridgeJSLowerParameter() + let jsObjectValue = jsObject.bridgeJSLowerParameter() + let ret = bjs_MyViewControllerDelegate_validate(jsObjectValue, valueValue) + if let error = _swift_js_take_exception() { throw error } + return Int.bridgeJSLiftReturn(ret) + } + + func loadLabel(_ key: String) async throws(JSException) -> String { + let resolved = try await _bjs_awaitPromise(makeResolveClosure: { JSTypedClosure<(sending String) -> Void>.sending($0) }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in + key.bridgeJSWithLoweredParameter { (keyWord0, keyWord1, keyWord2) in + let jsObjectValue = jsObject.bridgeJSLowerParameter() + bjs_MyViewControllerDelegate_loadLabel(resolveRef, rejectRef, jsObjectValue, keyWord0, keyWord1, keyWord2) + } + } + return resolved + } + + func reset() async throws(JSException) -> Void { + try await _bjs_awaitPromise(makeResolveClosure: { JSTypedClosure<() -> Void>($0) }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in + let jsObjectValue = jsObject.bridgeJSLowerParameter() + bjs_MyViewControllerDelegate_reset(resolveRef, rejectRef, jsObjectValue) + } + } + + func fetchCount() async -> Int { + let resolved = try! await _bjs_awaitPromise(makeResolveClosure: { JSTypedClosure<(sending Int) -> Void>.sending($0) }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in + let jsObjectValue = jsObject.bridgeJSLowerParameter() + bjs_MyViewControllerDelegate_fetchCount(resolveRef, rejectRef, jsObjectValue) + } + return resolved + } + var eventCount: Int { get { let jsObjectValue = jsObject.bridgeJSLowerParameter() @@ -369,6 +649,54 @@ fileprivate func bjs_MyViewControllerDelegate_getResult_extern(_ jsObject: Int32 return bjs_MyViewControllerDelegate_getResult_extern(jsObject) } +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_validate") +fileprivate func bjs_MyViewControllerDelegate_validate_extern(_ jsObject: Int32, _ value: Int32) -> Int32 +#else +fileprivate func bjs_MyViewControllerDelegate_validate_extern(_ jsObject: Int32, _ value: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_MyViewControllerDelegate_validate(_ jsObject: Int32, _ value: Int32) -> Int32 { + return bjs_MyViewControllerDelegate_validate_extern(jsObject, value) +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_loadLabel") +fileprivate func bjs_MyViewControllerDelegate_loadLabel_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32, _ keyWord0: Int32, _ keyWord1: Int32, _ keyWord2: Int32) -> Void +#else +fileprivate func bjs_MyViewControllerDelegate_loadLabel_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32, _ keyWord0: Int32, _ keyWord1: Int32, _ keyWord2: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_MyViewControllerDelegate_loadLabel(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32, _ keyWord0: Int32, _ keyWord1: Int32, _ keyWord2: Int32) -> Void { + return bjs_MyViewControllerDelegate_loadLabel_extern(resolveRef, rejectRef, jsObject, keyWord0, keyWord1, keyWord2) +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_reset") +fileprivate func bjs_MyViewControllerDelegate_reset_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32) -> Void +#else +fileprivate func bjs_MyViewControllerDelegate_reset_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_MyViewControllerDelegate_reset(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32) -> Void { + return bjs_MyViewControllerDelegate_reset_extern(resolveRef, rejectRef, jsObject) +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_fetchCount") +fileprivate func bjs_MyViewControllerDelegate_fetchCount_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32) -> Void +#else +fileprivate func bjs_MyViewControllerDelegate_fetchCount_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_MyViewControllerDelegate_fetchCount(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32) -> Void { + return bjs_MyViewControllerDelegate_fetchCount_extern(resolveRef, rejectRef, jsObject) +} + #if arch(wasm32) @_extern(wasm, module: "TestModule", name: "bjs_MyViewControllerDelegate_eventCount_get") fileprivate func bjs_MyViewControllerDelegate_eventCount_get_extern(_ jsObject: Int32) -> Int32 @@ -888,6 +1216,47 @@ public func _bjs_MyViewController_sendHelper(_ _self: UnsafeMutableRawPointer, _ #endif } +@_expose(wasm, "bjs_MyViewController_validateValue") +@_cdecl("bjs_MyViewController_validateValue") +public func _bjs_MyViewController_validateValue(_ _self: UnsafeMutableRawPointer, _ value: Int32) -> Int32 { + #if arch(wasm32) + let value = Int.bridgeJSLiftParameter(value) + let _self = MyViewController.bridgeJSLiftParameter(_self) + do { + let ret = try _self.validateValue(_: value) + return ret.bridgeJSLowerReturn() + } catch let error { + if let error = error.thrownValue.object { + withExtendedLifetime(error) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } else { + let jsError = JSError(message: error.description) + withExtendedLifetime(jsError.jsObject) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } + return 0 + } + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_MyViewController_loadLabel") +@_cdecl("bjs_MyViewController_loadLabel") +public func _bjs_MyViewController_loadLabel(_ _self: UnsafeMutableRawPointer, _ keyBytes: Int32, _ keyLength: Int32) -> Int32 { + #if arch(wasm32) + let key = String.bridgeJSLiftParameter(keyBytes, keyLength) + let _self = MyViewController.bridgeJSLiftParameter(_self) + return _bjs_makePromise(resolve: Promise_resolve_SS, reject: Promise_reject) { () async throws(JSException) -> String in + return try await _self.loadLabel(_: key) + } + #else + fatalError("Only available on WebAssembly") + #endif +} + @_expose(wasm, "bjs_MyViewController_delegate_get") @_cdecl("bjs_MyViewController_delegate_get") public func _bjs_MyViewController_delegate_get(_ _self: UnsafeMutableRawPointer) -> Int32 { @@ -1096,6 +1465,49 @@ extension Priority: BridgedSwiftGenericBridgeable { @_spi(BridgeJS) public static let bridgeJSTypeHandle = Priority.bridgeJSMakeTypeHandle() } +@JSFunction func Promise_reject(_ promise: JSObject, _ value: JSValue) throws(JSException) + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "promise_reject_TestModule") +fileprivate func promise_reject_TestModule_extern(_ promise: Int32, _ valueKind: Int32, _ valuePayload1: Int32, _ valuePayload2: Float64) -> Void +#else +fileprivate func promise_reject_TestModule_extern(_ promise: Int32, _ valueKind: Int32, _ valuePayload1: Int32, _ valuePayload2: Float64) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func promise_reject_TestModule(_ promise: Int32, _ valueKind: Int32, _ valuePayload1: Int32, _ valuePayload2: Float64) -> Void { + return promise_reject_TestModule_extern(promise, valueKind, valuePayload1, valuePayload2) +} + +func _$Promise_reject(_ promise: JSObject, _ value: JSValue) throws(JSException) -> Void { + let (valueKind, valuePayload1, valuePayload2) = value.bridgeJSLowerParameter() + let promiseValue = promise.bridgeJSLowerParameter() + promise_reject_TestModule(promiseValue, valueKind, valuePayload1, valuePayload2) + if let error = _swift_js_take_exception() { throw error } +} + +@JSFunction func Promise_resolve_SS(_ promise: JSObject, _ value: String) throws(JSException) + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "promise_resolve_TestModule_SS") +fileprivate func promise_resolve_TestModule_SS_extern(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void +#else +fileprivate func promise_resolve_TestModule_SS_extern(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func promise_resolve_TestModule_SS(_ promise: Int32, _ valueWord0: Int32, _ valueWord1: Int32, _ valueWord2: Int32) -> Void { + return promise_resolve_TestModule_SS_extern(promise, valueWord0, valueWord1, valueWord2) +} + +func _$Promise_resolve_SS(_ promise: JSObject, _ value: String) throws(JSException) -> Void { + value.bridgeJSWithLoweredParameter { (valueWord0, valueWord1, valueWord2) in + let promiseValue = promise.bridgeJSLowerParameter() + promise_resolve_TestModule_SS(promiseValue, valueWord0, valueWord1, valueWord2) + } + if let error = _swift_js_take_exception() { throw error } +} + #if arch(wasm32) @_extern(wasm, module: "bjs", name: "bjs_TestModule_register_type_handles") fileprivate func _bjs_TestModule_register_type_handles_extern(_ base: UnsafePointer?, _ count: Int32) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js index 5b2a085ac..856c42435 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js @@ -474,33 +474,57 @@ export async function createInstantiator(options, swift) { TestModule["bjs_asyncReturnVoid"] = function bjs_asyncReturnVoid(resolveRef, rejectRef) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); - imports.asyncReturnVoid().then(resolve, reject); + try { + Promise.resolve(imports.asyncReturnVoid()).then(resolve, reject); + } catch (error) { + reject(error); + } } TestModule["bjs_asyncRoundTripInt"] = function bjs_asyncRoundTripInt(resolveRef, rejectRef, v) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); - imports.asyncRoundTripInt(v).then(resolve, reject); + try { + Promise.resolve(imports.asyncRoundTripInt(v)).then(resolve, reject); + } catch (error) { + reject(error); + } } TestModule["bjs_asyncRoundTripString"] = function bjs_asyncRoundTripString(resolveRef, rejectRef, vWord0, vWord1, vWord2) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); - const string = decodeString(vWord0, vWord1, vWord2); - imports.asyncRoundTripString(string).then(resolve, reject); + try { + const string = decodeString(vWord0, vWord1, vWord2); + Promise.resolve(imports.asyncRoundTripString(string)).then(resolve, reject); + } catch (error) { + reject(error); + } } TestModule["bjs_asyncRoundTripBool"] = function bjs_asyncRoundTripBool(resolveRef, rejectRef, v) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); - imports.asyncRoundTripBool(v !== 0).then(resolve, reject); + try { + Promise.resolve(imports.asyncRoundTripBool(v !== 0)).then(resolve, reject); + } catch (error) { + reject(error); + } } TestModule["bjs_asyncRoundTripDouble"] = function bjs_asyncRoundTripDouble(resolveRef, rejectRef, v) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); - imports.asyncRoundTripDouble(v).then(resolve, reject); + try { + Promise.resolve(imports.asyncRoundTripDouble(v)).then(resolve, reject); + } catch (error) { + reject(error); + } } TestModule["bjs_asyncRoundTripJSObject"] = function bjs_asyncRoundTripJSObject(resolveRef, rejectRef, v) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); - imports.asyncRoundTripJSObject(swift.memory.getObject(v)).then(resolve, reject); + try { + Promise.resolve(imports.asyncRoundTripJSObject(swift.memory.getObject(v))).then(resolve, reject); + } catch (error) { + reject(error); + } } }, setInstance: (i) => { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js index 7a265486b..36d839ed9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js @@ -391,12 +391,20 @@ export async function createInstantiator(options, swift) { TestModule["bjs_AsyncBox_asyncStaticRoundTrip_static"] = function bjs_AsyncBox_asyncStaticRoundTrip_static(resolveRef, rejectRef, v) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); - imports.AsyncBox.asyncStaticRoundTrip(v).then(resolve, reject); + try { + Promise.resolve(imports.AsyncBox.asyncStaticRoundTrip(v)).then(resolve, reject); + } catch (error) { + reject(error); + } } TestModule["bjs_AsyncBox_asyncStaticVoid_static"] = function bjs_AsyncBox_asyncStaticVoid_static(resolveRef, rejectRef) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); - imports.AsyncBox.asyncStaticVoid().then(resolve, reject); + try { + Promise.resolve(imports.AsyncBox.asyncStaticVoid()).then(resolve, reject); + } catch (error) { + reject(error); + } } }, setInstance: (i) => { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.d.ts index a413fa500..e9b099f70 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.d.ts @@ -17,6 +17,10 @@ export interface MyViewControllerDelegate { createEnum(): ExampleEnumTag; handleResult(result: ResultTag): void; getResult(): ResultTag; + validate(value: number): number; + loadLabel(key: string): Promise; + reset(): Promise; + fetchCount(): Promise; eventCount: number; readonly delegateName: string; optionalName: string | null; @@ -87,6 +91,8 @@ export interface MyViewController extends SwiftHeapObject { updateLabel(prefix: string, suffix: string): void; checkEvenCount(): boolean; sendHelper(helper: Helper): void; + validateValue(value: number): number; + loadLabel(key: string): Promise; delegate: MyViewControllerDelegate; secondDelegate: MyViewControllerDelegate | null; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js index 96f132fda..f07007c79 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js @@ -380,6 +380,31 @@ export async function createInstantiator(options, swift) { return jsValue; } + const swiftClosureRegistry = (typeof FinalizationRegistry === "undefined") ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry((state) => { + if (state.unregistered) { return; } + instance?.exports?.bjs_release_swift_closure(state.pointer); + }); + const makeClosure = (pointer, file, line, func) => { + const state = { pointer, file, line, unregistered: false }; + const real = (...args) => { + if (state.unregistered) { + const bytes = new Uint8Array(memory.buffer, state.file >>> 0); + let length = 0; + while (bytes[length] !== 0) { length += 1; } + const fileID = decodeUTF8(state.file, length); + throw new Error(`Attempted to call a released JSTypedClosure created at ${fileID}:${state.line}`); + } + return func(...args); + }; + real.__unregister = () => { + if (state.unregistered) { return; } + state.unregistered = true; + swiftClosureRegistry.unregister(state); + }; + swiftClosureRegistry.register(real, state, state); + return swift.memory.retain(real); + }; + const __bjs_codec_M10TestModuleT24MyViewControllerDelegate = { lower: (v) => { const objId = swift.memory.retain(v); @@ -512,6 +537,22 @@ export async function createInstantiator(options, swift) { promise[__bjs_promiseSettlers] = { resolve, reject }; return swift.memory.retain(promise); } + bjs["promise_resolve_TestModule_SS"] = function(promise, valueWord0, valueWord1, valueWord2) { + try { + const string = decodeString(valueWord0, valueWord1, valueWord2); + swift.memory.getObject(promise)[__bjs_promiseSettlers].resolve(string); + } catch (error) { + setException(error); + } + } + bjs["promise_reject_TestModule"] = function(promise, valueKind, valuePayload1, valuePayload2) { + try { + const jsValue = __bjs_jsValueLift(valueKind, valuePayload1, valuePayload2); + swift.memory.getObject(promise)[__bjs_promiseSettlers].reject(jsValue); + } catch (error) { + setException(error); + } + } bjs["swift_js_return_optional_bool"] = function(isSome, value) { if (isSome === 0) { tmpRetOptionalBool = null; @@ -602,6 +643,95 @@ export async function createInstantiator(options, swift) { return pointer || 0; } bjs["swift_js_closure_unregister"] = function(funcRef) {} + bjs["swift_js_closure_unregister"] = function(funcRef) { + const func = swift.memory.getObject(funcRef); + func.__unregister(); + } + bjs["invoke_js_callback_TestModule_10TestModules7JSValueV_y"] = function(callbackId, param0Kind, param0Payload1, param0Payload2) { + try { + const callback = swift.memory.getObject(callbackId); + const jsValue = __bjs_jsValueLift(param0Kind, param0Payload1, param0Payload2); + callback(jsValue); + } catch (error) { + setException(error); + } + } + bjs["make_swift_closure_TestModule_10TestModules7JSValueV_y"] = function(boxPtr, file, line) { + const lower_closure_TestModule_10TestModules7JSValueV_y = function(param0) { + const [param0Kind, param0Payload1, param0Payload2] = __bjs_jsValueLower(param0); + instance.exports.invoke_swift_closure_TestModule_10TestModules7JSValueV_y(boxPtr, param0Kind, param0Payload1, param0Payload2); + if (tmpRetException) { + const error = swift.memory.getObject(tmpRetException); + swift.memory.release(tmpRetException); + tmpRetException = undefined; + throw error; + } + }; + return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModules7JSValueV_y); + } + bjs["invoke_js_callback_TestModule_10TestModulesSS_y"] = function(callbackId, param0Word0, param0Word1, param0Word2) { + try { + const callback = swift.memory.getObject(callbackId); + const string = decodeString(param0Word0, param0Word1, param0Word2); + callback(string); + } catch (error) { + setException(error); + } + } + bjs["make_swift_closure_TestModule_10TestModulesSS_y"] = function(boxPtr, file, line) { + const lower_closure_TestModule_10TestModulesSS_y = function(param0) { + const param0Bytes = textEncoder.encode(param0); + const param0Id = swift.memory.retain(param0Bytes); + instance.exports.invoke_swift_closure_TestModule_10TestModulesSS_y(boxPtr, param0Id, param0Bytes.length); + if (tmpRetException) { + const error = swift.memory.getObject(tmpRetException); + swift.memory.release(tmpRetException); + tmpRetException = undefined; + throw error; + } + }; + return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModulesSS_y); + } + bjs["invoke_js_callback_TestModule_10TestModulesSi_y"] = function(callbackId, param0) { + try { + const callback = swift.memory.getObject(callbackId); + callback(param0); + } catch (error) { + setException(error); + } + } + bjs["make_swift_closure_TestModule_10TestModulesSi_y"] = function(boxPtr, file, line) { + const lower_closure_TestModule_10TestModulesSi_y = function(param0) { + instance.exports.invoke_swift_closure_TestModule_10TestModulesSi_y(boxPtr, param0); + if (tmpRetException) { + const error = swift.memory.getObject(tmpRetException); + swift.memory.release(tmpRetException); + tmpRetException = undefined; + throw error; + } + }; + return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModulesSi_y); + } + bjs["invoke_js_callback_TestModule_10TestModuley_y"] = function(callbackId) { + try { + const callback = swift.memory.getObject(callbackId); + callback(); + } catch (error) { + setException(error); + } + } + bjs["make_swift_closure_TestModule_10TestModuley_y"] = function(boxPtr, file, line) { + const lower_closure_TestModule_10TestModuley_y = function() { + instance.exports.invoke_swift_closure_TestModule_10TestModuley_y(boxPtr); + if (tmpRetException) { + const error = swift.memory.getObject(tmpRetException); + swift.memory.release(tmpRetException); + tmpRetException = undefined; + throw error; + } + }; + return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuley_y); + } // Wrapper functions for module: TestModule if (!importObject["TestModule"]) { importObject["TestModule"] = {}; @@ -913,6 +1043,43 @@ export async function createInstantiator(options, swift) { setException(error); } } + TestModule["bjs_MyViewControllerDelegate_validate"] = function bjs_MyViewControllerDelegate_validate(self, value) { + try { + let ret = swift.memory.getObject(self).validate(value); + return ret; + } catch (error) { + setException(error); + return 0 + } + } + TestModule["bjs_MyViewControllerDelegate_loadLabel"] = function bjs_MyViewControllerDelegate_loadLabel(resolveRef, rejectRef, self, keyWord0, keyWord1, keyWord2) { + const resolve = swift.memory.getObject(resolveRef); + const reject = swift.memory.getObject(rejectRef); + try { + const string = decodeString(keyWord0, keyWord1, keyWord2); + Promise.resolve(swift.memory.getObject(self).loadLabel(string)).then(resolve, reject); + } catch (error) { + reject(error); + } + } + TestModule["bjs_MyViewControllerDelegate_reset"] = function bjs_MyViewControllerDelegate_reset(resolveRef, rejectRef, self) { + const resolve = swift.memory.getObject(resolveRef); + const reject = swift.memory.getObject(rejectRef); + try { + Promise.resolve(swift.memory.getObject(self).reset()).then(resolve, reject); + } catch (error) { + reject(error); + } + } + TestModule["bjs_MyViewControllerDelegate_fetchCount"] = function bjs_MyViewControllerDelegate_fetchCount(resolveRef, rejectRef, self) { + const resolve = swift.memory.getObject(resolveRef); + const reject = swift.memory.getObject(rejectRef); + try { + Promise.resolve(swift.memory.getObject(self).fetchCount()).then(resolve, reject); + } catch (error) { + reject(error); + } + } }, setInstance: (i) => { if (memory !== i.exports.memory) immortalStrings.clear(); @@ -1182,6 +1349,30 @@ export async function createInstantiator(options, swift) { sendHelper(helper) { instance.exports.bjs_MyViewController_sendHelper(this.pointer, helper.pointer); } + validateValue(value) { + const ret = instance.exports.bjs_MyViewController_validateValue(this.pointer, value); + if (tmpRetException) { + const error = swift.memory.getObject(tmpRetException); + swift.memory.release(tmpRetException); + tmpRetException = undefined; + throw error; + } + return ret; + } + loadLabel(key) { + const keyBytes = textEncoder.encode(key); + const keyId = swift.memory.retain(keyBytes); + const ret = instance.exports.bjs_MyViewController_loadLabel(this.pointer, keyId, keyBytes.length); + const ret1 = swift.memory.getObject(ret); + swift.memory.release(ret); + if (tmpRetException) { + const error = swift.memory.getObject(tmpRetException); + swift.memory.release(tmpRetException); + tmpRetException = undefined; + throw error; + } + return ret1; + } get delegate() { const ret = instance.exports.bjs_MyViewController_delegate_get(this.pointer); const ret1 = swift.memory.getObject(ret); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js index 928cc44a0..f56929d7c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js @@ -1380,9 +1380,13 @@ export async function createInstantiator(options, swift) { bjs["invoke_js_callback_TestModule_10TestModuleYaKSS_SS"] = function(resolveRef, rejectRef, callbackId, param0Word0, param0Word1, param0Word2) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); - const callback = swift.memory.getObject(callbackId); - const string = decodeString(param0Word0, param0Word1, param0Word2); - callback(string).then(resolve, reject); + try { + const callback = swift.memory.getObject(callbackId); + const string = decodeString(param0Word0, param0Word1, param0Word2); + Promise.resolve(callback(string)).then(resolve, reject); + } catch (error) { + reject(error); + } } bjs["make_swift_closure_TestModule_10TestModuleYaKSS_SS"] = function(boxPtr, file, line) { const lower_closure_TestModule_10TestModuleYaKSS_SS = function(param0) { @@ -1404,8 +1408,12 @@ export async function createInstantiator(options, swift) { bjs["invoke_js_callback_TestModule_10TestModuleYaKSb_9APIResultO"] = function(resolveRef, rejectRef, callbackId, param0) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); - const callback = swift.memory.getObject(callbackId); - callback(param0 !== 0).then(resolve, reject); + try { + const callback = swift.memory.getObject(callbackId); + Promise.resolve(callback(param0 !== 0)).then(resolve, reject); + } catch (error) { + reject(error); + } } bjs["make_swift_closure_TestModule_10TestModuleYaKSb_9APIResultO"] = function(boxPtr, file, line) { const lower_closure_TestModule_10TestModuleYaKSb_9APIResultO = function(param0) { @@ -1425,9 +1433,13 @@ export async function createInstantiator(options, swift) { bjs["invoke_js_callback_TestModule_10TestModuleYaSS_6AnimalV"] = function(resolveRef, rejectRef, callbackId, param0Word0, param0Word1, param0Word2) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); - const callback = swift.memory.getObject(callbackId); - const string = decodeString(param0Word0, param0Word1, param0Word2); - callback(string).then(resolve, reject); + try { + const callback = swift.memory.getObject(callbackId); + const string = decodeString(param0Word0, param0Word1, param0Word2); + Promise.resolve(callback(string)).then(resolve, reject); + } catch (error) { + reject(error); + } } bjs["make_swift_closure_TestModule_10TestModuleYaSS_6AnimalV"] = function(boxPtr, file, line) { const lower_closure_TestModule_10TestModuleYaSS_6AnimalV = function(param0) { @@ -1443,9 +1455,13 @@ export async function createInstantiator(options, swift) { bjs["invoke_js_callback_TestModule_10TestModuleYaSS_SS"] = function(resolveRef, rejectRef, callbackId, param0Word0, param0Word1, param0Word2) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); - const callback = swift.memory.getObject(callbackId); - const string = decodeString(param0Word0, param0Word1, param0Word2); - callback(string).then(resolve, reject); + try { + const callback = swift.memory.getObject(callbackId); + const string = decodeString(param0Word0, param0Word1, param0Word2); + Promise.resolve(callback(string)).then(resolve, reject); + } catch (error) { + reject(error); + } } bjs["make_swift_closure_TestModule_10TestModuleYaSS_SS"] = function(boxPtr, file, line) { const lower_closure_TestModule_10TestModuleYaSS_SS = function(param0) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js index c47a65b6b..3ba6f5c0f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js @@ -393,9 +393,13 @@ export async function createInstantiator(options, swift) { bjs["invoke_js_callback_TestModule_10TestModuleYaKSS_SS"] = function(resolveRef, rejectRef, callbackId, param0Word0, param0Word1, param0Word2) { const resolve = swift.memory.getObject(resolveRef); const reject = swift.memory.getObject(rejectRef); - const callback = swift.memory.getObject(callbackId); - const string = decodeString(param0Word0, param0Word1, param0Word2); - callback(string).then(resolve, reject); + try { + const callback = swift.memory.getObject(callbackId); + const string = decodeString(param0Word0, param0Word1, param0Word2); + Promise.resolve(callback(string)).then(resolve, reject); + } catch (error) { + reject(error); + } } bjs["make_swift_closure_TestModule_10TestModuleYaKSS_SS"] = function(boxPtr, file, line) { const lower_closure_TestModule_10TestModuleYaKSS_SS = function(param0) { diff --git a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Protocols.md b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Protocols.md index 4c91ba749..5bc907137 100644 --- a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Protocols.md +++ b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Protocols.md @@ -217,6 +217,8 @@ struct AnyCounter: Counter, _BridgedSwiftProtocolWrapper { | Swift Feature | Status | |:--------------|:-------| | Method requirements: `func foo(_ param: String?) -> FooClass?` | ✅ | +| Throwing method requirements: `func foo() throws(JSException)` | ✅ | +| Async method requirements: `func foo() async throws(JSException) -> Bar` | ✅ | | Property requirements: `var property: Type { get }` / `var property: Type { get set }` | ✅ | | Optional parameters / return values in methods | ✅ | | Optional properties | ✅ | diff --git a/Tests/BridgeJSRuntimeTests/AsyncImportTests.swift b/Tests/BridgeJSRuntimeTests/AsyncImportTests.swift index a092d111c..17184c427 100644 --- a/Tests/BridgeJSRuntimeTests/AsyncImportTests.swift +++ b/Tests/BridgeJSRuntimeTests/AsyncImportTests.swift @@ -24,6 +24,8 @@ import JavaScriptKit @JSFunction static func jsAsyncRoundTripOptionalAssociatedValueEnum( _ v: AsyncImportedPayloadResult? ) async throws(JSException) -> AsyncImportedPayloadResult? + @JSFunction static func jsAsyncThrowSynchronously(_ message: String) async throws(JSException) -> Double + @JSFunction static func jsAsyncReturnNonPromise(_ v: Double) async throws(JSException) -> Double } @Suite struct AsyncImportTests { @@ -104,6 +106,19 @@ import JavaScriptKit } } + // MARK: - Non-Promise behavior + + @Test func asyncSynchronousThrowRejects() async throws { + let error = await #expect(throws: JSException.self) { + try await AsyncImportImports.jsAsyncThrowSynchronously("SyncFailure") + } + #expect(error?.thrownValue.object?["message"].string == "SyncFailure") + } + + @Test func asyncNonPromiseReturnResolves() async throws { + try #expect(await AsyncImportImports.jsAsyncReturnNonPromise(42) == 42) + } + // MARK: - Structured return type @Test func fetchWeatherData() async throws { diff --git a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift index 8778c2c8e..c09b84c95 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -961,6 +961,10 @@ enum GraphOperations { func createOptionalGreeter() -> Greeter? func handleAPIResult(_ result: APIResult?) func getAPIResult() -> APIResult? + func validate(_ value: Int) throws(JSException) -> Int + func loadLabel(_ key: String) async throws(JSException) -> String + func reset() async throws(JSException) + func fetchCount() async -> Int } @JS class DataProcessorManager { @@ -1053,6 +1057,22 @@ enum GraphOperations { @JS func setProcessorAPIResult(_ apiResult: APIResult?) { processor.handleAPIResult(apiResult) } + + @JS func validateProcessorValue(_ value: Int) throws(JSException) -> Int { + return try processor.validate(value) + } + + @JS func loadProcessorLabel(_ key: String) async throws(JSException) -> String { + return try await processor.loadLabel(key) + } + + @JS func resetProcessor() async throws(JSException) { + try await processor.reset() + } + + @JS func fetchProcessorCount() async -> Int { + return await processor.fetchCount() + } } @JS class SwiftDataProcessor: DataProcessor { @@ -1117,6 +1137,25 @@ enum GraphOperations { @JS func getAPIResult() -> APIResult? { return apiResult } + + @JS func validate(_ value: Int) throws(JSException) -> Int { + guard value >= 0 else { + throw JSException(JSError(message: "SwiftDataProcessor rejects negative values").jsValue) + } + return value + } + + @JS func loadLabel(_ key: String) async throws(JSException) -> String { + return "\(label):\(key)" + } + + @JS func reset() async throws(JSException) { + count = 0 + } + + @JS func fetchCount() async -> Int { + return count + } } @JS class ProtocolReturnTests { diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index 52799fa7c..b89bdb510 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -4366,6 +4366,39 @@ extension DataProcessor where Self: _BridgedSwiftProtocolWrapper { return Optional.bridgeJSLiftReturn(ret) } + func validate(_ value: Int) throws(JSException) -> Int { + let valueValue = value.bridgeJSLowerParameter() + let jsObjectValue = jsObject.bridgeJSLowerParameter() + let ret = bjs_DataProcessor_validate(jsObjectValue, valueValue) + if let error = _swift_js_take_exception() { throw error } + return Int.bridgeJSLiftReturn(ret) + } + + func loadLabel(_ key: String) async throws(JSException) -> String { + let resolved = try await _bjs_awaitPromise(makeResolveClosure: { JSTypedClosure<(sending String) -> Void>.sending($0) }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in + key.bridgeJSWithLoweredParameter { (keyWord0, keyWord1, keyWord2) in + let jsObjectValue = jsObject.bridgeJSLowerParameter() + bjs_DataProcessor_loadLabel(resolveRef, rejectRef, jsObjectValue, keyWord0, keyWord1, keyWord2) + } + } + return resolved + } + + func reset() async throws(JSException) -> Void { + try await _bjs_awaitPromise(makeResolveClosure: { JSTypedClosure<() -> Void>($0) }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in + let jsObjectValue = jsObject.bridgeJSLowerParameter() + bjs_DataProcessor_reset(resolveRef, rejectRef, jsObjectValue) + } + } + + func fetchCount() async -> Int { + let resolved = try! await _bjs_awaitPromise(makeResolveClosure: { JSTypedClosure<(sending Int) -> Void>.sending($0) }, makeRejectClosure: { JSTypedClosure<(sending JSValue) -> Void>.sending($0) }) { resolveRef, rejectRef in + let jsObjectValue = jsObject.bridgeJSLowerParameter() + bjs_DataProcessor_fetchCount(resolveRef, rejectRef, jsObjectValue) + } + return resolved + } + var count: Int { get { let jsObjectValue = jsObject.bridgeJSLowerParameter() @@ -4634,6 +4667,54 @@ fileprivate func bjs_DataProcessor_getAPIResult_extern(_ jsObject: Int32) -> Int return bjs_DataProcessor_getAPIResult_extern(jsObject) } +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_validate") +fileprivate func bjs_DataProcessor_validate_extern(_ jsObject: Int32, _ value: Int32) -> Int32 +#else +fileprivate func bjs_DataProcessor_validate_extern(_ jsObject: Int32, _ value: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_DataProcessor_validate(_ jsObject: Int32, _ value: Int32) -> Int32 { + return bjs_DataProcessor_validate_extern(jsObject, value) +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_loadLabel") +fileprivate func bjs_DataProcessor_loadLabel_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32, _ keyWord0: Int32, _ keyWord1: Int32, _ keyWord2: Int32) -> Void +#else +fileprivate func bjs_DataProcessor_loadLabel_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32, _ keyWord0: Int32, _ keyWord1: Int32, _ keyWord2: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_DataProcessor_loadLabel(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32, _ keyWord0: Int32, _ keyWord1: Int32, _ keyWord2: Int32) -> Void { + return bjs_DataProcessor_loadLabel_extern(resolveRef, rejectRef, jsObject, keyWord0, keyWord1, keyWord2) +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_reset") +fileprivate func bjs_DataProcessor_reset_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32) -> Void +#else +fileprivate func bjs_DataProcessor_reset_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_DataProcessor_reset(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32) -> Void { + return bjs_DataProcessor_reset_extern(resolveRef, rejectRef, jsObject) +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_fetchCount") +fileprivate func bjs_DataProcessor_fetchCount_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32) -> Void +#else +fileprivate func bjs_DataProcessor_fetchCount_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_DataProcessor_fetchCount(_ resolveRef: Int32, _ rejectRef: Int32, _ jsObject: Int32) -> Void { + return bjs_DataProcessor_fetchCount_extern(resolveRef, rejectRef, jsObject) +} + #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_DataProcessor_count_get") fileprivate func bjs_DataProcessor_count_get_extern(_ jsObject: Int32) -> Int32 @@ -14415,6 +14496,73 @@ public func _bjs_DataProcessorManager_setProcessorAPIResult(_ _self: UnsafeMutab #endif } +@_expose(wasm, "bjs_DataProcessorManager_validateProcessorValue") +@_cdecl("bjs_DataProcessorManager_validateProcessorValue") +public func _bjs_DataProcessorManager_validateProcessorValue(_ _self: UnsafeMutableRawPointer, _ value: Int32) -> Int32 { + #if arch(wasm32) + let value = Int.bridgeJSLiftParameter(value) + let _self = DataProcessorManager.bridgeJSLiftParameter(_self) + do { + let ret = try _self.validateProcessorValue(_: value) + return ret.bridgeJSLowerReturn() + } catch let error { + if let error = error.thrownValue.object { + withExtendedLifetime(error) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } else { + let jsError = JSError(message: error.description) + withExtendedLifetime(jsError.jsObject) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } + return 0 + } + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_DataProcessorManager_loadProcessorLabel") +@_cdecl("bjs_DataProcessorManager_loadProcessorLabel") +public func _bjs_DataProcessorManager_loadProcessorLabel(_ _self: UnsafeMutableRawPointer, _ keyBytes: Int32, _ keyLength: Int32) -> Int32 { + #if arch(wasm32) + let key = String.bridgeJSLiftParameter(keyBytes, keyLength) + let _self = DataProcessorManager.bridgeJSLiftParameter(_self) + return _bjs_makePromise(resolve: Promise_resolve_SS, reject: Promise_reject) { () async throws(JSException) -> String in + return try await _self.loadProcessorLabel(_: key) + } + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_DataProcessorManager_resetProcessor") +@_cdecl("bjs_DataProcessorManager_resetProcessor") +public func _bjs_DataProcessorManager_resetProcessor(_ _self: UnsafeMutableRawPointer) -> Int32 { + #if arch(wasm32) + let _self = DataProcessorManager.bridgeJSLiftParameter(_self) + return _bjs_makePromise(resolve: Promise_resolve_y, reject: Promise_reject) { () async throws(JSException) -> Void in + try await _self.resetProcessor() + } + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_DataProcessorManager_fetchProcessorCount") +@_cdecl("bjs_DataProcessorManager_fetchProcessorCount") +public func _bjs_DataProcessorManager_fetchProcessorCount(_ _self: UnsafeMutableRawPointer) -> Int32 { + #if arch(wasm32) + let _self = DataProcessorManager.bridgeJSLiftParameter(_self) + return _bjs_makePromise(resolve: Promise_resolve_Si, reject: Promise_reject) { + return await _self.fetchProcessorCount() + } + #else + fatalError("Only available on WebAssembly") + #endif +} + @_expose(wasm, "bjs_DataProcessorManager_processor_get") @_cdecl("bjs_DataProcessorManager_processor_get") public func _bjs_DataProcessorManager_processor_get(_ _self: UnsafeMutableRawPointer) -> Int32 { @@ -14644,6 +14792,73 @@ public func _bjs_SwiftDataProcessor_getAPIResult(_ _self: UnsafeMutableRawPointe #endif } +@_expose(wasm, "bjs_SwiftDataProcessor_validate") +@_cdecl("bjs_SwiftDataProcessor_validate") +public func _bjs_SwiftDataProcessor_validate(_ _self: UnsafeMutableRawPointer, _ value: Int32) -> Int32 { + #if arch(wasm32) + let value = Int.bridgeJSLiftParameter(value) + let _self = SwiftDataProcessor.bridgeJSLiftParameter(_self) + do { + let ret = try _self.validate(_: value) + return ret.bridgeJSLowerReturn() + } catch let error { + if let error = error.thrownValue.object { + withExtendedLifetime(error) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } else { + let jsError = JSError(message: error.description) + withExtendedLifetime(jsError.jsObject) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } + return 0 + } + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_SwiftDataProcessor_loadLabel") +@_cdecl("bjs_SwiftDataProcessor_loadLabel") +public func _bjs_SwiftDataProcessor_loadLabel(_ _self: UnsafeMutableRawPointer, _ keyBytes: Int32, _ keyLength: Int32) -> Int32 { + #if arch(wasm32) + let key = String.bridgeJSLiftParameter(keyBytes, keyLength) + let _self = SwiftDataProcessor.bridgeJSLiftParameter(_self) + return _bjs_makePromise(resolve: Promise_resolve_SS, reject: Promise_reject) { () async throws(JSException) -> String in + return try await _self.loadLabel(_: key) + } + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_SwiftDataProcessor_reset") +@_cdecl("bjs_SwiftDataProcessor_reset") +public func _bjs_SwiftDataProcessor_reset(_ _self: UnsafeMutableRawPointer) -> Int32 { + #if arch(wasm32) + let _self = SwiftDataProcessor.bridgeJSLiftParameter(_self) + return _bjs_makePromise(resolve: Promise_resolve_y, reject: Promise_reject) { () async throws(JSException) -> Void in + try await _self.reset() + } + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_SwiftDataProcessor_fetchCount") +@_cdecl("bjs_SwiftDataProcessor_fetchCount") +public func _bjs_SwiftDataProcessor_fetchCount(_ _self: UnsafeMutableRawPointer) -> Int32 { + #if arch(wasm32) + let _self = SwiftDataProcessor.bridgeJSLiftParameter(_self) + return _bjs_makePromise(resolve: Promise_resolve_Si, reject: Promise_reject) { + return await _self.fetchCount() + } + #else + fatalError("Only available on WebAssembly") + #endif +} + @_expose(wasm, "bjs_SwiftDataProcessor_count_get") @_cdecl("bjs_SwiftDataProcessor_count_get") public func _bjs_SwiftDataProcessor_count_get(_ _self: UnsafeMutableRawPointer) -> Int32 { @@ -17729,6 +17944,30 @@ fileprivate func bjs_AsyncImportImports_jsAsyncRoundTripOptionalAssociatedValueE return bjs_AsyncImportImports_jsAsyncRoundTripOptionalAssociatedValueEnum_static_extern(resolveRef, rejectRef, vIsSome, vCaseId) } +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_AsyncImportImports_jsAsyncThrowSynchronously_static") +fileprivate func bjs_AsyncImportImports_jsAsyncThrowSynchronously_static_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ messageWord0: Int32, _ messageWord1: Int32, _ messageWord2: Int32) -> Void +#else +fileprivate func bjs_AsyncImportImports_jsAsyncThrowSynchronously_static_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ messageWord0: Int32, _ messageWord1: Int32, _ messageWord2: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_AsyncImportImports_jsAsyncThrowSynchronously_static(_ resolveRef: Int32, _ rejectRef: Int32, _ messageWord0: Int32, _ messageWord1: Int32, _ messageWord2: Int32) -> Void { + return bjs_AsyncImportImports_jsAsyncThrowSynchronously_static_extern(resolveRef, rejectRef, messageWord0, messageWord1, messageWord2) +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_AsyncImportImports_jsAsyncReturnNonPromise_static") +fileprivate func bjs_AsyncImportImports_jsAsyncReturnNonPromise_static_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ v: Float64) -> Void +#else +fileprivate func bjs_AsyncImportImports_jsAsyncReturnNonPromise_static_extern(_ resolveRef: Int32, _ rejectRef: Int32, _ v: Float64) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_AsyncImportImports_jsAsyncReturnNonPromise_static(_ resolveRef: Int32, _ rejectRef: Int32, _ v: Float64) -> Void { + return bjs_AsyncImportImports_jsAsyncReturnNonPromise_static_extern(resolveRef, rejectRef, v) +} + func _$AsyncImportImports_jsAsyncRoundTripVoid() async throws(JSException) -> Void { try await _bjs_awaitPromise(makeResolveClosure: { JSTypedClosure<() -> Void>($0) @@ -17874,6 +18113,31 @@ func _$AsyncImportImports_jsAsyncRoundTripOptionalAssociatedValueEnum(_ v: Optio return resolved } +func _$AsyncImportImports_jsAsyncThrowSynchronously(_ message: String) async throws(JSException) -> Double { + let resolved = try await _bjs_awaitPromise(makeResolveClosure: { + JSTypedClosure<(sending Double) -> Void>.sending($0) + }, makeRejectClosure: { + JSTypedClosure<(sending JSValue) -> Void>.sending($0) + }) { resolveRef, rejectRef in + message.bridgeJSWithLoweredParameter { (messageWord0, messageWord1, messageWord2) in + bjs_AsyncImportImports_jsAsyncThrowSynchronously_static(resolveRef, rejectRef, messageWord0, messageWord1, messageWord2) + } + } + return resolved +} + +func _$AsyncImportImports_jsAsyncReturnNonPromise(_ v: Double) async throws(JSException) -> Double { + let resolved = try await _bjs_awaitPromise(makeResolveClosure: { + JSTypedClosure<(sending Double) -> Void>.sending($0) + }, makeRejectClosure: { + JSTypedClosure<(sending JSValue) -> Void>.sending($0) + }) { resolveRef, rejectRef in + let vValue = v.bridgeJSLowerParameter() + bjs_AsyncImportImports_jsAsyncReturnNonPromise_static(resolveRef, rejectRef, vValue) + } + return resolved +} + #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ClosureAsyncImports_runJsClosureAsyncTests_static") fileprivate func bjs_ClosureAsyncImports_runJsClosureAsyncTests_static_extern(_ resolveRef: Int32, _ rejectRef: Int32) -> Void diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index d649d4e76..9d5da0a7f 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -3019,6 +3019,99 @@ } } + }, + { + "abiName" : "bjs_DataProcessorManager_validateProcessorValue", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "validateProcessorValue", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } + ], + "returnType" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + }, + { + "abiName" : "bjs_DataProcessorManager_loadProcessorLabel", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : true + }, + "name" : "loadProcessorLabel", + "parameters" : [ + { + "label" : "_", + "name" : "key", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_DataProcessorManager_resetProcessor", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : true + }, + "name" : "resetProcessor", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_DataProcessorManager_fetchProcessorCount", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : false + }, + "name" : "fetchProcessorCount", + "parameters" : [ + + ], + "returnType" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } } ], "name" : "DataProcessorManager", @@ -3325,6 +3418,99 @@ "_1" : "null" } } + }, + { + "abiName" : "bjs_SwiftDataProcessor_validate", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "validate", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } + ], + "returnType" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + }, + { + "abiName" : "bjs_SwiftDataProcessor_loadLabel", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : true + }, + "name" : "loadLabel", + "parameters" : [ + { + "label" : "_", + "name" : "key", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_SwiftDataProcessor_reset", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : true + }, + "name" : "reset", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_SwiftDataProcessor_fetchCount", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : false + }, + "name" : "fetchCount", + "parameters" : [ + + ], + "returnType" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } } ], "name" : "SwiftDataProcessor", @@ -19336,6 +19522,99 @@ "_1" : "null" } } + }, + { + "abiName" : "bjs_DataProcessor_validate", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "validate", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } + ], + "returnType" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + }, + { + "abiName" : "bjs_DataProcessor_loadLabel", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : true + }, + "name" : "loadLabel", + "parameters" : [ + { + "label" : "_", + "name" : "key", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_DataProcessor_reset", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : true + }, + "name" : "reset", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_DataProcessor_fetchCount", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : false + }, + "name" : "fetchCount", + "parameters" : [ + + ], + "returnType" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } } ], "name" : "DataProcessor", @@ -23286,6 +23565,54 @@ "_1" : "null" } } + }, + { + "accessLevel" : "internal", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : true + }, + "name" : "jsAsyncThrowSynchronously", + "parameters" : [ + { + "name" : "message", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "double" : { + + } + } + }, + { + "accessLevel" : "internal", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : true + }, + "name" : "jsAsyncReturnNonPromise", + "parameters" : [ + { + "name" : "v", + "type" : { + "double" : { + + } + } + } + ], + "returnType" : { + "double" : { + + } + } } ] } diff --git a/Tests/BridgeJSRuntimeTests/JavaScript/AsyncImportTests.mjs b/Tests/BridgeJSRuntimeTests/JavaScript/AsyncImportTests.mjs index 9be7af1be..a0f9a6ebd 100644 --- a/Tests/BridgeJSRuntimeTests/JavaScript/AsyncImportTests.mjs +++ b/Tests/BridgeJSRuntimeTests/JavaScript/AsyncImportTests.mjs @@ -44,6 +44,12 @@ export function getImports(importsContext) { jsAsyncRoundTripOptionalAssociatedValueEnum: (v) => { return Promise.resolve(v); }, + jsAsyncThrowSynchronously: (message) => { + throw new Error(message); + }, + jsAsyncReturnNonPromise: (v) => { + return v; + }, }; } diff --git a/Tests/BridgeJSRuntimeTests/JavaScript/ClosureAsyncTests.mjs b/Tests/BridgeJSRuntimeTests/JavaScript/ClosureAsyncTests.mjs index 3267d8fd6..07b1ec1ed 100644 --- a/Tests/BridgeJSRuntimeTests/JavaScript/ClosureAsyncTests.mjs +++ b/Tests/BridgeJSRuntimeTests/JavaScript/ClosureAsyncTests.mjs @@ -38,6 +38,14 @@ export async function runJsClosureAsyncTests(exports) { assert.notEqual(directionAReject, null); assert.equal(directionAReject.message, "CallbackRejected"); + await assert.rejects( + () => exports.awaitAsyncCallback(() => { + throw new Error("CallbackThrewSynchronously"); + }), + (error) => error instanceof Error && error.message === "CallbackThrewSynchronously" + ); + assert.equal(await exports.awaitAsyncCallback((req) => `plain-${req}`), "swift-saw:plain-request"); + const parser = exports.makeAsyncParser(); const parsed = parser("42"); diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index 8a109bcb5..f54e3a149 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -145,6 +145,7 @@ export async function setupOptions(options, context) { throw new Error("No exports!?"); } await runAsyncWorksTests(exports); + await testAsyncProtocolSupport(exports); return; }, AsyncImportImports: getAsyncImportImports(importsContext), @@ -1311,6 +1312,102 @@ function setupTestGlobals(global) { }; } +/** @param {import('./../.build/plugins/PackageToJS/outputs/PackageTests/bridge-js.d.ts').Exports} exports */ +async function testAsyncProtocolSupport(exports) { + let processorValue = 3; + let shouldRejectReset = false; + const jsProcessor = { + count: 0, + name: "AsyncJSProcessor", + optionalTag: null, + direction: null, + optionalTheme: null, + httpStatus: null, + apiResult: null, + helper: new exports.Greeter("AsyncHelper"), + optionalHelper: null, + optionalCount: null, + increment(amount) { processorValue += amount; }, + getValue() { return processorValue; }, + setLabelElements(labelPrefix, labelSuffix) { }, + getLabel() { return "async"; }, + isEven() { return processorValue % 2 === 0; }, + processGreeter(greeter) { return ""; }, + createGreeter() { return new exports.Greeter("AsyncGreeter"); }, + processOptionalGreeter(greeter) { return ""; }, + createOptionalGreeter() { return null; }, + handleAPIResult(result) { }, + getAPIResult() { return { tag: exports.APIResult.Tag.Info }; }, + validate(value) { return value; }, + loadLabel(key) { + if (key === "invalid") { + throw new Error("Invalid key thrown synchronously"); + } + return (async () => { + await Promise.resolve(); + if (key === "missing") { + throw new Error(`No label for ${key}`); + } + return `async:${key}`; + })(); + }, + async reset() { + await Promise.resolve(); + if (shouldRejectReset) { + throw new Error("Reset rejected"); + } + processorValue = 0; + }, + fetchCount() { return Promise.resolve(processorValue); } + }; + + const jsManager = new exports.DataProcessorManager(jsProcessor); + + assert.equal(await jsManager.loadProcessorLabel("key"), "async:key"); + await assert.rejects( + () => jsManager.loadProcessorLabel("missing"), + (error) => error instanceof Error && error.message === "No label for missing" + ); + await assert.rejects( + () => jsManager.loadProcessorLabel("invalid"), + (error) => error instanceof Error && error.message === "Invalid key thrown synchronously" + ); + const [firstLabel, secondLabel] = await Promise.all([ + jsManager.loadProcessorLabel("first"), + jsManager.loadProcessorLabel("second"), + ]); + assert.equal(firstLabel, "async:first"); + assert.equal(secondLabel, "async:second"); + + assert.equal(await jsManager.fetchProcessorCount(), 3); + await jsManager.resetProcessor(); + assert.equal(await jsManager.fetchProcessorCount(), 0); + + shouldRejectReset = true; + jsManager.incrementByAmount(2); + await assert.rejects( + () => jsManager.resetProcessor(), + (error) => error instanceof Error && error.message === "Reset rejected" + ); + assert.equal(await jsManager.fetchProcessorCount(), 2); + + jsManager.release(); + jsProcessor.helper.release(); + + const swiftProcessor = new exports.SwiftDataProcessor(); + const swiftManager = new exports.DataProcessorManager(swiftProcessor); + + swiftManager.setProcessorLabel("Swift", "Label"); + swiftManager.incrementByAmount(4); + assert.equal(await swiftManager.loadProcessorLabel("key"), "SwiftLabel:key"); + assert.equal(await swiftManager.fetchProcessorCount(), 4); + await swiftManager.resetProcessor(); + assert.equal(await swiftManager.fetchProcessorCount(), 0); + + swiftManager.release(); + swiftProcessor.release(); +} + /** @param {import('./../.build/plugins/PackageToJS/outputs/PackageTests/bridge-js.d.ts').Exports} exports */ function testProtocolSupport(exports) { let processorValue = 0; @@ -1340,7 +1437,16 @@ function testProtocolSupport(exports) { }, createOptionalGreeter() { return new exports.Greeter("JSOptionalGreeter"); }, handleAPIResult(result) { lastAPIResult = result; }, - getAPIResult() { return lastAPIResult; } + getAPIResult() { return lastAPIResult; }, + validate(value) { + if (value < 0) { + throw new Error("JSProcessor rejects negative values"); + } + return value * 2; + }, + async loadLabel(key) { return `${processorLabel}:${key}`; }, + async reset() { processorValue = 0; }, + async fetchCount() { return processorValue; } }; const successResult = { tag: exports.Utilities.Result.Tag.Success, param0: "Operation completed" }; @@ -1444,6 +1550,13 @@ function testProtocolSupport(exports) { jsProcessor.optionalCount = null; assert.equal(jsProcessor.optionalCount, null); + assert.equal(jsManager.validateProcessorValue(21), 42); + assert.throws( + () => jsManager.validateProcessorValue(-1), + (error) => error instanceof Error && error.message === "JSProcessor rejects negative values" + ); + assert.equal(jsManager.validateProcessorValue(5), 10); + newHelper.release(); optHelper.release(); jsManager.release(); @@ -1497,6 +1610,9 @@ function testProtocolSupport(exports) { swiftManager.setProcessorAPIResult(successResult); assert.deepEqual(swiftProcessor.getAPIResult(), successResult); + assert.equal(swiftManager.validateProcessorValue(7), 7); + assert.throws(() => swiftManager.validateProcessorValue(-1), /SwiftDataProcessor rejects negative values/); + swiftManager.release(); swiftProcessor.release(); @@ -1522,7 +1638,11 @@ function testProtocolSupport(exports) { processOptionalGreeter(greeter) { return ""; }, createOptionalGreeter() { return null; }, handleAPIResult(result) { }, - getAPIResult() { return { tag: exports.APIResult.Tag.Info }; } + getAPIResult() { return { tag: exports.APIResult.Tag.Info }; }, + validate(value) { return value; }, + async loadLabel(key) { return ""; }, + async reset() { }, + async fetchCount() { return 0; } }; let mainValue = 0; @@ -1547,7 +1667,11 @@ function testProtocolSupport(exports) { processOptionalGreeter(greeter) { return ""; }, createOptionalGreeter() { return null; }, handleAPIResult(result) { }, - getAPIResult() { return { tag: exports.APIResult.Tag.Info }; } + getAPIResult() { return { tag: exports.APIResult.Tag.Info }; }, + validate(value) { return value; }, + async loadLabel(key) { return ""; }, + async reset() { }, + async fetchCount() { return 0; } }; const managerWithOptional = new exports.DataProcessorManager(mainProcessor); From 681bb0b231a2680a6b25256c54115f7313bcd386 Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Thu, 15 Oct 2026 11:34:25 +0200 Subject: [PATCH 06/18] [NFC] BridgeJS: Update renderAsyncFunction doc comment --- Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index c97bdf293..8e7c4939c 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -2897,9 +2897,8 @@ extension BridgeJSLink { /// Renders an async import function with resolve/reject closure refs. /// - /// The generated function takes `resolveRef` and `rejectRef` as the first parameters, - /// looks up the resolve/reject closures from memory, and executes the body which - /// chains `.then(resolve, reject)` on the import's returned Promise. + /// The generated function takes `resolveRef` and `rejectRef` as the first parameters + /// and settles them with the result of the import call. private func renderAsyncFunction(name: String?) -> [String] { let printer = CodeFragmentPrinter() let allParams = ["resolveRef", "rejectRef"] + parameterNames From 0b3eb04082aa9f71348259149f81cdbc8f58c1ee Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Fri, 16 Oct 2026 08:30:57 +0200 Subject: [PATCH 07/18] JavaScriptEventLoop: Add opt-in `yieldInterval` for host responsiveness --- .../JavaScriptEventLoop+YieldInterval.swift | 105 ++++++++++++++++++ .../JavaScriptEventLoop.swift | 20 ++++ Sources/JavaScriptEventLoop/JobQueue.swift | 14 +++ .../JavaScript-Interop-Cheat-Sheet.md | 1 + ...avaScriptEventLoopYieldIntervalTests.swift | 79 +++++++++++++ 5 files changed, 219 insertions(+) create mode 100644 Sources/JavaScriptEventLoop/JavaScriptEventLoop+YieldInterval.swift create mode 100644 Tests/JavaScriptEventLoopTests/JavaScriptEventLoopYieldIntervalTests.swift diff --git a/Sources/JavaScriptEventLoop/JavaScriptEventLoop+YieldInterval.swift b/Sources/JavaScriptEventLoop/JavaScriptEventLoop+YieldInterval.swift new file mode 100644 index 000000000..73effb850 --- /dev/null +++ b/Sources/JavaScriptEventLoop/JavaScriptEventLoop+YieldInterval.swift @@ -0,0 +1,105 @@ +// Clock and host task scheduling for `JavaScriptEventLoop.yieldInterval`. + +import JavaScriptKit +import _Concurrency + +#if compiler(>=5.5) + +@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) +extension JavaScriptEventLoop { + + #if hasFeature(Embedded) + // `ContinuousClock` is unavailable in Embedded Swift; use `performance.now()` in milliseconds. + typealias DrainInstant = Double + + func drainClockNow() -> DrainInstant { + if performanceNow == nil { + let performance = JSObject.global.performance.object! + performanceNow = (performance, performance.now.function!) + } + return performanceNow!.now(this: performanceNow!.performance).number! + } + + func hasRun(since start: DrainInstant, for interval: Duration) -> Bool { + let (seconds, attoseconds) = interval.components + let intervalMilliseconds = Double(seconds) * 1_000 + Double(attoseconds) / 1_000_000_000_000_000 + return drainClockNow() - start >= intervalMilliseconds + } + #else + typealias DrainInstant = ContinuousClock.Instant + + func drainClockNow() -> DrainInstant { + ContinuousClock.now + } + + func hasRun(since start: DrainInstant, for interval: Duration) -> Bool { + start.duration(to: .now) >= interval + } + #endif + + /// Runs `body` in a new JavaScript task via `setImmediate`, `MessageChannel`, or `setTimeout`. + func queueHostTask(_ body: @escaping () -> Void) { + if hostTaskScheduler == nil { + hostTaskScheduler = Self.makeHostTaskScheduler() + } + hostTaskScheduler!(body) + } + + private static func makeHostTaskScheduler() -> (@escaping () -> Void) -> Void { + let global = JSObject.global + if let setImmediate = global.setImmediate.function { + return { body in + _ = setImmediate( + JSOneshotClosure { _ in + body() + return .undefined + } + ) + } + } + if let messageChannel = global.MessageChannel.function { + // Unlike nested `setTimeout` calls, messages are not clamped to 4 ms. + let channel = messageChannel.new(arguments: [JSValue]()) + let sender = channel.port1.object! + let postMessage = sender.postMessage.function! + let pending = PendingHostTasks() + let receiver = JSClosure { _ in + pending.runAll() + return .undefined + } + channel.port2.object!.onmessage = .object(receiver) + return { body in + pending.bodies.append(body) + // Keep `receiver` alive as long as the scheduler. + withExtendedLifetime(receiver) { + _ = postMessage(this: sender, JSValue.undefined) + } + } + } + let setTimeout = global.setTimeout.function! + return { body in + _ = setTimeout( + JSOneshotClosure { _ in + body() + return .undefined + }, + 0 + ) + } + } +} + +/// Bodies waiting for the next `MessageChannel` message. +private final class PendingHostTasks { + var bodies: [() -> Void] = [] + + func runAll() { + let bodies = self.bodies + self.bodies = [] + for body in bodies { + body() + } + } +} + +#endif diff --git a/Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift b/Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift index ead6157bf..ffca27795 100644 --- a/Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift +++ b/Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift @@ -48,6 +48,26 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable { /// A function that invokes a given closure after a specified number of milliseconds. public var setTimeout: (Double, @escaping () -> Void) -> Void + /// The maximum time to run queued jobs before yielding to the JavaScript event loop. + /// + /// By default (`nil`), all queued jobs run in a single microtask, so long-running async work + /// blocks rendering, input, and other JavaScript tasks until it completes. When set, the + /// remaining jobs continue in a new JavaScript task after the interval, at the cost of some + /// latency. A single job is never interrupted. + /// + /// ```swift + /// JavaScriptEventLoop.shared.yieldInterval = .milliseconds(16) + /// ``` + public var yieldInterval: Duration? + + /// Continues a drain that stopped at ``yieldInterval``. Created lazily. + var hostTaskScheduler: ((@escaping () -> Void) -> Void)? + + #if hasFeature(Embedded) + /// Cached `performance.now` used by ``yieldInterval`` in Embedded Swift. + var performanceNow: (performance: JSObject, now: JSFunction)? + #endif + /// A mutable state to manage internal job queue /// Note that this should be guarded atomically when supporting multi-threaded environment. var queueState = QueueState() diff --git a/Sources/JavaScriptEventLoop/JobQueue.swift b/Sources/JavaScriptEventLoop/JobQueue.swift index a0f2c4bbb..280ddb035 100644 --- a/Sources/JavaScriptEventLoop/JobQueue.swift +++ b/Sources/JavaScriptEventLoop/JobQueue.swift @@ -43,12 +43,26 @@ extension JavaScriptEventLoop { func runAllJobs() { assert(queueState.isSpinning) + // The clock is only read while `yieldInterval` is set. + var start: DrainInstant? = yieldInterval == nil ? nil : drainClockNow() while let job = self.claimNextFromQueue() { #if compiler(>=5.9) job.runSynchronously(on: self.asUnownedSerialExecutor()) #else job._runSynchronously(on: self.asUnownedSerialExecutor()) #endif + + if let yieldInterval, queueState.headJob != nil { + if let start { + if hasRun(since: start, for: yieldInterval) { + // Keep `isSpinning` set so new jobs wait for the continuation. + queueHostTask { self.runAllJobs() } + return + } + } else { + start = drainClockNow() + } + } } queueState.isSpinning = false diff --git a/Sources/JavaScriptKit/Documentation.docc/Articles/JavaScript-Interop-Cheat-Sheet.md b/Sources/JavaScriptKit/Documentation.docc/Articles/JavaScript-Interop-Cheat-Sheet.md index 4280a4637..b554e5a7b 100644 --- a/Sources/JavaScriptKit/Documentation.docc/Articles/JavaScript-Interop-Cheat-Sheet.md +++ b/Sources/JavaScriptKit/Documentation.docc/Articles/JavaScript-Interop-Cheat-Sheet.md @@ -373,4 +373,5 @@ let swiftPromise = JSPromise.async { - Use `JSPromise.async(body:)` (with `Void` or `JSValue` return type) to expose Swift `async/await` work to JavaScript callers. - To await JavaScript `Promise` from Swift, import `JavaScriptEventLoop`, call `JavaScriptEventLoop.installGlobalExecutor()` early, and use the `value` property. - The `value` property suspends until the promise resolves or rejects, rethrowing rejections as ``JSException``. +- Long-running async work blocks rendering and input until it completes. Set `JavaScriptEventLoop.shared.yieldInterval` (for example, `.milliseconds(16)`) to yield to the JavaScript event loop between jobs. diff --git a/Tests/JavaScriptEventLoopTests/JavaScriptEventLoopYieldIntervalTests.swift b/Tests/JavaScriptEventLoopTests/JavaScriptEventLoopYieldIntervalTests.swift new file mode 100644 index 000000000..4269b89b2 --- /dev/null +++ b/Tests/JavaScriptEventLoopTests/JavaScriptEventLoopYieldIntervalTests.swift @@ -0,0 +1,79 @@ +import JavaScriptEventLoop +import JavaScriptKit +import XCTest + +final class JavaScriptEventLoopYieldIntervalTests: XCTestCase { + final class Box: @unchecked Sendable { + var value: Value + init(_ value: Value) { self.value = value } + } + + override func tearDown() { + JavaScriptEventLoop.shared.yieldInterval = nil + super.tearDown() + } + + static func busyWait(milliseconds: Int) { + let end = ContinuousClock.now + .milliseconds(milliseconds) + while ContinuousClock.now < end {} + } + + /// Returns, for each busy task, whether a JavaScript timer scheduled before them had fired. + func timerRanAfterEachTask(count: Int, milliseconds: Int) async -> [Bool] { + let timerRan = Box(false) + _ = JSObject.global.setTimeout!( + JSOneshotClosure { _ in + timerRan.value = true + return .undefined + }, + 0 + ) + let observed = Box([Bool]()) + let tasks = (0.. Date: Fri, 16 Oct 2026 11:40:19 +0200 Subject: [PATCH 08/18] JavaScriptEventLoop: Read the clock less often with `yieldInterval` --- .../JavaScriptEventLoop+YieldInterval.swift | 10 ++++------ Sources/JavaScriptEventLoop/JobQueue.swift | 13 ++++++++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Sources/JavaScriptEventLoop/JavaScriptEventLoop+YieldInterval.swift b/Sources/JavaScriptEventLoop/JavaScriptEventLoop+YieldInterval.swift index 73effb850..dbcd30b9f 100644 --- a/Sources/JavaScriptEventLoop/JavaScriptEventLoop+YieldInterval.swift +++ b/Sources/JavaScriptEventLoop/JavaScriptEventLoop+YieldInterval.swift @@ -20,10 +20,8 @@ extension JavaScriptEventLoop { return performanceNow!.now(this: performanceNow!.performance).number! } - func hasRun(since start: DrainInstant, for interval: Duration) -> Bool { - let (seconds, attoseconds) = interval.components - let intervalMilliseconds = Double(seconds) * 1_000 + Double(attoseconds) / 1_000_000_000_000_000 - return drainClockNow() - start >= intervalMilliseconds + func drainElapsed(since start: DrainInstant) -> Duration { + .milliseconds(drainClockNow() - start) } #else typealias DrainInstant = ContinuousClock.Instant @@ -32,8 +30,8 @@ extension JavaScriptEventLoop { ContinuousClock.now } - func hasRun(since start: DrainInstant, for interval: Duration) -> Bool { - start.duration(to: .now) >= interval + func drainElapsed(since start: DrainInstant) -> Duration { + start.duration(to: .now) } #endif diff --git a/Sources/JavaScriptEventLoop/JobQueue.swift b/Sources/JavaScriptEventLoop/JobQueue.swift index 280ddb035..0dcbcdc17 100644 --- a/Sources/JavaScriptEventLoop/JobQueue.swift +++ b/Sources/JavaScriptEventLoop/JobQueue.swift @@ -45,6 +45,10 @@ extension JavaScriptEventLoop { // The clock is only read while `yieldInterval` is set. var start: DrainInstant? = yieldInterval == nil ? nil : drainClockNow() + // A clock read costs more than a small job. Read it every `clockStride` jobs, and double + // the stride (up to 256) while the drain is far from the interval. + var clockStride = 1 + var jobsUntilClockRead = 1 while let job = self.claimNextFromQueue() { #if compiler(>=5.9) job.runSynchronously(on: self.asUnownedSerialExecutor()) @@ -54,11 +58,18 @@ extension JavaScriptEventLoop { if let yieldInterval, queueState.headJob != nil { if let start { - if hasRun(since: start, for: yieldInterval) { + jobsUntilClockRead -= 1 + if jobsUntilClockRead > 0 { continue } + let elapsed = drainElapsed(since: start) + if elapsed >= yieldInterval { // Keep `isSpinning` set so new jobs wait for the continuation. queueHostTask { self.runAllJobs() } return } + if elapsed * 4 < yieldInterval { + clockStride = min(clockStride * 2, 256) + } + jobsUntilClockRead = clockStride } else { start = drainClockNow() } From ed4bedb226150c055a4ce0cee994faea41f846c2 Mon Sep 17 00:00:00 2001 From: William Taylor Date: Tue, 20 Oct 2026 10:13:50 +1100 Subject: [PATCH 09/18] BridgeJS: Escape reserved words --- .../Sources/BridgeJSCore/ExportSwift.swift | 18 +- .../Sources/BridgeJSLink/BridgeJSLink.swift | 31 +- .../MacroSwift/ReservedWordParameters.swift | 1 + .../ReservedWordParameters.json | 81 ++++ .../ReservedWordParameters.swift | 13 + .../ReservedWordParameters.d.ts | 18 + .../ReservedWordParameters.js | 382 ++++++++++++++++++ .../BridgeJSRuntimeTests/ExportAPITests.swift | 3 + .../Generated/BridgeJS.swift | 15 + .../Generated/JavaScript/BridgeJS.json | 55 +++ Tests/prelude.mjs | 1 + 11 files changed, 605 insertions(+), 13 deletions(-) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ReservedWordParameters.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ReservedWordParameters.json create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ReservedWordParameters.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.d.ts create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.js diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index 7d402aa9c..cf0907fa9 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -216,7 +216,7 @@ public class ExportSwift { let liftingInfo = try param.type.liftParameterInfo() let argumentsToLift: [String] if liftingInfo.parameters.count == 1 { - argumentsToLift = [param.name] + argumentsToLift = [param.escapedSwiftIdentifier] } else { argumentsToLift = liftingInfo.parameters.map { (name, _) in param.name + name.capitalizedFirstLetter } } @@ -227,7 +227,9 @@ public class ExportSwift { switch param.type { case .closure(let signature, _): typeNameForIntrinsic = param.type.swiftType - liftingExpr = ExprSyntax("_BJS_Closure_\(raw: signature.mangleName).bridgeJSLift(\(raw: param.name))") + liftingExpr = ExprSyntax( + "_BJS_Closure_\(raw: signature.mangleName).bridgeJSLift(\(raw: param.escapedSwiftIdentifier))" + ) case .swiftStruct(let structName): typeNameForIntrinsic = structName liftingExpr = ExprSyntax("\(raw: structName).bridgeJSLiftParameter()") @@ -252,7 +254,7 @@ public class ExportSwift { ) } - parameterBindings.insert("let \(raw: param.name) = \(liftingExpr)", at: 0) + parameterBindings.insert("let \(raw: param.escapedSwiftIdentifier) = \(liftingExpr)", at: 0) for (name, type) in zip(argumentsToLift, liftingInfo.parameters.map { $0.type }) { abiParameterSignatures.append((name, type)) } @@ -268,14 +270,14 @@ public class ExportSwift { } private func removeFirstLiftedParameter() -> String { - return parameters.removeFirst().name + return parameters.removeFirst().escapedSwiftIdentifier } private func renderCallStatement(callee: ExprSyntax, returnType: BridgeType) -> CodeBlockItemSyntax { let labeledParams = parameters.map { param in LabeledExprSyntax( label: param.label, - expression: DeclReferenceExprSyntax(baseName: .identifier(param.name)) + expression: DeclReferenceExprSyntax(baseName: .identifier(param.escapedSwiftIdentifier)) ) } var callExpr: ExprSyntax = @@ -1593,6 +1595,12 @@ struct ProtocolCodegen { } } +extension Parameter { + fileprivate var escapedSwiftIdentifier: String { + name.backtickIfNeeded() + } +} + extension WasmCoreType { var swiftType: String { switch self { diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 8e7c4939c..ee9531d31 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -1758,7 +1758,7 @@ public struct BridgeJSLink { loweringFragment.parameters.count == 1, "Lowering fragment should have exactly one parameter to lower" ) - let paramName = scope.variable(param.name) + let paramName = scope.variable(param.escapedJSIdentifier) let loweredValues = try loweringFragment.printCode([paramName], context) parameterForwardings.append(contentsOf: loweredValues) } @@ -1950,7 +1950,7 @@ public struct BridgeJSLink { } let parameterSignatures = parameters.map { param in let optional = param.hasDefault ? "?" : "" - return "\(param.name)\(optional): \(resolveTypeScriptType(param.type))" + return "\(param.escapedJSIdentifier)\(optional): \(resolveTypeScriptType(param.type))" } return "(\(parameterSignatures.joined(separator: ", "))): \(returnTypeWithEffect)" } @@ -2669,7 +2669,7 @@ extension BridgeJSLink { if let constructor = klass.constructor { let paramSignatures = constructor.parameters.map { param in let optional = param.hasDefault ? "?" : "" - return "\(param.name)\(optional): \(resolveTypeScriptType(param.type))" + return "\(param.escapedJSIdentifier)\(optional): \(resolveTypeScriptType(param.type))" } printer.write( lines: renderJSDoc(documentation: constructor.documentation, parameters: constructor.parameters) @@ -4321,9 +4321,9 @@ enum DefaultValueUtils { return parameters.map { param in if let defaultValue = param.defaultValue { let defaultJs = format(defaultValue, as: .javascript, resolveTypeName: resolveTypeName) - return "\(param.name) = \(defaultJs)" + return "\(param.escapedJSIdentifier) = \(defaultJs)" } - return param.name + return param.escapedJSIdentifier }.joined(separator: ", ") } } @@ -4348,11 +4348,11 @@ extension BridgeJSLink { } switch (docText, defaultValue) { case let (.some(text), .some(value)): - tagLines.append("@param \(parameter.name) \(text) (default: \(value))") + tagLines.append("@param \(parameter.escapedJSIdentifier) \(text) (default: \(value))") case let (.some(text), .none): - tagLines.append("@param \(parameter.name) \(text)") + tagLines.append("@param \(parameter.escapedJSIdentifier) \(text)") case let (.none, .some(value)): - tagLines.append("@param \(parameter.name) - Optional parameter (default: \(value))") + tagLines.append("@param \(parameter.escapedJSIdentifier) - Optional parameter (default: \(value))") case (.none, .none): continue } @@ -4477,6 +4477,21 @@ struct BridgeJSLinkError: Error { let message: String } +extension Parameter { + // From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words + private static let javaScriptReservedWords: Set = [ + "break", "case", "catch", "class", "const", "continue", "debugger", "default", "delete", "do", "else", + "export", "extends", "false", "finally", "for", "function", "if", "import", "in", "instanceof", "new", + "null", "return", "super", "switch", "this", "throw", "true", "try", "typeof", "var", "void", "while", + "with", "let", "static", "yield", "await", "enum", "implements", "interface", "package", "private", + "protected", "public", "arguments", "eval", + ] + + fileprivate var escapedJSIdentifier: String { + Self.javaScriptReservedWords.contains(name) ? "_\(name)" : name + } +} + extension ClosureSignature { fileprivate func renderTSFunctionType(renderType: (BridgeType) -> String) -> String { let renderedParameters = parameters.enumerated().map { index, parameter in diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ReservedWordParameters.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ReservedWordParameters.swift new file mode 100644 index 000000000..2c4c062cb --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ReservedWordParameters.swift @@ -0,0 +1 @@ +@JS func check(extension: Int, break: Double, function: Bool, in: String) {} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ReservedWordParameters.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ReservedWordParameters.json new file mode 100644 index 000000000..c27a4eb46 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ReservedWordParameters.json @@ -0,0 +1,81 @@ +{ + "exported" : { + "aliases" : [ + + ], + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_check", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "check", + "parameters" : [ + { + "label" : "extension", + "name" : "extension", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + }, + { + "label" : "break", + "name" : "break", + "type" : { + "double" : { + + } + } + }, + { + "label" : "function", + "name" : "function", + "type" : { + "bool" : { + + } + } + }, + { + "label" : "in", + "name" : "in", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule", + "usedExternalModules" : [ + + ] +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ReservedWordParameters.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ReservedWordParameters.swift new file mode 100644 index 000000000..b09e1a76d --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ReservedWordParameters.swift @@ -0,0 +1,13 @@ +@_expose(wasm, "bjs_check") +@_cdecl("bjs_check") +public func _bjs_check(_ `extension`: Int32, _ `break`: Float64, _ function: Int32, _ inBytes: Int32, _ inLength: Int32) -> Void { + #if arch(wasm32) + let `in` = String.bridgeJSLiftParameter(inBytes, inLength) + let function = Bool.bridgeJSLiftParameter(function) + let `break` = Double.bridgeJSLiftParameter(`break`) + let `extension` = Int.bridgeJSLiftParameter(`extension`) + check(extension: `extension`, break: `break`, function: function, in: `in`) + #else + fatalError("Only available on WebAssembly") + #endif +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.d.ts new file mode 100644 index 000000000..027a6b9db --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.d.ts @@ -0,0 +1,18 @@ +// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// `swift package bridge-js`. + +export type Exports = { + check(extension: number, _break: number, _function: boolean, _in: string): void; +} +export type Imports = { +} +export function createInstantiator(options: { + imports: Imports; +}, swift: any): Promise<{ + addImports: (importObject: WebAssembly.Imports) => void; + setInstance: (instance: WebAssembly.Instance) => void; + createExports: (instance: WebAssembly.Instance) => Exports; +}>; \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.js new file mode 100644 index 000000000..0abe5fdbf --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.js @@ -0,0 +1,382 @@ +// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// `swift package bridge-js`. + +export async function createInstantiator(options, swift) { + let instance; + let memory; + let setException; + let decodeString; + let decodeUTF8; + const immortalStrings = new Map(); + const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true }); + const textEncoder = new TextEncoder("utf-8"); + let tmpRetString; + let tmpRetBytes; + let tmpRetException; + let tmpRetOptionalBool; + let tmpRetOptionalInt; + let tmpRetOptionalFloat; + let tmpRetOptionalDouble; + let tmpRetOptionalHeapObject; + let strStack = []; + let i32Stack = []; + let i64Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; + let taStack = []; + const enumHelpers = {}; + const structHelpers = {}; + + let _exports = null; + let bjs = null; + + return { + /** + * @param {WebAssembly.Imports} importObject + */ + addImports: (importObject, importsContext) => { + bjs = {}; + importObject["bjs"] = bjs; + bjs["swift_js_return_string"] = function(word0, word1, word2) { + tmpRetString = decodeString(word0, word1, word2); + } + bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { + const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); + const bytes = new Uint8Array(memory.buffer, bytesPtr >>> 0); + bytes.set(source); + } + bjs["swift_js_make_js_string"] = function(word0, word1, word2) { + return swift.memory.retain(decodeString(word0, word1, word2)); + } + bjs["swift_js_init_memory_with_result"] = function(ptr, len) { + const target = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); + target.set(tmpRetBytes); + tmpRetBytes = undefined; + } + bjs["swift_js_throw"] = function(id) { + tmpRetException = swift.memory.retainByRef(id); + } + bjs["swift_js_retain"] = function(id) { + return swift.memory.retainByRef(id); + } + bjs["swift_js_release"] = function(id) { + swift.memory.release(id); + } + bjs["swift_js_push_i32"] = function(v) { + i32Stack.push(v | 0); + } + bjs["swift_js_push_f32"] = function(v) { + f32Stack.push(Math.fround(v)); + } + bjs["swift_js_push_f64"] = function(v) { + f64Stack.push(v); + } + bjs["swift_js_push_string"] = function(word0, word1, word2) { + const value = decodeString(word0, word1, word2); + strStack.push(value); + } + bjs["swift_js_pop_i32"] = function() { + return i32Stack.pop(); + } + bjs["swift_js_pop_f32"] = function() { + return f32Stack.pop(); + } + bjs["swift_js_pop_f64"] = function() { + return f64Stack.pop(); + } + bjs["swift_js_push_pointer"] = function(pointer) { + ptrStack.push(pointer); + } + bjs["swift_js_pop_pointer"] = function() { + return ptrStack.pop(); + } + bjs["swift_js_push_i64"] = function(v) { + i64Stack.push(v); + } + bjs["swift_js_pop_i64"] = function() { + return i64Stack.pop(); + } + const taCtors = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array]; + bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { + const Ctor = taCtors[kind]; + const byteLen = count * Ctor.BYTES_PER_ELEMENT; + const copy = memory.buffer.slice(ptr, ptr + byteLen); + taStack.push(Array.from(new Ctor(copy))); + } + bjs["bjs_core_register_type_handles"] = function() {}; + const __bjs_promiseSettlers = Symbol("JavaScriptKit.promiseSettlers"); + bjs["swift_js_make_promise"] = function() { + let resolve, reject; + const promise = new Promise((res, rej) => { resolve = res; reject = rej; }); + promise[__bjs_promiseSettlers] = { resolve, reject }; + return swift.memory.retain(promise); + } + bjs["swift_js_return_optional_bool"] = function(isSome, value) { + if (isSome === 0) { + tmpRetOptionalBool = null; + } else { + tmpRetOptionalBool = value !== 0; + } + } + bjs["swift_js_return_optional_int"] = function(isSome, value) { + if (isSome === 0) { + tmpRetOptionalInt = null; + } else { + tmpRetOptionalInt = value | 0; + } + } + bjs["swift_js_return_optional_float"] = function(isSome, value) { + if (isSome === 0) { + tmpRetOptionalFloat = null; + } else { + tmpRetOptionalFloat = Math.fround(value); + } + } + bjs["swift_js_return_optional_double"] = function(isSome, value) { + if (isSome === 0) { + tmpRetOptionalDouble = null; + } else { + tmpRetOptionalDouble = value; + } + } + bjs["swift_js_return_optional_string"] = function(isSome, word0, word1, word2) { + if (isSome === 0) { + tmpRetString = null; + } else { + tmpRetString = decodeString(word0, word1, word2); + } + } + bjs["swift_js_return_optional_object"] = function(isSome, objectId) { + if (isSome === 0) { + tmpRetString = null; + } else { + tmpRetString = swift.memory.getObject(objectId); + } + } + bjs["swift_js_return_optional_heap_object"] = function(isSome, pointer) { + if (isSome === 0) { + tmpRetOptionalHeapObject = null; + } else { + tmpRetOptionalHeapObject = pointer; + } + } + bjs["swift_js_get_optional_int_presence"] = function() { + return tmpRetOptionalInt != null ? 1 : 0; + } + bjs["swift_js_get_optional_int_value"] = function() { + const value = tmpRetOptionalInt; + tmpRetOptionalInt = undefined; + return value; + } + bjs["swift_js_get_optional_string"] = function() { + const str = tmpRetString; + tmpRetString = undefined; + if (str == null) { + return -1; + } else { + const bytes = textEncoder.encode(str); + tmpRetBytes = bytes; + return bytes.length; + } + } + bjs["swift_js_get_optional_float_presence"] = function() { + return tmpRetOptionalFloat != null ? 1 : 0; + } + bjs["swift_js_get_optional_float_value"] = function() { + const value = tmpRetOptionalFloat; + tmpRetOptionalFloat = undefined; + return value; + } + bjs["swift_js_get_optional_double_presence"] = function() { + return tmpRetOptionalDouble != null ? 1 : 0; + } + bjs["swift_js_get_optional_double_value"] = function() { + const value = tmpRetOptionalDouble; + tmpRetOptionalDouble = undefined; + return value; + } + bjs["swift_js_get_optional_heap_object_pointer"] = function() { + const pointer = tmpRetOptionalHeapObject; + tmpRetOptionalHeapObject = undefined; + return pointer || 0; + } + bjs["swift_js_closure_unregister"] = function(funcRef) {} + }, + setInstance: (i) => { + if (memory !== i.exports.memory) immortalStrings.clear(); + instance = i; + memory = instance.exports.memory; + + decodeUTF8 = (ptr, len) => { const bytes = new Uint8Array(memory.buffer, ptr >>> 0, len >>> 0); return textDecoder.decode(bytes); } + decodeString = (() => { + const byteAt = (word0, word1, byteIndex) => + byteIndex < 4 + ? (word0 >>> (byteIndex * 8)) & 255 + : (word1 >>> ((byteIndex - 4) * 8)) & 255; + // Valid small Swift strings need at most eight UTF-16 code units. + const decodeSmallUTF8 = (word0, word1, count) => { + if (count > 8) { + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + let byteIndex = 0, + unitCount = 0, + u0 = 0, + u1 = 0, + u2 = 0, + u3 = 0, + u4 = 0, + u5 = 0, + u6 = 0, + u7 = 0; + while (byteIndex < count) { + const b0 = byteAt(word0, word1, byteIndex++); + let codePoint; + if (b0 < 128) codePoint = b0; + else if (b0 < 224) codePoint = ((b0 & 31) << 6) | (byteAt(word0, word1, byteIndex++) & 63); + else if (b0 < 240) { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 15) << 12) | ((b1 & 63) << 6) | (b2 & 63); + } else { + const b1 = byteAt(word0, word1, byteIndex++), + b2 = byteAt(word0, word1, byteIndex++), + b3 = byteAt(word0, word1, byteIndex++); + codePoint = ((b0 & 7) << 18) | ((b1 & 63) << 12) | ((b2 & 63) << 6) | (b3 & 63); + } + const supplementary = codePoint > 0xffff; + const codeUnit = supplementary + ? 0xd800 + ((codePoint - 0x10000) >>> 10) + : codePoint; + switch (unitCount++) { + case 0: + u0 = codeUnit; + break; + case 1: + u1 = codeUnit; + break; + case 2: + u2 = codeUnit; + break; + case 3: + u3 = codeUnit; + break; + case 4: + u4 = codeUnit; + break; + case 5: + u5 = codeUnit; + break; + case 6: + u6 = codeUnit; + break; + case 7: + u7 = codeUnit; + break; + } + if (supplementary) { + const lowSurrogate = 0xdc00 + ((codePoint - 0x10000) & 1023); + switch (unitCount++) { + case 0: + u0 = lowSurrogate; + break; + case 1: + u1 = lowSurrogate; + break; + case 2: + u2 = lowSurrogate; + break; + case 3: + u3 = lowSurrogate; + break; + case 4: + u4 = lowSurrogate; + break; + case 5: + u5 = lowSurrogate; + break; + case 6: + u6 = lowSurrogate; + break; + case 7: + u7 = lowSurrogate; + break; + } + } + } + switch (unitCount) { + case 0: + return ""; + case 1: + return String.fromCharCode(u0); + case 2: + return String.fromCharCode(u0, u1); + case 3: + return String.fromCharCode(u0, u1, u2); + case 4: + return String.fromCharCode(u0, u1, u2, u3); + case 5: + return String.fromCharCode(u0, u1, u2, u3, u4); + case 6: + return String.fromCharCode(u0, u1, u2, u3, u4, u5); + case 7: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6); + case 8: + return String.fromCharCode(u0, u1, u2, u3, u4, u5, u6, u7); + } + }; + const decodeSmall = (word0, word1, word2) => { + const count = (word2 >>> 8) & 0x0f; + if ((word2 & 0x4000 /* ASCII */) === 0) return decodeSmallUTF8(word0, word1, count); + const char = String.fromCharCode; + switch (count) { + case 0: return ""; + case 1: return char(word0 & 0xff); + case 2: return char(word0 & 0xff, (word0 >>> 8) & 0xff); + case 3: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff); + case 4: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24); + case 5: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff); + case 6: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff); + case 7: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff); + case 8: return char(word0 & 0xff, (word0 >>> 8) & 0xff, (word0 >>> 16) & 0xff, word0 >>> 24, word1 & 0xff, (word1 >>> 8) & 0xff, (word1 >>> 16) & 0xff, word1 >>> 24); + default: + throw new Error(`Unsupported Swift inline String length: ${count} UTF-8 bytes (maximum 8). The Swift String layout may have changed; update JavaScriptKit and regenerate BridgeJS glue.`); + } + }; + return (word0, word1, word2) => { + if (word2 & 0x2000 /* small */) return decodeSmall(word0, word1, word2); + const ptr = (word1 + 20 /* nativeBias */) >>> 0; + const len = word0 >>> 0; + if ((word2 & 0x8000 /* immortal */) === 0 || len >= 0x200000 /* 2^21 Number key */) return decodeUTF8(ptr, len); + const key = ptr + len * 0x100000000; + const cached = immortalStrings.get(key); + if (cached !== undefined) return cached; + const value = decodeUTF8(ptr, len); + immortalStrings.set(key, value); + return value; + }; + })(); + + setException = (error) => { + instance.exports._swift_js_exception.value = swift.memory.retain(error) + } + }, + /** @param {WebAssembly.Instance} instance */ + createExports: (instance) => { + const js = swift.memory.heap; + const exports = { + check: function bjs_check(extension, _break, _function, _in) { + const _inBytes = textEncoder.encode(_in); + const _inId = swift.memory.retain(_inBytes); + instance.exports.bjs_check(extension, _break, _function, _inId, _inBytes.length); + }, + }; + _exports = exports; + return exports; + }, + } +} \ No newline at end of file diff --git a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift index c231d0ce9..9e5892a87 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -22,6 +22,9 @@ func runJsWorks() -> Void @JS func roundTripString(v: String) -> String { return v } +@JS func describeReservedWordParameters(extension: Int, break: Double, function: Bool, in: String) -> String { + return "\(`extension`):\(`break`):\(function):\(`in`)" +} @JS func roundTripSwiftHeapObject(v: Greeter) -> Greeter { return v } diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index b89bdb510..884ecb8e1 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -10324,6 +10324,21 @@ public func _bjs_roundTripString(_ vBytes: Int32, _ vLength: Int32) -> Void { #endif } +@_expose(wasm, "bjs_describeReservedWordParameters") +@_cdecl("bjs_describeReservedWordParameters") +public func _bjs_describeReservedWordParameters(_ `extension`: Int32, _ `break`: Float64, _ function: Int32, _ inBytes: Int32, _ inLength: Int32) -> Void { + #if arch(wasm32) + let `in` = String.bridgeJSLiftParameter(inBytes, inLength) + let function = Bool.bridgeJSLiftParameter(function) + let `break` = Double.bridgeJSLiftParameter(`break`) + let `extension` = Int.bridgeJSLiftParameter(`extension`) + let ret = describeReservedWordParameters(extension: `extension`, break: `break`, function: function, in: `in`) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + @_expose(wasm, "bjs_roundTripSwiftHeapObject") @_cdecl("bjs_roundTripSwiftHeapObject") public func _bjs_roundTripSwiftHeapObject(_ v: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index 9d5da0a7f..8598361b6 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -15214,6 +15214,61 @@ } } }, + { + "abiName" : "bjs_describeReservedWordParameters", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "describeReservedWordParameters", + "parameters" : [ + { + "label" : "extension", + "name" : "extension", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + }, + { + "label" : "break", + "name" : "break", + "type" : { + "double" : { + + } + } + }, + { + "label" : "function", + "name" : "function", + "type" : { + "bool" : { + + } + } + }, + { + "label" : "in", + "name" : "in", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, { "abiName" : "bjs_roundTripSwiftHeapObject", "effects" : { diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index f54e3a149..15631bcbe 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -305,6 +305,7 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { ]) { assert.equal(exports.roundTripString(v), v); } + assert.equal(exports.describeReservedWordParameters(1, 2.5, true, "in"), "1:2.5:true:in"); const dict = { a: 1, b: 2 }; assert.deepEqual(exports.roundTripDictionaryExport(dict), dict); const optDict = { hello: "world" }; From 89057a154b644b2ef12599636b44f46548dd279c Mon Sep 17 00:00:00 2001 From: William Taylor Date: Wed, 28 Oct 2026 16:12:22 +1100 Subject: [PATCH 10/18] BridgeJS: Escape on import too --- .../Sources/BridgeJSCore/ExportSwift.swift | 13 +- .../Sources/BridgeJSCore/ImportTS.swift | 42 +- .../BridgeJSCore/SwiftToSkeleton.swift | 2 +- .../Sources/BridgeJSLink/BridgeJSLink.swift | 122 +++--- .../Sources/BridgeJSLink/JSGlueGen.swift | 28 +- .../BridgeJSMacros/JSMacroSupport.swift | 5 +- .../MacroSwift/ReservedWordParameters.swift | 22 + .../ReservedWordParameters.json | 378 ++++++++++++++++++ .../ReservedWordParameters.swift | 267 +++++++++++++ .../ReservedWordParameters.d.ts | 27 ++ .../ReservedWordParameters.js | 172 ++++++++ .../BridgeJSRuntimeTests/ExportAPITests.swift | 12 + .../Generated/BridgeJS.swift | 98 +++++ .../Generated/JavaScript/BridgeJS.json | 199 +++++++++ .../BridgeJSRuntimeTests/ImportAPITests.swift | 10 + Tests/prelude.mjs | 7 + 16 files changed, 1296 insertions(+), 108 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index cf0907fa9..3197f559c 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -213,10 +213,11 @@ public class ExportSwift { func liftParameter(param: Parameter) throws { parameters.append(param) + let escapedName = param.escapedSwiftIdentifier let liftingInfo = try param.type.liftParameterInfo() let argumentsToLift: [String] if liftingInfo.parameters.count == 1 { - argumentsToLift = [param.escapedSwiftIdentifier] + argumentsToLift = [escapedName] } else { argumentsToLift = liftingInfo.parameters.map { (name, _) in param.name + name.capitalizedFirstLetter } } @@ -228,7 +229,7 @@ public class ExportSwift { case .closure(let signature, _): typeNameForIntrinsic = param.type.swiftType liftingExpr = ExprSyntax( - "_BJS_Closure_\(raw: signature.mangleName).bridgeJSLift(\(raw: param.escapedSwiftIdentifier))" + "_BJS_Closure_\(raw: signature.mangleName).bridgeJSLift(\(raw: escapedName))" ) case .swiftStruct(let structName): typeNameForIntrinsic = structName @@ -254,7 +255,7 @@ public class ExportSwift { ) } - parameterBindings.insert("let \(raw: param.escapedSwiftIdentifier) = \(liftingExpr)", at: 0) + parameterBindings.insert("let \(raw: param.escapedSwiftBindingIdentifier) = \(liftingExpr)", at: 0) for (name, type) in zip(argumentsToLift, liftingInfo.parameters.map { $0.type }) { abiParameterSignatures.append((name, type)) } @@ -1595,12 +1596,6 @@ struct ProtocolCodegen { } } -extension Parameter { - fileprivate var escapedSwiftIdentifier: String { - name.backtickIfNeeded() - } -} - extension WasmCoreType { var swiftType: String { switch self { diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift index 841c0409c..504b955d2 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift @@ -143,7 +143,8 @@ public struct ImportTS { } func lowerParameter(param: Parameter) throws { - if let genericPush = param.type.genericStackPushStatement(value: param.name) { + let escapedName = param.escapedSwiftIdentifier + if let genericPush = param.type.genericStackPushStatement(value: escapedName) { stackLoweringStmts.insert(genericPush, at: 0) return } @@ -153,10 +154,10 @@ public struct ImportTS { switch param.type { case .closure(let signature, useJSTypedClosure: false): let jsTypedClosureType = BridgeType.closure(signature, useJSTypedClosure: true).swiftType - body.write("let \(param.name) = \(jsTypedClosureType)(\(param.name))") + body.write("let \(param.escapedSwiftBindingIdentifier) = \(jsTypedClosureType)(\(escapedName))") // The just created JSObject is not owned by the caller unlike those passed in parameters, // so we need to extend its lifetime during the call to ensure the JSObject.id is valid. - valuesToExtendLifetimeDuringCall.append(param.name) + valuesToExtendLifetimeDuringCall.append(escapedName) default: break } @@ -177,7 +178,7 @@ public struct ImportTS { if loweringInfo.useBorrowing { let returnVariableName = "ret\(borrowedArguments.count)" let assign = needsReturnVariable ? "let \(returnVariableName) = " : "" - body.write("\(assign)\(param.name).bridgeJSWithLoweredParameter { \(pattern) in") + body.write("\(assign)\(escapedName).bridgeJSWithLoweredParameter { \(pattern) in") body.indent() borrowedArguments.append( BorrowedArgument( @@ -190,10 +191,10 @@ public struct ImportTS { ) } else if case .nullable(.swiftProtocol(let protocolName), _) = param.type, context == .exportSwift { body.write("let \(pattern): (Int32, Int32)") - body.write("if let \(param.name) {") + body.write("if let \(param.escapedSwiftBindingIdentifier) {") body.indent { body.write( - "\(pattern) = (1, _bridgeJSUnwrapProtocolExportable(\(param.name), \"\(protocolName)\").bridgeJSLowerAsProtocolReturn())" + "\(pattern) = (1, _bridgeJSUnwrapProtocolExportable(\(escapedName), \"\(protocolName)\").bridgeJSLowerAsProtocolReturn())" ) } body.write("} else {") @@ -205,10 +206,10 @@ public struct ImportTS { let initializerExpr: ExprSyntax if case .swiftProtocol(let protocolName) = param.type, context == .exportSwift { initializerExpr = ExprSyntax( - "_bridgeJSUnwrapProtocolExportable(\(raw: param.name), \"\(raw: protocolName)\").bridgeJSLowerAsProtocolReturn()" + "_bridgeJSUnwrapProtocolExportable(\(raw: escapedName), \"\(raw: protocolName)\").bridgeJSLowerAsProtocolReturn()" ) } else { - initializerExpr = ExprSyntax("\(raw: param.name).bridgeJSLowerParameter()") + initializerExpr = ExprSyntax("\(raw: escapedName).bridgeJSLowerParameter()") } let binding = loweringInfo.loweredParameters.isEmpty ? "_" : pattern @@ -218,10 +219,10 @@ public struct ImportTS { // Add to signatures and forwardings (unified for both single and multiple) for (index, (paramName, type)) in loweringInfo.loweredParameters.enumerated() { - // For single parameter, use param.name; for multiple, use constructed name + // For single parameter, use the escaped name; for multiple, use constructed name let abiParamName: String if loweringInfo.loweredParameters.count == 1 { - abiParamName = param.name + abiParamName = escapedName } else { abiParamName = "\(param.name)\(paramName.capitalizedFirstLetter)" } @@ -723,20 +724,21 @@ struct SwiftSignatureBuilder { var out = "(" out += parameters.map { param in let label = param.label ?? param.name + let escapedName = param.escapedSwiftIdentifier let paramType = buildParameterTypeSyntax(from: param.type) if useWildcardLabels { // Always use wildcard labels: "_ name: Type" - return "_ \(param.name): \(paramType)" - } else if label == param.name { + return "_ \(escapedName): \(paramType)" + } else if SwiftToSkeleton.normalizeIdentifier(label) == param.name { // External label same as parameter name: "count: Int" - return "\(param.name): \(paramType)" + return "\(escapedName): \(paramType)" } else if param.label == nil { // No label specified: use wildcard "_ name: Type" - return "_ \(param.name): \(paramType)" + return "_ \(escapedName): \(paramType)" } else { // External label differs: "label count: Int" - return "\(label) \(param.name): \(paramType)" + return "\(label) \(escapedName): \(paramType)" } }.joined(separator: ", ") out += ")" @@ -1065,3 +1067,13 @@ extension String { return self.isValidSwiftIdentifier(for: .variableName) ? self : "`\(self)`" } } + +extension Parameter { + var escapedSwiftIdentifier: String { + name == "self" ? name : name.backtickIfNeeded() + } + + var escapedSwiftBindingIdentifier: String { + name.backtickIfNeeded() + } +} diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index ad3722dac..ef39000b1 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -1587,7 +1587,7 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { continue } - let name = param.secondName?.text ?? param.firstName.text + let name = SwiftToSkeleton.normalizeIdentifier(param.secondName?.text ?? param.firstName.text) let label = param.firstName.text let defaultValue: DefaultValue? diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index ee9531d31..686f8d1e0 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -1730,6 +1730,9 @@ public struct BridgeJSLink { class ExportedThunkBuilder { var body: CodeFragmentPrinter var parameterForwardings: [String] = [] + + private var signatureParameters: [(parameter: Parameter, name: String)] = [] + let effects: Effects let scope: JSGlueVariableScope let context: IntrinsicJSFragment.PrintCodeContext @@ -1759,6 +1762,7 @@ public struct BridgeJSLink { "Lowering fragment should have exactly one parameter to lower" ) let paramName = scope.variable(param.escapedJSIdentifier) + signatureParameters.append((param, paramName)) let loweredValues = try loweringFragment.printCode([paramName], context) parameterForwardings.append(contentsOf: loweredValues) } @@ -1767,6 +1771,20 @@ public struct BridgeJSLink { parameterForwardings.append("this.pointer") } + var parameterList: String { + signatureParameters.map { parameter, name in + guard let defaultValue = parameter.defaultValue else { + return name + } + let defaultJs = DefaultValueUtils.format( + defaultValue, + as: .javascript, + resolveTypeName: context.defaultValueTypeName + ) + return "\(name) = \(defaultJs)" + }.joined(separator: ", ") + } + func call(abiName: String, returnType: BridgeType) throws -> String? { if effects.isAsync { return try _call(abiName: abiName, returnType: .jsObject(nil)) @@ -1830,17 +1848,11 @@ public struct BridgeJSLink { func renderFunction( name: String, - parameters: [Parameter], returnExpr: String?, declarationPrefixKeyword: String? ) -> [String] { let printer = CodeFragmentPrinter() - let parameterList = DefaultValueUtils.formatParameterList( - parameters, - resolveTypeName: context.defaultValueTypeName - ) - printer.write( "\(declarationPrefixKeyword.map { "\($0) "} ?? "")\(name)(\(parameterList)) {" ) @@ -1948,11 +1960,15 @@ public struct BridgeJSLink { } else { returnTypeWithEffect = resolveTypeScriptType(returnType) } - let parameterSignatures = parameters.map { param in + return "\(renderTSParameterList(parameters)): \(returnTypeWithEffect)" + } + + private func renderTSParameterList(_ parameters: [Parameter]) -> String { + let parameterSignatures = zip(parameters, parameters.uniqueJSIdentifiers).map { param, name in let optional = param.hasDefault ? "?" : "" - return "\(param.escapedJSIdentifier)\(optional): \(resolveTypeScriptType(param.type))" + return "\(name)\(optional): \(resolveTypeScriptType(param.type))" } - return "(\(parameterSignatures.joined(separator: ", "))): \(returnTypeWithEffect)" + return "(\(parameterSignatures.joined(separator: ", ")))" } private func renderGenericClause(_ genericParameters: [GenericParameter]) -> String { @@ -2062,11 +2078,7 @@ public struct BridgeJSLink { ) let constructorPrinter = CodeFragmentPrinter() - let paramList = DefaultValueUtils.formatParameterList( - constructor.parameters, - resolveTypeName: thunkBuilder.context.defaultValueTypeName - ) - constructorPrinter.write("init: function(\(paramList)) {") + constructorPrinter.write("init: function(\(thunkBuilder.parameterList)) {") constructorPrinter.indent { thunkBuilder.renderFunctionBody(into: constructorPrinter, returnExpr: returnExpr) } @@ -2290,7 +2302,6 @@ extension BridgeJSLink { let returnExpr = try thunkBuilder.call(abiName: function.abiName, returnType: function.returnType) let funcLines = thunkBuilder.renderFunction( name: function.abiName, - parameters: function.parameters, returnExpr: returnExpr, declarationPrefixKeyword: "function" ) @@ -2341,7 +2352,6 @@ extension BridgeJSLink { let funcLines = thunkBuilder.renderFunction( name: function.resolvedJSName, - parameters: function.parameters, returnExpr: returnExpr, declarationPrefixKeyword: "static" ) @@ -2371,11 +2381,7 @@ extension BridgeJSLink { let returnExpr = try thunkBuilder.call(abiName: function.abiName, returnType: function.returnType) let printer = CodeFragmentPrinter() - let parameterList = DefaultValueUtils.formatParameterList( - function.parameters, - resolveTypeName: thunkBuilder.context.defaultValueTypeName - ) - printer.write("\(function.resolvedJSName)(\(parameterList)) {") + printer.write("\(function.resolvedJSName)(\(thunkBuilder.parameterList)) {") printer.indent { thunkBuilder.renderFunctionBody(into: printer, returnExpr: returnExpr) } @@ -2407,7 +2413,6 @@ extension BridgeJSLink { let funcLines = thunkBuilder.renderFunction( name: function.abiName, - parameters: function.parameters, returnExpr: returnExpr, declarationPrefixKeyword: "function" ) @@ -2431,12 +2436,8 @@ extension BridgeJSLink { let returnExpr = try thunkBuilder.call(abiName: method.abiName, returnType: method.returnType) let methodPrinter = CodeFragmentPrinter() - let parameterList = DefaultValueUtils.formatParameterList( - method.parameters, - resolveTypeName: thunkBuilder.context.defaultValueTypeName - ) methodPrinter.write( - "\(method.resolvedJSName): function(\(parameterList)) {" + "\(method.resolvedJSName): function(\(thunkBuilder.parameterList)) {" ) methodPrinter.indent { thunkBuilder.renderFunctionBody(into: methodPrinter, returnExpr: returnExpr) @@ -2486,7 +2487,7 @@ extension BridgeJSLink { returnType: .void ) - propertyPrinter.write("set \(property.resolvedJSName)(value) {") + propertyPrinter.write("set \(property.resolvedJSName)(\(setterThunkBuilder.parameterList)) {") propertyPrinter.indent { setterThunkBuilder.renderFunctionBody(into: propertyPrinter, returnExpr: nil) } @@ -2540,13 +2541,8 @@ extension BridgeJSLink { try thunkBuilder.lowerParameter(param: param) } - let constructorParamList = DefaultValueUtils.formatParameterList( - constructor.parameters, - resolveTypeName: thunkBuilder.context.defaultValueTypeName - ) - jsPrinter.indent { - jsPrinter.write("constructor(\(constructorParamList)) {") + jsPrinter.write("constructor(\(thunkBuilder.parameterList)) {") let returnExpr = thunkBuilder.callConstructor(abiName: constructor.abiName) let constructCall = "\(klass.resolvedJSName).__construct(\(returnExpr))" jsPrinter.indent { @@ -2574,7 +2570,6 @@ extension BridgeJSLink { jsPrinter.write( lines: thunkBuilder.renderFunction( name: method.resolvedJSName, - parameters: method.parameters, returnExpr: returnExpr, declarationPrefixKeyword: "static" ) @@ -2595,7 +2590,6 @@ extension BridgeJSLink { jsPrinter.write( lines: thunkBuilder.renderFunction( name: method.resolvedJSName, - parameters: method.parameters, returnExpr: returnExpr, declarationPrefixKeyword: nil ) @@ -2667,14 +2661,10 @@ extension BridgeJSLink { printer.write("class \(klass.resolvedJSName) {") printer.indent { if let constructor = klass.constructor { - let paramSignatures = constructor.parameters.map { param in - let optional = param.hasDefault ? "?" : "" - return "\(param.escapedJSIdentifier)\(optional): \(resolveTypeScriptType(param.type))" - } printer.write( lines: renderJSDoc(documentation: constructor.documentation, parameters: constructor.parameters) ) - printer.write("constructor(\(paramSignatures.joined(separator: ", ")));") + printer.write("constructor\(renderTSParameterList(constructor.parameters));") } for method in klass.methods.sorted(by: { $0.resolvedJSName < $1.resolvedJSName }) { let staticKeyword = method.effects.isStatic ? "static " : "" @@ -2720,7 +2710,6 @@ extension BridgeJSLink { jsPrinter.write( lines: getterThunkBuilder.renderFunction( name: property.resolvedJSName, - parameters: [], returnExpr: getterReturnExpr, declarationPrefixKeyword: getterKeyword ) @@ -2748,7 +2737,6 @@ extension BridgeJSLink { jsPrinter.write( lines: setterThunkBuilder.renderFunction( name: property.resolvedJSName, - parameters: [.init(label: nil, name: "value", type: property.type)], returnExpr: nil, declarationPrefixKeyword: setterKeyword ) @@ -2823,7 +2811,7 @@ extension BridgeJSLink { message: "Generic codec for '\(name)' was not declared before lifting parameter '\(param.name)'" ) } - let valueVar = scope.variable(param.name) + let valueVar = scope.variable(param.escapedJSIdentifier) let liftExpr = GenericJSCodegen.genericCodecLiftExpression(type: param.type, codec: codecVar) ?? "\(codecVar).lift()" @@ -2836,8 +2824,9 @@ extension BridgeJSLink { if liftingFragment.parameters.count == 0 { valuesToLift = [] } else if liftingFragment.parameters.count == 1 { - parameterNames.append(param.name) - valuesToLift = [scope.variable(param.name)] + let name = scope.variable(param.escapedJSIdentifier) + parameterNames.append(name) + valuesToLift = [name] } else { valuesToLift = liftingFragment.parameters.map { scope.variable(param.name + $0.capitalizedFirstLetter) } parameterNames.append(contentsOf: valuesToLift) @@ -3525,7 +3514,7 @@ extension BridgeJSLink { ) let setterPrinter = CodeFragmentPrinter() - setterPrinter.write("set \(property.resolvedJSName)(value) {") + setterPrinter.write("set \(property.resolvedJSName)(\(setterThunkBuilder.parameterList)) {") setterPrinter.indent { setterPrinter.write(contentsOf: setterThunkBuilder.body) setterPrinter.write(lines: setterThunkBuilder.checkExceptionLines()) @@ -4312,20 +4301,6 @@ enum DefaultValueUtils { .replacingOccurrences(of: "\\", with: "\\\\") .replacingOccurrences(of: "\"", with: "\\\"") } - - /// Generates a JavaScript parameter list with default values - static func formatParameterList( - _ parameters: [Parameter], - resolveTypeName: (BridgeType, OutputFormat) -> String? = { _, _ in nil } - ) -> String { - return parameters.map { param in - if let defaultValue = param.defaultValue { - let defaultJs = format(defaultValue, as: .javascript, resolveTypeName: resolveTypeName) - return "\(param.escapedJSIdentifier) = \(defaultJs)" - } - return param.escapedJSIdentifier - }.joined(separator: ", ") - } } extension BridgeJSLink { @@ -4337,7 +4312,7 @@ extension BridgeJSLink { let resolveTypeName = makeCodecPrintContext(printer: CodeFragmentPrinter()).defaultValueTypeName var tagLines: [String] = [] - for parameter in parameters { + for (parameter, name) in zip(parameters, parameters.uniqueJSIdentifiers) { let docText = parsed.parameter(named: parameter.name) let defaultValue = parameter.defaultValue.map { DefaultValueUtils.format( @@ -4348,11 +4323,11 @@ extension BridgeJSLink { } switch (docText, defaultValue) { case let (.some(text), .some(value)): - tagLines.append("@param \(parameter.escapedJSIdentifier) \(text) (default: \(value))") + tagLines.append("@param \(name) \(text) (default: \(value))") case let (.some(text), .none): - tagLines.append("@param \(parameter.escapedJSIdentifier) \(text)") + tagLines.append("@param \(name) \(text)") case let (.none, .some(value)): - tagLines.append("@param \(parameter.escapedJSIdentifier) - Optional parameter (default: \(value))") + tagLines.append("@param \(name) - Optional parameter (default: \(value))") case (.none, .none): continue } @@ -4492,6 +4467,23 @@ extension Parameter { } } +extension [Parameter] { + fileprivate var uniqueJSIdentifiers: [String] { + var names: [String] = [] + for parameter in self { + let escapedName = parameter.escapedJSIdentifier + var name = escapedName + var suffix = 1 + while names.contains(name) { + name = escapedName + suffix.description + suffix += 1 + } + names.append(name) + } + return names + } +} + extension ClosureSignature { fileprivate func renderTSFunctionType(renderType: (BridgeType) -> String) -> String { let renderedParameters = parameters.enumerated().map { index, parameter in diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index 2da07f2be..673a64212 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -2586,25 +2586,21 @@ struct IntrinsicJSFragment: Sendable { // Attach instance methods to the struct instance for method in structDef.methods where !method.effects.isStatic { - let paramList = DefaultValueUtils.formatParameterList( - method.parameters, - resolveTypeName: context.defaultValueTypeName + let builder = BridgeJSLink.ExportedThunkBuilder( + effects: method.effects, + context: context + ) + builder.body.write( + "\(JSGlueVariableScope.reservedStructHelpers).\(context.scope.helperKey(forTypeNamed: structDef.swiftCallName)).lower(this);" ) + for param in method.parameters { + try builder.lowerParameter(param: param) + } + let returnExpr = try builder.call(abiName: method.abiName, returnType: method.returnType) printer.write( - "\(instanceVar).\(method.resolvedJSName) = function(\(paramList)) {" + "\(instanceVar).\(method.resolvedJSName) = function(\(builder.parameterList)) {" ) - try printer.indent { - let builder = BridgeJSLink.ExportedThunkBuilder( - effects: method.effects, - context: context - ) - builder.body.write( - "\(JSGlueVariableScope.reservedStructHelpers).\(context.scope.helperKey(forTypeNamed: structDef.swiftCallName)).lower(this);" - ) - for param in method.parameters { - try builder.lowerParameter(param: param) - } - let returnExpr = try builder.call(abiName: method.abiName, returnType: method.returnType) + printer.indent { builder.renderFunctionBody(into: printer, returnExpr: returnExpr) } printer.write("}.bind(\(instanceVar));") diff --git a/Plugins/BridgeJS/Sources/BridgeJSMacros/JSMacroSupport.swift b/Plugins/BridgeJS/Sources/BridgeJSMacros/JSMacroSupport.swift index 224462ddb..c347bfb21 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSMacros/JSMacroSupport.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSMacros/JSMacroSupport.swift @@ -90,8 +90,9 @@ enum JSMacroHelper { static func parameterNames(_ parameters: FunctionParameterListSyntax) -> [String] { parameters.compactMap { param in let nameToken = param.secondName ?? param.firstName - let nameText = nameToken.text - return nameText == "_" ? nil : nameText + guard nameToken.text != "_" else { return nil } + let nameText = stripBackticks(nameToken.text) + return nameText.isValidSwiftIdentifier(for: .variableName) ? nameText : "`\(nameText)`" } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ReservedWordParameters.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ReservedWordParameters.swift index 2c4c062cb..d17db250d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ReservedWordParameters.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ReservedWordParameters.swift @@ -1 +1,23 @@ @JS func check(extension: Int, break: Double, function: Bool, in: String) {} +@JS func checkEscaped(_ `in`: String) {} + +@JS class ReservedWordBox { + @JS init(in: Int) {} + @JS func run(for: Int) {} + @JS static func make(default: Int) -> Int { 0 } +} + +@JS protocol ReservedWordDelegate { + func handle(in: Int, for: String, _ `default`: Bool) +} + +@JSFunction func importedCheck(in: Int, for: String, _ `default`: Bool) throws(JSException) + +@JS func checkEscapedCollision(in: Int, _in: Int) {} +@JS func checkGlueNameCollision(instance: Int, swift: String) {} + +@JS protocol BacktickedLabelDelegate { + func handle(`in`: Int) +} + +@JSFunction func importedSelfClosure(_ `self`: @escaping () -> Void) throws(JSException) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ReservedWordParameters.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ReservedWordParameters.json index c27a4eb46..380de8738 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ReservedWordParameters.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ReservedWordParameters.json @@ -4,7 +4,101 @@ ], "classes" : [ + { + "constructor" : { + "abiName" : "bjs_ReservedWordBox_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "in", + "name" : "in", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } + ] + }, + "methods" : [ + { + "abiName" : "bjs_ReservedWordBox_run", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "run", + "parameters" : [ + { + "label" : "for", + "name" : "for", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } + ], + "returnType" : { + "void" : { + } + } + }, + { + "abiName" : "bjs_ReservedWordBox_static_make", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "make", + "parameters" : [ + { + "label" : "default", + "name" : "default", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } + ], + "returnType" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + }, + "staticContext" : { + "className" : { + "_0" : "ReservedWordBox" + } + } + } + ], + "name" : "ReservedWordBox", + "properties" : [ + + ], + "swiftCallName" : "ReservedWordBox" + } ], "enums" : [ @@ -63,17 +157,301 @@ "returnType" : { "void" : { + } + } + }, + { + "abiName" : "bjs_checkEscaped", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "checkEscaped", + "parameters" : [ + { + "label" : "_", + "name" : "in", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_checkEscapedCollision", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "checkEscapedCollision", + "parameters" : [ + { + "label" : "in", + "name" : "in", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + }, + { + "label" : "_in", + "name" : "_in", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_checkGlueNameCollision", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "checkGlueNameCollision", + "parameters" : [ + { + "label" : "instance", + "name" : "instance", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + }, + { + "label" : "swift", + "name" : "swift", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "void" : { + } } } ], "protocols" : [ + { + "methods" : [ + { + "abiName" : "bjs_ReservedWordDelegate_handle", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "handle", + "parameters" : [ + { + "label" : "in", + "name" : "in", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + }, + { + "label" : "for", + "name" : "for", + "type" : { + "string" : { + + } + } + }, + { + "label" : "_", + "name" : "default", + "type" : { + "bool" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "ReservedWordDelegate", + "properties" : [ + ] + }, + { + "methods" : [ + { + "abiName" : "bjs_BacktickedLabelDelegate_handle", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "handle", + "parameters" : [ + { + "label" : "`in`", + "name" : "in", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "BacktickedLabelDelegate", + "properties" : [ + + ] + } ], "structs" : [ ] }, + "imported" : { + "children" : [ + { + "functions" : [ + { + "accessLevel" : "internal", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "importedCheck", + "parameters" : [ + { + "name" : "in", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + }, + { + "name" : "for", + "type" : { + "string" : { + + } + } + }, + { + "name" : "default", + "type" : { + "bool" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "accessLevel" : "internal", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "importedSelfClosure", + "parameters" : [ + { + "name" : "self", + "type" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModuley_y", + "moduleName" : "TestModule", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + }, + "sendingParameters" : false + }, + "useJSTypedClosure" : false + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "types" : [ + + ] + } + ] + }, "moduleName" : "TestModule", "usedExternalModules" : [ diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ReservedWordParameters.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ReservedWordParameters.swift index b09e1a76d..51b65629f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ReservedWordParameters.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ReservedWordParameters.swift @@ -1,3 +1,122 @@ +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModuley_y") +fileprivate func invoke_js_callback_TestModule_10TestModuley_y_extern(_ callback: Int32) -> Void +#else +fileprivate func invoke_js_callback_TestModule_10TestModuley_y_extern(_ callback: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuley_y(_ callback: Int32) -> Void { + return invoke_js_callback_TestModule_10TestModuley_y_extern(callback) +} + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "make_swift_closure_TestModule_10TestModuley_y") +fileprivate func make_swift_closure_TestModule_10TestModuley_y_extern(_ boxPtr: UnsafeMutableRawPointer, _ file: UnsafePointer, _ line: UInt32) -> Int32 +#else +fileprivate func make_swift_closure_TestModule_10TestModuley_y_extern(_ boxPtr: UnsafeMutableRawPointer, _ file: UnsafePointer, _ line: UInt32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func make_swift_closure_TestModule_10TestModuley_y(_ boxPtr: UnsafeMutableRawPointer, _ file: UnsafePointer, _ line: UInt32) -> Int32 { + return make_swift_closure_TestModule_10TestModuley_y_extern(boxPtr, file, line) +} + +private enum _BJS_Closure_10TestModuley_y { + static func bridgeJSLift(_ callbackId: Int32) -> () -> Void { + let callback = JSObject.bridgeJSLiftParameter(callbackId) + return { [callback] in + #if arch(wasm32) + let callbackValue = callback.bridgeJSLowerParameter() + invoke_js_callback_TestModule_10TestModuley_y(callbackValue) + #else + fatalError("Only available on WebAssembly") + #endif + } + } +} + +extension JSTypedClosure where Signature == () -> Void { + init(fileID: StaticString = #fileID, line: UInt32 = #line, _ body: @escaping () -> Void) { + self.init( + makeClosure: make_swift_closure_TestModule_10TestModuley_y, + body: body, + fileID: fileID, + line: line + ) + } +} + +@_expose(wasm, "invoke_swift_closure_TestModule_10TestModuley_y") +@_cdecl("invoke_swift_closure_TestModule_10TestModuley_y") +public func _invoke_swift_closure_TestModule_10TestModuley_y(_ boxPtr: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let closure = Unmanaged<_BridgeJSTypedClosureBox<() -> Void>>.fromOpaque(boxPtr).takeUnretainedValue().closure + closure() + #else + fatalError("Only available on WebAssembly") + #endif +} + +extension ReservedWordDelegate where Self: _BridgedSwiftProtocolWrapper { + func handle(`in`: Int, `for`: String, _ `default`: Bool) -> Void { + `for`.bridgeJSWithLoweredParameter { (forWord0, forWord1, forWord2) in + let defaultValue = `default`.bridgeJSLowerParameter() + let inValue = `in`.bridgeJSLowerParameter() + let jsObjectValue = jsObject.bridgeJSLowerParameter() + bjs_ReservedWordDelegate_handle(jsObjectValue, inValue, forWord0, forWord1, forWord2, defaultValue) + } + } +} + +struct AnyReservedWordDelegate: ReservedWordDelegate, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject + + static func bridgeJSLiftParameter(_ value: Int32) -> Self { + return AnyReservedWordDelegate(jsObject: JSObject(id: UInt32(bitPattern: value))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_ReservedWordDelegate_handle") +fileprivate func bjs_ReservedWordDelegate_handle_extern(_ jsObject: Int32, _ `in`: Int32, _ forWord0: Int32, _ forWord1: Int32, _ forWord2: Int32, _ `default`: Int32) -> Void +#else +fileprivate func bjs_ReservedWordDelegate_handle_extern(_ jsObject: Int32, _ `in`: Int32, _ forWord0: Int32, _ forWord1: Int32, _ forWord2: Int32, _ `default`: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ReservedWordDelegate_handle(_ jsObject: Int32, _ `in`: Int32, _ forWord0: Int32, _ forWord1: Int32, _ forWord2: Int32, _ `default`: Int32) -> Void { + return bjs_ReservedWordDelegate_handle_extern(jsObject, `in`, forWord0, forWord1, forWord2, `default`) +} + +extension BacktickedLabelDelegate where Self: _BridgedSwiftProtocolWrapper { + func handle(`in`: Int) -> Void { + let inValue = `in`.bridgeJSLowerParameter() + let jsObjectValue = jsObject.bridgeJSLowerParameter() + bjs_BacktickedLabelDelegate_handle(jsObjectValue, inValue) + } +} + +struct AnyBacktickedLabelDelegate: BacktickedLabelDelegate, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject + + static func bridgeJSLiftParameter(_ value: Int32) -> Self { + return AnyBacktickedLabelDelegate(jsObject: JSObject(id: UInt32(bitPattern: value))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_BacktickedLabelDelegate_handle") +fileprivate func bjs_BacktickedLabelDelegate_handle_extern(_ jsObject: Int32, _ `in`: Int32) -> Void +#else +fileprivate func bjs_BacktickedLabelDelegate_handle_extern(_ jsObject: Int32, _ `in`: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_BacktickedLabelDelegate_handle(_ jsObject: Int32, _ `in`: Int32) -> Void { + return bjs_BacktickedLabelDelegate_handle_extern(jsObject, `in`) +} + @_expose(wasm, "bjs_check") @_cdecl("bjs_check") public func _bjs_check(_ `extension`: Int32, _ `break`: Float64, _ function: Int32, _ inBytes: Int32, _ inLength: Int32) -> Void { @@ -10,4 +129,152 @@ public func _bjs_check(_ `extension`: Int32, _ `break`: Float64, _ function: Int #else fatalError("Only available on WebAssembly") #endif +} + +@_expose(wasm, "bjs_checkEscaped") +@_cdecl("bjs_checkEscaped") +public func _bjs_checkEscaped(_ inBytes: Int32, _ inLength: Int32) -> Void { + #if arch(wasm32) + let `in` = String.bridgeJSLiftParameter(inBytes, inLength) + checkEscaped(_: `in`) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_checkEscapedCollision") +@_cdecl("bjs_checkEscapedCollision") +public func _bjs_checkEscapedCollision(_ `in`: Int32, _ _in: Int32) -> Void { + #if arch(wasm32) + let _in = Int.bridgeJSLiftParameter(_in) + let `in` = Int.bridgeJSLiftParameter(`in`) + checkEscapedCollision(in: `in`, _in: _in) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_checkGlueNameCollision") +@_cdecl("bjs_checkGlueNameCollision") +public func _bjs_checkGlueNameCollision(_ instance: Int32, _ swiftBytes: Int32, _ swiftLength: Int32) -> Void { + #if arch(wasm32) + let swift = String.bridgeJSLiftParameter(swiftBytes, swiftLength) + let instance = Int.bridgeJSLiftParameter(instance) + checkGlueNameCollision(instance: instance, swift: swift) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_ReservedWordBox_init") +@_cdecl("bjs_ReservedWordBox_init") +public func _bjs_ReservedWordBox_init(_ `in`: Int32) -> UnsafeMutableRawPointer { + #if arch(wasm32) + let `in` = Int.bridgeJSLiftParameter(`in`) + let ret = ReservedWordBox(in: `in`) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_ReservedWordBox_run") +@_cdecl("bjs_ReservedWordBox_run") +public func _bjs_ReservedWordBox_run(_ _self: UnsafeMutableRawPointer, _ `for`: Int32) -> Void { + #if arch(wasm32) + let `for` = Int.bridgeJSLiftParameter(`for`) + let _self = ReservedWordBox.bridgeJSLiftParameter(_self) + _self.run(for: `for`) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_ReservedWordBox_static_make") +@_cdecl("bjs_ReservedWordBox_static_make") +public func _bjs_ReservedWordBox_static_make(_ `default`: Int32) -> Int32 { + #if arch(wasm32) + let `default` = Int.bridgeJSLiftParameter(`default`) + let ret = ReservedWordBox.make(default: `default`) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_ReservedWordBox_deinit") +@_cdecl("bjs_ReservedWordBox_deinit") +public func _bjs_ReservedWordBox_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + Unmanaged.fromOpaque(pointer).release() + #else + fatalError("Only available on WebAssembly") + #endif +} + +extension ReservedWordBox: ConvertibleToJSValue, _BridgedSwiftHeapObject, _BridgedSwiftProtocolExportable { + var jsValue: JSValue { + return .object(JSObject(id: UInt32(bitPattern: _bjs_ReservedWordBox_wrap(Unmanaged.passRetained(self).toOpaque())))) + } + consuming func bridgeJSLowerAsProtocolReturn() -> Int32 { + _bjs_ReservedWordBox_wrap(Unmanaged.passRetained(self).toOpaque()) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_ReservedWordBox_wrap") +fileprivate func _bjs_ReservedWordBox_wrap_extern(_ pointer: UnsafeMutableRawPointer) -> Int32 +#else +fileprivate func _bjs_ReservedWordBox_wrap_extern(_ pointer: UnsafeMutableRawPointer) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func _bjs_ReservedWordBox_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { + return _bjs_ReservedWordBox_wrap_extern(pointer) +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_importedCheck") +fileprivate func bjs_importedCheck_extern(_ `in`: Int32, _ forWord0: Int32, _ forWord1: Int32, _ forWord2: Int32, _ `default`: Int32) -> Void +#else +fileprivate func bjs_importedCheck_extern(_ `in`: Int32, _ forWord0: Int32, _ forWord1: Int32, _ forWord2: Int32, _ `default`: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_importedCheck(_ `in`: Int32, _ forWord0: Int32, _ forWord1: Int32, _ forWord2: Int32, _ `default`: Int32) -> Void { + return bjs_importedCheck_extern(`in`, forWord0, forWord1, forWord2, `default`) +} + +func _$importedCheck(_ `in`: Int, _ `for`: String, _ `default`: Bool) throws(JSException) -> Void { + `for`.bridgeJSWithLoweredParameter { (forWord0, forWord1, forWord2) in + let defaultValue = `default`.bridgeJSLowerParameter() + let inValue = `in`.bridgeJSLowerParameter() + bjs_importedCheck(inValue, forWord0, forWord1, forWord2, defaultValue) + } + if let error = _swift_js_take_exception() { + throw error + } +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_importedSelfClosure") +fileprivate func bjs_importedSelfClosure_extern(_ self: Int32) -> Void +#else +fileprivate func bjs_importedSelfClosure_extern(_ self: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_importedSelfClosure(_ self: Int32) -> Void { + return bjs_importedSelfClosure_extern(self) +} + +func _$importedSelfClosure(_ self: @escaping () -> Void) throws(JSException) -> Void { + let `self` = JSTypedClosure<() -> Void>(self) + let selfFuncRef = self.bridgeJSLowerParameter() + withExtendedLifetime((self)) { + bjs_importedSelfClosure(selfFuncRef) + } + if let error = _swift_js_take_exception() { + throw error + } } \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.d.ts index 027a6b9db..82dc96f71 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.d.ts @@ -4,10 +4,37 @@ // To update this file, just rebuild your project or run // `swift package bridge-js`. +export interface ReservedWordDelegate { + handle(_in: number, _for: string, _default: boolean): void; +} + +export interface BacktickedLabelDelegate { + handle(_in: number): void; +} + +/// Represents a Swift heap object like a class instance or an actor instance. +export interface SwiftHeapObject { + /// Release the heap object. + /// + /// Note: Calling this method will release the heap object and it will no longer be accessible. + release(): void; +} +export interface ReservedWordBox extends SwiftHeapObject { + run(_for: number): void; +} export type Exports = { check(extension: number, _break: number, _function: boolean, _in: string): void; + checkEscaped(_in: string): void; + checkEscapedCollision(_in: number, _in1: number): void; + checkGlueNameCollision(instance: number, swift: string): void; + ReservedWordBox: { + new(_in: number): ReservedWordBox; + make(_default: number): number; + }, } export type Imports = { + importedCheck(_in: number, _for: string, _default: boolean): void; + importedSelfClosure(self: () => void): void; } export function createInstantiator(options: { imports: Imports; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.js index 0abe5fdbf..c5e67f8ae 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.js @@ -33,6 +33,31 @@ export async function createInstantiator(options, swift) { let _exports = null; let bjs = null; + const swiftClosureRegistry = (typeof FinalizationRegistry === "undefined") ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry((state) => { + if (state.unregistered) { return; } + instance?.exports?.bjs_release_swift_closure(state.pointer); + }); + const makeClosure = (pointer, file, line, func) => { + const state = { pointer, file, line, unregistered: false }; + const real = (...args) => { + if (state.unregistered) { + const bytes = new Uint8Array(memory.buffer, state.file >>> 0); + let length = 0; + while (bytes[length] !== 0) { length += 1; } + const fileID = decodeUTF8(state.file, length); + throw new Error(`Attempted to call a released JSTypedClosure created at ${fileID}:${state.line}`); + } + return func(...args); + }; + real.__unregister = () => { + if (state.unregistered) { return; } + state.unregistered = true; + swiftClosureRegistry.unregister(state); + }; + swiftClosureRegistry.register(real, state, state); + return swift.memory.retain(real); + }; + return { /** @@ -41,6 +66,7 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; + const imports = options.getImports(importsContext); bjs["swift_js_return_string"] = function(word0, word1, word2) { tmpRetString = decodeString(word0, word1, word2); } @@ -206,6 +232,69 @@ export async function createInstantiator(options, swift) { return pointer || 0; } bjs["swift_js_closure_unregister"] = function(funcRef) {} + bjs["swift_js_closure_unregister"] = function(funcRef) { + const func = swift.memory.getObject(funcRef); + func.__unregister(); + } + bjs["invoke_js_callback_TestModule_10TestModuley_y"] = function(callbackId) { + try { + const callback = swift.memory.getObject(callbackId); + callback(); + } catch (error) { + setException(error); + } + } + bjs["make_swift_closure_TestModule_10TestModuley_y"] = function(boxPtr, file, line) { + const lower_closure_TestModule_10TestModuley_y = function() { + instance.exports.invoke_swift_closure_TestModule_10TestModuley_y(boxPtr); + if (tmpRetException) { + const error = swift.memory.getObject(tmpRetException); + swift.memory.release(tmpRetException); + tmpRetException = undefined; + throw error; + } + }; + return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuley_y); + } + // Wrapper functions for module: TestModule + if (!importObject["TestModule"]) { + importObject["TestModule"] = {}; + } + importObject["TestModule"]["bjs_ReservedWordBox_wrap"] = function(pointer) { + const obj = _exports['ReservedWordBox'].__construct(pointer); + return swift.memory.retain(obj); + }; + const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; + TestModule["bjs_importedCheck"] = function bjs_importedCheck(_in, forWord0, forWord1, forWord2, _default) { + try { + const string = decodeString(forWord0, forWord1, forWord2); + imports.importedCheck(_in, string, _default !== 0); + } catch (error) { + setException(error); + } + } + TestModule["bjs_importedSelfClosure"] = function bjs_importedSelfClosure(self) { + try { + imports.importedSelfClosure(swift.memory.getObject(self)); + } catch (error) { + setException(error); + } + } + TestModule["bjs_ReservedWordDelegate_handle"] = function bjs_ReservedWordDelegate_handle(self, _in, forWord0, forWord1, forWord2, _default) { + try { + const string = decodeString(forWord0, forWord1, forWord2); + swift.memory.getObject(self).handle(_in, string, _default !== 0); + } catch (error) { + setException(error); + } + } + TestModule["bjs_BacktickedLabelDelegate_handle"] = function bjs_BacktickedLabelDelegate_handle(self, _in) { + try { + swift.memory.getObject(self).handle(_in); + } catch (error) { + setException(error); + } + } }, setInstance: (i) => { if (memory !== i.exports.memory) immortalStrings.clear(); @@ -368,12 +457,95 @@ export async function createInstantiator(options, swift) { /** @param {WebAssembly.Instance} instance */ createExports: (instance) => { const js = swift.memory.heap; + const swiftHeapObjectFinalizationRegistry = (typeof FinalizationRegistry === "undefined") ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry((state) => { + if (state.hasReleased) { + return; + } + state.hasReleased = true; + state.identityMap?.delete(state.pointer); + state.deinit(state.pointer); + }); + + /// Represents a Swift heap object like a class instance or an actor instance. + class SwiftHeapObject { + static __wrap(pointer, deinit, prototype, identityCache) { + pointer = pointer >>> 0; + const makeFresh = (identityMap) => { + const obj = Object.create(prototype); + const state = { pointer, deinit, hasReleased: false, identityMap }; + obj.pointer = pointer; + obj.__swiftHeapObjectState = state; + swiftHeapObjectFinalizationRegistry.register(obj, state, state); + if (identityMap) { + identityMap.set(pointer, new WeakRef(obj)); + } + return obj; + }; + + if (!identityCache) { + return makeFresh(null); + } + + const cached = identityCache.get(pointer)?.deref(); + if (cached && !cached.__swiftHeapObjectState.hasReleased) { + deinit(pointer); + return cached; + } + if (identityCache.has(pointer)) { + identityCache.delete(pointer); + } + + return makeFresh(identityCache); + } + + release() { + const state = this.__swiftHeapObjectState; + if (state.hasReleased) { + return; + } + state.hasReleased = true; + swiftHeapObjectFinalizationRegistry.unregister(state); + state.identityMap?.delete(state.pointer); + state.deinit(state.pointer); + } + } + class ReservedWordBox extends SwiftHeapObject { + static __construct(ptr) { + return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_ReservedWordBox_deinit, ReservedWordBox.prototype, null); + } + + constructor(_in) { + const ret = instance.exports.bjs_ReservedWordBox_init(_in); + return ReservedWordBox.__construct(ret); + } + run(_for) { + instance.exports.bjs_ReservedWordBox_run(this.pointer, _for); + } + static make(_default) { + const ret = instance.exports.bjs_ReservedWordBox_static_make(_default); + return ret; + } + } const exports = { check: function bjs_check(extension, _break, _function, _in) { const _inBytes = textEncoder.encode(_in); const _inId = swift.memory.retain(_inBytes); instance.exports.bjs_check(extension, _break, _function, _inId, _inBytes.length); }, + checkEscaped: function bjs_checkEscaped(_in) { + const _inBytes = textEncoder.encode(_in); + const _inId = swift.memory.retain(_inBytes); + instance.exports.bjs_checkEscaped(_inId, _inBytes.length); + }, + checkEscapedCollision: function bjs_checkEscapedCollision(_in, _in1) { + instance.exports.bjs_checkEscapedCollision(_in, _in1); + }, + checkGlueNameCollision: function bjs_checkGlueNameCollision(instance1, swift1) { + const swift1Bytes = textEncoder.encode(swift1); + const swift1Id = swift.memory.retain(swift1Bytes); + instance.exports.bjs_checkGlueNameCollision(instance1, swift1Id, swift1Bytes.length); + }, + ReservedWordBox, }; _exports = exports; return exports; diff --git a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift index 9e5892a87..1429bb0fb 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -25,6 +25,18 @@ func runJsWorks() -> Void @JS func describeReservedWordParameters(extension: Int, break: Double, function: Bool, in: String) -> String { return "\(`extension`):\(`break`):\(function):\(`in`)" } +@JS func describeBacktickedParameter(_ `in`: String) -> String { + return `in` +} +@JS func describeCollidingParameters(in: Int, _in: Int, instance: Int, swift: String) -> String { + return "\(`in`):\(_in):\(instance):\(swift)" +} +@JS protocol ReservedWordDescriber { + func describe(in: Int, for: String) -> String +} +@JS func describeWithReservedWordDescriber(_ describer: any ReservedWordDescriber) -> String { + return describer.describe(in: 1, for: "for") +} @JS func roundTripSwiftHeapObject(v: Greeter) -> Greeter { return v } diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index 884ecb8e1..f2c868c84 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -4294,6 +4294,39 @@ fileprivate func bjs_ArrayElementProtocol_value_set_extern(_ jsObject: Int32, _ return bjs_ArrayElementProtocol_value_set_extern(jsObject, newValue) } +extension ReservedWordDescriber where Self: _BridgedSwiftProtocolWrapper { + func describe(`in`: Int, `for`: String) -> String { + let ret0 = `for`.bridgeJSWithLoweredParameter { (forWord0, forWord1, forWord2) in + let inValue = `in`.bridgeJSLowerParameter() + let jsObjectValue = jsObject.bridgeJSLowerParameter() + let ret = bjs_ReservedWordDescriber_describe(jsObjectValue, inValue, forWord0, forWord1, forWord2) + return ret + } + let ret = ret0 + return String.bridgeJSLiftReturn(ret) + } +} + +struct AnyReservedWordDescriber: ReservedWordDescriber, _BridgedSwiftProtocolWrapper { + let jsObject: JSObject + + static func bridgeJSLiftParameter(_ value: Int32) -> Self { + return AnyReservedWordDescriber(jsObject: JSObject(id: UInt32(bitPattern: value))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ReservedWordDescriber_describe") +fileprivate func bjs_ReservedWordDescriber_describe_extern(_ jsObject: Int32, _ `in`: Int32, _ forWord0: Int32, _ forWord1: Int32, _ forWord2: Int32) -> Int32 +#else +fileprivate func bjs_ReservedWordDescriber_describe_extern(_ jsObject: Int32, _ `in`: Int32, _ forWord0: Int32, _ forWord1: Int32, _ forWord2: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ReservedWordDescriber_describe(_ jsObject: Int32, _ `in`: Int32, _ forWord0: Int32, _ forWord1: Int32, _ forWord2: Int32) -> Int32 { + return bjs_ReservedWordDescriber_describe_extern(jsObject, `in`, forWord0, forWord1, forWord2) +} + extension DataProcessor where Self: _BridgedSwiftProtocolWrapper { func increment(by amount: Int) -> Void { let amountValue = amount.bridgeJSLowerParameter() @@ -10339,6 +10372,45 @@ public func _bjs_describeReservedWordParameters(_ `extension`: Int32, _ `break`: #endif } +@_expose(wasm, "bjs_describeBacktickedParameter") +@_cdecl("bjs_describeBacktickedParameter") +public func _bjs_describeBacktickedParameter(_ inBytes: Int32, _ inLength: Int32) -> Void { + #if arch(wasm32) + let `in` = String.bridgeJSLiftParameter(inBytes, inLength) + let ret = describeBacktickedParameter(_: `in`) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_describeCollidingParameters") +@_cdecl("bjs_describeCollidingParameters") +public func _bjs_describeCollidingParameters(_ `in`: Int32, _ _in: Int32, _ instance: Int32, _ swiftBytes: Int32, _ swiftLength: Int32) -> Void { + #if arch(wasm32) + let swift = String.bridgeJSLiftParameter(swiftBytes, swiftLength) + let instance = Int.bridgeJSLiftParameter(instance) + let _in = Int.bridgeJSLiftParameter(_in) + let `in` = Int.bridgeJSLiftParameter(`in`) + let ret = describeCollidingParameters(in: `in`, _in: _in, instance: instance, swift: swift) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_describeWithReservedWordDescriber") +@_cdecl("bjs_describeWithReservedWordDescriber") +public func _bjs_describeWithReservedWordDescriber(_ describer: Int32) -> Void { + #if arch(wasm32) + let describer = AnyReservedWordDescriber.bridgeJSLiftParameter(describer) + let ret = describeWithReservedWordDescriber(_: describer) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + @_expose(wasm, "bjs_roundTripSwiftHeapObject") @_cdecl("bjs_roundTripSwiftHeapObject") public func _bjs_roundTripSwiftHeapObject(_ v: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { @@ -19975,6 +20047,32 @@ func _$jsJoinStringThenStackParams(_ s: String, _ a: Optional<[Int]>, _ b: [Int] return String.bridgeJSLiftReturn(ret) } +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsDescribeReservedWordParameters") +fileprivate func bjs_jsDescribeReservedWordParameters_extern(_ `in`: Int32, _ forWord0: Int32, _ forWord1: Int32, _ forWord2: Int32, _ `default`: Int32) -> Int32 +#else +fileprivate func bjs_jsDescribeReservedWordParameters_extern(_ `in`: Int32, _ forWord0: Int32, _ forWord1: Int32, _ forWord2: Int32, _ `default`: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_jsDescribeReservedWordParameters(_ `in`: Int32, _ forWord0: Int32, _ forWord1: Int32, _ forWord2: Int32, _ `default`: Int32) -> Int32 { + return bjs_jsDescribeReservedWordParameters_extern(`in`, forWord0, forWord1, forWord2, `default`) +} + +func _$jsDescribeReservedWordParameters(_ `in`: Int, _ `for`: String, _ `default`: Bool) throws(JSException) -> String { + let ret0 = `for`.bridgeJSWithLoweredParameter { (forWord0, forWord1, forWord2) in + let defaultValue = `default`.bridgeJSLowerParameter() + let inValue = `in`.bridgeJSLowerParameter() + let ret = bjs_jsDescribeReservedWordParameters(inValue, forWord0, forWord1, forWord2, defaultValue) + return ret + } + let ret = ret0 + if let error = _swift_js_take_exception() { + throw error + } + return String.bridgeJSLiftReturn(ret) +} + #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsGenericRoundTrip") fileprivate func bjs_jsGenericRoundTrip_extern(_ _generic0TypeId: Int32) -> Void diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index 8598361b6..265fcf9cb 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -15269,6 +15269,117 @@ } } }, + { + "abiName" : "bjs_describeBacktickedParameter", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "describeBacktickedParameter", + "parameters" : [ + { + "label" : "_", + "name" : "in", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_describeCollidingParameters", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "describeCollidingParameters", + "parameters" : [ + { + "label" : "in", + "name" : "in", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + }, + { + "label" : "_in", + "name" : "_in", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + }, + { + "label" : "instance", + "name" : "instance", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + }, + { + "label" : "swift", + "name" : "swift", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_describeWithReservedWordDescriber", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "describeWithReservedWordDescriber", + "parameters" : [ + { + "label" : "_", + "name" : "describer", + "type" : { + "swiftProtocol" : { + "_0" : "ReservedWordDescriber" + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, { "abiName" : "bjs_roundTripSwiftHeapObject", "effects" : { @@ -19314,6 +19425,51 @@ } ] }, + { + "methods" : [ + { + "abiName" : "bjs_ReservedWordDescriber_describe", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "describe", + "parameters" : [ + { + "label" : "in", + "name" : "in", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + }, + { + "label" : "for", + "name" : "for", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "ReservedWordDescriber", + "properties" : [ + + ] + }, { "methods" : [ { @@ -26306,6 +26462,49 @@ "returnType" : { "string" : { + } + } + }, + { + "accessLevel" : "internal", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "jsDescribeReservedWordParameters", + "parameters" : [ + { + "name" : "in", + "type" : { + "integer" : { + "_0" : { + "isSigned" : true, + "width" : "word" + } + } + } + }, + { + "name" : "for", + "type" : { + "string" : { + + } + } + }, + { + "name" : "default", + "type" : { + "bool" : { + + } + } + } + ], + "returnType" : { + "string" : { + } } } diff --git a/Tests/BridgeJSRuntimeTests/ImportAPITests.swift b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift index c98ab3e61..b3e921672 100644 --- a/Tests/BridgeJSRuntimeTests/ImportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift @@ -31,6 +31,12 @@ import JavaScriptKit _ b: [Int] ) throws(JSException) -> String +@JSFunction func jsDescribeReservedWordParameters( + in: Int, + for: String, + _ `default`: Bool +) throws(JSException) -> String + class ImportAPITests: XCTestCase { func testRoundTripVoid() throws { try jsRoundTripVoid() @@ -211,4 +217,8 @@ class ImportAPITests: XCTestCase { #""s"|[1,2]|[7,8,9]"# ) } + + func testReservedWordParameters() throws { + XCTAssertEqual(try jsDescribeReservedWordParameters(in: 1, for: "for", true), "1:for:true") + } } diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index 15631bcbe..17b48679c 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -164,6 +164,7 @@ export async function setupOptions(options, context) { jsJoinOptionalStructThenArray: joinStackParams, jsJoinEnumThenArray: joinStackParams, jsJoinStringThenStackParams: joinStackParams, + jsDescribeReservedWordParameters: (a, b, c) => `${a}:${b}:${c}`, jsGenericRoundTrip: (v) => v, jsGenericRoundTripClass: (v) => v, jsGenericParsePoint: (json) => JSON.parse(json), @@ -306,6 +307,12 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { assert.equal(exports.roundTripString(v), v); } assert.equal(exports.describeReservedWordParameters(1, 2.5, true, "in"), "1:2.5:true:in"); + assert.equal(exports.describeBacktickedParameter("in"), "in"); + assert.equal(exports.describeCollidingParameters(1, 2, 3, "swift"), "1:2:3:swift"); + assert.equal( + exports.describeWithReservedWordDescriber({ describe: (a, b) => `${a}:${b}` }), + "1:for" + ); const dict = { a: 1, b: 2 }; assert.deepEqual(exports.roundTripDictionaryExport(dict), dict); const optDict = { hello: "world" }; From c332a3bef097ce585ce61f360ef47b0ab3059e5b Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Wed, 28 Oct 2026 20:28:41 +1000 Subject: [PATCH 11/18] JavaScriptEventLoop: Avoid O(N^2) job queue insert for bursts of jobs --- Sources/JavaScriptEventLoop/JobQueue.swift | 38 +++++-- .../JavaScriptEventLoopTests.swift | 107 ++++++++++++++++++ ...avaScriptEventLoopYieldIntervalTests.swift | 27 +++++ 3 files changed, 163 insertions(+), 9 deletions(-) diff --git a/Sources/JavaScriptEventLoop/JobQueue.swift b/Sources/JavaScriptEventLoop/JobQueue.swift index 0dcbcdc17..8ca74e1c8 100644 --- a/Sources/JavaScriptEventLoop/JobQueue.swift +++ b/Sources/JavaScriptEventLoop/JobQueue.swift @@ -1,6 +1,6 @@ // This file contains the job queue implementation which re-order jobs based on their priority. -// The current implementation is much simple to be easily debugged, but should be re-implemented -// using priority queue ideally. +// Jobs form runs, one per priority in descending order, FIFO within a run. The first job of each +// run points to its last job, so an insert steps over whole runs. import _Concurrency import _CJavaScriptEventLoop @@ -19,15 +19,18 @@ extension JavaScriptEventLoop { func insertJobQueue(job newJob: UnownedJob) { withUnsafeMutablePointer(to: &queueState.headJob) { headJobPtr in var position: UnsafeMutablePointer = headJobPtr - while let cur = position.pointee { - if cur.rawPriority < newJob.rawPriority { - newJob.nextInQueue().pointee = cur - position.pointee = newJob + while let runHead = position.pointee, runHead.rawPriority >= newJob.rawPriority { + let runTail = runHead.lastInRun().pointee! + if runHead.rawPriority == newJob.rawPriority { + newJob.nextInQueue().pointee = runTail.nextInQueue().pointee + runTail.nextInQueue().pointee = newJob + runHead.lastInRun().pointee = newJob return } - position = cur.nextInQueue() + position = runTail.nextInQueue() } - newJob.nextInQueue().pointee = nil + newJob.nextInQueue().pointee = position.pointee + newJob.lastInRun().pointee = newJob position.pointee = newJob } @@ -81,7 +84,14 @@ extension JavaScriptEventLoop { func claimNextFromQueue() -> UnownedJob? { if let job = self.queueState.headJob { - self.queueState.headJob = job.nextInQueue().pointee + let nextJob = job.nextInQueue().pointee + if let nextJob { + let runTail = job.lastInRun().pointee! + if !runTail.isSameJob(as: job) { + nextJob.lastInRun().pointee = runTail + } + } + self.queueState.headJob = nextJob return job } return nil @@ -107,6 +117,16 @@ extension UnownedJob { } } + /// The last job of the run. Valid only on the first job of a run. + fileprivate func lastInRun() -> UnsafeMutablePointer { + return withUnsafeMutablePointer(to: &asImpl().pointee.SchedulerPrivate.1) { rawLastJobPtr in + UnsafeMutableRawPointer(rawLastJobPtr).bindMemory(to: UnownedJob?.self, capacity: 1) + } + } + + fileprivate func isSameJob(as other: UnownedJob) -> Bool { + asImpl() == other.asImpl() + } } private struct JobFlags { diff --git a/Tests/JavaScriptEventLoopTests/JavaScriptEventLoopTests.swift b/Tests/JavaScriptEventLoopTests/JavaScriptEventLoopTests.swift index 8fbbd817f..7fbb712a7 100644 --- a/Tests/JavaScriptEventLoopTests/JavaScriptEventLoopTests.swift +++ b/Tests/JavaScriptEventLoopTests/JavaScriptEventLoopTests.swift @@ -113,6 +113,113 @@ final class JavaScriptEventLoopTests: XCTestCase { XCTAssertEqual(context.completed, ["t4", "t3", "t5"]) } + final class OrderContext: @unchecked Sendable { + var completed: [String] = [] + var expectedCount = 0 + var continuation: CheckedContinuation? + + func record(_ name: String) { + completed.append(name) + if completed.count == expectedCount { + continuation?.resume() + continuation = nil + } + } + } + + /// Starts tasks without awaiting them, so no await raises the priority of a queued task. + func runUnawaited(expectedCount: Int, _ start: (OrderContext) -> Void) async -> [String] { + let context = OrderContext() + context.expectedCount = expectedCount + await withCheckedContinuation { continuation in + context.continuation = continuation + start(context) + } + return context.completed + } + + func testTaskPriorityOrderWithMixedPriorities() async throws { + let burst: [(String, TaskPriority)] = [ + ("low1", .low), ("medium1", .medium), ("low2", .low), ("high1", .high), + ("medium2", .medium), ("low3", .low), ("high2", .high), ("medium3", .medium), + ] + let burstOrder = await runUnawaited(expectedCount: burst.count) { context in + for (name, priority) in burst { + Task(priority: priority) { context.record(name) } + } + } + XCTAssertEqual(burstOrder, ["high1", "high2", "medium1", "medium2", "medium3", "low1", "low2", "low3"]) + + let nestedOrder = await runUnawaited(expectedCount: 7) { context in + Task(priority: .medium) { + context.record("outer") + let nested: [(String, TaskPriority)] = [ + ("nestedLow1", .low), ("nestedHigh", .high), ("nestedMedium", .medium), ("nestedLow2", .low), + ] + for (name, priority) in nested { + Task(priority: priority) { context.record(name) } + } + } + Task(priority: .medium) { context.record("medium") } + Task(priority: .low) { context.record("low") } + } + XCTAssertEqual( + nestedOrder, + ["outer", "nestedHigh", "medium", "nestedMedium", "low", "nestedLow1", "nestedLow2"] + ) + + let priorities: [TaskPriority] = [ + .low, .high, .background, .medium, TaskPriority(rawValue: 22), TaskPriority(rawValue: 5), + ] + let many = (0..<600).map { index in ("\(index)", priorities[index % priorities.count]) } + let manyOrder = await runUnawaited(expectedCount: many.count) { context in + for (name, priority) in many { + Task(priority: priority) { context.record(name) } + } + } + let expectedManyOrder = many.enumerated() + .sorted { lhs, rhs in + lhs.element.1.rawValue != rhs.element.1.rawValue + ? lhs.element.1.rawValue > rhs.element.1.rawValue + : lhs.offset < rhs.offset + } + .map(\.element.0) + XCTAssertEqual(manyOrder, expectedManyOrder) + } + + func testTaskPriorityOrderAfterQueueEmpties() async throws { + let rounds: [[(String, TaskPriority)]] = [ + [("low1", .low), ("low2", .low), ("high1", .high), ("low3", .low)], + [("high1", .high), ("medium1", .medium), ("high2", .high), ("low1", .low)], + [("medium1", .medium), ("medium2", .medium), ("medium3", .medium)], + ] + let expectedOrders = [ + ["high1", "low1", "low2", "low3"], + ["high1", "high2", "medium1", "low1"], + ["medium1", "medium2", "medium3"], + ] + for (round, expectedOrder) in zip(rounds, expectedOrders) { + let order = await runUnawaited(expectedCount: round.count) { context in + for (name, priority) in round { + Task(priority: priority) { context.record(name) } + } + } + XCTAssertEqual(order, expectedOrder) + } + } + + func testTaskPriorityOrderAfterSingleJobRunIsClaimed() async throws { + let order = await runUnawaited(expectedCount: 4) { context in + Task(priority: .low) { context.record("low1") } + Task(priority: .low) { context.record("low2") } + Task(priority: .high) { + context.record("high") + Task(priority: .low) { context.record("low3") } + } + } + XCTAssertEqual(order, ["high", "low1", "low2", "low3"]) + } + // MARK: - Promise Tests func testPromiseResolution() async throws { diff --git a/Tests/JavaScriptEventLoopTests/JavaScriptEventLoopYieldIntervalTests.swift b/Tests/JavaScriptEventLoopTests/JavaScriptEventLoopYieldIntervalTests.swift index 4269b89b2..a18c162ce 100644 --- a/Tests/JavaScriptEventLoopTests/JavaScriptEventLoopYieldIntervalTests.swift +++ b/Tests/JavaScriptEventLoopTests/JavaScriptEventLoopYieldIntervalTests.swift @@ -76,4 +76,31 @@ final class JavaScriptEventLoopYieldIntervalTests: XCTestCase { for task in tasks { await task.value } XCTAssertEqual(order.value, Array(0..<20)) } + + func testPriorityOrderAcrossYields() async { + JavaScriptEventLoop.shared.yieldInterval = .milliseconds(1) + let order = Box([String]()) + let expectedOrder = ["h0", "h1", "h2", "h3", "h4", "m0", "m1", "m2", "m3", "l0", "l1", "l2", "l3", "l4"] + // Tasks are not awaited, so no await raises the priority of a queued task. + await withCheckedContinuation { (continuation: CheckedContinuation) in + @Sendable func record(_ name: String) { + Self.busyWait(milliseconds: 1) + order.value.append(name) + if order.value.count == expectedOrder.count { continuation.resume() } + } + let priorities: [(String, TaskPriority)] = [("l", .low), ("m", .medium), ("h", .high)] + for index in 0..<12 { + let (prefix, priority) = priorities[index % 3] + let name = "\(prefix)\(index / 3)" + Task(priority: priority) { + record(name) + if name == "h0" { + Task(priority: .low) { record("l4") } + Task(priority: .high) { record("h4") } + } + } + } + } + XCTAssertEqual(order.value, expectedOrder) + } } From 835ee61f8879b50165badf721cefb04e4dcf5121 Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Tue, 3 Nov 2026 01:41:20 +0100 Subject: [PATCH 12/18] BridgeJS: Check thrown errors before lifting return values --- .../Sources/BridgeJSLink/BridgeJSLink.swift | 9 ++- .../Inputs/MacroSwift/Protocol.swift | 5 ++ .../BridgeJSCodegenTests/Protocol.json | 17 +++++ .../BridgeJSCodegenTests/Protocol.swift | 26 ++++++++ .../__Snapshots__/BridgeJSLinkTests/Async.js | 8 +-- .../ImportedTypeInExportedInterface.js | 4 +- .../BridgeJSLinkTests/Protocol.d.ts | 1 + .../BridgeJSLinkTests/Protocol.js | 12 ++++ .../BridgeJSLinkTests/ProtocolInClosure.js | 16 ++--- .../BridgeJSLinkTests/SwiftClosure.js | 64 +++++++++---------- .../BridgeJSLinkTests/SwiftClosureImports.js | 4 +- .../BridgeJSRuntimeTests/ExportAPITests.swift | 6 ++ .../Generated/BridgeJS.swift | 50 +++++++++++++++ .../Generated/JavaScript/BridgeJS.json | 34 ++++++++++ Tests/prelude.mjs | 3 + 15 files changed, 206 insertions(+), 53 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 686f8d1e0..d882aad1c 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -1809,6 +1809,7 @@ public struct BridgeJSLink { body.write("const \(returnVariable) = \(call);") fragmentArguments = [returnVariable] } + body.write(lines: checkExceptionLines()) let liftedValues = try liftingFragment.printCode(fragmentArguments, context) assert(liftedValues.count <= 1, "Lifting fragment should produce at most one value") return liftedValues.first @@ -1818,10 +1819,11 @@ public struct BridgeJSLink { let call = "\(JSGlueVariableScope.reservedInstance).exports.\(abiName)(\(parameterForwardings.joined(separator: ", ")))" body.write("const ret = \(call);") + body.write(lines: checkExceptionLines()) return "ret" } - func checkExceptionLines() -> [String] { + private func checkExceptionLines() -> [String] { guard effects.isThrows else { return [] } @@ -1837,10 +1839,9 @@ public struct BridgeJSLink { ] } - /// Renders the thunk body (body code, exception handling, and optional return) into a printer. + /// Renders the thunk body and optional return; `call`/`callConstructor` put the exception check in `body`. func renderFunctionBody(into printer: CodeFragmentPrinter, returnExpr: String?) { printer.write(contentsOf: body) - printer.write(lines: checkExceptionLines()) if let returnExpr = returnExpr { printer.write("return \(returnExpr);") } @@ -3490,7 +3491,6 @@ extension BridgeJSLink { getterPrinter.write("get \(property.resolvedJSName)() {") getterPrinter.indent { getterPrinter.write(contentsOf: getterThunkBuilder.body) - getterPrinter.write(lines: getterThunkBuilder.checkExceptionLines()) if let returnExpr = getterReturnExpr { getterPrinter.write("return \(returnExpr);") } @@ -3517,7 +3517,6 @@ extension BridgeJSLink { setterPrinter.write("set \(property.resolvedJSName)(\(setterThunkBuilder.parameterList)) {") setterPrinter.indent { setterPrinter.write(contentsOf: setterThunkBuilder.body) - setterPrinter.write(lines: setterThunkBuilder.checkExceptionLines()) } setterPrinter.write("},") diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift index 106f30761..670cb29fc 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift @@ -107,6 +107,11 @@ import JavaScriptKit @JS func loadLabel(_ key: String) async throws(JSException) -> String { return try await delegate.loadLabel(key) } + + @JS func validatedDelegate() throws(JSException) -> MyViewControllerDelegate { + _ = try delegate.validate(0) + return delegate + } } // Protocol array support diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json index 4fbec6b49..40aa34cdf 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json @@ -286,6 +286,23 @@ } } + }, + { + "abiName" : "bjs_MyViewController_validatedDelegate", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "validatedDelegate", + "parameters" : [ + + ], + "returnType" : { + "swiftProtocol" : { + "_0" : "MyViewControllerDelegate" + } + } } ], "name" : "MyViewController", diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift index 3c4ba2a78..2f75db462 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift @@ -1257,6 +1257,32 @@ public func _bjs_MyViewController_loadLabel(_ _self: UnsafeMutableRawPointer, _ #endif } +@_expose(wasm, "bjs_MyViewController_validatedDelegate") +@_cdecl("bjs_MyViewController_validatedDelegate") +public func _bjs_MyViewController_validatedDelegate(_ _self: UnsafeMutableRawPointer) -> Int32 { + #if arch(wasm32) + let _self = MyViewController.bridgeJSLiftParameter(_self) + do { + let ret = _bridgeJSUnwrapProtocolExportable(try _self.validatedDelegate(), "MyViewControllerDelegate") + return ret.bridgeJSLowerAsProtocolReturn() + } catch let error { + if let error = error.thrownValue.object { + withExtendedLifetime(error) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } else { + let jsError = JSError(message: error.description) + withExtendedLifetime(jsError.jsObject) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } + return 0 + } + #else + fatalError("Only available on WebAssembly") + #endif +} + @_expose(wasm, "bjs_MyViewController_delegate_get") @_cdecl("bjs_MyViewController_delegate_get") public func _bjs_MyViewController_delegate_get(_ _self: UnsafeMutableRawPointer) -> Int32 { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js index 33c4ff195..6cc51f282 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js @@ -944,26 +944,26 @@ export async function createInstantiator(options, swift) { asyncRoundTripStructThrows: function bjs_asyncRoundTripStructThrows(v) { structHelpers.M10TestModuleT10AsyncPoint.lower(v); const ret = instance.exports.bjs_asyncRoundTripStructThrows(); - const ret1 = swift.memory.getObject(ret); - swift.memory.release(ret); if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const ret1 = swift.memory.getObject(ret); + swift.memory.release(ret); return ret1; }, asyncThrowsZeroArg: function bjs_asyncThrowsZeroArg() { const ret = instance.exports.bjs_asyncThrowsZeroArg(); - const ret1 = swift.memory.getObject(ret); - swift.memory.release(ret); if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const ret1 = swift.memory.getObject(ret); + swift.memory.release(ret); return ret1; }, asyncCombineStructs: function bjs_asyncCombineStructs(a, b) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js index 4bfce3e14..2f45f8eed 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js @@ -755,14 +755,14 @@ export async function createInstantiator(options, swift) { const exports = { makeFoo: function bjs_makeFoo() { const ret = instance.exports.bjs_makeFoo(); - const ret1 = swift.memory.getObject(ret); - swift.memory.release(ret); if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const ret1 = swift.memory.getObject(ret); + swift.memory.release(ret); return ret1; }, processFooArray: function bjs_processFooArray(foos) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.d.ts index e9b099f70..4259fb347 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.d.ts @@ -93,6 +93,7 @@ export interface MyViewController extends SwiftHeapObject { sendHelper(helper: Helper): void; validateValue(value: number): number; loadLabel(key: string): Promise; + validatedDelegate(): MyViewControllerDelegate; delegate: MyViewControllerDelegate; secondDelegate: MyViewControllerDelegate | null; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js index f07007c79..8802e8786 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js @@ -1363,14 +1363,26 @@ export async function createInstantiator(options, swift) { const keyBytes = textEncoder.encode(key); const keyId = swift.memory.retain(keyBytes); const ret = instance.exports.bjs_MyViewController_loadLabel(this.pointer, keyId, keyBytes.length); + if (tmpRetException) { + const error = swift.memory.getObject(tmpRetException); + swift.memory.release(tmpRetException); + tmpRetException = undefined; + throw error; + } const ret1 = swift.memory.getObject(ret); swift.memory.release(ret); + return ret1; + } + validatedDelegate() { + const ret = instance.exports.bjs_MyViewController_validatedDelegate(this.pointer); if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const ret1 = swift.memory.getObject(ret); + swift.memory.release(ret); return ret1; } get delegate() { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js index d6fa6f143..a9730573c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js @@ -248,14 +248,14 @@ export async function createInstantiator(options, swift) { bjs["make_swift_closure_TestModule_10TestModule10RenderableP_10RenderableP"] = function(boxPtr, file, line) { const lower_closure_TestModule_10TestModule10RenderableP_10RenderableP = function(param0) { const ret = instance.exports.invoke_swift_closure_TestModule_10TestModule10RenderableP_10RenderableP(boxPtr, swift.memory.retain(param0)); - const ret1 = swift.memory.getObject(ret); - swift.memory.release(ret); if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const ret1 = swift.memory.getObject(ret); + swift.memory.release(ret); return ret1; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModule10RenderableP_10RenderableP); @@ -273,14 +273,14 @@ export async function createInstantiator(options, swift) { bjs["make_swift_closure_TestModule_10TestModule10RenderableP_SS"] = function(boxPtr, file, line) { const lower_closure_TestModule_10TestModule10RenderableP_SS = function(param0) { instance.exports.invoke_swift_closure_TestModule_10TestModule10RenderableP_SS(boxPtr, swift.memory.retain(param0)); - const ret = tmpRetString; - tmpRetString = undefined; if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const ret = tmpRetString; + tmpRetString = undefined; return ret; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModule10RenderableP_SS); @@ -305,14 +305,14 @@ export async function createInstantiator(options, swift) { result = 0; } instance.exports.invoke_swift_closure_TestModule_10TestModuleSq10RenderableP_SS(boxPtr, +isSome, result); - const ret = tmpRetString; - tmpRetString = undefined; if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const ret = tmpRetString; + tmpRetString = undefined; return ret; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSq10RenderableP_SS); @@ -330,14 +330,14 @@ export async function createInstantiator(options, swift) { bjs["make_swift_closure_TestModule_10TestModuley_10RenderableP"] = function(boxPtr, file, line) { const lower_closure_TestModule_10TestModuley_10RenderableP = function() { const ret = instance.exports.invoke_swift_closure_TestModule_10TestModuley_10RenderableP(boxPtr); - const ret1 = swift.memory.getObject(ret); - swift.memory.release(ret); if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const ret1 = swift.memory.getObject(ret); + swift.memory.release(ret); return ret1; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuley_10RenderableP); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js index f56929d7c..3f4ab6e05 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js @@ -751,14 +751,14 @@ export async function createInstantiator(options, swift) { const param0Bytes = textEncoder.encode(param0); const param0Id = swift.memory.retain(param0Bytes); instance.exports.invoke_swift_closure_TestModule_10TestModule5ThemeO_5ThemeO(boxPtr, param0Id, param0Bytes.length); - const ret = tmpRetString; - tmpRetString = undefined; if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const ret = tmpRetString; + tmpRetString = undefined; return ret; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModule5ThemeO_5ThemeO); @@ -777,13 +777,13 @@ export async function createInstantiator(options, swift) { const lower_closure_TestModule_10TestModule6AnimalV_6AnimalV = function(param0) { structHelpers.M10TestModuleT6Animal.lower(param0); instance.exports.invoke_swift_closure_TestModule_10TestModule6AnimalV_6AnimalV(boxPtr); - const structValue = structHelpers.M10TestModuleT6Animal.lift(); if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const structValue = structHelpers.M10TestModuleT6Animal.lift(); return structValue; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModule6AnimalV_6AnimalV); @@ -826,13 +826,13 @@ export async function createInstantiator(options, swift) { const lower_closure_TestModule_10TestModule9APIResultO_9APIResultO = function(param0) { const param0CaseId = enumHelpers.M10TestModuleT9APIResult.lower(param0); instance.exports.invoke_swift_closure_TestModule_10TestModule9APIResultO_9APIResultO(boxPtr, param0CaseId); - const ret = enumHelpers.M10TestModuleT9APIResult.lift(i32Stack.pop()); if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const ret = enumHelpers.M10TestModuleT9APIResult.lift(i32Stack.pop()); return ret; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModule9APIResultO_9APIResultO); @@ -928,14 +928,14 @@ export async function createInstantiator(options, swift) { const param0Bytes = textEncoder.encode(param0); const param0Id = swift.memory.retain(param0Bytes); instance.exports.invoke_swift_closure_TestModule_10TestModuleSS_SS(boxPtr, param0Id, param0Bytes.length); - const ret = tmpRetString; - tmpRetString = undefined; if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const ret = tmpRetString; + tmpRetString = undefined; return ret; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSS_SS); @@ -1046,14 +1046,14 @@ export async function createInstantiator(options, swift) { const lower_closure_TestModule_10TestModuleSq10HttpStatusO_Sq10HttpStatusO = function(param0) { const isSome = param0 != null; instance.exports.invoke_swift_closure_TestModule_10TestModuleSq10HttpStatusO_Sq10HttpStatusO(boxPtr, +isSome, isSome ? param0 : 0); - const optResult = tmpRetOptionalInt; - tmpRetOptionalInt = undefined; if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const optResult = tmpRetOptionalInt; + tmpRetOptionalInt = undefined; return optResult; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSq10HttpStatusO_Sq10HttpStatusO); @@ -1089,14 +1089,14 @@ export async function createInstantiator(options, swift) { result1 = 0; } instance.exports.invoke_swift_closure_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO(boxPtr, +isSome, result, result1); - const optResult = tmpRetString; - tmpRetString = undefined; if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const optResult = tmpRetString; + tmpRetString = undefined; return optResult; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO); @@ -1115,13 +1115,13 @@ export async function createInstantiator(options, swift) { const lower_closure_TestModule_10TestModuleSq6AnimalV_Sq6AnimalV = function(param0) { __bjs_codec_Optional_M10TestModuleT6Animal.lower(param0); instance.exports.invoke_swift_closure_TestModule_10TestModuleSq6AnimalV_Sq6AnimalV(boxPtr); - const optValue = __bjs_codec_Optional_M10TestModuleT6Animal.lift(); if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const optValue = __bjs_codec_Optional_M10TestModuleT6Animal.lift(); return optValue; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSq6AnimalV_Sq6AnimalV); @@ -1146,15 +1146,15 @@ export async function createInstantiator(options, swift) { result = 0; } instance.exports.invoke_swift_closure_TestModule_10TestModuleSq6PersonC_Sq6PersonC(boxPtr, +isSome, result); - const pointer = tmpRetOptionalHeapObject; - tmpRetOptionalHeapObject = undefined; - const optResult = pointer === null ? null : _exports['Person'].__construct(pointer); if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const pointer = tmpRetOptionalHeapObject; + tmpRetOptionalHeapObject = undefined; + const optResult = pointer === null ? null : _exports['Person'].__construct(pointer); return optResult; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSq6PersonC_Sq6PersonC); @@ -1192,14 +1192,14 @@ export async function createInstantiator(options, swift) { result = 0; } instance.exports.invoke_swift_closure_TestModule_10TestModuleSq9APIResultO_Sq9APIResultO(boxPtr, +isSome, result); - const tag = i32Stack.pop(); - const optResult = tag === -1 ? null : enumHelpers.M10TestModuleT9APIResult.lift(tag); if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const tag = i32Stack.pop(); + const optResult = tag === -1 ? null : enumHelpers.M10TestModuleT9APIResult.lift(tag); return optResult; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSq9APIResultO_Sq9APIResultO); @@ -1218,14 +1218,14 @@ export async function createInstantiator(options, swift) { const lower_closure_TestModule_10TestModuleSq9DirectionO_Sq9DirectionO = function(param0) { const isSome = param0 != null; instance.exports.invoke_swift_closure_TestModule_10TestModuleSq9DirectionO_Sq9DirectionO(boxPtr, +isSome, isSome ? param0 : 0); - const optResult = tmpRetOptionalInt; - tmpRetOptionalInt = undefined; if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const optResult = tmpRetOptionalInt; + tmpRetOptionalInt = undefined; return optResult; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSq9DirectionO_Sq9DirectionO); @@ -1261,14 +1261,14 @@ export async function createInstantiator(options, swift) { result1 = 0; } instance.exports.invoke_swift_closure_TestModule_10TestModuleSqSS_SqSS(boxPtr, +isSome, result, result1); - const optResult = tmpRetString; - tmpRetString = undefined; if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const optResult = tmpRetString; + tmpRetString = undefined; return optResult; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSqSS_SqSS); @@ -1287,14 +1287,14 @@ export async function createInstantiator(options, swift) { const lower_closure_TestModule_10TestModuleSqSb_SqSb = function(param0) { const isSome = param0 != null; instance.exports.invoke_swift_closure_TestModule_10TestModuleSqSb_SqSb(boxPtr, +isSome, isSome ? param0 ? 1 : 0 : 0); - const optResult = tmpRetOptionalBool; - tmpRetOptionalBool = undefined; if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const optResult = tmpRetOptionalBool; + tmpRetOptionalBool = undefined; return optResult; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSqSb_SqSb); @@ -1313,14 +1313,14 @@ export async function createInstantiator(options, swift) { const lower_closure_TestModule_10TestModuleSqSd_SqSd = function(param0) { const isSome = param0 != null; instance.exports.invoke_swift_closure_TestModule_10TestModuleSqSd_SqSd(boxPtr, +isSome, isSome ? param0 : 0.0); - const optResult = tmpRetOptionalDouble; - tmpRetOptionalDouble = undefined; if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const optResult = tmpRetOptionalDouble; + tmpRetOptionalDouble = undefined; return optResult; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSqSd_SqSd); @@ -1339,14 +1339,14 @@ export async function createInstantiator(options, swift) { const lower_closure_TestModule_10TestModuleSqSf_SqSf = function(param0) { const isSome = param0 != null; instance.exports.invoke_swift_closure_TestModule_10TestModuleSqSf_SqSf(boxPtr, +isSome, isSome ? param0 : 0.0); - const optResult = tmpRetOptionalFloat; - tmpRetOptionalFloat = undefined; if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const optResult = tmpRetOptionalFloat; + tmpRetOptionalFloat = undefined; return optResult; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSqSf_SqSf); @@ -1365,14 +1365,14 @@ export async function createInstantiator(options, swift) { const lower_closure_TestModule_10TestModuleSqSi_SqSi = function(param0) { const isSome = param0 != null; instance.exports.invoke_swift_closure_TestModule_10TestModuleSqSi_SqSi(boxPtr, +isSome, isSome ? param0 : 0); - const optResult = tmpRetOptionalInt; - tmpRetOptionalInt = undefined; if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const optResult = tmpRetOptionalInt; + tmpRetOptionalInt = undefined; return optResult; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSqSi_SqSi); @@ -1393,14 +1393,14 @@ export async function createInstantiator(options, swift) { const param0Bytes = textEncoder.encode(param0); const param0Id = swift.memory.retain(param0Bytes); const ret = instance.exports.invoke_swift_closure_TestModule_10TestModuleYaKSS_SS(boxPtr, param0Id, param0Bytes.length); - const ret1 = swift.memory.getObject(ret); - swift.memory.release(ret); if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const ret1 = swift.memory.getObject(ret); + swift.memory.release(ret); return ret1; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleYaKSS_SS); @@ -1418,14 +1418,14 @@ export async function createInstantiator(options, swift) { bjs["make_swift_closure_TestModule_10TestModuleYaKSb_9APIResultO"] = function(boxPtr, file, line) { const lower_closure_TestModule_10TestModuleYaKSb_9APIResultO = function(param0) { const ret = instance.exports.invoke_swift_closure_TestModule_10TestModuleYaKSb_9APIResultO(boxPtr, param0); - const ret1 = swift.memory.getObject(ret); - swift.memory.release(ret); if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const ret1 = swift.memory.getObject(ret); + swift.memory.release(ret); return ret1; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleYaKSb_9APIResultO); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js index 3ba6f5c0f..b15678998 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js @@ -406,14 +406,14 @@ export async function createInstantiator(options, swift) { const param0Bytes = textEncoder.encode(param0); const param0Id = swift.memory.retain(param0Bytes); const ret = instance.exports.invoke_swift_closure_TestModule_10TestModuleYaKSS_SS(boxPtr, param0Id, param0Bytes.length); - const ret1 = swift.memory.getObject(ret); - swift.memory.release(ret); if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); tmpRetException = undefined; throw error; } + const ret1 = swift.memory.getObject(ret); + swift.memory.release(ret); return ret1; }; return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleYaKSS_SS); diff --git a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift index 1429bb0fb..55ab78e7a 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -110,6 +110,12 @@ struct TestError: Error { @JS func throwsWithDoubleResult() throws(JSException) -> Double { return 1.0 } @JS func throwsWithSwiftHeapObjectResult() throws(JSException) -> Greeter { return Greeter(name: "Test") } @JS func throwsWithJSObjectResult() throws(JSException) -> JSObject { return JSObject() } +@JS func throwsBeforeJSObjectResult() throws(JSException) -> JSObject { + throw JSException(JSError(message: "JSObjectResultError").jsValue) +} +@JS func throwsBeforeProtocolResult() throws(JSException) -> DataProcessor { + throw JSException(JSError(message: "ProtocolResultError").jsValue) +} @JS func zeroArgAsyncThrows() async throws(JSException) -> String { throw JSException(JSError(message: "ZeroArgAsyncThrowsError").jsValue) diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index f2c868c84..3b82a15d5 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -10793,6 +10793,56 @@ public func _bjs_throwsWithJSObjectResult() -> Int32 { #endif } +@_expose(wasm, "bjs_throwsBeforeJSObjectResult") +@_cdecl("bjs_throwsBeforeJSObjectResult") +public func _bjs_throwsBeforeJSObjectResult() -> Int32 { + #if arch(wasm32) + do { + let ret = try throwsBeforeJSObjectResult() + return ret.bridgeJSLowerReturn() + } catch let error { + if let error = error.thrownValue.object { + withExtendedLifetime(error) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } else { + let jsError = JSError(message: error.description) + withExtendedLifetime(jsError.jsObject) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } + return 0 + } + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_throwsBeforeProtocolResult") +@_cdecl("bjs_throwsBeforeProtocolResult") +public func _bjs_throwsBeforeProtocolResult() -> Int32 { + #if arch(wasm32) + do { + let ret = _bridgeJSUnwrapProtocolExportable(try throwsBeforeProtocolResult(), "DataProcessor") + return ret.bridgeJSLowerAsProtocolReturn() + } catch let error { + if let error = error.thrownValue.object { + withExtendedLifetime(error) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } else { + let jsError = JSError(message: error.description) + withExtendedLifetime(jsError.jsObject) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } + return 0 + } + #else + fatalError("Only available on WebAssembly") + #endif +} + @_expose(wasm, "bjs_zeroArgAsyncThrows") @_cdecl("bjs_zeroArgAsyncThrows") public func _bjs_zeroArgAsyncThrows() -> Int32 { diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index 265fcf9cb..c4fd1d602 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -15971,6 +15971,40 @@ } } }, + { + "abiName" : "bjs_throwsBeforeJSObjectResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "throwsBeforeJSObjectResult", + "parameters" : [ + + ], + "returnType" : { + "jsObject" : { + + } + } + }, + { + "abiName" : "bjs_throwsBeforeProtocolResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "throwsBeforeProtocolResult", + "parameters" : [ + + ], + "returnType" : { + "swiftProtocol" : { + "_0" : "DataProcessor" + } + } + }, { "abiName" : "bjs_zeroArgAsyncThrows", "effects" : { diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index 17b48679c..e1d856647 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -629,6 +629,9 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { assert.fail("Expected no error"); } + assert.throws(() => exports.throwsBeforeJSObjectResult(), { name: "Error", message: "JSObjectResultError" }); + assert.throws(() => exports.throwsBeforeProtocolResult(), { name: "Error", message: "ProtocolResultError" }); + // Test enums assert.equal(exports.Direction.North, 0); assert.equal(exports.Direction.South, 1); From 99bfd1e8fec8a2f4b14aa724046a48eb41979116 Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Tue, 3 Nov 2026 06:59:32 +0100 Subject: [PATCH 13/18] CI: Run example builds on ubuntu-22.04 --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a9e90c175..7f4f6c87e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -163,7 +163,7 @@ jobs: # which collapses the wall-clock time from ~1h to that of the slowest single example. build-examples: if: github.event_name == 'pull_request' - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: @@ -196,7 +196,7 @@ jobs: # main: build all examples in release and publish them to GitHub Pages. build-examples-deploy: if: github.event_name == 'push' && github.ref == 'refs/heads/main' - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v7 - uses: ./.github/actions/install-swift From b8003b8e945656e951b2174f317de1adc66f7555 Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Tue, 3 Nov 2026 02:23:30 +0100 Subject: [PATCH 14/18] BridgeJS: Diagnose async and throwing @JS struct initializers --- .../Sources/BridgeJSCore/SwiftToSkeleton.swift | 8 ++++++++ .../BridgeJSToolTests/DiagnosticsTests.swift | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index ef39000b1..7e075a8af 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -1986,6 +1986,14 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { guard let effects = collectEffects(signature: node.signature) else { return .skipChildren } + if effects.isAsync || effects.isThrows { + diagnose( + node: node, + message: "@JS struct initializer cannot be async or throw", + hint: "BridgeJS calls this initializer to rebuild struct values passed from JavaScript" + ) + return .skipChildren + } let structAbiName = exportedStructByName[structKey]?.abiName ?? "unknown" let constructor = ExportedConstructor( diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/DiagnosticsTests.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/DiagnosticsTests.swift index 580360bb7..aadf04f00 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/DiagnosticsTests.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/DiagnosticsTests.swift @@ -535,6 +535,21 @@ import Testing #expect(skeleton.exported != nil) } + @Test + func throwingStructInitProducesDiagnostic() throws { + let source = """ + @JS struct Point { + var x: Double + + @JS init(x: Double) throws(JSException) { + self.x = x + } + } + """ + let diagnostics = try #require(moduleDiagnostics(source: source)) + #expect(diagnostics.description.contains("@JS struct initializer cannot be async or throw")) + } + @Test func structWithoutExplicitInitSucceeds() throws { let source = """ From f1d5c94c4239d0fd9e398eb3ed19db98a2c629ae Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Tue, 3 Nov 2026 02:21:18 +0100 Subject: [PATCH 15/18] BridgeJS: Fix JSValue reference ownership across the bridge --- .../Sources/BridgeJSLink/JSGlueGen.swift | 124 +++++++++--------- .../__Snapshots__/BridgeJSLinkTests/Alias.js | 9 +- .../BridgeJSLinkTests/ArrayTypes.js | 9 +- .../__Snapshots__/BridgeJSLinkTests/Async.js | 9 +- .../AsyncAssociatedValueEnum.js | 7 + .../BridgeJSLinkTests/AsyncImport.js | 7 + .../BridgeJSLinkTests/AsyncStaticImport.js | 7 + .../BridgeJSLinkTests/DefaultParameters.js | 9 +- .../BridgeJSLinkTests/DictionaryTypes.js | 9 +- .../BridgeJSLinkTests/EnumAssociatedValue.js | 9 +- .../BridgeJSLinkTests/EnumRawType.js | 9 +- .../BridgeJSLinkTests/GenericImports.js | 9 +- .../BridgeJSLinkTests/ImportArray.js | 9 +- .../ImportedTypeInExportedInterface.js | 9 +- .../BridgeJSLinkTests/JSValue.js | 21 ++- .../BridgeJSLinkTests/Namespaces.Global.js | 9 +- .../BridgeJSLinkTests/Namespaces.js | 9 +- .../BridgeJSLinkTests/Optionals.js | 9 +- .../BridgeJSLinkTests/Protocol.js | 9 +- .../BridgeJSLinkTests/SwiftClosure.js | 9 +- .../BridgeJSLinkTests/SwiftClosureImports.js | 7 + .../BridgeJSLinkTests/SwiftStruct.js | 9 +- .../BridgeJSLinkTests/SwiftStructImports.js | 9 +- .../JavaScriptKit/BridgeJSIntrinsics.swift | 18 +-- .../BridgeJSRuntimeTests/ExportAPITests.swift | 8 ++ .../Generated/BridgeJS.swift | 22 ++++ .../Generated/JavaScript/BridgeJS.json | 34 +++++ Tests/prelude.mjs | 17 ++- 28 files changed, 330 insertions(+), 95 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index 673a64212..20f231dc8 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -749,6 +749,27 @@ struct IntrinsicJSFragment: Sendable { private static let jsValueLowerHelperName = "__bjs_jsValueLower" private static let jsValueLiftHelperName = "__bjs_jsValueLift" + private static let jsValueTakeHelperName = "__bjs_jsValueTake" + + /// Mirrors `JavaScriptValueKind` in `_CJavaScriptKit.h`. + private enum JSValueKind: Int, CaseIterable { + case boolean = 0 + case string = 1 + case number = 2 + case object = 3 + case null = 4 + case undefined = 5 + case symbol = 7 + case bigInt = 8 + + /// Whether `payload1` is a reference in `swift.memory`. + var holdsReference: Bool { + switch self { + case .string, .object, .symbol, .bigInt: return true + case .boolean, .number, .null, .undefined: return false + } + } + } private static func registerJSValueHelpers(scope: JSGlueVariableScope) { scope.registerIntrinsic("jsValueHelpers") { helperPrinter in @@ -777,6 +798,20 @@ struct IntrinsicJSFragment: Sendable { helperPrinter.write("return \(resultVar);") } helperPrinter.write("}") + helperPrinter.write("function \(jsValueTakeHelperName)(kind, payload1, payload2) {") + helperPrinter.indent { + helperPrinter.write("const value = \(jsValueLiftHelperName)(kind, payload1, payload2);") + let holdsReference = JSValueKind.allCases.filter(\.holdsReference) + .map { "kind === \($0.rawValue)" } + .joined(separator: " || ") + helperPrinter.write("if (\(holdsReference)) {") + helperPrinter.indent { + helperPrinter.write("\(JSGlueVariableScope.reservedSwift).memory.release(payload1);") + } + helperPrinter.write("}") + helperPrinter.write("return value;") + } + helperPrinter.write("}") } } @@ -792,7 +827,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("let \(payload2Var);") printer.write("if (\(value) === null) {") printer.indent { - printer.write("\(kindVar) = 4;") + printer.write("\(kindVar) = \(JSValueKind.null.rawValue);") printer.write("\(payload1Var) = 0;") printer.write("\(payload2Var) = 0;") } @@ -802,22 +837,22 @@ struct IntrinsicJSFragment: Sendable { printer.indent { printer.write("case \"boolean\":") printer.indent { - printer.write("\(kindVar) = 0;") + printer.write("\(kindVar) = \(JSValueKind.boolean.rawValue);") printer.write("\(payload1Var) = \(value) ? 1 : 0;") printer.write("\(payload2Var) = 0;") printer.write("break;") } printer.write("case \"number\":") printer.indent { - printer.write("\(kindVar) = 2;") + printer.write("\(kindVar) = \(JSValueKind.number.rawValue);") printer.write("\(payload1Var) = 0;") printer.write("\(payload2Var) = \(value);") printer.write("break;") } - func emitRetainCase(_ caseName: String, kind: Int) { + func emitRetainCase(_ caseName: String, kind: JSValueKind) { printer.write("case \"\(caseName)\":") printer.indent { - printer.write("\(kindVar) = \(kind);") + printer.write("\(kindVar) = \(kind.rawValue);") printer.write( "\(payload1Var) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(value));" ) @@ -825,18 +860,18 @@ struct IntrinsicJSFragment: Sendable { printer.write("break;") } } - emitRetainCase("string", kind: 1) + emitRetainCase("string", kind: .string) printer.write("case \"undefined\":") printer.indent { - printer.write("\(kindVar) = 5;") + printer.write("\(kindVar) = \(JSValueKind.undefined.rawValue);") printer.write("\(payload1Var) = 0;") printer.write("\(payload2Var) = 0;") printer.write("break;") } - emitRetainCase("object", kind: 3) - emitRetainCase("function", kind: 3) - emitRetainCase("symbol", kind: 7) - emitRetainCase("bigint", kind: 8) + emitRetainCase("object", kind: .object) + emitRetainCase("function", kind: .object) + emitRetainCase("symbol", kind: .symbol) + emitRetainCase("bigint", kind: .bigInt) printer.write("default:") printer.indent { printer.write("throw new TypeError(\"Unsupported JSValue type\");") @@ -874,53 +909,21 @@ struct IntrinsicJSFragment: Sendable { printer.write("let \(resultVar);") printer.write("switch (\(kind)) {") printer.indent { - printer.write("case 0:") - printer.indent { - printer.write("\(resultVar) = \(payload1) !== 0;") - printer.write("break;") - } - printer.write("case 1:") - printer.indent { - printer.write( - "\(resultVar) = \(JSGlueVariableScope.reservedSwift).memory.getObject(\(payload1));" - ) - printer.write("break;") - } - printer.write("case 2:") - printer.indent { - printer.write("\(resultVar) = \(payload2);") - printer.write("break;") - } - printer.write("case 3:") - printer.indent { - printer.write( - "\(resultVar) = \(JSGlueVariableScope.reservedSwift).memory.getObject(\(payload1));" - ) - printer.write("break;") - } - printer.write("case 4:") - printer.indent { - printer.write("\(resultVar) = null;") - printer.write("break;") - } - printer.write("case 5:") - printer.indent { - printer.write("\(resultVar) = undefined;") - printer.write("break;") - } - printer.write("case 7:") - printer.indent { - printer.write( - "\(resultVar) = \(JSGlueVariableScope.reservedSwift).memory.getObject(\(payload1));" - ) - printer.write("break;") - } - printer.write("case 8:") - printer.indent { - printer.write( - "\(resultVar) = \(JSGlueVariableScope.reservedSwift).memory.getObject(\(payload1));" - ) - printer.write("break;") + for valueKind in JSValueKind.allCases { + let value: String + switch valueKind { + case .boolean: value = "\(payload1) !== 0" + case .number: value = payload2 + case .null: value = "null" + case .undefined: value = "undefined" + case .string, .object, .symbol, .bigInt: + value = "\(JSGlueVariableScope.reservedSwift).memory.getObject(\(payload1))" + } + printer.write("case \(valueKind.rawValue):") + printer.indent { + printer.write("\(resultVar) = \(value);") + printer.write("break;") + } } printer.write("default:") printer.indent { @@ -961,11 +964,12 @@ struct IntrinsicJSFragment: Sendable { let resultVar = scope.variable("jsValue") registerJSValueHelpers(scope: scope) printer.write( - "const \(resultVar) = \(jsValueLiftHelperName)(\(kind), \(payload1), \(payload2));" + "const \(resultVar) = \(jsValueTakeHelperName)(\(kind), \(payload1), \(payload2));" ) return [resultVar] } ) + /// Swift lends the payload reference for the duration of the call, so it is not released here. static let jsValueLiftParameter = IntrinsicJSFragment( parameters: ["kind", "payload1", "payload2"], printCode: { arguments, context in @@ -2232,7 +2236,7 @@ struct IntrinsicJSFragment: Sendable { let resultVar = scope.variable("jsValue") registerJSValueHelpers(scope: scope) printer.write( - "const \(resultVar) = \(jsValueLiftHelperName)(\(kindVar), \(payload1Var), \(payload2Var));" + "const \(resultVar) = \(jsValueTakeHelperName)(\(kindVar), \(payload1Var), \(payload2Var));" ) return [resultVar] } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js index b434d4e5e..adc2e0fc9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js @@ -267,7 +267,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -361,6 +361,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_codec_M10TestModuleT16PolygonReference = { lower: (v) => { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js index f4c519fe9..6365fd99e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js @@ -274,7 +274,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -368,6 +368,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_codec_Array_Int = __bjs_arrayCodec(__bjs_primitiveCodecs.Int); const __bjs_codec_Array_String = __bjs_arrayCodec(__bjs_stringCodec); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js index 6cc51f282..980dd9fdc 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js @@ -271,7 +271,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -365,6 +365,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_codec_M10TestModuleT10AsyncPoint = { lower: (v) => { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncAssociatedValueEnum.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncAssociatedValueEnum.js index 099a0756e..69f17eae3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncAssociatedValueEnum.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncAssociatedValueEnum.js @@ -128,6 +128,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_createEnumHelpers_M10TestModuleT18AsyncPayloadResult = () => ({ lower: (value) => { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js index 856c42435..db15b92a8 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js @@ -121,6 +121,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const swiftClosureRegistry = (typeof FinalizationRegistry === "undefined") ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry((state) => { if (state.unregistered) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js index 36d839ed9..f6da4e275 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js @@ -121,6 +121,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const swiftClosureRegistry = (typeof FinalizationRegistry === "undefined") ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry((state) => { if (state.unregistered) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js index 03afa8031..cbca91ea2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js @@ -267,7 +267,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -361,6 +361,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_codec_M10TestModuleT6Config = { lower: (v) => { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js index 10f84209a..ab6cf6ebe 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js @@ -261,7 +261,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -355,6 +355,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_codec_Dict_Int = __bjs_dictCodec(__bjs_primitiveCodecs.Int); const __bjs_codec_Dict_String = __bjs_dictCodec(__bjs_stringCodec); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js index 3f0c005f2..36d219f64 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js @@ -342,7 +342,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -436,6 +436,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_codec_Optional_String = __bjs_optionalCodec(__bjs_stringCodec); const __bjs_codec_Optional_Bool = __bjs_optionalCodec(__bjs_primitiveCodecs.Bool); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js index ce8d4ed42..e33778458 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js @@ -336,7 +336,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -430,6 +430,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_codec_M10TestModuleT8FileSize = { lower: (v) => { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js index 49aaa5798..d6250c200 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js @@ -295,7 +295,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -389,6 +389,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_codec_Array_Int = __bjs_arrayCodec(__bjs_primitiveCodecs.Int); const __bjs_codec_Optional_Array_Int = __bjs_optionalCodec(__bjs_codec_Array_Int); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js index a3e0fd6d3..2a64c6775 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js @@ -261,7 +261,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -355,6 +355,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_codec_Array_Int = __bjs_arrayCodec(__bjs_primitiveCodecs.Int); const __bjs_codec_Array_String = __bjs_arrayCodec(__bjs_stringCodec); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js index 2f45f8eed..3c4743ee6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js @@ -261,7 +261,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -355,6 +355,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_codec_Foo = { lower: (v) => { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js index 07d7ba167..afccabed4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js @@ -261,7 +261,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -355,6 +355,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_codec_Array_JSValue = __bjs_arrayCodec(__bjs_primitiveCodecs.JSValue); const __bjs_codec_Optional_Array_JSValue = __bjs_optionalCodec(__bjs_codec_Array_JSValue); @@ -821,7 +828,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; } echoOptional(value) { @@ -844,7 +851,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); optResult = jsValue; } else { optResult = null; @@ -856,7 +863,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; } set value(value) { @@ -871,7 +878,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); optResult = jsValue; } else { optResult = null; @@ -901,7 +908,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, roundTripOptionalJSValue: function bjs_roundTripOptionalJSValue(value) { @@ -924,7 +931,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); optResult = jsValue; } else { optResult = null; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js index a5f6d34f4..e76f92d8f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js @@ -261,7 +261,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -355,6 +355,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_codec_M10TestModuleT7Greeter = { lower: (v) => { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js index b13010601..31e413e1f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js @@ -261,7 +261,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -355,6 +355,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_codec_M10TestModuleT7Greeter = { lower: (v) => { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js index fb8018c44..7aaa5296c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js @@ -261,7 +261,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -355,6 +355,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_codec_JSObject = { lower: (v) => { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js index 8802e8786..945759fb1 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js @@ -285,7 +285,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -379,6 +379,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const swiftClosureRegistry = (typeof FinalizationRegistry === "undefined") ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry((state) => { if (state.unregistered) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js index 3f4ab6e05..082a42323 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js @@ -291,7 +291,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -385,6 +385,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const swiftClosureRegistry = (typeof FinalizationRegistry === "undefined") ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry((state) => { if (state.unregistered) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js index b15678998..3045dd8cb 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js @@ -121,6 +121,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const swiftClosureRegistry = (typeof FinalizationRegistry === "undefined") ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry((state) => { if (state.unregistered) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js index 54aa63d69..39ba60207 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js @@ -266,7 +266,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -360,6 +360,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_codec_Optional_Int = __bjs_optionalCodec(__bjs_primitiveCodecs.Int); const __bjs_codec_Optional_Bool = __bjs_optionalCodec(__bjs_primitiveCodecs.Bool); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js index 2ebef1501..0f0838b41 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js @@ -261,7 +261,7 @@ export async function createInstantiator(options, swift) { const jsValuePayload2 = f64Stack.pop(); const jsValuePayload1 = i32Stack.pop(); const jsValueKind = i32Stack.pop(); - const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + const jsValue = __bjs_jsValueTake(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, }, @@ -355,6 +355,13 @@ export async function createInstantiator(options, swift) { } return jsValue; } + function __bjs_jsValueTake(kind, payload1, payload2) { + const value = __bjs_jsValueLift(kind, payload1, payload2); + if (kind === 1 || kind === 3 || kind === 7 || kind === 8) { + swift.memory.release(payload1); + } + return value; + } const __bjs_codec_M10TestModuleT5Point = { lower: (v) => { diff --git a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift index dd5e1e970..0b7fc3120 100644 --- a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift +++ b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift @@ -969,11 +969,14 @@ extension JSValue: _BridgedSwiftStackType { } @_spi(BridgeJS) public consuming func bridgeJSStackPush() -> Void { - let lowered = bridgeJSLowerParameter() - let retainedPayload1 = Self.bridgeJSRetainPayloadIfNeeded(kind: lowered.kind, payload1: lowered.payload1) - _swift_js_push_i32(lowered.kind) - _swift_js_push_i32(retainedPayload1) - _swift_js_push_f64(lowered.payload2) + // Retain inside `withRawJSValue` so `self` still owns the JS reference. + withRawJSValue { raw in + let kind = Int32(raw.kind.rawValue) + let payload1 = Int32(bitPattern: raw.payload1) + _swift_js_push_i32(kind) + _swift_js_push_i32(Self.bridgeJSRetainPayloadIfNeeded(kind: kind, payload1: payload1)) + _swift_js_push_f64(raw.payload2) + } } @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> (kind: Int32, payload1: Int32, payload2: Double) { @@ -986,19 +989,18 @@ extension JSValue: _BridgedSwiftStackType { } } + /// Takes ownership of the payload reference that JavaScript retained when it lowered the value. @_spi(BridgeJS) public static func bridgeJSLiftParameter( _ kind: Int32, _ payload1: Int32, _ payload2: Double ) -> JSValue { - let retainedPayload1 = bridgeJSRetainPayloadIfNeeded(kind: kind, payload1: payload1) - guard let kindEnum = JavaScriptValueKind(rawValue: UInt32(kind)) else { fatalError("Invalid JSValue kind: \(kind)") } let rawValue = RawJSValue( kind: kindEnum, - payload1: JavaScriptPayload1(UInt32(bitPattern: retainedPayload1)), + payload1: JavaScriptPayload1(UInt32(bitPattern: payload1)), payload2: payload2 ) return rawValue.jsValue diff --git a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift index 55ab78e7a..a3e60711f 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -73,6 +73,14 @@ func runJsWorks() -> Void return v } +@JS func makeJSValueString() -> JSValue { + return .string("makeJSValueString") +} + +@JS func makeJSValueObject() -> JSValue { + return .object(JSObject()) +} + @JS func roundTripOptionalJSValue(v: JSValue?) -> JSValue? { return v } diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index 3b82a15d5..8bfe460fc 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -10531,6 +10531,28 @@ public func _bjs_roundTripJSValue(_ vKind: Int32, _ vPayload1: Int32, _ vPayload #endif } +@_expose(wasm, "bjs_makeJSValueString") +@_cdecl("bjs_makeJSValueString") +public func _bjs_makeJSValueString() -> Void { + #if arch(wasm32) + let ret = makeJSValueString() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_makeJSValueObject") +@_cdecl("bjs_makeJSValueObject") +public func _bjs_makeJSValueObject() -> Void { + #if arch(wasm32) + let ret = makeJSValueObject() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + @_expose(wasm, "bjs_roundTripOptionalJSValue") @_cdecl("bjs_roundTripOptionalJSValue") public func _bjs_roundTripOptionalJSValue(_ vIsSome: Int32, _ vKind: Int32, _ vPayload1: Int32, _ vPayload2: Float64) -> Void { diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index c4fd1d602..fb4d924e7 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -15686,6 +15686,40 @@ } } }, + { + "abiName" : "bjs_makeJSValueString", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "makeJSValueString", + "parameters" : [ + + ], + "returnType" : { + "jsValue" : { + + } + } + }, + { + "abiName" : "bjs_makeJSValueObject", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "makeJSValueObject", + "parameters" : [ + + ], + "returnType" : { + "jsValue" : { + + } + } + }, { "abiName" : "bjs_roundTripOptionalJSValue", "effects" : { diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index e1d856647..6c53eb59f 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -227,7 +227,7 @@ export async function setupOptions(options, context) { }; }, addToCoreImports(importObject, importsContext) { - const { getInstance, getExports } = importsContext; + const { getInstance, getExports, _swift } = importsContext; options.addToCoreImports?.(importObject, importsContext); importObject["JavaScriptEventLoopTestSupportTests"] = { "isMainThread": () => context.isMainThread, @@ -238,7 +238,7 @@ export async function setupOptions(options, context) { if (!exports) { throw new Error("No exports!?"); } - return BridgeJSRuntimeTests_runJsWorks(getInstance(), exports); + return BridgeJSRuntimeTests_runJsWorks(getInstance(), exports, _swift); } bridgeJSRuntimeTests["runJsStructWorks"] = () => { const exports = getExports(); @@ -267,7 +267,7 @@ export async function setupOptions(options, context) { import assert from "node:assert"; /** @param {import('./../.build/plugins/PackageToJS/outputs/PackageTests/bridge-js.d.ts').Exports} exports */ -function BridgeJSRuntimeTests_runJsWorks(instance, exports) { +function BridgeJSRuntimeTests_runJsWorks(instance, exports, swift) { exports.roundTripVoid(); for (const v of [ 0.0, 1.0, -1.0, @@ -610,6 +610,17 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { const result = exports.roundTripJSValue(value); assert.strictEqual(result, value); } + assert.strictEqual(exports.makeJSValueString(), "makeJSValueString"); + const madeObject = exports.makeJSValueObject(); + assert.deepStrictEqual(madeObject, {}); + + const isRetained = (value) => swift.memory._slotByValue.has(value); + assert.equal(isRetained(madeObject), false); + for (const value of [{}, "roundTripJSValue-ownership", Symbol("ownership"), 0xfedcba9876543210n]) { + assert.strictEqual(exports.roundTripJSValue(value), value); + assert.deepStrictEqual(exports.roundTripOptionalJSValueArray([value]), [value]); + assert.equal(isRetained(value), false); + } assert.strictEqual(exports.roundTripOptionalJSValue(null), null); assert.strictEqual(exports.roundTripOptionalJSValue(undefined), null); From 817304f59df3b75873a565982d80e48a7b9b4179 Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Wed, 4 Nov 2026 01:13:26 +1000 Subject: [PATCH 16/18] PackageToJS: Import only the UWASI features Swift needs The UWASI platform wrappers imported `useAll` and `MemoryFileSystem`, so bundles always carried UWASI's in-memory file system and came out larger than the browser_wasi_shim default. Import `useStdio`, `useArgs`, `useEnviron`, `useClock`, `usePoll`, `useProc` and `useRandom` instead. File syscalls now return ENOSYS. With `--enable-code-coverage`, the Node wrapper adds `useMemoryFS`, because the test runner reads the coverage profile through `extractFile`. The browser wrapper never imports a file system. --- Plugins/PackageToJS/README.md | 6 + Plugins/PackageToJS/Sources/PackageToJS.swift | 1 + .../Templates/platforms/browser.js | 27 +- .../PackageToJS/Templates/platforms/node.js | 29 +- .../PackageToJS/Templates/platforms/uwasi.js | 50 ++- .../Tests/Inputs/UWASIAdapterTests.mjs | 168 +++++++--- .../Tests/PackagingPlannerTests.swift | 20 +- .../PackageToJS/Tests/TemplatesTests.swift | 18 +- .../planBuild_debug.json | 24 +- .../planBuild_debug_uwasi.json | 26 +- .../planBuild_debug_uwasi_coverage.json | 311 ++++++++++++++++++ .../planBuild_release.json | 24 +- .../planBuild_release_dwarf.json | 24 +- .../planBuild_release_name.json | 24 +- .../planBuild_release_no_optimize.json | 24 +- .../PackagingPlannerTests/planTestBuild.json | 32 +- .../Articles/Package-Output-Structure.md | 6 + 17 files changed, 622 insertions(+), 192 deletions(-) create mode 100644 Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_debug_uwasi_coverage.json diff --git a/Plugins/PackageToJS/README.md b/Plugins/PackageToJS/README.md index 0e3e0e124..01a420466 100644 --- a/Plugins/PackageToJS/README.md +++ b/Plugins/PackageToJS/README.md @@ -22,6 +22,12 @@ to generate browser and Node platform wrappers backed by `uwasi` instead: swift package --swift-sdk wasm32-unknown-wasi js --wasi-runtime uwasi ``` +The `uwasi` wrappers import only the stdio, args, environ, clock, poll, proc and +random features, so bundlers can drop `uwasi`'s file system and file syscalls return +`ENOSYS`. With `--enable-code-coverage`, the Node wrapper adds an in-memory file +system so the test runner can read the coverage profile. To give an application a +file system, pass your own `wasi` object to `instantiate`. + The generated browser main-thread setup rejects blocking WASI waits. Run guests that require `poll_oneoff` clock waits in a worker. Node and browser workers use `uwasi`'s blocking implementation. diff --git a/Plugins/PackageToJS/Sources/PackageToJS.swift b/Plugins/PackageToJS/Sources/PackageToJS.swift index cf236c5cc..b736cca69 100644 --- a/Plugins/PackageToJS/Sources/PackageToJS.swift +++ b/Plugins/PackageToJS/Sources/PackageToJS.swift @@ -957,6 +957,7 @@ struct PackagingPlanner { let staticConditions: [String: Bool] = [ "USE_WASI_CDN": options.useCDN, "USE_UWASI": options.wasiRuntime == .uwasi, + "USE_UWASI_FILESYSTEM": options.wasiRuntime == .uwasi && options.enableCodeCoverage, "HAS_BRIDGE": skeletons.count > 0, "HAS_IMPORTS": skeletons.count > 0, "TARGET_DEFAULT_PLATFORM_NODE": options.defaultPlatform == .node, diff --git a/Plugins/PackageToJS/Templates/platforms/browser.js b/Plugins/PackageToJS/Templates/platforms/browser.js index e8c596308..6b148685f 100644 --- a/Plugins/PackageToJS/Templates/platforms/browser.js +++ b/Plugins/PackageToJS/Templates/platforms/browser.js @@ -4,11 +4,12 @@ import { MODULE_PATH /* #if USE_SHARED_MEMORY */, MEMORY_TYPE /* #endif */} from /* #if USE_UWASI */ /* #if USE_WASI_CDN */ // @ts-ignore -import { WASI, MemoryFileSystem, useAll, lineBuffered } from 'https://cdn.jsdelivr.net/npm/uwasi@1.5.2/+esm'; +import { WASI, lineBuffered, useStdio, useArgs, useEnviron, useClock, usePoll, useProc, useRandom } from 'https://cdn.jsdelivr.net/npm/uwasi@1.5.2/+esm'; /* #else */ -import { WASI, MemoryFileSystem, useAll, lineBuffered } from 'uwasi'; +import { WASI, lineBuffered, useStdio, useArgs, useEnviron, useClock, usePoll, useProc, useRandom } from 'uwasi'; /* #endif */ import { browserMainThreadSleep, createUwasi } from './uwasi.js'; +const uwasiRuntime = { WASI, lineBuffered, useStdio, useArgs, useEnviron, useClock, usePoll, useProc, useRandom }; /* #else */ /* #if USE_WASI_CDN */ // @ts-ignore @@ -38,10 +39,7 @@ export async function defaultBrowserThreadSetup() { /* #if IS_WASI */ /* #if USE_UWASI */ - const { wasi } = createUwasi( - { WASI, MemoryFileSystem, useAll, lineBuffered }, - { modulePath: MODULE_PATH } - ) + const { wasi } = createUwasi(uwasiRuntime, { modulePath: MODULE_PATH }) /* #else */ const wasi = new WASI(/* args */[MODULE_PATH], /* env */[], /* fd */[ new OpenFile(new File([])), // stdin @@ -127,16 +125,13 @@ export async function defaultBrowserSetup(options) { const onStdoutLine = options.onStdoutLine ?? ((line) => console.log(line)) const onStderrLine = options.onStderrLine ?? ((line) => console.error(line)) /* #if USE_UWASI */ - const { wasi } = createUwasi( - { WASI, MemoryFileSystem, useAll, lineBuffered }, - { - modulePath: MODULE_PATH, - args, - onStdoutLine, - onStderrLine, - sleep: browserMainThreadSleep(), - } - ) + const { wasi } = createUwasi(uwasiRuntime, { + modulePath: MODULE_PATH, + args, + onStdoutLine, + onStderrLine, + sleep: browserMainThreadSleep(), + }) /* #else */ const wasi = new WASI(/* args */[MODULE_PATH, ...args], /* env */[], /* fd */[ new OpenFile(new File([])), // stdin diff --git a/Plugins/PackageToJS/Templates/platforms/node.js b/Plugins/PackageToJS/Templates/platforms/node.js index b01290252..4725201b7 100644 --- a/Plugins/PackageToJS/Templates/platforms/node.js +++ b/Plugins/PackageToJS/Templates/platforms/node.js @@ -4,8 +4,17 @@ import { Worker, parentPort } from "node:worker_threads"; import { MODULE_PATH /* #if USE_SHARED_MEMORY */, MEMORY_TYPE /* #endif */} from "../instantiate.js" /* #if IS_WASI */ /* #if USE_UWASI */ -import { WASI, MemoryFileSystem, useAll, lineBuffered } from 'uwasi'; +import { WASI, lineBuffered, useStdio, useArgs, useEnviron, useClock, usePoll, useProc, useRandom } from 'uwasi'; +/* #if USE_UWASI_FILESYSTEM */ +import { MemoryFileSystem, useMemoryFS } from 'uwasi'; +/* #endif */ import { createUwasi } from './uwasi.js'; +const uwasiRuntime = { + WASI, lineBuffered, useStdio, useArgs, useEnviron, useClock, usePoll, useProc, useRandom, +/* #if USE_UWASI_FILESYSTEM */ + MemoryFileSystem, useMemoryFS, +/* #endif */ +}; /* #else */ import { WASI, File, OpenFile, ConsoleStdout, PreopenDirectory, Directory, Inode } from '@bjorn3/browser_wasi_shim'; /* #endif */ @@ -28,10 +37,7 @@ export async function defaultNodeThreadSetup() { } /* #if USE_UWASI */ - const { wasi } = createUwasi( - { WASI, MemoryFileSystem, useAll, lineBuffered }, - { modulePath: MODULE_PATH } - ) + const { wasi } = createUwasi(uwasiRuntime, { modulePath: MODULE_PATH }) /* #else */ const wasi = new WASI(/* args */[MODULE_PATH], /* env */[], /* fd */[ new OpenFile(new File([])), // stdin @@ -136,14 +142,11 @@ export async function defaultNodeSetup(options = {}) { const args = options.args ?? process.argv.slice(2) /* #if USE_UWASI */ - const { wasi } = createUwasi( - { WASI, MemoryFileSystem, useAll, lineBuffered }, - { - modulePath: MODULE_PATH, - args, - withExtractFile: true, - } - ) + const { wasi } = createUwasi(uwasiRuntime, { + modulePath: MODULE_PATH, + args, + withExtractFile: true, + }) /* #else */ const rootFs = new Map(); const wasi = new WASI(/* args */[MODULE_PATH, ...args], /* env */[], /* fd */[ diff --git a/Plugins/PackageToJS/Templates/platforms/uwasi.js b/Plugins/PackageToJS/Templates/platforms/uwasi.js index e7a9ce1bc..56212a108 100644 --- a/Plugins/PackageToJS/Templates/platforms/uwasi.js +++ b/Plugins/PackageToJS/Templates/platforms/uwasi.js @@ -17,7 +17,19 @@ export function browserMainThreadSleep() { } /** - * @param {{ WASI: any, MemoryFileSystem: any, useAll: any, lineBuffered: any }} runtime + * @param {{ + * WASI: any, + * lineBuffered: any, + * useStdio: any, + * useArgs: any, + * useEnviron: any, + * useClock: any, + * usePoll: any, + * useProc: any, + * useRandom: any, + * MemoryFileSystem?: any, + * useMemoryFS?: any, + * }} runtime * @param {{ * modulePath: string, * args?: string[], @@ -32,27 +44,35 @@ export function createUwasi(runtime, options) { const onStdoutLine = options.onStdoutLine ?? ((line) => console.log(line)); const onStderrLine = options.onStderrLine ?? ((line) => console.error(line)); - const fileSystem = new runtime.MemoryFileSystem({ "/": "/" }); - const stdout = runtime.lineBuffered(onStdoutLine); - const stderr = runtime.lineBuffered(onStderrLine); + const stdio = { + stdin: () => "", + stdout: runtime.lineBuffered(onStdoutLine), + stderr: runtime.lineBuffered(onStderrLine), + outputBuffers: true, + }; + const fileSystem = runtime.MemoryFileSystem + ? new runtime.MemoryFileSystem({ "/": "/" }) + : undefined; const wasi = new runtime.WASI({ args: [options.modulePath, ...args], env: {}, features: [ - runtime.useAll({ - withFileSystem: fileSystem, - withStdio: { - stdin: () => "", - stdout, - stderr, - outputBuffers: true, - }, - sleep: options.sleep, - }), + fileSystem + ? runtime.useMemoryFS({ + withFileSystem: fileSystem, + withStdio: stdio, + }) + : runtime.useStdio(stdio), + runtime.useArgs(), + runtime.useEnviron(), + runtime.useClock(), + runtime.usePoll({ sleep: options.sleep }), + runtime.useProc(), + runtime.useRandom(), ], }); - if (options.withExtractFile) { + if (fileSystem && options.withExtractFile) { Object.assign(wasi, { extractFile(filePath) { const node = fileSystem.lookup(filePath); diff --git a/Plugins/PackageToJS/Tests/Inputs/UWASIAdapterTests.mjs b/Plugins/PackageToJS/Tests/Inputs/UWASIAdapterTests.mjs index 94dfab59e..8084c5805 100644 --- a/Plugins/PackageToJS/Tests/Inputs/UWASIAdapterTests.mjs +++ b/Plugins/PackageToJS/Tests/Inputs/UWASIAdapterTests.mjs @@ -1,25 +1,72 @@ import assert from "node:assert/strict"; import { test } from "node:test"; -import { MemoryFileSystem, useAll, WASI } from "uwasi"; +import { + MemoryFileSystem, + useArgs, + useClock, + useEnviron, + useMemoryFS, + usePoll, + useProc, + useRandom, + useStdio, + WASI, +} from "uwasi"; import { browserMainThreadSleep, createUwasi, } from "../../Templates/platforms/uwasi.js"; -test("PackageToJS UWASI adapter preserves its host contracts", () => { - const stdout = []; - const stderr = []; - let lineBufferedCalls = 0; +const minimalRuntime = { + WASI, + useStdio, + useArgs, + useEnviron, + useClock, + usePoll, + useProc, + useRandom, +}; +const fileSystemRuntime = { ...minimalRuntime, MemoryFileSystem, useMemoryFS }; +const WASI_ERRNO_NOSYS = 52; + +function recordingLineBuffered() { + const calls = { count: 0 }; const lineBuffered = (writeLine) => { - lineBufferedCalls += 1; + calls.count += 1; return (chunk) => { const line = new TextDecoder().decode(chunk).replace(/\n$/, ""); writeLine(line); }; }; + return { calls, lineBuffered }; +} + +function bindMemory(wasi) { + const memory = new WebAssembly.Memory({ initial: 1 }); + wasi.setInstance({ exports: { memory } }); + return { + view: new DataView(memory.buffer), + bytes: new Uint8Array(memory.buffer), + }; +} + +function writeTo(wasi, { view, bytes }, fd, text) { + const chunk = new TextEncoder().encode(text); + bytes.set(chunk, 64); + view.setUint32(0, 64, true); + view.setUint32(4, chunk.length, true); + assert.equal(wasi.wasiImport.fd_write(fd, 0, 1, 8), 0); + assert.equal(view.getUint32(8, true), chunk.length); +} + +test("PackageToJS UWASI adapter preserves its host contracts with a file system", () => { + const stdout = []; + const stderr = []; + const { calls, lineBuffered } = recordingLineBuffered(); const { wasi, fileSystem } = createUwasi( - { WASI, MemoryFileSystem, useAll, lineBuffered }, + { ...fileSystemRuntime, lineBuffered }, { modulePath: "main.wasm", onStdoutLine: (line) => stdout.push(line), @@ -27,22 +74,11 @@ test("PackageToJS UWASI adapter preserves its host contracts", () => { withExtractFile: true, }, ); - const memory = new WebAssembly.Memory({ initial: 1 }); - wasi.setInstance({ exports: { memory } }); - - const view = new DataView(memory.buffer); - const bytes = new Uint8Array(memory.buffer); - const write = (fd, chunk) => { - bytes.set(chunk, 64); - view.setUint32(0, 64, true); - view.setUint32(4, chunk.length, true); - assert.equal(wasi.wasiImport.fd_write(fd, 0, 1, 8), 0); - assert.equal(view.getUint32(8, true), chunk.length); - }; + const memory = bindMemory(wasi); - write(1, new TextEncoder().encode("output\n")); - write(2, new TextEncoder().encode("error\n")); - assert.equal(lineBufferedCalls, 2); + writeTo(wasi, memory, 1, "output\n"); + writeTo(wasi, memory, 2, "error\n"); + assert.equal(calls.count, 2); assert.deepEqual(stdout, ["output"]); assert.deepEqual(stderr, ["error"]); @@ -53,39 +89,77 @@ test("PackageToJS UWASI adapter preserves its host contracts", () => { ); }); -test("PackageToJS forwards the host sleep policy", (t) => { - t.mock.method(performance, "now", () => 0); - const { wasi } = createUwasi( - { - WASI, - MemoryFileSystem, - useAll, - lineBuffered: (writeLine) => writeLine, - }, +test("PackageToJS UWASI adapter omits the file system by default", () => { + const stdout = []; + const stderr = []; + const { calls, lineBuffered } = recordingLineBuffered(); + const { wasi, fileSystem } = createUwasi( + { ...minimalRuntime, lineBuffered }, { modulePath: "main.wasm", - sleep(milliseconds) { - throw new Error(`cannot block for ${milliseconds}ms`); - }, + onStdoutLine: (line) => stdout.push(line), + onStderrLine: (line) => stderr.push(line), + withExtractFile: true, }, ); - const memory = new WebAssembly.Memory({ initial: 1 }); - wasi.setInstance({ exports: { memory } }); + const memory = bindMemory(wasi); + + writeTo(wasi, memory, 1, "output\n"); + writeTo(wasi, memory, 2, "error\n"); + assert.equal(calls.count, 2); + assert.deepEqual(stdout, ["output"]); + assert.deepEqual(stderr, ["error"]); - const view = new DataView(memory.buffer); - view.setBigUint64(0, 0n, true); - view.setUint8(8, 0); - view.setUint32(16, 1, true); - view.setBigUint64(24, 1_000_000n, true); - view.setBigUint64(32, 0n, true); - view.setUint16(40, 0, true); - - assert.throws( - () => wasi.wasiImport.poll_oneoff(0, 128, 1, 256), - /cannot block for 1ms/, + assert.equal(fileSystem, undefined); + assert.equal("extractFile" in wasi, false); + assert.equal(wasi.wasiImport.fd_prestat_get(3, 0), 8); + assert.equal( + wasi.wasiImport.path_open(3, 0, 0, 0, 0, 0n, 0n, 0, 0), + WASI_ERRNO_NOSYS, ); + for (const name of [ + "args_get", + "environ_get", + "clock_time_get", + "poll_oneoff", + "proc_exit", + "random_get", + ]) { + assert.ok(wasi.wasiImport[name].length > 0, `${name} must be provided`); + } }); +for (const [name, runtime] of [ + ["minimal", minimalRuntime], + ["file system", fileSystemRuntime], +]) { + test(`PackageToJS forwards the host sleep policy (${name})`, (t) => { + t.mock.method(performance, "now", () => 0); + const { wasi } = createUwasi( + { ...runtime, lineBuffered: (writeLine) => writeLine }, + { + modulePath: "main.wasm", + sleep(milliseconds) { + throw new Error(`cannot block for ${milliseconds}ms`); + }, + }, + ); + const { view } = bindMemory(wasi); + + view.setBigUint64(0, 0n, true); + view.setUint8(8, 0); + view.setUint32(16, 1, true); + view.setBigUint64(24, 1_000_000n, true); + view.setBigUint64(32, 0n, true); + view.setUint16(40, 0, true); + + assert.throws( + () => wasi.wasiImport.poll_oneoff(0, 128, 1, 256), + /cannot block for 1ms/, + ); + }); +} + test("PackageToJS blocks waits only on the browser main thread", () => { assert.equal(browserMainThreadSleep(), undefined); diff --git a/Plugins/PackageToJS/Tests/PackagingPlannerTests.swift b/Plugins/PackageToJS/Tests/PackagingPlannerTests.swift index 2341f59af..d94e672bc 100644 --- a/Plugins/PackageToJS/Tests/PackagingPlannerTests.swift +++ b/Plugins/PackageToJS/Tests/PackagingPlannerTests.swift @@ -52,27 +52,31 @@ import Testing @Test(arguments: [ ( variant: "debug", configuration: "debug", noOptimize: false, - debugInfoFormat: DebugInfoFormat.none, wasiRuntime: WASIRuntime.browserWASIShim + debugInfoFormat: DebugInfoFormat.none, wasiRuntime: WASIRuntime.browserWASIShim, enableCodeCoverage: false ), ( variant: "debug_uwasi", configuration: "debug", noOptimize: false, - debugInfoFormat: DebugInfoFormat.none, wasiRuntime: WASIRuntime.uwasi + debugInfoFormat: DebugInfoFormat.none, wasiRuntime: WASIRuntime.uwasi, enableCodeCoverage: false + ), + ( + variant: "debug_uwasi_coverage", configuration: "debug", noOptimize: false, + debugInfoFormat: DebugInfoFormat.none, wasiRuntime: WASIRuntime.uwasi, enableCodeCoverage: true ), ( variant: "release", configuration: "release", noOptimize: false, - debugInfoFormat: DebugInfoFormat.none, wasiRuntime: WASIRuntime.browserWASIShim + debugInfoFormat: DebugInfoFormat.none, wasiRuntime: WASIRuntime.browserWASIShim, enableCodeCoverage: false ), ( variant: "release_no_optimize", configuration: "release", noOptimize: true, - debugInfoFormat: DebugInfoFormat.none, wasiRuntime: WASIRuntime.browserWASIShim + debugInfoFormat: DebugInfoFormat.none, wasiRuntime: WASIRuntime.browserWASIShim, enableCodeCoverage: false ), ( variant: "release_dwarf", configuration: "release", noOptimize: false, - debugInfoFormat: DebugInfoFormat.dwarf, wasiRuntime: WASIRuntime.browserWASIShim + debugInfoFormat: DebugInfoFormat.dwarf, wasiRuntime: WASIRuntime.browserWASIShim, enableCodeCoverage: false ), ( variant: "release_name", configuration: "release", noOptimize: false, - debugInfoFormat: DebugInfoFormat.name, wasiRuntime: WASIRuntime.browserWASIShim + debugInfoFormat: DebugInfoFormat.name, wasiRuntime: WASIRuntime.browserWASIShim, enableCodeCoverage: false ), ]) func planBuild( @@ -80,10 +84,12 @@ import Testing configuration: String, noOptimize: Bool, debugInfoFormat: PackageToJS.DebugInfoFormat, - wasiRuntime: WASIRuntime + wasiRuntime: WASIRuntime, + enableCodeCoverage: Bool ) throws { var options = PackageToJS.PackageOptions() options.wasiRuntime = wasiRuntime + options.enableCodeCoverage = enableCodeCoverage let system = TestPackagingSystem() let planner = PackagingPlanner( options: options, diff --git a/Plugins/PackageToJS/Tests/TemplatesTests.swift b/Plugins/PackageToJS/Tests/TemplatesTests.swift index cc2b4d2a0..81240658b 100644 --- a/Plugins/PackageToJS/Tests/TemplatesTests.swift +++ b/Plugins/PackageToJS/Tests/TemplatesTests.swift @@ -17,12 +17,14 @@ import Foundation /// `npx tsc -p Templates/tsconfig.json` /// Test both WASI runtimes in node and browser platform variants. @Test(arguments: [ - (platform: "node", runtime: "browser-wasi-shim", sharedMemory: false), - (platform: "browser", runtime: "browser-wasi-shim", sharedMemory: false), - (platform: "node", runtime: "uwasi", sharedMemory: false), - (platform: "browser", runtime: "uwasi", sharedMemory: true), + (platform: "node", runtime: "browser-wasi-shim", sharedMemory: false, filesystem: false), + (platform: "browser", runtime: "browser-wasi-shim", sharedMemory: false, filesystem: false), + (platform: "node", runtime: "uwasi", sharedMemory: false, filesystem: false), + (platform: "node", runtime: "uwasi", sharedMemory: false, filesystem: true), + (platform: "browser", runtime: "uwasi", sharedMemory: true, filesystem: false), + (platform: "browser", runtime: "uwasi", sharedMemory: false, filesystem: true), ]) - func tscCheck(platform: String, runtime: String, sharedMemory: Bool) throws { + func tscCheck(platform: String, runtime: String, sharedMemory: Bool, filesystem: Bool) throws { // Use a local temporary directory to place instantiated templates so that // they can reference repo-root node_modules packages like @types/node. try FileManager.default.createDirectory( @@ -41,6 +43,7 @@ import Foundation "IS_WASI": true, "USE_WASI_CDN": false, "USE_UWASI": runtime == "uwasi", + "USE_UWASI_FILESYSTEM": runtime == "uwasi" && filesystem, "HAS_BRIDGE": false, "HAS_IMPORTS": false, "TARGET_DEFAULT_PLATFORM_NODE": platform == "node", @@ -78,6 +81,11 @@ import Foundation ) let expectedImport = runtime == "uwasi" ? "from 'uwasi'" : "from '@bjorn3/browser_wasi_shim'" #expect(platformSource.contains(expectedImport)) + if runtime == "uwasi" { + #expect(!platformSource.contains("useAll")) + #expect(platformSource.contains("useStdio")) + #expect(platformSource.contains("MemoryFileSystem") == (platform == "node" && filesystem)) + } let manifestData = try Data(contentsOf: destination.appending(path: "package.json")) let manifest = try #require( diff --git a/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_debug.json b/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_debug.json index a21b94fd6..5ac062bc4 100644 --- a/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_debug.json +++ b/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_debug.json @@ -46,7 +46,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/index.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -63,7 +63,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/index.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -80,7 +80,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/instantiate.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -97,7 +97,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/instantiate.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -127,7 +127,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/package.json", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json" @@ -155,7 +155,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -172,7 +172,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -189,7 +189,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.worker.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -206,7 +206,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/node.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -223,7 +223,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/node.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -240,7 +240,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/runtime.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -257,7 +257,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/runtime.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", diff --git a/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_debug_uwasi.json b/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_debug_uwasi.json index 0948e2b74..b75adacfb 100644 --- a/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_debug_uwasi.json +++ b/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_debug_uwasi.json @@ -46,7 +46,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/index.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjpmYWxzZSwiVVNFX1dBU0lfQ0ROIjpmYWxzZX0sInN1YnN0aXR1dGlvbnMiOnsiUEFDS0FHRV9UT19KU19NT0RVTEVfUEFUSCI6Im1haW4ud2FzbSIsIlBBQ0tBR0VfVE9fSlNfUEFDS0FHRV9OQU1FIjoidGVzdCJ9fQ==", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -63,7 +63,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/index.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjpmYWxzZSwiVVNFX1dBU0lfQ0ROIjpmYWxzZX0sInN1YnN0aXR1dGlvbnMiOnsiUEFDS0FHRV9UT19KU19NT0RVTEVfUEFUSCI6Im1haW4ud2FzbSIsIlBBQ0tBR0VfVE9fSlNfUEFDS0FHRV9OQU1FIjoidGVzdCJ9fQ==", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -80,7 +80,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/instantiate.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjpmYWxzZSwiVVNFX1dBU0lfQ0ROIjpmYWxzZX0sInN1YnN0aXR1dGlvbnMiOnsiUEFDS0FHRV9UT19KU19NT0RVTEVfUEFUSCI6Im1haW4ud2FzbSIsIlBBQ0tBR0VfVE9fSlNfUEFDS0FHRV9OQU1FIjoidGVzdCJ9fQ==", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -97,7 +97,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/instantiate.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjpmYWxzZSwiVVNFX1dBU0lfQ0ROIjpmYWxzZX0sInN1YnN0aXR1dGlvbnMiOnsiUEFDS0FHRV9UT19KU19NT0RVTEVfUEFUSCI6Im1haW4ud2FzbSIsIlBBQ0tBR0VfVE9fSlNfUEFDS0FHRV9OQU1FIjoidGVzdCJ9fQ==", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -127,7 +127,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/package.json", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjpmYWxzZSwiVVNFX1dBU0lfQ0ROIjpmYWxzZX0sInN1YnN0aXR1dGlvbnMiOnsiUEFDS0FHRV9UT19KU19NT0RVTEVfUEFUSCI6Im1haW4ud2FzbSIsIlBBQ0tBR0VfVE9fSlNfUEFDS0FHRV9OQU1FIjoidGVzdCJ9fQ==", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json" @@ -155,7 +155,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjpmYWxzZSwiVVNFX1dBU0lfQ0ROIjpmYWxzZX0sInN1YnN0aXR1dGlvbnMiOnsiUEFDS0FHRV9UT19KU19NT0RVTEVfUEFUSCI6Im1haW4ud2FzbSIsIlBBQ0tBR0VfVE9fSlNfUEFDS0FHRV9OQU1FIjoidGVzdCJ9fQ==", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -172,7 +172,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjpmYWxzZSwiVVNFX1dBU0lfQ0ROIjpmYWxzZX0sInN1YnN0aXR1dGlvbnMiOnsiUEFDS0FHRV9UT19KU19NT0RVTEVfUEFUSCI6Im1haW4ud2FzbSIsIlBBQ0tBR0VfVE9fSlNfUEFDS0FHRV9OQU1FIjoidGVzdCJ9fQ==", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -189,7 +189,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.worker.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjpmYWxzZSwiVVNFX1dBU0lfQ0ROIjpmYWxzZX0sInN1YnN0aXR1dGlvbnMiOnsiUEFDS0FHRV9UT19KU19NT0RVTEVfUEFUSCI6Im1haW4ud2FzbSIsIlBBQ0tBR0VfVE9fSlNfUEFDS0FHRV9OQU1FIjoidGVzdCJ9fQ==", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -206,7 +206,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/node.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjpmYWxzZSwiVVNFX1dBU0lfQ0ROIjpmYWxzZX0sInN1YnN0aXR1dGlvbnMiOnsiUEFDS0FHRV9UT19KU19NT0RVTEVfUEFUSCI6Im1haW4ud2FzbSIsIlBBQ0tBR0VfVE9fSlNfUEFDS0FHRV9OQU1FIjoidGVzdCJ9fQ==", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -223,7 +223,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/node.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjpmYWxzZSwiVVNFX1dBU0lfQ0ROIjpmYWxzZX0sInN1YnN0aXR1dGlvbnMiOnsiUEFDS0FHRV9UT19KU19NT0RVTEVfUEFUSCI6Im1haW4ud2FzbSIsIlBBQ0tBR0VfVE9fSlNfUEFDS0FHRV9OQU1FIjoidGVzdCJ9fQ==", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -240,7 +240,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/uwasi.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjpmYWxzZSwiVVNFX1dBU0lfQ0ROIjpmYWxzZX0sInN1YnN0aXR1dGlvbnMiOnsiUEFDS0FHRV9UT19KU19NT0RVTEVfUEFUSCI6Im1haW4ud2FzbSIsIlBBQ0tBR0VfVE9fSlNfUEFDS0FHRV9OQU1FIjoidGVzdCJ9fQ==", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -257,7 +257,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/runtime.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjpmYWxzZSwiVVNFX1dBU0lfQ0ROIjpmYWxzZX0sInN1YnN0aXR1dGlvbnMiOnsiUEFDS0FHRV9UT19KU19NT0RVTEVfUEFUSCI6Im1haW4ud2FzbSIsIlBBQ0tBR0VfVE9fSlNfUEFDS0FHRV9OQU1FIjoidGVzdCJ9fQ==", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -274,7 +274,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/runtime.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjpmYWxzZSwiVVNFX1dBU0lfQ0ROIjpmYWxzZX0sInN1YnN0aXR1dGlvbnMiOnsiUEFDS0FHRV9UT19KU19NT0RVTEVfUEFUSCI6Im1haW4ud2FzbSIsIlBBQ0tBR0VfVE9fSlNfUEFDS0FHRV9OQU1FIjoidGVzdCJ9fQ==", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", diff --git a/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_debug_uwasi_coverage.json b/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_debug_uwasi_coverage.json new file mode 100644 index 000000000..c503152db --- /dev/null +++ b/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_debug_uwasi_coverage.json @@ -0,0 +1,311 @@ +[ + { + "attributes" : [ + "silent" + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH" + ], + "output" : "$INTERMEDIATES", + "wants" : [ + + ] + }, + { + "attributes" : [ + + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH", + "$WASM_PRODUCT_ARTIFACT" + ], + "output" : "$INTERMEDIATES\/wasm-imports.json", + "wants" : [ + "$INTERMEDIATES" + ] + }, + { + "attributes" : [ + "silent" + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH" + ], + "output" : "$OUTPUT", + "wants" : [ + + ] + }, + { + "attributes" : [ + + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH", + "$SELF_PACKAGE\/Plugins\/PackageToJS\/Templates\/index.d.ts", + "$INTERMEDIATES\/wasm-imports.json" + ], + "output" : "$OUTPUT\/index.d.ts", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjp0cnVlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "wants" : [ + "$OUTPUT", + "$INTERMEDIATES\/wasm-imports.json", + "$OUTPUT\/platforms" + ] + }, + { + "attributes" : [ + + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH", + "$SELF_PACKAGE\/Plugins\/PackageToJS\/Templates\/index.js", + "$INTERMEDIATES\/wasm-imports.json" + ], + "output" : "$OUTPUT\/index.js", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjp0cnVlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "wants" : [ + "$OUTPUT", + "$INTERMEDIATES\/wasm-imports.json", + "$OUTPUT\/platforms" + ] + }, + { + "attributes" : [ + + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH", + "$SELF_PACKAGE\/Plugins\/PackageToJS\/Templates\/instantiate.d.ts", + "$INTERMEDIATES\/wasm-imports.json" + ], + "output" : "$OUTPUT\/instantiate.d.ts", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjp0cnVlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "wants" : [ + "$OUTPUT", + "$INTERMEDIATES\/wasm-imports.json", + "$OUTPUT\/platforms" + ] + }, + { + "attributes" : [ + + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH", + "$SELF_PACKAGE\/Plugins\/PackageToJS\/Templates\/instantiate.js", + "$INTERMEDIATES\/wasm-imports.json" + ], + "output" : "$OUTPUT\/instantiate.js", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjp0cnVlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "wants" : [ + "$OUTPUT", + "$INTERMEDIATES\/wasm-imports.json", + "$OUTPUT\/platforms" + ] + }, + { + "attributes" : [ + + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH", + "$WASM_PRODUCT_ARTIFACT" + ], + "output" : "$OUTPUT\/main.wasm", + "wants" : [ + "$OUTPUT" + ] + }, + { + "attributes" : [ + + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH", + "$SELF_PACKAGE\/Plugins\/PackageToJS\/Templates\/package.json", + "$INTERMEDIATES\/wasm-imports.json" + ], + "output" : "$OUTPUT\/package.json", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjp0cnVlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "wants" : [ + "$OUTPUT", + "$INTERMEDIATES\/wasm-imports.json" + ] + }, + { + "attributes" : [ + "silent" + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH" + ], + "output" : "$OUTPUT\/platforms", + "wants" : [ + + ] + }, + { + "attributes" : [ + + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH", + "$SELF_PACKAGE\/Plugins\/PackageToJS\/Templates\/platforms\/browser.d.ts", + "$INTERMEDIATES\/wasm-imports.json" + ], + "output" : "$OUTPUT\/platforms\/browser.d.ts", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjp0cnVlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "wants" : [ + "$OUTPUT", + "$INTERMEDIATES\/wasm-imports.json", + "$OUTPUT\/platforms" + ] + }, + { + "attributes" : [ + + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH", + "$SELF_PACKAGE\/Plugins\/PackageToJS\/Templates\/platforms\/browser.js", + "$INTERMEDIATES\/wasm-imports.json" + ], + "output" : "$OUTPUT\/platforms\/browser.js", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjp0cnVlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "wants" : [ + "$OUTPUT", + "$INTERMEDIATES\/wasm-imports.json", + "$OUTPUT\/platforms" + ] + }, + { + "attributes" : [ + + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH", + "$SELF_PACKAGE\/Plugins\/PackageToJS\/Templates\/platforms\/browser.worker.js", + "$INTERMEDIATES\/wasm-imports.json" + ], + "output" : "$OUTPUT\/platforms\/browser.worker.js", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjp0cnVlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "wants" : [ + "$OUTPUT", + "$INTERMEDIATES\/wasm-imports.json", + "$OUTPUT\/platforms" + ] + }, + { + "attributes" : [ + + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH", + "$SELF_PACKAGE\/Plugins\/PackageToJS\/Templates\/platforms\/node.d.ts", + "$INTERMEDIATES\/wasm-imports.json" + ], + "output" : "$OUTPUT\/platforms\/node.d.ts", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjp0cnVlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "wants" : [ + "$OUTPUT", + "$INTERMEDIATES\/wasm-imports.json", + "$OUTPUT\/platforms" + ] + }, + { + "attributes" : [ + + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH", + "$SELF_PACKAGE\/Plugins\/PackageToJS\/Templates\/platforms\/node.js", + "$INTERMEDIATES\/wasm-imports.json" + ], + "output" : "$OUTPUT\/platforms\/node.js", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjp0cnVlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "wants" : [ + "$OUTPUT", + "$INTERMEDIATES\/wasm-imports.json", + "$OUTPUT\/platforms" + ] + }, + { + "attributes" : [ + + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH", + "$SELF_PACKAGE\/Plugins\/PackageToJS\/Templates\/platforms\/uwasi.js", + "$INTERMEDIATES\/wasm-imports.json" + ], + "output" : "$OUTPUT\/platforms\/uwasi.js", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjp0cnVlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "wants" : [ + "$OUTPUT", + "$INTERMEDIATES\/wasm-imports.json", + "$OUTPUT\/platforms" + ] + }, + { + "attributes" : [ + + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH", + "$SELF_PACKAGE\/Sources\/JavaScriptKit\/Runtime\/index.d.ts", + "$INTERMEDIATES\/wasm-imports.json" + ], + "output" : "$OUTPUT\/runtime.d.ts", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjp0cnVlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "wants" : [ + "$OUTPUT", + "$INTERMEDIATES\/wasm-imports.json", + "$OUTPUT\/platforms" + ] + }, + { + "attributes" : [ + + ], + "inputs" : [ + "$PLANNER_SOURCE_PATH", + "$SELF_PACKAGE\/Sources\/JavaScriptKit\/Runtime\/index.mjs", + "$INTERMEDIATES\/wasm-imports.json" + ], + "output" : "$OUTPUT\/runtime.js", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOnRydWUsIlVTRV9VV0FTSV9GSUxFU1lTVEVNIjp0cnVlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "wants" : [ + "$OUTPUT", + "$INTERMEDIATES\/wasm-imports.json", + "$OUTPUT\/platforms" + ] + }, + { + "attributes" : [ + "phony", + "silent" + ], + "inputs" : [ + + ], + "output" : "all", + "wants" : [ + "$OUTPUT\/main.wasm", + "$INTERMEDIATES\/wasm-imports.json", + "$OUTPUT\/package.json", + "$OUTPUT\/index.js", + "$OUTPUT\/index.d.ts", + "$OUTPUT\/instantiate.js", + "$OUTPUT\/instantiate.d.ts", + "$OUTPUT\/platforms\/browser.js", + "$OUTPUT\/platforms\/browser.d.ts", + "$OUTPUT\/platforms\/browser.worker.js", + "$OUTPUT\/platforms\/node.js", + "$OUTPUT\/platforms\/node.d.ts", + "$OUTPUT\/runtime.js", + "$OUTPUT\/runtime.d.ts", + "$OUTPUT\/platforms\/uwasi.js" + ] + } +] \ No newline at end of file diff --git a/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_release.json b/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_release.json index d2f0d0f38..7a881a621 100644 --- a/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_release.json +++ b/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_release.json @@ -60,7 +60,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/index.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -77,7 +77,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/index.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -94,7 +94,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/instantiate.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -111,7 +111,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/instantiate.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -142,7 +142,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/package.json", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json" @@ -170,7 +170,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -187,7 +187,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -204,7 +204,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.worker.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -221,7 +221,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/node.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -238,7 +238,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/node.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -255,7 +255,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/runtime.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -272,7 +272,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/runtime.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", diff --git a/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_release_dwarf.json b/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_release_dwarf.json index a21b94fd6..5ac062bc4 100644 --- a/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_release_dwarf.json +++ b/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_release_dwarf.json @@ -46,7 +46,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/index.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -63,7 +63,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/index.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -80,7 +80,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/instantiate.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -97,7 +97,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/instantiate.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -127,7 +127,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/package.json", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json" @@ -155,7 +155,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -172,7 +172,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -189,7 +189,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.worker.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -206,7 +206,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/node.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -223,7 +223,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/node.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -240,7 +240,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/runtime.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -257,7 +257,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/runtime.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", diff --git a/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_release_name.json b/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_release_name.json index d2f0d0f38..7a881a621 100644 --- a/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_release_name.json +++ b/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_release_name.json @@ -60,7 +60,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/index.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -77,7 +77,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/index.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -94,7 +94,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/instantiate.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -111,7 +111,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/instantiate.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -142,7 +142,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/package.json", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json" @@ -170,7 +170,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -187,7 +187,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -204,7 +204,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.worker.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -221,7 +221,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/node.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -238,7 +238,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/node.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -255,7 +255,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/runtime.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -272,7 +272,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/runtime.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", diff --git a/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_release_no_optimize.json b/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_release_no_optimize.json index a21b94fd6..5ac062bc4 100644 --- a/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_release_no_optimize.json +++ b/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planBuild_release_no_optimize.json @@ -46,7 +46,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/index.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -63,7 +63,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/index.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -80,7 +80,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/instantiate.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -97,7 +97,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/instantiate.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -127,7 +127,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/package.json", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json" @@ -155,7 +155,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -172,7 +172,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -189,7 +189,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.worker.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -206,7 +206,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/node.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -223,7 +223,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/node.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -240,7 +240,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/runtime.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -257,7 +257,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/runtime.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", diff --git a/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planTestBuild.json b/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planTestBuild.json index 3c4029927..e9a0b9fea 100644 --- a/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planTestBuild.json +++ b/Plugins/PackageToJS/Tests/__Snapshots__/PackagingPlannerTests/planTestBuild.json @@ -72,7 +72,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/bin\/test.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -89,7 +89,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/index.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -106,7 +106,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/index.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -123,7 +123,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/instantiate.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -140,7 +140,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/instantiate.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -170,7 +170,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/package.json", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json" @@ -198,7 +198,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -215,7 +215,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -232,7 +232,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/browser.worker.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -249,7 +249,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/node.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -266,7 +266,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/platforms\/node.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -283,7 +283,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/runtime.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -300,7 +300,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/runtime.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -317,7 +317,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/test.browser.html", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -334,7 +334,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/test.d.ts", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", @@ -351,7 +351,7 @@ "$INTERMEDIATES\/wasm-imports.json" ], "output" : "$OUTPUT\/test.js", - "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfV0FTSV9DRE4iOmZhbHNlfSwic3Vic3RpdHV0aW9ucyI6eyJQQUNLQUdFX1RPX0pTX01PRFVMRV9QQVRIIjoibWFpbi53YXNtIiwiUEFDS0FHRV9UT19KU19QQUNLQUdFX05BTUUiOiJ0ZXN0In19", + "salt" : "eyJjb25kaXRpb25zIjp7IkhBU19CUklER0UiOmZhbHNlLCJIQVNfSU1QT1JUUyI6ZmFsc2UsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX0JST1dTRVIiOnRydWUsIlRBUkdFVF9ERUZBVUxUX1BMQVRGT1JNX05PREUiOmZhbHNlLCJVU0VfVVdBU0kiOmZhbHNlLCJVU0VfVVdBU0lfRklMRVNZU1RFTSI6ZmFsc2UsIlVTRV9XQVNJX0NETiI6ZmFsc2V9LCJzdWJzdGl0dXRpb25zIjp7IlBBQ0tBR0VfVE9fSlNfTU9EVUxFX1BBVEgiOiJtYWluLndhc20iLCJQQUNLQUdFX1RPX0pTX1BBQ0tBR0VfTkFNRSI6InRlc3QifX0=", "wants" : [ "$OUTPUT", "$INTERMEDIATES\/wasm-imports.json", diff --git a/Sources/JavaScriptKit/Documentation.docc/Articles/Package-Output-Structure.md b/Sources/JavaScriptKit/Documentation.docc/Articles/Package-Output-Structure.md index 6f3d30ac9..b0b84469a 100644 --- a/Sources/JavaScriptKit/Documentation.docc/Articles/Package-Output-Structure.md +++ b/Sources/JavaScriptKit/Documentation.docc/Articles/Package-Output-Structure.md @@ -128,6 +128,12 @@ PackageToJS uses `@bjorn3/browser_wasi_shim` for WASI packages by default. Pass `--wasi-runtime uwasi` to generate both platform wrappers against `uwasi`; this also adds `platforms/uwasi.js` to the package. +The `uwasi` wrappers import only the stdio, args, environ, clock, poll, proc and random +features, so file syscalls return `ENOSYS` and bundlers can drop `uwasi`'s file system. +With `--enable-code-coverage`, the Node wrapper adds an in-memory file system so the +test runner can read the coverage profile. To give an application a file system, pass +your own `wasi` object to `instantiate`. + The browser main-thread setup rejects blocking `poll_oneoff` clock waits instead of freezing the page. Run guests that require blocking waits in a worker. Node and browser workers use `uwasi`'s blocking implementation. From 0cd2df484e879efb74b6a33e5a77bebaedb7ee62 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sat, 7 Nov 2026 16:26:57 +0900 Subject: [PATCH 17/18] Runtime: Copy only the view's window in swjs_load_typed_array (#810) * Runtime: Copy only the view's window in swjs_load_typed_array `new Uint8Array(typedArray.buffer)` views the whole backing `ArrayBuffer`, ignoring the `byteOffset` and `byteLength` of the view it was handed. A view with a non-zero offset (anything from `subarray`, or `new Uint8Array(buffer, offset, length)`) therefore arrives in the guest shifted by that offset, silently wrong rather than failing. It is also a memory-safety bug: `JSTypedArray.copyMemory(to:)` sizes the destination from the view's own `length`, so whenever the view is smaller than its backing buffer the runtime writes past the end of the destination and corrupts whatever follows it in linear memory. Co-Authored-By: Claude Opus 5 * Tests: Use Int32(bitPattern:) for the 0xDEADBEEF sentinel Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5 --- Plugins/PackageToJS/Templates/runtime.mjs | 7 +- Runtime/src/index.ts | 11 +- Runtime/test/load-typed-array.test.ts | 107 ++++++++++++++++++ .../JSTypedArrayTests.swift | 78 +++++++++++++ 4 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 Runtime/test/load-typed-array.test.ts diff --git a/Plugins/PackageToJS/Templates/runtime.mjs b/Plugins/PackageToJS/Templates/runtime.mjs index b0be54bb4..6170e58d0 100644 --- a/Plugins/PackageToJS/Templates/runtime.mjs +++ b/Plugins/PackageToJS/Templates/runtime.mjs @@ -759,7 +759,12 @@ class SwiftRuntime { swjs_load_typed_array: (ref, buffer) => { const memory = this.memory; const typedArray = memory.getObject(ref); - const bytes = new Uint8Array(typedArray.buffer); + // Copy only the window the view describes. `typedArray.buffer` + // is the whole backing `ArrayBuffer`, which may be larger than + // the view and may start before it; the guest sizes the + // destination from the view's own length, so viewing the entire + // buffer would both shift the bytes and overrun the destination. + const bytes = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); this.getUint8Array().set(bytes, buffer >>> 0); }, swjs_release: (ref) => { diff --git a/Runtime/src/index.ts b/Runtime/src/index.ts index 879774a7d..e05bf712e 100644 --- a/Runtime/src/index.ts +++ b/Runtime/src/index.ts @@ -763,7 +763,16 @@ export class SwiftRuntime { swjs_load_typed_array: (ref: ref, buffer: pointer) => { const memory = this.memory; const typedArray = memory.getObject(ref); - const bytes = new Uint8Array(typedArray.buffer); + // Copy only the window the view describes. `typedArray.buffer` + // is the whole backing `ArrayBuffer`, which may be larger than + // the view and may start before it; the guest sizes the + // destination from the view's own length, so viewing the entire + // buffer would both shift the bytes and overrun the destination. + const bytes = new Uint8Array( + typedArray.buffer, + typedArray.byteOffset, + typedArray.byteLength, + ); this.getUint8Array().set(bytes, buffer >>> 0); }, diff --git a/Runtime/test/load-typed-array.test.ts b/Runtime/test/load-typed-array.test.ts new file mode 100644 index 000000000..724aa23fa --- /dev/null +++ b/Runtime/test/load-typed-array.test.ts @@ -0,0 +1,107 @@ +import { describe, expect, test } from "vitest"; +import { SwiftRuntime } from "../src/index.js"; + +// `swjs_load_typed_array` must copy only the window a TypedArray view describes, +// not its whole backing `ArrayBuffer`. The guest sizes the destination from the +// view's own `length`/`byteLength`, so copying the entire buffer both shifts the +// bytes (a view with a non-zero `byteOffset` lands offset in the guest) and +// writes past the end of the destination. +const DESTINATION = 1024; + +function makeRuntime(): { runtime: SwiftRuntime; memory: WebAssembly.Memory } { + const memory = new WebAssembly.Memory({ initial: 1 }); + const runtime = new SwiftRuntime(); + runtime.setInstance({ + exports: { + memory, + swjs_library_version: () => 708, + }, + } as unknown as WebAssembly.Instance); + return { runtime, memory }; +} + +describe("swjs_load_typed_array respects the view's window", () => { + test("copies a Uint8Array view from its byteOffset", () => { + const { runtime, memory } = makeRuntime(); + const backing = new ArrayBuffer(32); + new Uint8Array(backing).set( + Array.from({ length: 32 }, (_, i) => 0xa0 + i), + ); + const view = new Uint8Array(backing, 8, 8); + + const space = (runtime as any).memory; + const imports = runtime.wasmImports as any; + imports.swjs_load_typed_array(space.retain(view), DESTINATION); + + const guest = new Uint8Array(memory.buffer); + expect( + Array.from(guest.subarray(DESTINATION, DESTINATION + 8)), + ).toEqual(Array.from(view)); + }); + + test("does not write past the end of the view", () => { + const { runtime, memory } = makeRuntime(); + const backing = new ArrayBuffer(32); + new Uint8Array(backing).fill(0xff); + const view = new Uint8Array(backing, 8, 8); + + // Fill the guest memory around the destination with a sentinel so any + // byte written beyond the view's `byteLength` is visible. + const guest = new Uint8Array(memory.buffer); + guest.fill(0x5a, DESTINATION, DESTINATION + 64); + + const space = (runtime as any).memory; + const imports = runtime.wasmImports as any; + imports.swjs_load_typed_array(space.retain(view), DESTINATION); + + expect( + Array.from(guest.subarray(DESTINATION + 8, DESTINATION + 64)), + ).toEqual(new Array(56).fill(0x5a)); + }); + + test("copies a multi-byte element view from its byteOffset", () => { + const { runtime, memory } = makeRuntime(); + const backing = new ArrayBuffer(32); + new Int32Array(backing).set([1, 2, 3, 4, 5, 6, 7, 8]); + const view = new Int32Array(backing, 8, 4); + + const space = (runtime as any).memory; + const imports = runtime.wasmImports as any; + imports.swjs_load_typed_array(space.retain(view), DESTINATION); + + const guest = new Int32Array(memory.buffer, DESTINATION, 4); + expect(Array.from(guest)).toEqual([3, 4, 5, 6]); + }); + + test("copies a DataView from its byteOffset", () => { + const { runtime, memory } = makeRuntime(); + const backing = new ArrayBuffer(32); + new Uint8Array(backing).set( + Array.from({ length: 32 }, (_, i) => 0xa0 + i), + ); + const view = new DataView(backing, 8, 8); + + const space = (runtime as any).memory; + const imports = runtime.wasmImports as any; + imports.swjs_load_typed_array(space.retain(view), DESTINATION); + + const guest = new Uint8Array(memory.buffer); + expect( + Array.from(guest.subarray(DESTINATION, DESTINATION + 8)), + ).toEqual(Array.from(new Uint8Array(backing, 8, 8))); + }); + + test("still copies a whole-buffer view unchanged", () => { + const { runtime, memory } = makeRuntime(); + const view = new Uint8Array([1, 2, 3, 4, 5]); + + const space = (runtime as any).memory; + const imports = runtime.wasmImports as any; + imports.swjs_load_typed_array(space.retain(view), DESTINATION); + + const guest = new Uint8Array(memory.buffer); + expect( + Array.from(guest.subarray(DESTINATION, DESTINATION + 5)), + ).toEqual([1, 2, 3, 4, 5]); + }); +}); diff --git a/Tests/JavaScriptKitTests/JSTypedArrayTests.swift b/Tests/JavaScriptKitTests/JSTypedArrayTests.swift index a4649879e..ad12a4e81 100644 --- a/Tests/JavaScriptKitTests/JSTypedArrayTests.swift +++ b/Tests/JavaScriptKitTests/JSTypedArrayTests.swift @@ -110,6 +110,84 @@ final class JSTypedArrayTests: XCTestCase { } } + func testTypedArrayWithByteOffset() { + // A view over part of a larger `ArrayBuffer`: `byteOffset` is non-zero and + // `byteLength` is smaller than the backing buffer. Copying the whole + // buffer instead of the view's window would both shift the bytes and + // write past the end of the destination, which is sized from `length`. + let backingLength = 32 + let viewOffset = 8 + let viewLength = 8 + + let arrayBuffer = JSObject.global.ArrayBuffer.function!.new(backingLength) + let wholeBuffer = JSTypedArray( + unsafelyWrapping: JSObject.global.Uint8Array.function!.new(arrayBuffer) + ) + for i in 0..( + unsafelyWrapping: JSObject.global.Uint8Array.function!.new( + arrayBuffer, + viewOffset, + viewLength + ) + ) + XCTAssertEqual(view.length, viewLength) + XCTAssertEqual(view.lengthInBytes, viewLength) + + let expected = (0...allocate(capacity: backingLength) + defer { storage.deallocate() } + storage.initialize(repeating: sentinel) + let destination = UnsafeMutableBufferPointer(rebasing: storage[0..(elements).jsObject.buffer.object! + let view = JSTypedArray( + unsafelyWrapping: JSObject.global.Int32Array.function!.new( + arrayBuffer, + viewOffsetInBytes, + viewLength + ) + ) + XCTAssertEqual(view.length, viewLength) + XCTAssertEqual(view.lengthInBytes, viewLength * MemoryLayout.size) + + let expected: [Int32] = [3, 4, 5, 6] + XCTAssertEqual(view.withUnsafeBytes { Array($0) }, expected) + + let sentinel = Int32(bitPattern: 0xDEAD_BEEF) + let storage = UnsafeMutableBufferPointer.allocate(capacity: elements.count) + defer { storage.deallocate() } + storage.initialize(repeating: sentinel) + let destination = UnsafeMutableBufferPointer(rebasing: storage[0..(length: 100) for i in 0..<100 { From 0a1c5a89adf273f99a626fce1dd3f255c45285d2 Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Sat, 7 Nov 2026 17:28:18 +1000 Subject: [PATCH 18/18] BridgeJS: Normalize pointer in swift_js_push_typed_array (#828) --- Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift | 3 ++- .../BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/AliasInClosure.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/ArrayTypes.js | 3 ++- .../BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js | 3 ++- .../BridgeJSLinkTests/AsyncAssociatedValueEnum.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/AsyncImport.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/ClassWithNestedTypes.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/DefaultParameters.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/DocComments.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/EnumAlias.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js | 3 ++- .../BridgeJSLinkTests/EnumAssociatedValueImport.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/EnumCase.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/EnumCaseImport.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/EnumNamespace.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/EnumRawType.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/ExtensionNestedTypes.js | 3 ++- .../BridgeJSLinkTests/ExtensionOrderIndependence.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/ExtensionScopeParity.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/FixedWidthIntegers.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/GenericImports.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/GlobalGetter.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js | 3 ++- .../BridgeJSLinkTests/IdentityModeClass.ConfigPointer.js | 3 ++- .../BridgeJSLinkTests/IdentityModeClass.PerClass.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/IdentityModeClass.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/ImportArray.js | 3 ++- .../BridgeJSLinkTests/ImportedTypeInExportedInterface.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/JSClass.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/JSImportBareModule.js | 3 ++- .../BridgeJSLinkTests/JSImportBareModuleFallback.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/JSImportModule.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/JSNameOverride.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/JSNameTypes.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/JSTypedArrayTypes.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/JSValue.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/MixedGlobal.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/MixedModules.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/MixedPrivate.js | 3 ++- .../BridgeJSLinkTests/NamespacedClassSignature.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/Namespaces.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/NestedType.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/NestedTypeNameCollision.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/Optionals.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/PropertyTypes.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/Protocol.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/RelativeQualifiedTypes.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/StaticFunctions.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/StaticProperties.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/StringParameter.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/StringReturn.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/StructWithNestedTypes.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/SwiftClass.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/SwiftClosure.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/SwiftStruct.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/SwiftTypedClosureAccess.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/Throws.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/UnsafePointer.js | 3 ++- .../__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js | 3 ++- 74 files changed, 148 insertions(+), 74 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index d882aad1c..82150d065 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -782,9 +782,10 @@ public struct BridgeJSLink { printer.indent { printer.write("const Ctor = taCtors[kind];") printer.write("const byteLen = count * Ctor.BYTES_PER_ELEMENT;") + printer.write("const start = ptr >>> 0;") // slice() copies the bytes into a new ArrayBuffer that is properly aligned printer.write( - "const copy = \(JSGlueVariableScope.reservedMemory).buffer.slice(ptr, ptr + byteLen);" + "const copy = \(JSGlueVariableScope.reservedMemory).buffer.slice(start, start + byteLen);" ) printer.write("\(JSGlueVariableScope.reservedTaStack).push(Array.from(new Ctor(copy)));") } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js index adc2e0fc9..dafac12d3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Alias.js @@ -505,7 +505,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AliasInClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AliasInClosure.js index d4174627e..4793a3d48 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AliasInClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AliasInClosure.js @@ -130,7 +130,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js index 6365fd99e..1e46aa559 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js @@ -568,7 +568,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_Point"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js index 980dd9fdc..ab64ccfa0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js @@ -480,7 +480,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_AsyncPoint"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncAssociatedValueEnum.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncAssociatedValueEnum.js index 69f17eae3..3e1483580 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncAssociatedValueEnum.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncAssociatedValueEnum.js @@ -245,7 +245,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js index db15b92a8..7e6c1e2c4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncImport.js @@ -227,7 +227,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js index f6da4e275..0b854158d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/AsyncStaticImport.js @@ -227,7 +227,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ClassWithNestedTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ClassWithNestedTypes.js index 1d7ebeabf..08cab592c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ClassWithNestedTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ClassWithNestedTypes.js @@ -122,7 +122,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_Account_Credentials"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js index cbca91ea2..f8a62adb1 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js @@ -492,7 +492,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_Config"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js index ab6cf6ebe..6e763b743 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js @@ -472,7 +472,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_Counters"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DocComments.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DocComments.js index 902f06ff9..aa3ac20c9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DocComments.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DocComments.js @@ -122,7 +122,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_Point"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAlias.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAlias.js index 3ff888129..00725576a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAlias.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAlias.js @@ -105,7 +105,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js index 36d219f64..3369c92f9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js @@ -1067,7 +1067,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_Point"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValueImport.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValueImport.js index 0d770ed41..df18151cc 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValueImport.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValueImport.js @@ -150,7 +150,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js index 999d1847f..5e55689ff 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js @@ -129,7 +129,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCaseImport.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCaseImport.js index 3a78dd143..20e16735c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCaseImport.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCaseImport.js @@ -111,7 +111,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js index b838f4c96..a8a01bda5 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js @@ -149,7 +149,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js index 929f55c86..e63ffc2ff 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js @@ -130,7 +130,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js index e33778458..299a1d730 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js @@ -532,7 +532,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionNestedTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionNestedTypes.js index 1b54d416e..b573e3559 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionNestedTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionNestedTypes.js @@ -176,7 +176,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_Library_Shelf"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionOrderIndependence.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionOrderIndependence.js index cda13ba4c..094d37c11 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionOrderIndependence.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionOrderIndependence.js @@ -125,7 +125,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_Depot_Crate"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionScopeParity.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionScopeParity.js index d0d1ea8bd..ca1cf7361 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionScopeParity.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ExtensionScopeParity.js @@ -121,7 +121,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_Meta"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/FixedWidthIntegers.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/FixedWidthIntegers.js index 50d25d09b..636aacd1e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/FixedWidthIntegers.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/FixedWidthIntegers.js @@ -106,7 +106,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js index d6250c200..a39fe8bd7 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GenericImports.js @@ -579,7 +579,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_GenericPoint"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js index 1d299cab4..6917cc24e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js @@ -106,7 +106,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js index 8c3f0b5b4..435110d18 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js @@ -105,7 +105,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.ConfigPointer.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.ConfigPointer.js index cc70a978a..308778af0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.ConfigPointer.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.ConfigPointer.js @@ -105,7 +105,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.PerClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.PerClass.js index b9b854e52..e1717e32e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.PerClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.PerClass.js @@ -105,7 +105,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.js index b9b854e52..e1717e32e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/IdentityModeClass.js @@ -105,7 +105,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js index 2a64c6775..56a1489f5 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js @@ -440,7 +440,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js index 3c4743ee6..ea45f4fb1 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js @@ -476,7 +476,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_FooContainer"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js index edcedc1b7..8de2a8dc0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js @@ -106,7 +106,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js index cbec50c8f..732b4aaec 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js @@ -106,7 +106,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js index 9cbaf2a3e..abd4e32d5 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js @@ -106,7 +106,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModule.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModule.js index 50ed98d9a..f72355ae0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModule.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModule.js @@ -111,7 +111,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModuleFallback.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModuleFallback.js index ca94e5a13..bf2c55047 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModuleFallback.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportBareModuleFallback.js @@ -108,7 +108,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportModule.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportModule.js index af4273cc3..130c0367c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportModule.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSImportModule.js @@ -108,7 +108,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameOverride.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameOverride.js index 0190b9c65..5025b2803 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameOverride.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameOverride.js @@ -127,7 +127,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_RenamedVector"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameTypes.js index 107f497fc..bbd490bd5 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSNameTypes.js @@ -110,7 +110,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSTypedArrayTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSTypedArrayTypes.js index 9d03440f5..8ce616dd0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSTypedArrayTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSTypedArrayTypes.js @@ -105,7 +105,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js index afccabed4..37c4134d6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js @@ -439,7 +439,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js index 964b97e3a..dfe74e98b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js @@ -105,7 +105,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js index d8eee50de..4219f5249 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js @@ -105,7 +105,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js index 359f5ddd9..405be1d28 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js @@ -105,7 +105,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NamespacedClassSignature.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NamespacedClassSignature.js index 1d6b6c343..db7ead8eb 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NamespacedClassSignature.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NamespacedClassSignature.js @@ -130,7 +130,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js index e76f92d8f..a40655ea6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js @@ -447,7 +447,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js index 31e413e1f..815e564be 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js @@ -447,7 +447,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedType.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedType.js index 82710d04b..a1c133290 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedType.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedType.js @@ -130,7 +130,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_User_Stats"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedTypeNameCollision.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedTypeNameCollision.js index 541ad55df..b9697fc97 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedTypeNameCollision.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/NestedTypeNameCollision.js @@ -126,7 +126,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_Catalog_Entry"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js index 7aaa5296c..ac372c3d1 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js @@ -463,7 +463,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js index 3b8c9adbc..2d89454c2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js @@ -106,7 +106,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js index 1177dc82b..d3b49e4f3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js @@ -106,7 +106,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js index 44eab0d15..d136df4fc 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js @@ -105,7 +105,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js index 945759fb1..5ab588886 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js @@ -532,7 +532,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js index a9730573c..c35d725e6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ProtocolInClosure.js @@ -130,7 +130,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/RelativeQualifiedTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/RelativeQualifiedTypes.js index 06af75757..87daa2d84 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/RelativeQualifiedTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/RelativeQualifiedTypes.js @@ -148,7 +148,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_Library_Shelf"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.js index c5e67f8ae..deb145efa 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReservedWordParameters.js @@ -131,7 +131,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js index 4cc10e4b9..a5f1258e4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js @@ -149,7 +149,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js index b9c8414b0..e52f9d5dd 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js @@ -149,7 +149,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js index 7eff82661..94888662f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js @@ -110,7 +110,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js index f8aa35927..84fb321ae 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js @@ -110,7 +110,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js index 6dc173b63..78f6a8dbc 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js @@ -106,7 +106,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js index eb4e4c37b..0a8460da0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js @@ -106,7 +106,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StructWithNestedTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StructWithNestedTypes.js index f9b50f9f8..c5e8ebe24 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StructWithNestedTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StructWithNestedTypes.js @@ -164,7 +164,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_Shape"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js index e171064a6..fc6903739 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js @@ -106,7 +106,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js index 082a42323..ece62f6ac 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js @@ -574,7 +574,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_Animal"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js index 3045dd8cb..eb2347864 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js @@ -227,7 +227,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js index 39ba60207..7ba2ada2f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js @@ -617,7 +617,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_DataPoint"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js index 0f0838b41..c1bb5d023 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js @@ -458,7 +458,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_Point"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftTypedClosureAccess.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftTypedClosureAccess.js index 80e2a1984..1abc20336 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftTypedClosureAccess.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftTypedClosureAccess.js @@ -130,7 +130,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js index 5a575ffed..3b36bb511 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js @@ -105,7 +105,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {}; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js index ef00d53a6..f3d2a217a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js @@ -122,7 +122,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["swift_js_struct_lower_PointerFields"] = function(objectId) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js index 5abfccc3f..c8693eeb3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js @@ -106,7 +106,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_push_typed_array"] = function(kind, ptr, count) { const Ctor = taCtors[kind]; const byteLen = count * Ctor.BYTES_PER_ELEMENT; - const copy = memory.buffer.slice(ptr, ptr + byteLen); + const start = ptr >>> 0; + const copy = memory.buffer.slice(start, start + byteLen); taStack.push(Array.from(new Ctor(copy))); } bjs["bjs_core_register_type_handles"] = function() {};