Backed out 4 changesets (bug 1825722) for causing reftest failures CLOSED TREE
[gecko.git] / dom / webgpu / crashtests / 1809567.html
blob7b922182ebc8bf80b1827d69d856f3d1d1465723
1 <!DOCTYPE html>
2 <html class="reftest-wait">
3 <body>
4 <script>
5 // The bulk of the test is wrapped in an async function because
6 // the WebGPU API returns promises of adapters and devices,
7 // which we would like to conveniently await.
8 async function orphan_webgpu_device() {
9 // Create an iframe in the same origin as this code.
10 let iframe = document.createElement('iframe');
11 document.body.appendChild(iframe);
13 // Define a function in that iframe that creates a WebGPU
14 // `GPUDevice`.
15 let script = iframe.contentDocument.createElement('script');
16 script.type = 'text/javascript';
17 script.text = `
18 async function create_device() {
19 // WebGPU is not yet available in beta or release.
20 if (!navigator.gpu) {
21 return null;
24 let adapter = await navigator.gpu.requestAdapter({ });
25 // Not all GPUs are capable of supporting WebGPU.
26 if (!adapter) {
27 return null;
30 return await adapter.requestDevice({ });
33 iframe.contentDocument.body.appendChild(script);
35 // Call that function to create a `GPUDevice` in the iframe.
36 let device = await iframe.contentWindow.create_device();
38 // If we can't run WebGPU in this browser, then we can't reach the crash.
39 if (device) {
40 // Remove the iframe from our document. This closes its window.
41 iframe.remove();
43 try {
44 // When a Web API JavaScript object has had its parent window
45 // closed, C++ implementations of its WebIDL methods become unable
46 // to create JavaScript objects as usual: calling
47 // `EventTarget::GetParentObject` returns `nullptr`.
49 // Since we removed `iframe` from this document, the following
50 // call will fail trying to create a `Promise` of the module's
51 // `GPUCompilationInfo`.
52 device.createShaderModule({ code: '' });
53 } catch (error) {
54 // Eating errors indiscriminately wastes later developers' time.
55 if (error.name != "NS_ERROR_UNEXPECTED") {
56 throw error;
62 orphan_webgpu_device()
63 .catch((error) => {
64 console.log(error);
66 .finally(() => {
67 // End the crashtest.
68 document.documentElement.removeAttribute("class");
69 });
70 </script>
71 </body>
72 </html>