fix(webidl): correct signed integer bounds in ConvertToInt#5038
fix(webidl): correct signed integer bounds in ConvertToInt#5038KhafraDev merged 1 commit intonodejs:mainfrom
Conversation
The signed integer lower bound was computed as `Math.pow(-2, bitLength) - 1`, which evaluates to `(-2)^bitLength - 1` instead of the spec-required `-2^(bitLength - 1)`. The step 11 overflow threshold similarly used `2^bitLength - 1` instead of `2^(bitLength - 1)`, causing values in `[2^(bitLength-1), 2^bitLength - 2]` to skip the signed wrap. Fix both expressions and update the surrounding comments to match the WebIDL spec. Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: DeepView Autofix <276251120+deepview-autofix@users.noreply.github.com> Co-Authored-By: Nikita Skovoroda <chalkerx@gmail.com> Signed-off-by: Nikita Skovoroda <chalkerx@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5038 +/- ##
==========================================
- Coverage 93.03% 93.03% -0.01%
==========================================
Files 110 110
Lines 35793 35793
==========================================
- Hits 33301 33299 -2
- Misses 2492 2494 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
KhafraDev
left a comment
There was a problem hiding this comment.
the comments come from https://webidl.spec.whatwg.org/#abstract-opdef-converttoint, the changes to them should be reverted
|
@KhafraDev No. The comments were copy-pasted incorrectly originally due to them including formatting. It's the Please check the spec you linked |
|
I see what you mean though |
|
@KhafraDev Also, you already added |
|
Yeah it appears as though it is wrong in both cases unfortunately |
WDYM? |
|
When refactoring (especially in the fetch spec) one of the best parts of the undici code base is the ability to copy a comment and CTRL+F to find where exactly a step was moved/changed to/from in the spec. It makes refactoring much easier from what I've found. In this case, I'd prefer to keep webidl comments the same, but they should also be readable (and the spec doesn't really ever change, due to its nature). |
That already doesn't work as |
|
Which is why I approved, main is wrong, it's not your responsibility to fix an unrelated 'issue' in a comment |

The signed integer lower bound was computed as
Math.pow(-2, bitLength) - 1, which evaluates to(-2)^bitLength - 1instead of the spec-required-2^(bitLength - 1). The step 11 overflow threshold similarly used2^bitLength - 1instead of2^(bitLength - 1), causing values in[2^(bitLength-1), 2^bitLength - 2]to skip the signed wrap. Fix both expressions and update the surrounding comments to match the WebIDL spec.