const errorConstructors = {
    Error,
    TypeError,
    RangeError,
    ReferenceError,
    SyntaxError,
    URIError,
    EvalError,
};
export class ErrorReviver {
    nativeTypeName() {
        return "Error";
    }
    isInstance(value) {
        return value instanceof Error;
    }
    serialize(value) {
        return {
            __nativeType: this.nativeTypeName(),
            name: value.name,
            message: value.message,
            stack: value.stack,
        };
    }
    validate(value) {
        return typeof value.name === "string" && typeof value.message === "string";
    }
    revive(value) {
        const Ctor = errorConstructors[value.name] ?? Error;
        const error = new Ctor(value.message);
        error.name = value.name;
        if (typeof value.stack === "string") {
            error.stack = value.stack;
        }
        return error;
    }
}
