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
5 changes: 4 additions & 1 deletion Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3704,7 +3704,10 @@ extension BridgeType {
extension WasmCoreType {
fileprivate var placeholderValue: String {
switch self {
case .i32, .i64, .f32, .f64, .pointer: return "0"
// A Wasm `i64` return is a JavaScript `BigInt`, so the error-path placeholder
// must be a BigInt literal rather than a plain number.
case .i64: return "0n"
case .i32, .f32, .f64, .pointer: return "0"
}
}
}
5 changes: 4 additions & 1 deletion Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2603,7 +2603,10 @@ fileprivate extension WasmCoreType {
var jsZeroLiteral: String {
switch self {
case .f32, .f64: return "0.0"
case .i32, .i64, .pointer: return "0"
// A Wasm `i64` parameter is passed as a JavaScript `BigInt`, so its zero
// placeholder must be a BigInt literal rather than a plain number.
case .i64: return "0n"
case .i32, .pointer: return "0"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export async function createInstantiator(options, swift) {
},
roundTripOptionalFileSize: function bjs_roundTripOptionalFileSize(input) {
const isSome = input != null;
instance.exports.bjs_roundTripOptionalFileSize(+isSome, isSome ? input : 0);
instance.exports.bjs_roundTripOptionalFileSize(+isSome, isSome ? input : 0n);
const isSome1 = i32Stack.pop();
let optResult;
if (isSome1) {
Expand Down Expand Up @@ -488,7 +488,7 @@ export async function createInstantiator(options, swift) {
},
roundTripOptionalSessionId: function bjs_roundTripOptionalSessionId(input) {
const isSome = input != null;
instance.exports.bjs_roundTripOptionalSessionId(+isSome, isSome ? input : 0);
instance.exports.bjs_roundTripOptionalSessionId(+isSome, isSome ? input : 0n);
const isSome1 = i32Stack.pop();
let optResult;
if (isSome1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export async function createInstantiator(options, swift) {
return ret;
} catch (error) {
setException(error);
return 0
return 0n
}
}
TestModule["bjs_roundTripUInt64"] = function bjs_roundTripUInt64(v) {
Expand All @@ -267,7 +267,7 @@ export async function createInstantiator(options, swift) {
return ret;
} catch (error) {
setException(error);
return 0
return 0n
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export function runJsOptionalSupportTests(rootExports) {
assert.equal(exports.roundTripOptionalIntRawValueEnum(HttpStatus.Ok), HttpStatusValues.Ok);
assert.equal(exports.roundTripOptionalInt64RawValueEnum(FileSize.Tiny), FileSizeValues.Tiny);
assert.equal(exports.roundTripOptionalUInt64RawValueEnum(SessionId.Active), SessionIdValues.Active);
// The `none` case lowers the i64/u64 placeholder as a BigInt (`0n`); a plain `0`
// would throw "Cannot convert 0 to a BigInt" when calling the Wasm export.
assert.equal(exports.roundTripOptionalInt64RawValueEnum(null), null);
assert.equal(exports.roundTripOptionalUInt64RawValueEnum(null), null);
assert.equal(exports.roundTripOptionalTSEnum(TSDirection.North), TSDirection.North);
assert.equal(exports.roundTripOptionalTSStringEnum(TSTheme.Light), TSTheme.Light);
assert.equal(exports.roundTripOptionalNamespacedEnum(Networking.API.Method.Get), Networking.API.Method.Get);
Expand Down
Loading