Skip to content

fix(wasm): host getters read inside an async function are values, not calls (#14720) - #14724

Merged
TheHypnoo merged 2 commits into
PerryTS:mainfrom
raliclo:fix/wasm-async-host-getter
Nov 16, 2026
Merged

TheHypnoo merged 2 commits into
PerryTS:mainfrom
raliclo:fix/wasm-async-host-getter

Conversation

@raliclo

@raliclo raliclo commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #14720. Refs #14595.

On --target web, an async function body is emitted as JavaScript. Inside that body, reading r.status, r.ok, r.statusText or r.headers on a fetch Response threw TypeError: toJsValue(...).status is not a function.

Cause: the HIR lowers a bare read of a native getter (is_fetch_response_getter_name, and the other rows of native_property_read_dispatches) to an Expr::NativeMethodCall with no arguments. That is the same shape as a zero-argument method call such as r.text(). The JS emitter's generic NativeMethodCall arm emitted every such node as obj.member(), so the getter's value was called.

Changes

  • js_fallback.rs: a zero-argument native member on an object now emits __jsNativeMember(obj, name). Calls with arguments are unchanged.
  • wasm_runtime.js: add __jsNativeMember. It reads the member once. If the member is a function it calls it with the object as receiver; any other value is returned as the result of the read.
  • emit/tests.rs: add async_body_reads_host_getters_and_calls_host_methods. It reads status, ok, statusText and headers.get(...) from a data: URL response, then calls text().

Known limit (same as the HIR's shape): for the modules whose bare reads all dispatch (net, dns, Headers, …), reading a method as a value without calling it (const g = h.get) still invokes the method. Telling that case apart would need the HIR to mark reads separately from calls.

Overlaps: none with #14696, #14664 or #14718. git merge-tree is clean against each of them and against #14723. __jsNativeMember sits beside __jsMethodGet, which #14664 also edits, in a separate hunk.

Test plan

All commands were run on this branch and on upstream/main dc9dd6b. The branch was then rebased onto 64257c3, which changes nothing under perry-codegen-wasm, perry-hir, perry-transform or perry-parser.

  • Repro from wasm/web: reading Response.status / ok / statusText / headers inside an async function throws "is not a function" #14720: async function f(){ const r = await fetch("data:text/plain,hi"); console.log(r.status, r.ok, r.statusText, r.headers.get("content-type")) } f().
    • main: TypeError: toJsValue(...).status is not a function.
    • this branch: 200 true OK text/plain, the same as node --experimental-strip-types.
  • cargo test --release -p perry-codegen-wasm async_body_reads_host:
    • It fails on main with threw TypeError: toJsValue(...).status is not a function and passes here.
    • Mutation check: I restored main's js_fallback.rs and wasm_runtime.js and kept the test. The test failed the same way. Restoring the fixed files gave identical shasums.
  • cargo test --release -p perry-codegen-wasm: 77 passed, 0 failed (main: 76 passed).
  • rustfmt --check --edition 2021 on the changed .rs files: clean.
  • cargo clippy --release -p perry-codegen-wasm: 227 warnings on this branch and on main.
  • tests/integration/wasm/run_wasm_tests.sh (pointed at each binary): 30 pass / 3 fail on both main and this branch, the same three (04_functions, 10_higher_order, 19_ffi_imports).
  • BASE_SHA=<merge-base> SKIP_COMPILE_GATES=1 bash scripts/run_lint_gates.sh: the FAIL set (20 gates, environment-dependent) is identical to main's.

Checklist

  • I have NOT bumped the workspace version or edited CHANGELOG.md (maintainer handles these at merge)
  • My commits follow the loose feat: / fix: / docs: / chore: prefix convention used in the log
  • I've read CONTRIBUTING.md and agree to the Code of Conduct

🤖 Generated with Claude Code

https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue in web builds where reading properties from a fetch response inside an async function could fail. Response details, including status and headers, can now be read correctly, and response methods such as reading the body continue to work as expected. Missing host methods now produce a TypeError.

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

For --target web, zero-argument native member reads in async functions now return non-function property values instead of calling them. Function-valued members are called with their original object as the receiver. Tests cover fetch response getters and methods, and a missing method.

Changes: Async web host getter handling

Layer / File(s) Summary
Native member lookup and async fetch tests
crates/perry-codegen-wasm/src/wasm_runtime.js, crates/perry-codegen-wasm/src/emit/js_fallback.rs, crates/perry-codegen-wasm/src/emit/tests.rs, changelog.d/14724-wasm-async-host-getter.md
The runtime helper returns non-function property values and calls function-valued properties with their original object as the receiver. The emitter uses the helper for zero-argument native calls with receivers. Tests cover fetch response getters, headers.get, text(), and rejection with a TypeError when a method is missing. The changelog records the behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

Suggested reviewers: thehypnoo

Merge Risk: Minimal · up to 0c9fe

This change makes reads of fetch Response getters such as status and headers inside async functions on the web target return their values instead of failing. Calls with arguments and zero-argument method calls such as text() keep their previous behavior. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: host getter reads inside an async function now return values instead of being called. It matches the changeset, which emits zero-argument native members through __jsNa…
Description check Passed The description follows the template well. It has a Summary that explains the cause and the fix, and a Changes list that names each file. It links the issue with 'Fixes #14720' and gives a detailed te…
Linked Issues check Passed Issue #14720 requires two things on --target web. First, a bare read of Response.status, ok, statusText, or headers inside an async body must yield the value. Second, a zero-argument method such as r.…
Out of Scope Changes check Passed The supplied file summaries list four changed paths: changelog.d/14724-wasm-async-host-getter.md (documents the same fix), js_fallback.rs (zero-argument native member branch), emit/tests.rs (regressio…
Full details: Title check

Explanation

The title names the main change: host getter reads inside an async function now return values instead of being called. It matches the changeset, which emits zero-argument native members through __jsNativeMember in the WASM async-body emitter. The title is 84 characters, which is long, but it is specific and accurate.

Full details: Description check

Explanation

The description follows the template well. It has a Summary that explains the cause and the fix, and a Changes list that names each file. It links the issue with 'Fixes #14720' and gives a detailed test plan with commands and results. The template's Checklist items are present and checked. The description does not use the template's HTML comments, which is acceptable. The template's test plan asks for a paste of commands, and the author gives that. The check passes.

Full details: Linked Issues check

Explanation

Issue #14720 requires two things on --target web. First, a bare read of Response.status, ok, statusText, or headers inside an async body must yield the value. Second, a zero-argument method such as r.text() must remain a call. The supplied raw summary of crates/perry-codegen-wasm/src/emit/js_fallback.rs states that a receiver-bearing, zero-argument NativeMethodCall now emits __jsNativeMember, and that calls with arguments keep the direct invocation path. The raw summary of wasm_runtime.js states that __jsNativeMember calls a function-valued member with the object as receiver and returns a non-function member's value. Together these cover both requirements. The added test async_body_reads_host_getters_and_calls_host_methods covers status, ok, statusText, headers.get(...), and text(), per the PR description. Limits: the whole-PR and incremental diff reads returned unavailable, and the changed blobs were not readable. The js_fallback.rs and wasm_runtime.js source was not read directly at head. The PASS therefore rests on the supplied summaries and the author's test report. The const g = h.get limit is not an issue requirement.

Full details: Out of Scope Changes check

Explanation

The supplied file summaries list four changed paths: changelog.d/14724-wasm-async-host-getter.md (documents the same fix), js_fallback.rs (zero-argument native member branch), emit/tests.rs (regression tests), and wasm_runtime.js (__jsNativeMember helper). Each path ties directly to the #14720 fix. The raw summary for emit/tests.rs describes two tests, while the PR description names one. The second test covers absent-member behavior, which the commit message describes, so it still supports this fix. The author reports no changes under perry-hir, perry-transform, or perry-parser. No unrelated change appears in the available evidence. The diff reads were unavailable, so this verdict rests on the supplied summaries, not a full diff read.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 13b4a0bb-52bf-4013-be9e-b011685eeff0
Commits

Reviewing files that changed from the base of the PR and between 902c1aa and 0c9fe61.

Files selected for processing: 3

  • changelog.d/14724-wasm-async-host-getter.md
  • crates/perry-codegen-wasm/src/emit/tests.rs
  • crates/perry-codegen-wasm/src/wasm_runtime.js
Files skipped from review as they are similar to previous changes: 1

  • changelog.d/14724-wasm-async-host-getter.md

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.

An async function body on --target web is emitted as JavaScript. The HIR
lowers a bare read of a native getter (`res.status`, `res.ok`,
`res.statusText`, `res.headers`) to a NativeMethodCall with no arguments,
the same shape as `res.text()`, and the JS emitter called every such member:
`toJsValue(r).status()` threw "status is not a function". A zero-argument
native member now goes through `__jsNativeMember`, which calls a method and
returns any other value as the read.

Fixes PerryTS#14720.
@TheHypnoo
TheHypnoo force-pushed the fix/wasm-async-host-getter branch from 4948b70 to 902c1aa Compare November 16, 2026 13:42
… throws

__jsNativeMember reads a non-function member only when the object has it; an absent member throws TypeError as the call would, instead of yielding undefined.
@TheHypnoo
TheHypnoo merged commit c5bf748 into PerryTS:main Nov 16, 2026
115 of 134 checks passed
@raliclo
raliclo deleted the fix/wasm-async-host-getter branch November 17, 2026 01:36
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.

wasm/web: reading Response.status / ok / statusText / headers inside an async function throws "is not a function"

3 participants