Commit 887f71a
committed
fix: in js 0 is falsy, which messes with ternary logic
We have this helper function which converts `bigint` to `number`
or raises an error in the unlikely case that it's out of bounds.
And for typing reasons, we want to keep its signature purely
`function(bigint): number`.
But in a few places, we needed to call that function on a value
which might be undefined. So we used ternary logic, like this:
```js
foo? saveBigIntToNumber(foo): undefined
```
And on its face that does the right thing: both `null` and
`undefined` are falsy in JS, so you get `undefined` out.
What we hadn't considered was that the defined number 0 is _also_
falsy in JS, meaning that those instances could change a defined
value to an undefined one, causing some subtle bugs.
So let's get really explicit about this and do things properly.1 parent ec4d0df commit 887f71a
File tree
3 files changed
+13
-6
lines changed- crypto-ffi/bindings/js/src
3 files changed
+13
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
201 | | - | |
202 | | - | |
203 | | - | |
| 201 | + | |
204 | 202 | | |
205 | 203 | | |
206 | 204 | | |
| |||
0 commit comments