You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7cca6e9
Browse filesBrowse the repository at this point in the historyBrowse files
fix(worker): hand worker_threads 'error' listeners an Error rebuilt from the thrown value
A worker_threads 'error' listener received the runtime's ErrorEvent, not an Error, and the message it carried was V8's "Uncaught Error: ..." text. The worker now reads the thrown value's name and message and forwards them with the error payload. The parent rebuilds an Error from them with the worker's stack, using the built-in constructor the name belongs to, and the parent's global error event carries that same Error when nothing handled it.
The Worker shim cancels an error its listeners took with preventDefault() rather than through the truthy-return contract of onerror.
Copy file name to clipboardExpand all lines: docs/worker-threads.md
+17-1Lines changed: 17 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,7 +54,7 @@ means deliberately unsupported.
54
54
|`threadName`| shim | Always `undefined`. |
55
55
|`workerData`| shim | Always `null` — see below. |
56
56
|`parentPort`| shim |`null` on the main isolate. Inside a worker, a `MessagePort`-shaped `EventTarget` over the worker's existing parent channel: `postMessage` forwards to the global `postMessage`, `message`/`messageerror` are re-dispatched from the worker global scope, `start()` and `close()` are no-ops. It is **not** a real port: not transferable, no queue of its own. |
57
-
|`Worker`| shim | A class over the runtime's global `Worker` with a small Node-style emitter (`on`/`once`/`off`/`removeListener`) for `message`, `messageerror`, `error`, `online` and `exit`. `postMessage(value, transfer)` and `terminate()` forward. `online` is emitted off a microtask after construction, not from the thread. Unsupported options throw a `TypeError` naming the option: `workerData`, `env`, `eval`, `transferList`, and `stdin`/`stdout`/`stderr` when explicitly truthy. The runtime's own `Worker` options (`androidPriority`) ride along untouched — the native constructor ignores keys it does not know. |
57
+
|`Worker`| shim | A class over the runtime's global `Worker` with a small Node-style emitter (`on`/`once`/`off`/`removeListener`) for `message`, `messageerror`, `error`, `online` and `exit`. An `error` listener receives the worker's error rebuilt as an `Error` (see below). `postMessage(value, transfer)` and `terminate()` forward. `online` is emitted off a microtask after construction, not from the thread. Unsupported options throw a `TypeError` naming the option: `workerData`, `env`, `eval`, `transferList`, and `stdin`/`stdout`/`stderr` when explicitly truthy. The runtime's own `Worker` options (`androidPriority`) ride along untouched — the native constructor ignores keys it does not know. |
58
58
|`postMessageToThread`| throws |`Error: postMessageToThread is not supported in this runtime`. |
59
59
|`moveMessagePortToContext`| throws |`Error: moveMessagePortToContext is not supported in this runtime`. |
60
60
|`locks`| absent | Web Locks are not implemented; the property does not exist. |
@@ -79,6 +79,22 @@ finished. `terminate()` therefore resolves with `0` and emits `exit` with code
79
79
`0` on the way, and that is the only path that emits it. A worker that ends by
80
80
its own `close()` produces no `exit`.
81
81
82
+
### An `error` listener receives a rebuilt `Error`
83
+
84
+
Node hands an `error` listener the worker's error deserialized on the parent.
85
+
Only strings cross the isolate boundary here, so the parent rebuilds it from
86
+
the thrown value's `name` and `message`, with the worker's stack as its
87
+
`stack`. A built-in name (`TypeError`, `RangeError`, …) rebuilds with that
88
+
constructor, so `instanceof` holds; any other name, a subclass's or a
89
+
`DOMException`'s, is an own `name` on an `Error`. Other properties, such as a
90
+
`code` or a `cause`, are not carried. A thrown value with no string `message`,
91
+
such as a string or a number, arrives as an `Error` whose message is its string
92
+
form, where Node hands over the value itself.
93
+
94
+
Once an `error` listener has received it, the error counts as handled and is
95
+
not reported on the parent's global scope. With no `error` listener, the
96
+
parent's global `error` event carries the same rebuilt `Error`.
97
+
82
98
### A worker error carries no `error` object, and the worker scope's `onerror` is not an event
83
99
84
100
An error the worker scope leaves unhandled reaches the parent as a real
0 commit comments