bytecodealliance / bytecodealliance/ComponentizeJS

ReferenceError when resource has no functions

Open
#221 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
391
Forks
53
Avg merge
3d 5h
Merged PRs (30d)
1

Description

Having an empty resource:
```wit
interface execution {

resource join-set-id {
// id: func() -> string;
}

new-join-set: func() -> join-set-id;
}
```
Calling `new-join-set` from a JavaScript guest fails with an error: `ReferenceError: import_execution_1_0_0$JoinSetId is not defined`.
This is because the generated `initializer.js`does not contain `class import_execution_1_0_0$JoinSetId {...}`, but tries to use it in the generated `new-join-set` function: `var rsc2 = new.target === import_execution_1_0_0$JoinSetId ? this : Object.create(import_execution_1_0_0$JoinSetId.prototype);`

The workaround is to add a function, which triggers the `class` generation.
Tested with componentize-js version 0.18.2 .

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the empty-resource WIT example with componentize-js 0.18.2 and inspect the generated initializer.js. Trace the generated new-join-set function and verify that the empty resource produces its JoinSetId class and no longer raises a ReferenceError when called from a JavaScript guest.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, wasm
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.