diff options
author | Julian Schurhammer <julian.schurhammer@gmail.com> | 2023-03-13 10:30:28 +1300 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2023-03-13 10:49:34 +0000 |
commit | 0f417867fb439be95c9eea9885034be4cb2f146a (patch) | |
tree | 6c797cad535fe3ba1b7bae1ab5609d80d2b02c6a | |
parent | 13e17d41c43e7acc1cb2479e69f88858a71e2251 (diff) | |
download | gleam_stdlib-0f417867fb439be95c9eea9885034be4cb2f146a.tar.gz gleam_stdlib-0f417867fb439be95c9eea9885034be4cb2f146a.zip |
check that custom hashcode is a number
-rw-r--r-- | src/persistent-hash-map.mjs | 11 |
1 files changed, 9 insertions, 2 deletions
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() {} |