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