Skip to content

Commit e2db2e2

Browse files
committed
fix for js
1 parent cf64f30 commit e2db2e2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/pure/hashes.nim

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,17 @@ proc hashData*(data: pointer, size: int): Hash =
9191

9292
proc hashBiggestIntVM(x: BiggestInt): Hash = discard # in vmops
9393

94+
proc hash*(x: string): Hash
95+
9496
proc hashBiggestInt*(x: BiggestInt): Hash {.inline.} =
9597
## for internal use; user code should prefer `hash` overloads
9698
when nimvm: hashBiggestIntVM(x)
97-
else: hashData(cast[pointer](unsafeAddr x), type(x).sizeof)
98-
99+
else:
100+
when defined(js):
101+
# could use BigInt, see https://github.com/nim-lang/RFCs/issues/187
102+
hash($x)
103+
else:
104+
hashData(cast[pointer](unsafeAddr x), type(x).sizeof)
99105

100106
proc hash*[T: SomeNumber | Ordinal | char](x: T): Hash {.inline.} =
101107
## Efficient hashing of numbers, ordinals (eg enum), char.

0 commit comments

Comments
 (0)