mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-15 23:52:57 +00:00
105 lines
4.9 KiB
HTML
105 lines
4.9 KiB
HTML
<script src="../include.js"></script>
|
|
<script>
|
|
asyncTest(async (done) => {
|
|
let wasm;
|
|
|
|
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
|
|
|
|
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
|
|
cachedTextDecoder.decode();
|
|
|
|
function getUint8Memory0() {
|
|
return new Uint8Array(wasm.memory.buffer);
|
|
}
|
|
|
|
function getStringFromWasm0(ptr, len) {
|
|
ptr = ptr >>> 0;
|
|
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
}
|
|
|
|
const exports = {
|
|
"./wasm_test_bg.js": {
|
|
__wbg_println_95d984b86202de7b(arg0, arg1) {
|
|
println(getStringFromWasm0(arg0, arg1));
|
|
},
|
|
greet() {
|
|
wasm.greet();
|
|
},
|
|
},
|
|
};
|
|
|
|
const arrayBuffer = new Uint8Array([
|
|
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x09, 0x02, 0x60, 0x02, 0x7f, 0x7f, 0x00,
|
|
0x60, 0x00, 0x00, 0x02, 0x34, 0x01, 0x11, 0x2e, 0x2f, 0x77, 0x61, 0x73, 0x6d, 0x5f, 0x74, 0x65,
|
|
0x73, 0x74, 0x5f, 0x62, 0x67, 0x2e, 0x6a, 0x73, 0x1e, 0x5f, 0x5f, 0x77, 0x62, 0x67, 0x5f, 0x70,
|
|
0x72, 0x69, 0x6e, 0x74, 0x6c, 0x6e, 0x5f, 0x39, 0x35, 0x64, 0x39, 0x38, 0x34, 0x62, 0x38, 0x36,
|
|
0x32, 0x30, 0x32, 0x64, 0x65, 0x37, 0x62, 0x00, 0x00, 0x03, 0x02, 0x01, 0x01, 0x05, 0x03, 0x01,
|
|
0x00, 0x11, 0x07, 0x12, 0x02, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x05, 0x67,
|
|
0x72, 0x65, 0x65, 0x74, 0x00, 0x01, 0x0a, 0x0d, 0x01, 0x0b, 0x00, 0x41, 0x80, 0x80, 0xc0, 0x00,
|
|
0x41, 0x15, 0x10, 0x00, 0x0b, 0x0b, 0x1e, 0x01, 0x00, 0x41, 0x80, 0x80, 0xc0, 0x00, 0x0b, 0x15,
|
|
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x77, 0x61, 0x73, 0x6d, 0x21,
|
|
0x21, 0x21, 0x21, 0x21, 0x21, 0x00, 0x7b, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x72,
|
|
0x73, 0x02, 0x08, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x01, 0x04, 0x52, 0x75, 0x73,
|
|
0x74, 0x00, 0x0c, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x2d, 0x62, 0x79, 0x03,
|
|
0x05, 0x72, 0x75, 0x73, 0x74, 0x63, 0x1d, 0x31, 0x2e, 0x37, 0x33, 0x2e, 0x30, 0x20, 0x28, 0x63,
|
|
0x63, 0x36, 0x36, 0x61, 0x64, 0x34, 0x36, 0x38, 0x20, 0x32, 0x30, 0x32, 0x33, 0x2d, 0x31, 0x30,
|
|
0x2d, 0x30, 0x33, 0x29, 0x06, 0x77, 0x61, 0x6c, 0x72, 0x75, 0x73, 0x06, 0x30, 0x2e, 0x31, 0x39,
|
|
0x2e, 0x30, 0x0c, 0x77, 0x61, 0x73, 0x6d, 0x2d, 0x62, 0x69, 0x6e, 0x64, 0x67, 0x65, 0x6e, 0x12,
|
|
0x30, 0x2e, 0x32, 0x2e, 0x38, 0x38, 0x20, 0x28, 0x30, 0x62, 0x35, 0x66, 0x30, 0x65, 0x65, 0x63,
|
|
0x32, 0x29, 0x00, 0x2c, 0x0f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x66, 0x65, 0x61, 0x74,
|
|
0x75, 0x72, 0x65, 0x73, 0x02, 0x2b, 0x0f, 0x6d, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2d, 0x67,
|
|
0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x73, 0x2b, 0x08, 0x73, 0x69, 0x67, 0x6e, 0x2d, 0x65, 0x78, 0x74
|
|
]).buffer;
|
|
|
|
const BUFFER_SOURCES = [
|
|
{ constructor: Uint8Array},
|
|
{ constructor: Uint8ClampedArray },
|
|
{ constructor: Uint16Array },
|
|
{ constructor: Uint32Array },
|
|
{ constructor: Int8Array },
|
|
{ constructor: Int16Array },
|
|
{ constructor: Float32Array },
|
|
{ constructor: Float64Array },
|
|
{ constructor: BigUint64Array },
|
|
{ constructor: BigInt64Array },
|
|
{ constructor: DataView },
|
|
];
|
|
|
|
async function runTest(buffer) {
|
|
println("-------------")
|
|
println(buffer.constructor.name);
|
|
println("-------------")
|
|
const module = await WebAssembly.instantiate(buffer, exports).catch(e => {
|
|
println(`FIXME: Failed to instantiate with ${buffer.constructor.name}: ${e.name}: ${e.message}`);
|
|
return Promise.resolve();
|
|
});
|
|
if (!module) {
|
|
return Promise.resolve();
|
|
}
|
|
wasm = module.instance?.exports ?? module.exports;
|
|
try {
|
|
wasm.greet();
|
|
} catch (e) {
|
|
println(`FIXME: Failed to execute with ${buffer.constructor.name}: ${e.name}: ${e.message}`);
|
|
}
|
|
return Promise.resolve();
|
|
}
|
|
|
|
await runTest(arrayBuffer);
|
|
|
|
for (const { constructor } of BUFFER_SOURCES) {
|
|
await runTest(new constructor(arrayBuffer));
|
|
}
|
|
|
|
const compiledModule = await WebAssembly.compile(arrayBuffer).catch(() => {
|
|
println(`FIXME: Failed to compile with ArrayBuffer`);
|
|
return Promise.resolve()
|
|
});
|
|
if (compiledModule) {
|
|
await runTest(compiledModule);
|
|
}
|
|
|
|
done();
|
|
});
|
|
</script>
|