Commit 0f245d2
lib: fix modulo sign in webidl convertToInt
The modulo() helper in lib/internal/webidl.js is documented to implement
ECMA-262's "x modulo y" (result has the same sign as y), but it used the
JS % operator directly, whose result takes the sign of x. convertToInt
step 10 relies on modulo(x, 2^bitLength) producing a non-negative
representative in [0, 2^bitLength); step 11 only handles the signed
upper half, so negative results of % were returned unchanged.
As a result, negative inputs to unsigned WebIDL integer types returned
the original negative value instead of the two's-complement wrap (e.g.
convertToInt('v', -3, 8) returned -3 instead of 253), and signed inputs
in the one-wrap band below the lower bound were returned as-is
(convertToInt('v', -200, 8, { signed: true }) returned -200 instead of
56). This diverged from typed-array coercion.
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: DeepView Autofix <[email protected]>
Co-Authored-By: Nikita Skovoroda <[email protected]>
Assisted-by: Claude <[email protected]>
Signed-off-by: Nikita Skovoroda <[email protected]>1 parent 4744070 commit 0f245d2
2 files changed
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
| 117 | + | |
| 118 | + | |
116 | 119 | | |
117 | 120 | | |
118 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
0 commit comments