Skip to content

Stop using re-assignment thunks when WASM_ASYNC_COMPILATION is enabled. #23339

Open
@sbc100

Description

@sbc100

In release mode, when WASM_ASYNC_COMPILATION is used (i.e the default) we generate little thunks for all wasm exports. They looks like this:

var _foo = Module['_foo'] = () => (_foo = Module['_cfoo'] = wasmExports['foo'])();

The idea here is that these would then get re-assigned on first use. However, there are several problem with this:

  1. If somebody takes a reference early they will get a reference to wrapper that will not get re-assigned and will cause perpetual re-assignment:
// This runs early on
var myfunc = Module['foo'];

// Now my func will forever point to the wrapper:

myfunc();  // always goes via wrapper and always re-assigns.. strange
Module['foo'](); // now goes direct
  1. The identity of these function changes which can be observable (since we don't this re-assignment thing in debug builds):
var myfunc = Module['foo'];
// later after instantiation and usage
if (myfunc == Module['foo']) // would always be true in debug builds, but can be false in release builds

See #23337

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