dawn.node: Handle shaders containing a \0.

They should be errors but instead the source was being truncated.
Explicitly detect this case and generate an error shader module. This
fixes the webgpu:shader,validation,parse,blankspace:null_characters:contains_null=true
tests on dawn.node.

Bug: None
Change-Id: Ie6532b2a6d970d1a6e05535d63b242599ed0cf12
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/177662
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/dawn/node/binding/GPUDevice.cpp b/src/dawn/node/binding/GPUDevice.cpp
index aefb47e..b7198fc 100644
--- a/src/dawn/node/binding/GPUDevice.cpp
+++ b/src/dawn/node/binding/GPUDevice.cpp
@@ -372,6 +372,16 @@
     }
     sm_desc.nextInChain = &wgsl_desc;
 
+    // Special case for a source containing a \0. This should be an error instead of just truncating
+    // the source.
+    if (descriptor.code.find('\0') != std::string::npos) {
+        return interop::GPUShaderModule::Create<GPUShaderModule>(
+            env, sm_desc,
+            device_.CreateErrorShaderModule(&sm_desc,
+                                            "The WGSL shader contains an illegal character '\\0'"),
+            async_);
+    }
+
     return interop::GPUShaderModule::Create<GPUShaderModule>(
         env, sm_desc, device_.CreateShaderModule(&sm_desc), async_);
 }