[dawn][node] Validate mappedAtCreation requires size%4==0

Change-Id: I4a809f80636aa285bced4ac3ec3902615da5de58
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/265435
Commit-Queue: Gregg Tavares <gman@chromium.org>
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Gregg Tavares <gman@chromium.org>
diff --git a/src/dawn/node/binding/GPUDevice.cpp b/src/dawn/node/binding/GPUDevice.cpp
index 0e790b8..77a4f03 100644
--- a/src/dawn/node/binding/GPUDevice.cpp
+++ b/src/dawn/node/binding/GPUDevice.cpp
@@ -317,6 +317,13 @@
         return {};
     }
 
+    if (desc.mappedAtCreation && desc.size % 4 != 0) {
+        Napi::RangeError::New(
+            env, "createBuffer failed, size is not a multiple of 4 when mappedAtCreation is true.")
+            .ThrowAsJavaScriptException();
+        return {};
+    }
+
     wgpu::Buffer dawnBuffer = device_.CreateBuffer(&desc);
     // Buffer creation may return nullptr if it fails to map at creation. Translate that to a
     // RangeError as required by the spec.