Skip to content

fix(webidl): wrap negative values in ConvertToInt via two's complement#5107

Open
deepview-autofix wants to merge 1 commit intonodejs:mainfrom
deepview-autofix:deepview/7882bb906c
Open

fix(webidl): wrap negative values in ConvertToInt via two's complement#5107
deepview-autofix wants to merge 1 commit intonodejs:mainfrom
deepview-autofix:deepview/7882bb906c

Conversation

@deepview-autofix
Copy link
Copy Markdown
Contributor

ConvertToInt's step 10 used JS %, whose result has the sign of the dividend, so negative inputs were not wrapped to the modulo range. For unsigned types without [EnforceRange]/[Clamp] this returned a negative number (e.g. -3 in 8 bits returned -3 instead of 253), and for signed types values in the one-wrap band below the lower bound were returned unchanged and outside the valid range (e.g. -200 in 8 bits returned -200 instead of 56). Implement ECMA-262's "x modulo y" semantics so the result lies in [0, 2^bitLength), matching typed-array behavior, and normalize -0 to +0.

ConvertToInt's step 10 used JS `%`, whose result has the sign of the
dividend, so negative inputs were not wrapped to the modulo range. For
unsigned types without [EnforceRange]/[Clamp] this returned a negative
number (e.g. -3 in 8 bits returned -3 instead of 253), and for signed
types values in the one-wrap band below the lower bound were returned
unchanged and outside the valid range (e.g. -200 in 8 bits returned -200
instead of 56). Implement ECMA-262's "x modulo y" semantics so the
result lies in [0, 2^bitLength), matching typed-array behavior, and
normalize -0 to +0.

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>
Copy link
Copy Markdown
Member

@ChALkeR ChALkeR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

@ChALkeR ChALkeR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has to be rewritten on bitLength = 64, will do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants