ladybird/Tests/LibWeb/Text/input/Wasm/WebAssembly-exported-function-metadata.html
Timothy Flynn a7ce007ff4 LibWeb: Define name and length properties on exported wasm functions
We were previously not setting any name or length properties on exported
functions. Some sites like https://squeel.frankmayer.dev/ rely on these
properties.

The name property is a bit strange. Exported wasm functions have a name
property which is its index in its module instance's function-address
list.

This patch is not enough for the squeel site to be fully functional; we
will need to implement navigator.locks.
2026-06-23 08:57:08 +02:00

32 lines
1.5 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<script>
asyncTest(async (done) => {
const wasmBytes = new Uint8Array([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,
0x01, 0x07, 0x01, 0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f,
0x03, 0x02, 0x01, 0x00,
0x07, 0x1d, 0x01, 0x19,
0x73, 0x71, 0x6c, 0x69, 0x74, 0x65, 0x33, 0x5f,
0x61, 0x67, 0x67, 0x72, 0x65, 0x67, 0x61, 0x74,
0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74,
0x00, 0x00,
0x0a, 0x06, 0x01, 0x04, 0x00, 0x20, 0x00, 0x0b,
]);
const { instance } = await WebAssembly.instantiate(wasmBytes);
const fn = instance.exports.sqlite3_aggregate_context;
const exportName = Object.getOwnPropertyNames(instance.exports)[0];
const lengthDescriptor = Object.getOwnPropertyDescriptor(fn, "length");
const nameDescriptor = Object.getOwnPropertyDescriptor(fn, "name");
println(`length: ${fn.length}`);
println(`name: ${fn.name}`);
println(`export name: ${exportName}`);
println(`length descriptor: writable=${lengthDescriptor.writable}, enumerable=${lengthDescriptor.enumerable}, configurable=${lengthDescriptor.configurable}`);
println(`name descriptor: writable=${nameDescriptor.writable}, enumerable=${nameDescriptor.enumerable}, configurable=${nameDescriptor.configurable}`);
println(`call result: ${fn(42, 7)}`);
done();
});
</script>