Skip to content

Proposal: loader instantiation fix/improvement #780

@sijakret

Description

@sijakret

Hi Everyone,

When instantiating any real-world module (>4KB) using the loader the following error comes up (at the very least in chrome):

RangeError: WebAssembly.Instance is disallowed on the main thread, if the buffer size is larger than 4KB. Use WebAssembly.instantiate.

This is the code segment that causes the issue (lib/loader/index.js):

/** Instantiates an AssemblyScript module using the specified imports. */
function instantiate(module, imports) {
  return postInstantiate(
    preInstantiate(imports || (imports = {})),
    new WebAssembly.Instance(module, imports)
  );
}

If i monkey patch it like below it becomes usable (albeit async)

/** Instantiates an AssemblyScript module using the specified imports. */
async function instantiate(module, imports) {
  return postInstantiate(
    preInstantiate(imports || (imports = {})),
    await WebAssembly.instantiate(module, imports)
  );
}

I would assume that this issue will be faced by others..

I see two easy ways to fix it:

  1. my patch above
  2. export postInstantiate(..) and preInstantiate(..) hooks so users can build costum instantiation flows.

What do you guys think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions