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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,11 @@
@JS func convertPriority(_ status: HttpStatus) -> Priority
@JS func validateSession(_ session: SessionId) -> Theme

enum FeatureFlag: String {
@JS enum ImportedFlag: String {
case foo = "foo"
case bar = "bar"
}
extension FeatureFlag: _BridgedSwiftEnumNoPayload {}

@JSFunction func takesFeatureFlag(_ flag: FeatureFlag) throws(JSException) -> Void
@JSFunction func takesFeatureFlag(_ flag: ImportedFlag) throws(JSException) -> Void

@JSFunction func returnsFeatureFlag() throws(JSException) -> FeatureFlag
@JSFunction func returnsFeatureFlag() throws(JSException) -> ImportedFlag
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,35 @@
],
"swiftCallName" : "Ratio",
"tsFullPath" : "Ratio"
},
{
"cases" : [
{
"associatedValues" : [

],
"name" : "foo",
"rawValue" : "foo"
},
{
"associatedValues" : [

],
"name" : "bar",
"rawValue" : "bar"
}
],
"emitStyle" : "const",
"name" : "ImportedFlag",
"rawType" : "String",
"staticMethods" : [

],
"staticProperties" : [

],
"swiftCallName" : "ImportedFlag",
"tsFullPath" : "ImportedFlag"
}
],
"exposeToGlobal" : false,
Expand Down Expand Up @@ -640,7 +669,7 @@
"type" : {
"rawValueEnum" : {
"_0" : "FeatureFlag",
"_1" : "String"
"_1" : "Bool"
}
}
}
Expand All @@ -665,7 +694,7 @@
"returnType" : {
"rawValueEnum" : {
"_0" : "FeatureFlag",
"_1" : "String"
"_1" : "Bool"
}
}
},
Expand All @@ -686,7 +715,7 @@
"_0" : {
"rawValueEnum" : {
"_0" : "FeatureFlag",
"_1" : "String"
"_1" : "Bool"
}
},
"_1" : "null"
Expand All @@ -699,7 +728,7 @@
"_0" : {
"rawValueEnum" : {
"_0" : "FeatureFlag",
"_1" : "String"
"_1" : "Bool"
}
},
"_1" : "null"
Expand Down Expand Up @@ -1541,7 +1570,7 @@
"name" : "flag",
"type" : {
"rawValueEnum" : {
"_0" : "FeatureFlag",
"_0" : "ImportedFlag",
"_1" : "String"
}
}
Expand All @@ -1566,7 +1595,7 @@
],
"returnType" : {
"rawValueEnum" : {
"_0" : "FeatureFlag",
"_0" : "ImportedFlag",
"_1" : "String"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ extension Precision: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {
extension Ratio: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {
}

extension ImportedFlag: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {
}

@_expose(wasm, "bjs_setTheme")
@_cdecl("bjs_setTheme")
public func _bjs_setTheme(_ themeBytes: Int32, _ themeLength: Int32) -> Void {
Expand Down Expand Up @@ -104,9 +107,9 @@ public func _bjs_roundTripOptionalTSTheme(_ inputIsSome: Int32, _ inputBytes: In

@_expose(wasm, "bjs_setFeatureFlag")
@_cdecl("bjs_setFeatureFlag")
public func _bjs_setFeatureFlag(_ flagBytes: Int32, _ flagLength: Int32) -> Void {
public func _bjs_setFeatureFlag(_ flag: Int32) -> Void {
#if arch(wasm32)
let flag = FeatureFlag.bridgeJSLiftParameter(flagBytes, flagLength)
let flag = FeatureFlag.bridgeJSLiftParameter(flag)
setFeatureFlag(_: flag)
#else
fatalError("Only available on WebAssembly")
Expand All @@ -115,7 +118,7 @@ public func _bjs_setFeatureFlag(_ flagBytes: Int32, _ flagLength: Int32) -> Void

@_expose(wasm, "bjs_getFeatureFlag")
@_cdecl("bjs_getFeatureFlag")
public func _bjs_getFeatureFlag() -> Void {
public func _bjs_getFeatureFlag() -> Int32 {
#if arch(wasm32)
let ret = getFeatureFlag()
return ret.bridgeJSLowerReturn()
Expand All @@ -126,9 +129,9 @@ public func _bjs_getFeatureFlag() -> Void {

@_expose(wasm, "bjs_roundTripOptionalFeatureFlag")
@_cdecl("bjs_roundTripOptionalFeatureFlag")
public func _bjs_roundTripOptionalFeatureFlag(_ inputIsSome: Int32, _ inputBytes: Int32, _ inputLength: Int32) -> Void {
public func _bjs_roundTripOptionalFeatureFlag(_ inputIsSome: Int32, _ inputValue: Int32) -> Void {
#if arch(wasm32)
let input = Optional<FeatureFlag>.bridgeJSLiftParameter(inputIsSome, inputBytes, inputLength)
let input = Optional<FeatureFlag>.bridgeJSLiftParameter(inputIsSome, inputValue)
let ret = roundTripOptionalFeatureFlag(_: input)
return ret.bridgeJSLowerReturn()
#else
Expand Down Expand Up @@ -526,6 +529,10 @@ extension Ratio: BridgedSwiftGenericBridgeable {
@_spi(BridgeJS) public static let bridgeJSTypeHandle = Ratio.bridgeJSMakeTypeHandle()
}

extension ImportedFlag: BridgedSwiftGenericBridgeable {
@_spi(BridgeJS) public static let bridgeJSTypeHandle = ImportedFlag.bridgeJSMakeTypeHandle()
}

#if arch(wasm32)
@_extern(wasm, module: "TestModule", name: "bjs_takesFeatureFlag")
fileprivate func bjs_takesFeatureFlag_extern(_ flagWord0: Int32, _ flagWord1: Int32, _ flagWord2: Int32) -> Void
Expand All @@ -538,7 +545,7 @@ fileprivate func bjs_takesFeatureFlag_extern(_ flagWord0: Int32, _ flagWord1: In
return bjs_takesFeatureFlag_extern(flagWord0, flagWord1, flagWord2)
}

func _$takesFeatureFlag(_ flag: FeatureFlag) throws(JSException) -> Void {
func _$takesFeatureFlag(_ flag: ImportedFlag) throws(JSException) -> Void {
flag.bridgeJSWithLoweredParameter { (flagWord0, flagWord1, flagWord2) in
bjs_takesFeatureFlag(flagWord0, flagWord1, flagWord2)
}
Expand All @@ -559,12 +566,12 @@ fileprivate func bjs_returnsFeatureFlag_extern() -> Int32 {
return bjs_returnsFeatureFlag_extern()
}

func _$returnsFeatureFlag() throws(JSException) -> FeatureFlag {
func _$returnsFeatureFlag() throws(JSException) -> ImportedFlag {
let ret = bjs_returnsFeatureFlag()
if let error = _swift_js_take_exception() {
throw error
}
return FeatureFlag.bridgeJSLiftReturn(ret)
return ImportedFlag.bridgeJSLiftReturn(ret)
}

#if arch(wasm32)
Expand All @@ -586,6 +593,7 @@ public func _bjs_TestModule_register_type_handles() {
SessionId.bridgeJSTypeID,
Precision.bridgeJSTypeID,
Ratio.bridgeJSTypeID,
ImportedFlag.bridgeJSTypeID,
]
typeIds.withUnsafeBufferPointer { buffer in
_bjs_TestModule_register_type_handles_extern(buffer.baseAddress, Int32(buffer.count))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export const RatioValues: {
};
export type RatioTag = typeof RatioValues[keyof typeof RatioValues];

export const ImportedFlagValues: {
readonly Foo: "foo";
readonly Bar: "bar";
};
export type ImportedFlagTag = typeof ImportedFlagValues[keyof typeof ImportedFlagValues];

export type ThemeObject = typeof ThemeValues;

export type FeatureFlagObject = typeof FeatureFlagValues;
Expand All @@ -109,6 +115,8 @@ export type PrecisionObject = typeof PrecisionValues;

export type RatioObject = typeof RatioValues;

export type ImportedFlagObject = typeof ImportedFlagValues;

export type Exports = {
setTheme(theme: ThemeTag): void;
getTheme(): ThemeTag;
Expand Down Expand Up @@ -159,10 +167,11 @@ export type Exports = {
SessionId: SessionIdObject
Precision: PrecisionObject
Ratio: RatioObject
ImportedFlag: ImportedFlagObject
}
export type Imports = {
takesFeatureFlag(flag: FeatureFlagTag): void;
returnsFeatureFlag(): FeatureFlagTag;
takesFeatureFlag(flag: ImportedFlagTag): void;
returnsFeatureFlag(): ImportedFlagTag;
}
export function createInstantiator(options: {
imports: Imports;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export const RatioValues = {
Pi: 3.14159,
};

export const ImportedFlagValues = {
Foo: "foo",
Bar: "bar",
};

export async function createInstantiator(options, swift) {
let instance;
let memory;
Expand Down Expand Up @@ -873,31 +878,17 @@ export async function createInstantiator(options, swift) {
return optResult;
},
setFeatureFlag: function bjs_setFeatureFlag(flag) {
const flagBytes = textEncoder.encode(flag);
const flagId = swift.memory.retain(flagBytes);
instance.exports.bjs_setFeatureFlag(flagId, flagBytes.length);
instance.exports.bjs_setFeatureFlag(flag);
},
getFeatureFlag: function bjs_getFeatureFlag() {
instance.exports.bjs_getFeatureFlag();
const ret = tmpRetString;
tmpRetString = undefined;
return ret;
const ret = instance.exports.bjs_getFeatureFlag();
return ret !== 0;
},
roundTripOptionalFeatureFlag: function bjs_roundTripOptionalFeatureFlag(input) {
const isSome = input != null;
let result, result1;
if (isSome) {
const inputBytes = textEncoder.encode(input);
const inputId = swift.memory.retain(inputBytes);
result = inputId;
result1 = inputBytes.length;
} else {
result = 0;
result1 = 0;
}
instance.exports.bjs_roundTripOptionalFeatureFlag(+isSome, result, result1);
const optResult = tmpRetString;
tmpRetString = undefined;
instance.exports.bjs_roundTripOptionalFeatureFlag(+isSome, isSome ? input ? 1 : 0 : 0);
const optResult = tmpRetOptionalBool;
tmpRetOptionalBool = undefined;
return optResult;
},
setHttpStatus: function bjs_setHttpStatus(status) {
Expand Down Expand Up @@ -1050,6 +1041,7 @@ export async function createInstantiator(options, swift) {
SessionId: SessionIdValues,
Precision: PrecisionValues,
Ratio: RatioValues,
ImportedFlag: ImportedFlagValues,
};
_exports = exports;
return exports;
Expand Down
Loading