2 <html class=
"reftest-wait">
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
15 let script
= iframe
.contentDocument
.createElement('script');
16 script
.type
= 'text/javascript';
18 async function create_device() {
19 // WebGPU is not yet available in beta or release.
24 let adapter = await navigator.gpu.requestAdapter({ });
25 // Not all GPUs are capable of supporting WebGPU.
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.
40 // Remove the iframe from our document. This closes its window.
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
: '' });
54 // Eating errors indiscriminately wastes later developers' time.
55 if (error
.name
!= "NS_ERROR_UNEXPECTED") {
62 orphan_webgpu_device()
68 document
.documentElement
.removeAttribute("class");