Skip to content

Generated trampoline treats resource methods as free functions #1313

@ritalin

Description

@ritalin

Related to #1314, but this focuses on incorrect code generation for methods.

When importing a JS class as a WIT resource, the generated code in the trampoline appears to be incorrect.

Current generated code:

foo?._isHostProvided = true;
...

await foo(arg);

Observation:

  • A runtime error occurs when calling the method
  • The generated code attempts to call the method as a free function

This suggests the generated code does not preserve the method context (this).

Workaround:
The generate code should call the method on the resource instance instead of treating it as a free function.

let hostProvided = false;
hostProvided = rsc0.constructor._isHostProvided;

...

await rsc0.foo(arg);

Full discussion (including context and workaround):
#jco > Unexpected error when using async JS types/functions with im

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions