Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/internal/webidl.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ function pow2(exponent) {

// https://tc39.es/ecma262/#eqn-modulo
// The notation “x modulo y” computes a value k of the same sign as y.
// As y is always positive in this file, we can do a simple r < 0 check for that.
function modulo(x, y) {
const r = x % y;
// Convert -0 to +0.
if (r === 0) {
return 0;
} else if (r < 0) {
return r + y;
}
return r;
}
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-internal-webidl-converttoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
assert.strictEqual(convertToInt('x', 1, 64), 1);
assert.strictEqual(convertToInt('x', -0.5, 64), 0);
assert.strictEqual(convertToInt('x', -0.5, 64, { signed: true }), 0);
assert.strictEqual(convertToInt('x', -1.5, 64, { signed: true }), -1);

Check failure on line 22 in test/parallel/test-internal-webidl-converttoint.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04)

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: 0 !== -1 at Object.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-internal-webidl-converttoint.js:22:8) at Module._compile (node:internal/modules/cjs/loader:1829:14) at Object..js (node:internal/modules/cjs/loader:1969:10) at Module.load (node:internal/modules/cjs/loader:1552:32) at Module._load (node:internal/modules/cjs/loader:1354:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 0, expected: -1, operator: 'strictEqual', diff: 'simple' } Node.js v26.0.0-pre Command: out/Release/node --expose-internals /home/runner/work/node/node/node/test/parallel/test-internal-webidl-converttoint.js

Check failure on line 22 in test/parallel/test-internal-webidl-converttoint.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04-arm)

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: 0 !== -1 at Object.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-internal-webidl-converttoint.js:22:8) at Module._compile (node:internal/modules/cjs/loader:1829:14) at Object..js (node:internal/modules/cjs/loader:1969:10) at Module.load (node:internal/modules/cjs/loader:1552:32) at Module._load (node:internal/modules/cjs/loader:1354:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 0, expected: -1, operator: 'strictEqual', diff: 'simple' } Node.js v26.0.0-pre Command: out/Release/node --expose-internals /home/runner/work/node/node/node/test/parallel/test-internal-webidl-converttoint.js

Check failure on line 22 in test/parallel/test-internal-webidl-converttoint.js

View workflow job for this annotation

GitHub Actions / test-macOS

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: 0 !== -1 at Object.<anonymous> (/Users/runner/work/node/node/node/test/parallel/test-internal-webidl-converttoint.js:22:8) at Module._compile (node:internal/modules/cjs/loader:1829:14) at Object..js (node:internal/modules/cjs/loader:1969:10) at Module.load (node:internal/modules/cjs/loader:1552:32) at Module._load (node:internal/modules/cjs/loader:1354:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 0, expected: -1, operator: 'strictEqual', diff: 'simple' } Node.js v26.0.0-pre Command: out/Release/node --expose-internals /Users/runner/work/node/node/node/test/parallel/test-internal-webidl-converttoint.js

Check failure on line 22 in test/parallel/test-internal-webidl-converttoint.js

View workflow job for this annotation

GitHub Actions / x86_64-darwin: with shared libraries

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: 0 !== -1 at Object.<anonymous> (/Users/runner/work/_temp/node-v26.0.0-nightly2026-04-25b2b15c36ae-slim/test/parallel/test-internal-webidl-converttoint.js:22:8) at Module._compile (node:internal/modules/cjs/loader:1829:14) at Object..js (node:internal/modules/cjs/loader:1969:10) at Module.load (node:internal/modules/cjs/loader:1552:32) at Module._load (node:internal/modules/cjs/loader:1354:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 0, expected: -1, operator: 'strictEqual', diff: 'simple' } Node.js v26.0.0-pre Command: out/Release/node --expose-internals /Users/runner/work/_temp/node-v26.0.0-nightly2026-04-25b2b15c36ae-slim/test/parallel/test-internal-webidl-converttoint.js

Check failure on line 22 in test/parallel/test-internal-webidl-converttoint.js

View workflow job for this annotation

GitHub Actions / aarch64-darwin: with shared libraries

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: 0 !== -1 at Object.<anonymous> (/Users/runner/work/_temp/node-v26.0.0-nightly2026-04-25b2b15c36ae-slim/test/parallel/test-internal-webidl-converttoint.js:22:8) at Module._compile (node:internal/modules/cjs/loader:1829:14) at Object..js (node:internal/modules/cjs/loader:1969:10) at Module.load (node:internal/modules/cjs/loader:1552:32) at Module._load (node:internal/modules/cjs/loader:1354:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 0, expected: -1, operator: 'strictEqual', diff: 'simple' } Node.js v26.0.0-pre Command: out/Release/node --expose-internals /Users/runner/work/_temp/node-v26.0.0-nightly2026-04-25b2b15c36ae-slim/test/parallel/test-internal-webidl-converttoint.js

Check failure on line 22 in test/parallel/test-internal-webidl-converttoint.js

View workflow job for this annotation

GitHub Actions / x86_64-linux: with shared libraries

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: 0 !== -1 at Object.<anonymous> (/home/runner/work/_temp/node-v26.0.0-nightly2026-04-25b2b15c36ae-slim/test/parallel/test-internal-webidl-converttoint.js:22:8) at Module._compile (node:internal/modules/cjs/loader:1829:14) at Object..js (node:internal/modules/cjs/loader:1969:10) at Module.load (node:internal/modules/cjs/loader:1552:32) at Module._load (node:internal/modules/cjs/loader:1354:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 0, expected: -1, operator: 'strictEqual', diff: 'simple' } Node.js v26.0.0-pre Command: out/Release/node --expose-internals /home/runner/work/_temp/node-v26.0.0-nightly2026-04-25b2b15c36ae-slim/test/parallel/test-internal-webidl-converttoint.js

Check failure on line 22 in test/parallel/test-internal-webidl-converttoint.js

View workflow job for this annotation

GitHub Actions / aarch64-linux: with shared libraries

--- stderr --- node:internal/assert/utils:146 throw error; ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: 0 !== -1 at Object.<anonymous> (/home/runner/work/_temp/node-v26.0.0-nightly2026-04-25b2b15c36ae-slim/test/parallel/test-internal-webidl-converttoint.js:22:8) at Module._compile (node:internal/modules/cjs/loader:1829:14) at Object..js (node:internal/modules/cjs/loader:1969:10) at Module.load (node:internal/modules/cjs/loader:1552:32) at Module._load (node:internal/modules/cjs/loader:1354:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { generatedMessage: true, code: 'ERR_ASSERTION', actual: 0, expected: -1, operator: 'strictEqual', diff: 'simple' } Node.js v26.0.0-pre Command: out/Release/node --expose-internals /home/runner/work/_temp/node-v26.0.0-nightly2026-04-25b2b15c36ae-slim/test/parallel/test-internal-webidl-converttoint.js

// EnforceRange
const OutOfRangeValues = [ NaN, Infinity, -Infinity, 2 ** 53, -(2 ** 53) ];
Expand Down Expand Up @@ -56,3 +56,12 @@
// Out of range, step 11.
assert.strictEqual(convertToInt('x', 0x8000_0000, 32, { signed: true }), -0x8000_0000);
assert.strictEqual(convertToInt('x', 0xFFF_FFFF, 32, { signed: true }), 0xFFF_FFFF);

// Negative values must wrap as two's-complement, matching typed-array behavior.
assert.strictEqual(convertToInt('x', -3, 8), 253);
assert.strictEqual(convertToInt('x', -3, 8), new Uint8Array([-3])[0]);
assert.strictEqual(convertToInt('x', -1, 32), 0xFFFF_FFFF);
assert.strictEqual(convertToInt('x', -1, 32), new Uint32Array([-1])[0]);
assert.strictEqual(convertToInt('x', -200, 8, { signed: true }), 56);
assert.strictEqual(convertToInt('x', -200, 8, { signed: true }),
new Int8Array([-200])[0]);
Loading