diff --git a/Plugins/PackageToJS/Templates/runtime.mjs b/Plugins/PackageToJS/Templates/runtime.mjs index e0bcf3e05..d79275476 100644 --- a/Plugins/PackageToJS/Templates/runtime.mjs +++ b/Plugins/PackageToJS/Templates/runtime.mjs @@ -30,6 +30,7 @@ const decode = (kind, payload1, payload2, objectSpace) => { case 1: return true; } + // falls through case 2 /* Kind.Number */: return payload2; case 1 /* Kind.String */: @@ -555,7 +556,7 @@ class SwiftRuntime { swjs_call_function: (ref, argv, argc, payload1_ptr, payload2_ptr) => { const memory = this.memory; const func = memory.getObject(ref); - let result = undefined; + let result; try { const args = decodeArray(argv, argc, this.getDataView(), memory); result = func(...args); @@ -590,9 +591,8 @@ class SwiftRuntime { const memory = this.memory; const obj = memory.getObject(obj_ref); const func = memory.getObject(func_ref); - let result = undefined; const args = decodeArray(argv, argc, this.getDataView(), memory); - result = func.apply(obj, args); + const result = func.apply(obj, args); return writeAndReturnKindBits(result, payload1_ptr, payload2_ptr, false, this.getDataView(), this.memory); }, swjs_call_new: (ref, argv, argc) => { @@ -744,9 +744,10 @@ class SwiftRuntime { broker.onReceivingResponse(message); break; } - default: + default: { const unknownMessage = message; throw new Error(`Unknown message type: ${unknownMessage}`); + } } }); }, @@ -773,9 +774,10 @@ class SwiftRuntime { broker.onReceivingResponse(message); break; } - default: + default: { const unknownMessage = message; throw new Error(`Unknown message type: ${unknownMessage}`); + } } }); }, diff --git a/Runtime/src/index.ts b/Runtime/src/index.ts index 1d36c95d1..5d6fe258f 100644 --- a/Runtime/src/index.ts +++ b/Runtime/src/index.ts @@ -430,7 +430,7 @@ export class SwiftRuntime { ) => { const memory = this.memory; const func = memory.getObject(ref); - let result = undefined; + let result: any; try { const args = JSValue.decodeArray( argv, @@ -534,14 +534,13 @@ export class SwiftRuntime { const memory = this.memory; const obj = memory.getObject(obj_ref); const func = memory.getObject(func_ref); - let result = undefined; const args = JSValue.decodeArray( argv, argc, this.getDataView(), memory, ); - result = func.apply(obj, args); + const result = func.apply(obj, args); return JSValue.writeAndReturnKindBits( result, payload1_ptr, @@ -799,11 +798,12 @@ export class SwiftRuntime { broker.onReceivingResponse(message); break; } - default: + default: { const unknownMessage: never = message; throw new Error( `Unknown message type: ${unknownMessage}`, ); + } } }); }, @@ -838,11 +838,12 @@ export class SwiftRuntime { broker.onReceivingResponse(message); break; } - default: + default: { const unknownMessage: never = message; throw new Error( `Unknown message type: ${unknownMessage}`, ); + } } }); }, diff --git a/Runtime/src/js-value.ts b/Runtime/src/js-value.ts index 26574b532..b044e5cbe 100644 --- a/Runtime/src/js-value.ts +++ b/Runtime/src/js-value.ts @@ -31,6 +31,7 @@ export const decode = ( case 1: return true; } + // falls through case Kind.Number: return payload2;