Bug 1935611 - Fix libyuv/libpng link failed for loongarch64. r=glandium,tnikkel,ng
[gecko.git] / dom / webgpu / crashtests / 1907222_truncate_error.html
blob0db83f496c10777abf22b81340a037534ac00632
1 <!DOCTYPE html>
2 <html class="reftest-wait">
3 <head>
4 <meta charset="utf-8" />
5 <script src="/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel="stylesheet" href="/tests/SimpleTest/test.css" />
7 </head>
8 <body>
9 <script>
10 // Ensure that, when WebGPU generates an error message that is later
11 // truncated by `wgpu_bindings::error::ErrorBuffer::init`, that
12 // truncation always produces valid UTF-8, even when the error contains
13 // multi-byte encodings.
14 async function truncate_error_messages() {
15 // The specific error we'll try to provoke is submitting a command
16 // buffer to the wrong device's queue.
17 const adapter = await navigator.gpu.requestAdapter();
18 const device1 = await adapter.requestDevice();
19 const device2 = await adapter.requestDevice();
21 // Try a range of label lengths (578±200, where 578 is the length that
22 // tickles the original bug), searching for one that, when combined with
23 // the error message and then truncated at whatever error message byte
24 // length limit Firefox is imposing, will produce invalid UTF-8.
26 // Use a label containing n space characters followed by a crab emoji,
27 // U+1F980, which requires four bytes to encode in UTF-8. Since this has
28 // a four-byte encoding at the end, we only need to try every third
29 // length to ensure we will always try a truncation point in the midst
30 // of that encoding.
31 for (let len = 378; len < 778; len += 3) {
32 const label = ' '.repeat(len) + '\uD83E\uDD80';
33 const encoder = device1.createCommandEncoder({ label });
34 const command_buffer = encoder.finish();
36 // We don't want an error scope around this, because what makes
37 // Firefox notice the bad UTF-8 is attempting to log the uncaught
38 // WebGPU error as a warning.
39 device2.queue.submit([command_buffer]);
43 truncate_error_messages()
44 .catch(e => {
45 console.log(e);
47 .finally(() => {
48 // End the crashtest.
49 document.documentElement.removeAttribute("class");
50 });
51 </script>
52 </body>
53 </html>