Skip to content

Compiler: dynamically imported hosted modules inherit the guest caller receiver #3561

Closed

Description

@nickna

A compiled hosted module with top-level await inherits the dynamic import caller's receiver when the caller invokes import from an explicitly bound function. The module should have its own undefined top-level receiver.

main.mjs

const receiver = {};
let preserved;
function load() {
    const before = this === receiver;
    const pending = import("./lazy.mjs");
    preserved = before && this === receiver;
    return pending;
}
const lazy = await load.call(receiver);
console.log(preserved, lazy.before === undefined, lazy.after === undefined,
    lazy.before === receiver, lazy.after === receiver);
export {};

lazy.mjs

export const before = this;
await Promise.resolve();
export const after = this;

Node v22.23.2 prints true true true false false. Both clean SharpTS main a3683d903 and PR #3552 at 1f2bebf06 print true false false true true when run through the compiled hosted ABI. The caller's receiver remains intact, but the imported module exposes that same object on both sides of its suspension.

Compile with --no-tsconfig --noLib --compile main.mjs --hosted --verify -o main.dll, load the assembly with SharpTSHostedAssembly.CreateRuntime, and initialize it while pumping the host dispatcher. Both assemblies passed full IL verification. Found while reviewing #3552. This is independent of #3504's strict-deletion behavior and #3548's interpreted top-level module receiver.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions