-
Notifications
You must be signed in to change notification settings - Fork 120
Open
Description
Returning an Invalid Date, new Date(NaN), causes a serialization error because JSON converts NaN values to null. It should be returned as Invalid Date without throwing an error.
Reproduction:
import { RpcTarget, newMessagePortRpcSession } from "capnweb";
class MyApi extends RpcTarget {
getInvalidDate(): Date {
return new Date(NaN);
}
}
const localApi = new MyApi();
console.log(localApi.getInvalidDate()); // Invalid Date, no error (as expected)
async function main() {
const channel = new MessageChannel();
newMessagePortRpcSession(channel.port1, new MyApi());
const api = newMessagePortRpcSession<MyApi>(channel.port2);
const invalidDate = await api.getInvalidDate(); // TypeError: unknown special value: ["date",null]
console.log(invalidDate); // expected: Invalid Date, without throwing an error
}
main();Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels