dawn.node: Throw TypeError on non-finite floating points
This is to match the WebIDL rules that floating point values should be
finite, unless they are "unrestricted" (which is never the case in
WebGPU at the moment).
This fixes a bunch of overridable constant tests for NaNs and Inifinity.
Bug: None
Change-Id: I0482dc51fa607ee89394f7b9f10493168da368dc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/159364
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn/node/binding/Converter.h b/src/dawn/node/binding/Converter.h
index 657e322..6ffeed0 100644
--- a/src/dawn/node/binding/Converter.h
+++ b/src/dawn/node/binding/Converter.h
@@ -297,18 +297,26 @@
return true;
}
- // Pass-through (no conversion)
- template <typename T>
- inline bool Convert(T& out, const T& in) {
+ // Floating point number conversion. IDL rules are that double/float that isn't "unrestricted"
+ // must be finite.
+ template <typename OUT,
+ typename IN,
+ std::enable_if_t<std::is_floating_point_v<IN> && std::is_floating_point_v<OUT>,
+ bool> = true>
+ [[nodiscard]] inline bool Convert(OUT& out, const IN& in) {
out = in;
+ if (!std::isfinite(out)) {
+ return Throw(Napi::TypeError::New(
+ env, "Floating-point value (" + std::to_string(out) + ") is not finite"));
+ }
return true;
}
// Integral number conversion, with dynamic limit checking
template <typename OUT,
typename IN,
- typename = std::enable_if_t<std::is_integral_v<IN> && std::is_integral_v<OUT>>>
- inline bool Convert(OUT& out, const IN& in) {
+ std::enable_if_t<std::is_integral_v<IN> && std::is_integral_v<OUT>, bool> = true>
+ [[nodiscard]] inline bool Convert(OUT& out, const IN& in) {
out = static_cast<OUT>(in);
if (static_cast<IN>(out) != in) {
return Throw("Integer value (" + std::to_string(in) +