From 0f417867fb439be95c9eea9885034be4cb2f146a Mon Sep 17 00:00:00 2001 From: Julian Schurhammer Date: Mon, 13 Mar 2023 10:30:28 +1300 Subject: check that custom hashcode is a number --- src/persistent-hash-map.mjs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/persistent-hash-map.mjs b/src/persistent-hash-map.mjs index bf5ef53..f454c7d 100644 --- a/src/persistent-hash-map.mjs +++ b/src/persistent-hash-map.mjs @@ -1,3 +1,8 @@ +/** + * This file uses jsdoc to annotate types. + * These types can be checked using the typescript compiler with "checkjs" option. + */ + import { isEqual } from "./gleam.mjs"; const referenceMap = new WeakMap(); @@ -70,7 +75,10 @@ function hashObject(o) { const proto = Object.getPrototypeOf(o); if (proto !== null && typeof proto.hashCode === "function") { try { - return o.hashCode(o); + const code = o.hashCode(o); + if (typeof code === "number") { + return code + } } catch {} } if (o instanceof Promise || o instanceof WeakSet || o instanceof WeakMap) { @@ -945,4 +953,3 @@ export default class PMap { } } -export function __include_me() {} -- cgit v1.2.3