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
12 changes: 7 additions & 5 deletions Plugins/PackageToJS/Templates/runtime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 */:
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -744,9 +744,10 @@ class SwiftRuntime {
broker.onReceivingResponse(message);
break;
}
default:
default: {
const unknownMessage = message;
throw new Error(`Unknown message type: ${unknownMessage}`);
}
}
});
},
Expand All @@ -773,9 +774,10 @@ class SwiftRuntime {
broker.onReceivingResponse(message);
break;
}
default:
default: {
const unknownMessage = message;
throw new Error(`Unknown message type: ${unknownMessage}`);
}
}
});
},
Expand Down
11 changes: 6 additions & 5 deletions Runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -799,11 +798,12 @@ export class SwiftRuntime {
broker.onReceivingResponse(message);
break;
}
default:
default: {
const unknownMessage: never = message;
throw new Error(
`Unknown message type: ${unknownMessage}`,
);
}
}
});
},
Expand Down Expand Up @@ -838,11 +838,12 @@ export class SwiftRuntime {
broker.onReceivingResponse(message);
break;
}
default:
default: {
const unknownMessage: never = message;
throw new Error(
`Unknown message type: ${unknownMessage}`,
);
}
}
});
},
Expand Down
1 change: 1 addition & 0 deletions Runtime/src/js-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const decode = (
case 1:
return true;
}
// falls through
case Kind.Number:
return payload2;

Expand Down