summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/throw.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/throw.js')
-rw-r--r--testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/throw.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/throw.js b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/throw.js
new file mode 100644
index 0000000000..704098a6d8
--- /dev/null
+++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/onerror/throw.js
@@ -0,0 +1,34 @@
+const params = new URL(self.location.href).searchParams;
+
+self.createError = (message) => {
+ if (params.get('error') === 'DOMException-TypeError') {
+ return new DOMException(message, 'TypeError');
+ } else {
+ return new Error(message);
+ }
+};
+
+onerror = function() {
+ if (params.has('throw-in-onerror')) {
+ throw createError('Throw in error handler');
+ }
+ return false;
+};
+onmessage = function() {
+ throw createError('Throw in message handler');
+ return false;
+};
+
+if (params.has('throw-in-toplevel')) {
+ throw createError('Throw in toplevel');
+}
+
+// We don't use step_timeout() here, because we have to test the behavior of
+// setTimeout() without wrappers.
+if (params.has('throw-in-setTimeout-function')) {
+ setTimeout(() => { throw createError('Throw in setTimeout function') }, 0);
+}
+
+if (params.has('throw-in-setTimeout-string')) {
+ setTimeout("throw createError('Throw in setTimeout string')", 0);
+}