Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,9 @@ extension BridgeType {
throw BridgeJSCoreError("Namespace enums cannot be used as parameters")
case .nullable(let wrappedType, _):
let wrappedInfo = try wrappedType.loweringParameterInfo(context: context)
if wrappedInfo.loweredParameters.isEmpty {
return LoweringParameterInfo(loweredParameters: [])
}
var params = [("isSome", WasmCoreType.i32)]
params.append(contentsOf: wrappedInfo.loweredParameters)
return LoweringParameterInfo(loweredParameters: params, useBorrowing: wrappedInfo.useBorrowing)
Expand Down
23 changes: 6 additions & 17 deletions Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1051,16 +1051,13 @@ struct IntrinsicJSFragment: Sendable {
)
}

let innerFragment =
if wrappedType.optionalParameterUsesStackABI {
try stackLiftFragment(elementType: wrappedType)
} else {
try liftParameter(type: wrappedType, context: bridgeContext)
}
if wrappedType.optionalParameterUsesStackABI {
return try optionalElementRaiseFragment(wrappedType: wrappedType, kind: kind)
}
return compositeOptionalLiftParameter(
wrappedType: wrappedType,
kind: kind,
innerFragment: innerFragment
innerFragment: try liftParameter(type: wrappedType, context: bridgeContext)
)
}

Expand All @@ -1075,22 +1072,14 @@ struct IntrinsicJSFragment: Sendable {
kind: JSOptionalKind,
innerFragment: IntrinsicJSFragment
) -> IntrinsicJSFragment {
let isStackConvention = wrappedType.optionalParameterUsesStackABI
let absenceLiteral = kind.absenceLiteral

let outerParams: [String]
if isStackConvention {
outerParams = ["isSome"]
} else {
outerParams = ["isSome"] + innerFragment.parameters
}

return IntrinsicJSFragment(
parameters: outerParams,
parameters: ["isSome"] + innerFragment.parameters,
printCode: { arguments, context in
let (scope, printer) = (context.scope, context.printer)
let isSome = arguments[0]
let innerArgs = isStackConvention ? [] : Array(arguments.dropFirst())
let innerArgs = Array(arguments.dropFirst())

let bufferPrinter = CodeFragmentPrinter()
let innerResults = try innerFragment.printCode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,20 +626,20 @@ func _$Promise_resolve_Sq10AsyncThemeO(_ promise: JSObject, _ value: Optional<As

#if arch(wasm32)
@_extern(wasm, module: "bjs", name: "promise_resolve_TestModule_Sq10AsyncPointV")
fileprivate func promise_resolve_TestModule_Sq10AsyncPointV_extern(_ promise: Int32, _ value: Int32) -> Void
fileprivate func promise_resolve_TestModule_Sq10AsyncPointV_extern(_ promise: Int32) -> Void
#else
fileprivate func promise_resolve_TestModule_Sq10AsyncPointV_extern(_ promise: Int32, _ value: Int32) -> Void {
fileprivate func promise_resolve_TestModule_Sq10AsyncPointV_extern(_ promise: Int32) -> Void {
fatalError("Only available on WebAssembly")
}
#endif
@inline(never) fileprivate func promise_resolve_TestModule_Sq10AsyncPointV(_ promise: Int32, _ value: Int32) -> Void {
return promise_resolve_TestModule_Sq10AsyncPointV_extern(promise, value)
@inline(never) fileprivate func promise_resolve_TestModule_Sq10AsyncPointV(_ promise: Int32) -> Void {
return promise_resolve_TestModule_Sq10AsyncPointV_extern(promise)
}

func _$Promise_resolve_Sq10AsyncPointV(_ promise: JSObject, _ value: Optional<AsyncPoint>) throws(JSException) -> Void {
let valueIsSome = value.bridgeJSLowerParameter()
let _ = value.bridgeJSLowerParameter()
let promiseValue = promise.bridgeJSLowerParameter()
promise_resolve_TestModule_Sq10AsyncPointV(promiseValue, valueIsSome)
promise_resolve_TestModule_Sq10AsyncPointV(promiseValue)
if let error = _swift_js_take_exception() { throw error }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,20 +354,20 @@ func _$importGenericDictionary<T: BridgedSwiftGenericBridgeable>(_ values: [Stri

#if arch(wasm32)
@_extern(wasm, module: "TestModule", name: "bjs_importGenericAfterOptionalArray")
fileprivate func bjs_importGenericAfterOptionalArray_extern(_ values: Int32, _ _generic0TypeId: Int32) -> Void
fileprivate func bjs_importGenericAfterOptionalArray_extern(_ _generic0TypeId: Int32) -> Void
#else
fileprivate func bjs_importGenericAfterOptionalArray_extern(_ values: Int32, _ _generic0TypeId: Int32) -> Void {
fileprivate func bjs_importGenericAfterOptionalArray_extern(_ _generic0TypeId: Int32) -> Void {
fatalError("Only available on WebAssembly")
}
#endif
@inline(never) fileprivate func bjs_importGenericAfterOptionalArray(_ values: Int32, _ _generic0TypeId: Int32) -> Void {
return bjs_importGenericAfterOptionalArray_extern(values, _generic0TypeId)
@inline(never) fileprivate func bjs_importGenericAfterOptionalArray(_ _generic0TypeId: Int32) -> Void {
return bjs_importGenericAfterOptionalArray_extern(_generic0TypeId)
}

func _$importGenericAfterOptionalArray<T: BridgedSwiftGenericBridgeable>(_ values: Optional<[Int]>, _ value: T) throws(JSException) -> T {
value.bridgeJSStackPush()
let valuesIsSome = values.bridgeJSLowerParameter()
bjs_importGenericAfterOptionalArray(valuesIsSome, T.bridgeJSTypeID)
let _ = values.bridgeJSLowerParameter()
bjs_importGenericAfterOptionalArray(T.bridgeJSTypeID)
if let error = _swift_js_take_exception() {
throw error
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ func _$logStrings(_ items: [String]) throws(JSException) -> Void {

#if arch(wasm32)
@_extern(wasm, module: "TestModule", name: "bjs_optionalArrayThenArray")
fileprivate func bjs_optionalArrayThenArray_extern(_ a: Int32) -> Int32
fileprivate func bjs_optionalArrayThenArray_extern() -> Int32
#else
fileprivate func bjs_optionalArrayThenArray_extern(_ a: Int32) -> Int32 {
fileprivate func bjs_optionalArrayThenArray_extern() -> Int32 {
fatalError("Only available on WebAssembly")
}
#endif
@inline(never) fileprivate func bjs_optionalArrayThenArray(_ a: Int32) -> Int32 {
return bjs_optionalArrayThenArray_extern(a)
@inline(never) fileprivate func bjs_optionalArrayThenArray() -> Int32 {
return bjs_optionalArrayThenArray_extern()
}

func _$optionalArrayThenArray(_ a: Optional<[Int]>, _ b: [Int]) throws(JSException) -> Int {
let _ = b.bridgeJSLowerParameter()
let aIsSome = a.bridgeJSLowerParameter()
let ret = bjs_optionalArrayThenArray(aIsSome)
let _ = a.bridgeJSLowerParameter()
let ret = bjs_optionalArrayThenArray()
if let error = _swift_js_take_exception() {
throw error
}
Expand All @@ -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, _ a: Int32) -> Int32
fileprivate func bjs_borrowedStringAroundStackParams_extern(_ sBytes: Int32, _ sLength: Int32) -> Int32
#else
fileprivate func bjs_borrowedStringAroundStackParams_extern(_ sBytes: Int32, _ sLength: Int32, _ a: Int32) -> Int32 {
fileprivate func bjs_borrowedStringAroundStackParams_extern(_ sBytes: Int32, _ sLength: Int32) -> Int32 {
fatalError("Only available on WebAssembly")
}
#endif
@inline(never) fileprivate func bjs_borrowedStringAroundStackParams(_ sBytes: Int32, _ sLength: Int32, _ a: Int32) -> Int32 {
return bjs_borrowedStringAroundStackParams_extern(sBytes, sLength, a)
@inline(never) fileprivate func bjs_borrowedStringAroundStackParams(_ sBytes: Int32, _ sLength: Int32) -> Int32 {
return bjs_borrowedStringAroundStackParams_extern(sBytes, sLength)
}

func _$borrowedStringAroundStackParams(_ s: String, _ a: Optional<[Int]>, _ b: [Int]) throws(JSException) -> Int {
let ret0 = s.bridgeJSWithLoweredParameter { (sBytes, sLength) in
let _ = b.bridgeJSLowerParameter()
let aIsSome = a.bridgeJSLowerParameter()
let ret = bjs_borrowedStringAroundStackParams(sBytes, sLength, aIsSome)
let _ = a.bridgeJSLowerParameter()
let ret = bjs_borrowedStringAroundStackParams(sBytes, sLength)
return ret
}
let ret = ret0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,14 +992,14 @@ public func _invoke_swift_closure_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO(_ b

#if arch(wasm32)
@_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModuleSq6AnimalV_Sq6AnimalV")
fileprivate func invoke_js_callback_TestModule_10TestModuleSq6AnimalV_Sq6AnimalV_extern(_ callback: Int32, _ param0: Int32) -> Void
fileprivate func invoke_js_callback_TestModule_10TestModuleSq6AnimalV_Sq6AnimalV_extern(_ callback: Int32) -> Void
#else
fileprivate func invoke_js_callback_TestModule_10TestModuleSq6AnimalV_Sq6AnimalV_extern(_ callback: Int32, _ param0: Int32) -> Void {
fileprivate func invoke_js_callback_TestModule_10TestModuleSq6AnimalV_Sq6AnimalV_extern(_ callback: Int32) -> Void {
fatalError("Only available on WebAssembly")
}
#endif
@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleSq6AnimalV_Sq6AnimalV(_ callback: Int32, _ param0: Int32) -> Void {
return invoke_js_callback_TestModule_10TestModuleSq6AnimalV_Sq6AnimalV_extern(callback, param0)
@inline(never) fileprivate func invoke_js_callback_TestModule_10TestModuleSq6AnimalV_Sq6AnimalV(_ callback: Int32) -> Void {
return invoke_js_callback_TestModule_10TestModuleSq6AnimalV_Sq6AnimalV_extern(callback)
}

#if arch(wasm32)
Expand All @@ -1019,9 +1019,9 @@ private enum _BJS_Closure_10TestModuleSq6AnimalV_Sq6AnimalV {
let callback = JSObject.bridgeJSLiftParameter(callbackId)
return { [callback] param0 in
#if arch(wasm32)
let param0IsSome = param0.bridgeJSLowerParameter()
let _ = param0.bridgeJSLowerParameter()
let callbackValue = callback.bridgeJSLowerParameter()
invoke_js_callback_TestModule_10TestModuleSq6AnimalV_Sq6AnimalV(callbackValue, param0IsSome)
invoke_js_callback_TestModule_10TestModuleSq6AnimalV_Sq6AnimalV(callbackValue)
return Optional<Animal>.bridgeJSLiftReturn()
#else
fatalError("Only available on WebAssembly")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ func _$translate(_ point: Point, _ dx: Int, _ dy: Int) throws(JSException) -> Po

#if arch(wasm32)
@_extern(wasm, module: "TestModule", name: "bjs_roundTripOptional")
fileprivate func bjs_roundTripOptional_extern(_ point: Int32) -> Void
fileprivate func bjs_roundTripOptional_extern() -> Void
#else
fileprivate func bjs_roundTripOptional_extern(_ point: Int32) -> Void {
fileprivate func bjs_roundTripOptional_extern() -> Void {
fatalError("Only available on WebAssembly")
}
#endif
@inline(never) fileprivate func bjs_roundTripOptional(_ point: Int32) -> Void {
return bjs_roundTripOptional_extern(point)
@inline(never) fileprivate func bjs_roundTripOptional() -> Void {
return bjs_roundTripOptional_extern()
}

func _$roundTripOptional(_ point: Optional<Point>) throws(JSException) -> Optional<Point> {
let pointIsSome = point.bridgeJSLowerParameter()
bjs_roundTripOptional(pointIsSome)
let _ = point.bridgeJSLowerParameter()
bjs_roundTripOptional()
if let error = _swift_js_take_exception() {
throw error
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,16 +584,10 @@ export async function createInstantiator(options, swift) {
setException(error);
}
}
bjs["promise_resolve_TestModule_Sq10AsyncPointV"] = function(promise, value) {
bjs["promise_resolve_TestModule_Sq10AsyncPointV"] = function(promise) {
try {
let optResult;
if (value) {
const struct = structHelpers.M10TestModuleT10AsyncPoint.lift();
optResult = struct;
} else {
optResult = null;
}
swift.memory.getObject(promise)[__bjs_promiseSettlers].resolve(optResult);
const optValue = __bjs_codec_Optional_M10TestModuleT10AsyncPoint.lift();
swift.memory.getObject(promise)[__bjs_promiseSettlers].resolve(optValue);
} catch (error) {
setException(error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ export async function createInstantiator(options, swift) {
}

const __bjs_codec_Array_Int = __bjs_arrayCodec(__bjs_primitiveCodecs.Int);
const __bjs_codec_Optional_Array_Int = __bjs_optionalCodec(__bjs_codec_Array_Int);
const __bjs_codec_M10TestModuleT12GenericPoint = {
lower: (v) => {
structHelpers.M10TestModuleT12GenericPoint.lower(v);
Expand Down Expand Up @@ -771,18 +772,12 @@ export async function createInstantiator(options, swift) {
setException(error);
}
}
TestModule["bjs_importGenericAfterOptionalArray"] = function bjs_importGenericAfterOptionalArray(values, tTypeId) {
TestModule["bjs_importGenericAfterOptionalArray"] = function bjs_importGenericAfterOptionalArray(tTypeId) {
try {
const codecT = __bjs_codecForTypeId(tTypeId);
let optResult;
if (values) {
const arrayResult = __bjs_codec_Array_Int.lift();
optResult = arrayResult;
} else {
optResult = null;
}
const optValue = __bjs_codec_Optional_Array_Int.lift();
const value = codecT.lift();
let ret = imports.importGenericAfterOptionalArray(optResult, value);
let ret = imports.importGenericAfterOptionalArray(optValue, value);
codecT.lower(ret);
} catch (error) {
setException(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ export async function createInstantiator(options, swift) {

const __bjs_codec_Array_Int = __bjs_arrayCodec(__bjs_primitiveCodecs.Int);
const __bjs_codec_Array_String = __bjs_arrayCodec(__bjs_stringCodec);
const __bjs_codec_Optional_Array_Int = __bjs_optionalCodec(__bjs_codec_Array_Int);


return {
Expand Down Expand Up @@ -549,35 +550,23 @@ export async function createInstantiator(options, swift) {
setException(error);
}
}
TestModule["bjs_optionalArrayThenArray"] = function bjs_optionalArrayThenArray(a) {
TestModule["bjs_optionalArrayThenArray"] = function bjs_optionalArrayThenArray() {
try {
let optResult;
if (a) {
const arrayResult = __bjs_codec_Array_Int.lift();
optResult = arrayResult;
} else {
optResult = null;
}
const arrayResult1 = __bjs_codec_Array_Int.lift();
let ret = imports.optionalArrayThenArray(optResult, arrayResult1);
const optValue = __bjs_codec_Optional_Array_Int.lift();
const arrayResult = __bjs_codec_Array_Int.lift();
let ret = imports.optionalArrayThenArray(optValue, arrayResult);
return ret;
} catch (error) {
setException(error);
return 0
}
}
TestModule["bjs_borrowedStringAroundStackParams"] = function bjs_borrowedStringAroundStackParams(sBytes, sCount, a) {
TestModule["bjs_borrowedStringAroundStackParams"] = function bjs_borrowedStringAroundStackParams(sBytes, sCount) {
try {
const string = decodeString(sBytes, sCount);
let optResult;
if (a) {
const arrayResult = __bjs_codec_Array_Int.lift();
optResult = arrayResult;
} else {
optResult = null;
}
const arrayResult1 = __bjs_codec_Array_Int.lift();
let ret = imports.borrowedStringAroundStackParams(string, optResult, arrayResult1);
const optValue = __bjs_codec_Optional_Array_Int.lift();
const arrayResult = __bjs_codec_Array_Int.lift();
let ret = imports.borrowedStringAroundStackParams(string, optValue, arrayResult);
return ret;
} catch (error) {
setException(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,17 +1099,11 @@ export async function createInstantiator(options, swift) {
};
return makeClosure(boxPtr, file, line, lower_closure_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO);
}
bjs["invoke_js_callback_TestModule_10TestModuleSq6AnimalV_Sq6AnimalV"] = function(callbackId, param0) {
bjs["invoke_js_callback_TestModule_10TestModuleSq6AnimalV_Sq6AnimalV"] = function(callbackId) {
try {
const callback = swift.memory.getObject(callbackId);
let optResult;
if (param0) {
const struct = structHelpers.M10TestModuleT6Animal.lift();
optResult = struct;
} else {
optResult = null;
}
let ret = callback(optResult);
const optValue = __bjs_codec_Optional_M10TestModuleT6Animal.lift();
let ret = callback(optValue);
__bjs_codec_Optional_M10TestModuleT6Animal.lower(ret);
} catch (error) {
setException(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,16 +568,10 @@ export async function createInstantiator(options, swift) {
setException(error);
}
}
TestModule["bjs_roundTripOptional"] = function bjs_roundTripOptional(point) {
TestModule["bjs_roundTripOptional"] = function bjs_roundTripOptional() {
try {
let optResult;
if (point) {
const struct = structHelpers.M10TestModuleT5Point.lift();
optResult = struct;
} else {
optResult = null;
}
let ret = imports.roundTripOptional(optResult);
const optValue = __bjs_codec_Optional_M10TestModuleT5Point.lift();
let ret = imports.roundTripOptional(optValue);
__bjs_codec_Optional_M10TestModuleT5Point.lower(ret);
} catch (error) {
setException(error);
Expand Down
Loading
Loading