Skip to content

Fix exported resource methods with arguments - #76

Merged
andreiltd merged 1 commit into
andreiltd:mainfrom
CN059:fix/exported-resource-method-receiver
Aug 31, 2026
Merged

andreiltd merged 1 commit into
andreiltd:mainfrom
CN059:fix/exported-resource-method-receiver

Conversation

@CN059

@CN059 CN059 commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Problem

For exported resource methods, canonical lowering places the resource receiver first and regular method arguments after it. The interpreter currently calls pop_value for the receiver, so any method with arguments removes the final argument and treats it as self. No-argument methods work, while scalar and variant arguments trap before the JavaScript method body.

Fix

Add a QjsCallContext operation that shifts the first stack value and use it for method receivers. The remaining argument values keep their existing order when drained into the JavaScript call.

Extend test_exported_resource with both a scalar method and a variant method, then assert their values are observed in JavaScript.

Test

cargo test --locked --test wit_types test_exported_resource -- --nocapture

Result: 1 passed; 0 failed.

Read the resource receiver from the first lowered argument instead of popping the final method argument. Extend the exported resource regression to prove scalar and variant arguments reach JavaScript in order.

Tests: cargo test --locked --test wit_types test_exported_resource -- --nocapture
@andreiltd
andreiltd merged commit 99a21aa into andreiltd:main Aug 31, 2026
5 checks passed
@github-actions github-actions Bot mentioned this pull request Aug 12, 2026
malformed-c added a commit to apsis-io/dwarf that referenced this pull request Sep 2, 2026
An exported resource method took `this` off the END of the argument stack,
where the receiver is lowered as the FIRST argument. A method with no
arguments works either way, which is why dwarf's existing coverage
(`increment()`) never noticed; every method that takes an argument got the
last argument as its receiver instead of the resource.

Ported rather than cherry-picked: dwarf's `export_call` has diverged too
far upstream to merge (string prefixes here, a `classify`/`FuncKind`
refactor there), so this is the two-line fix and their test, adapted to
dwarf's shape. Confirmed the test fails with `pop_value` restored and
passes with `shift_value`.

Upstream: andreiltd/componentize-qjs#76

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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