<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
function optimizedMethodCall(commandEncoder, buffer, offset, size) {
commandEncoder.clearBuffer(buffer, offset, size);
}
function test(t, hotLoop, commandEncoder, buffer, offset, size) {
try {
hotLoop(1, commandEncoder, buffer, offset, size);
} catch(e) {
assert_true(e instanceof TypeError);
return;
}
assert_unreached("A TypeError should be thrown.");
}
promise_test(async t => {
const adapter = await navigator.gpu.requestAdapter();
assert_true(adapter instanceof GPUAdapter, 'Failed to request WebGPU adapter');
const device = await adapter.requestDevice();
assert_true(device instanceof GPUDevice, 'Failed to request WebGPU device');
const encoder = device.createCommandEncoder();
const buffer = device.createBuffer({
size: 8,
usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST,
});
function hotLoop(count, commandEncoder, buffer, offset, size) {
for (let i = 0; i < count; ++i) {
optimizedMethodCall(commandEncoder, buffer, offset, size);
}
}
hotLoop(100, encoder, buffer, 4, 4);
// Wait a bit for V8 to optimize. Then call again with an out-of-bounds value.
// An exception should be thrown.
await new Promise(resolve => t.step_timeout(resolve, 50));
// kJSMaxInteger = 0x20000000000000 - 1;
test(t, hotLoop, encoder, buffer, 0x20000000000000, 4);
test(t, hotLoop, encoder, buffer, 4, 0x20000000000000);
});
</script>
</body>
</html>