Commit cfe9b6c
fix(runtime,codegen): bitnot ToNumber coercion + modulus zero/sign-of-zero (#5822)
* fix(runtime,codegen): bitnot ToNumber coercion + modulus zero/sign-of-zero (#5815)
Two spec bugs caught by the test262 radar:
**`~x` (bitwise NOT) — `js_dynamic_bitnot`**
- Missing `ToNumber` coercion before `ToInt32`: `~new Boolean(true)` gave
`-1` (treating the NaN-boxed pointer as `0`) instead of `~1 = -2`.
Fixed by calling `js_number_coerce` before the i64 truncation, which
dispatches through `valueOf`/`toPrimitive` for wrapper objects and
strings.
- Wrong `ToInt32` for `±Infinity`/`NaN`: Rust's saturating `f64 as i64`
gives `i64::MAX` for `+Infinity` → `i64::MAX as i32 = -1` → `~(-1) = 0`,
but the spec says `ToInt32(±Infinity) = 0` → `~0 = -1`. Fixed with an
explicit `if is_nan || !is_finite { 0i32 }` guard.
Fixes `S11.4.8_A2.2_T1`, `S11.4.8_A3_T1`, `S11.4.8_A3_T2`, `S11.4.8_A3_T3`
(100% parity on `language/expressions/bitwise-not`).
**`x % y` (modulus) — integer fast path in codegen**
- Zero-divisor UB: `srem(x, 0)` is undefined behaviour in LLVM (ARM gives
`0` silently; JS requires `NaN`). Guard added: skip the `fptosi/srem`
fast path when the RHS is a literal `0` or `0.0` and fall through to
`frem` (which gives `NaN` per IEEE 754).
- Sign-of-zero: `srem` returns an `i64` zero and `sitofp` always produces
`+0.0`, but JS requires `-0.0` when the dividend was negative (e.g.
`-1 % -1 === -0`). Fixed by emitting: `if m == 0 && l < 0.0 → fneg(0.0)`.
Fixes `S11.5.3_A4_T2`, `S11.5.3_A4_T4`.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* style: rustfmt
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Ralph <ralph@skelpo.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 6b25b52 commit cfe9b6c
2 files changed
Lines changed: 28 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
219 | | - | |
220 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
221 | 225 | | |
222 | 226 | | |
223 | 227 | | |
| 228 | + | |
224 | 229 | | |
225 | 230 | | |
226 | 231 | | |
227 | 232 | | |
228 | 233 | | |
229 | 234 | | |
230 | 235 | | |
231 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
232 | 246 | | |
233 | 247 | | |
234 | 248 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
458 | 458 | | |
459 | 459 | | |
460 | 460 | | |
461 | | - | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
462 | 472 | | |
463 | 473 | | |
464 | 474 | | |
| |||
0 commit comments