[emscripten] Use Emscripten `diagnostics.error` instead of `raise`

Makes errors show up as more nicely-formatted Emscripten error messages,
instead of as stack traces.

Also finally start documenting what bits of Emscripten we depend on.

Bug: none
Change-Id: I6f104db70dd65804f63aa170f52f8c7b056b77b5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/264636
Auto-Submit: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
diff --git a/src/emdawnwebgpu/README.md b/src/emdawnwebgpu/README.md
index 9617988..5dc7130 100644
--- a/src/emdawnwebgpu/README.md
+++ b/src/emdawnwebgpu/README.md
@@ -71,3 +71,45 @@
 - Build the `emdawnwebgpu` and `samples` GN build targets.
 
 Samples and tests produce HTML files in `out/<dir>/wasm` which can be served and viewed in a compatible browser.
+
+## Appendix: Bits of Emscripten we depend on
+
+(Internal docs for coordination between Emscripten and Emdawnwebgpu.)
+
+Emdawnwebgpu depends on a lot of random bits of Emscripten that aren't usually
+public. We assume they're "mostly stable" for now and will update this (and roll
+into Emscripten) as needed if they change. Most, but not all, incompatible
+changes will be detected on Emscripten's CI, because it tests Emdawnwebgpu. This
+list is a best effort to enumerate them, but definitely isn't complete.
+
+- Remote ports
+- In `emdawnwebgpu.port.py`:
+  - Ports API in general
+  - Modifying various settings in `linker_setup()`
+  - `tools.diagnostics.error`
+- In package build:
+  - `tools/gen_struct_info.py`
+- In `library_webgpu.js`:
+  - Various items from `parseTools`
+    - `i53abi`
+    - `makeGetValue`
+    - `runtimeKeepalivePush`/`runtimeKeepalivePop`
+  - Public settings:
+    - `ASSERTIONS`
+    - `ASYNCIFY`
+    - `USE_WEBGPU`
+    - `MEMORY64`, `WASM_BIGINT`
+  - `settings_internal.js` settings:
+    - `CAN_ADDRESS_2GB`
+  - Public preamble:
+    - `assert`, `abort`
+  - Internal library functions:
+    - `stackSave`, `stackRestore`
+    - `stringToUTF8OnStack`, `UTF8ToString`, `stringToNewUTF8`, `lengthBytesUTF8`
+    - `callUserCallback`
+    - `warnOnce`
+    - `readI53FromI64`
+    - `findCanvasEventTarget`
+- In `webgpu.cpp`:
+  - Public APIs:
+    - `emscripten_has_asyncify`
diff --git a/src/emdawnwebgpu/pkg/emdawnwebgpu.port.py b/src/emdawnwebgpu/pkg/emdawnwebgpu.port.py
index 32252be..651ea19 100644
--- a/src/emdawnwebgpu/pkg/emdawnwebgpu.port.py
+++ b/src/emdawnwebgpu/pkg/emdawnwebgpu.port.py
@@ -35,6 +35,9 @@
 import zlib
 from typing import Dict, Optional
 
+# Imports from Emscripten
+from tools import diagnostics
+
 if __name__ == '__main__':
     print('Please see README.md for details on how to use this port.')
     sys.exit(1)
@@ -85,7 +88,7 @@
 
 # Check for a generated file that would only be there in the built package
 if not os.path.isfile(os.path.join(_c_include_dir, 'webgpu', 'webgpu.h')):
-    raise Exception(
+    diagnostics.error(
         "emdawnwebgpu.port.py must sit in a built emdawnwebgpu_pkg, not be used standalone or "
         "from Dawn's source tree. Download a pre-built package from "
         "https://github.com/google/dawn/releases or build it locally.")
@@ -179,10 +182,10 @@
 
 def linker_setup(ports, settings):
     if settings.USE_WEBGPU:
-        raise Exception('emdawnwebgpu may not be used with -sUSE_WEBGPU=1')
+        diagnostics.error('emdawnwebgpu may not be used with -sUSE_WEBGPU=1')
 
     if not settings.LINK_AS_CXX:
-        raise Exception(
+        diagnostics.error(
             'emdawnwebgpu requires C++. Link using em++ (or emcc -sDEFAULT_TO_CXX), instead of emcc.'
         )