From c17b4f9b6900575c2d501075f7e1f4b58e20e28e Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Mon, 5 Dec 2022 13:54:44 +0000 Subject: [PATCH] node: Throw a TypeError for unsupported GPUQueryTypes The WebGPU spec requires this so that an extension not being enabled or not implemented by the browser both behave the same. Bug: None Change-Id: I52d991ba63438068d4adaf1391771336186a402a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/112422 Kokoro: Kokoro Reviewed-by: Ben Clayton Reviewed-by: Austin Eng Commit-Queue: Corentin Wallez --- src/dawn/node/binding/Converter.cpp | 10 ++++++++-- src/dawn/node/binding/GPUDevice.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/dawn/node/binding/Converter.cpp b/src/dawn/node/binding/Converter.cpp index 95c49162a9..f2718bd886 100644 --- a/src/dawn/node/binding/Converter.cpp +++ b/src/dawn/node/binding/Converter.cpp @@ -1609,8 +1609,14 @@ bool Converter::Convert(wgpu::QueryType& out, const interop::GPUQueryType& in) { out = wgpu::QueryType::Occlusion; return true; case interop::GPUQueryType::kTimestamp: - out = wgpu::QueryType::Timestamp; - return true; + if (HasFeature(wgpu::FeatureName::TimestampQuery)) { + out = wgpu::QueryType::Timestamp; + return true; + } else { + Napi::TypeError::New(env, "invalid value for GPUQueryType") + .ThrowAsJavaScriptException(); + return false; + } } Napi::Error::New(env, "invalid value for GPUQueryType").ThrowAsJavaScriptException(); return false; diff --git a/src/dawn/node/binding/GPUDevice.cpp b/src/dawn/node/binding/GPUDevice.cpp index b540d501a5..5aab3eb0b8 100644 --- a/src/dawn/node/binding/GPUDevice.cpp +++ b/src/dawn/node/binding/GPUDevice.cpp @@ -472,7 +472,7 @@ interop::Interface GPUDevice::createRenderBundl interop::Interface GPUDevice::createQuerySet( Napi::Env env, interop::GPUQuerySetDescriptor descriptor) { - Converter conv(env); + Converter conv(env, device_); wgpu::QuerySetDescriptor desc{}; if (!conv(desc.label, descriptor.label) || !conv(desc.type, descriptor.type) ||