wasm/web: async-body `-`, `*`, `/`, `%` use raw f64 arithmetic without ToNumber

Open Beginner friendly
#15,132 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust, typescript, wasm
Domain
backend, compilers

Research direction

Read crates/perry-codegen-wasm/src/emit/js_fallback.rs and compare the async-body emission for Sub, Mul, Div and Mod with the sync path's ToNumber handling. Reproduce the reported string and boolean operand cases in an async function, then check the generated behavior against the expected results. Done when those operators in async bodies produce the expected numeric results.

Written by the indexing model from the issue text.

Description

area:compiler effort:S impact:med platform:wasm type:bug

The async-body JS fallback (crates/perry-codegen-wasm/src/emit/js_fallback.rs) emits Sub/Mul/Div/Mod on the raw f64 representation of the operands, without the ToNumber conversion the sync path applies. A string or boolean operand is therefore expected to compute the wrong value inside an async function (not yet reproduced):

async function f() { console.log("5" - 2, "6" * "2", true + 0); }
f(); // node: 3 12 1

Noticed while reviewing #15092 (which fixed the bitwise, shift, ** and in operators on the same path). Related: #14595.

Dominant language
Rust
Stars
4.9k
Forks
166
Avg merge
6h 5m
Merged PRs (30d)
949

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PerryTS/perry

All issues in PerryTS/perry

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.