diff options
Diffstat (limited to 'ext/node/polyfills/worker_threads.ts')
| -rw-r--r-- | ext/node/polyfills/worker_threads.ts | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/ext/node/polyfills/worker_threads.ts b/ext/node/polyfills/worker_threads.ts index 96aa02fe1..8f531368a 100644 --- a/ext/node/polyfills/worker_threads.ts +++ b/ext/node/polyfills/worker_threads.ts @@ -29,7 +29,7 @@ import { EventEmitter } from "node:events"; import { BroadcastChannel } from "ext:deno_broadcast_channel/01_broadcast_channel.js"; import process from "node:process"; -const { ObjectPrototypeIsPrototypeOf } = primordials; +const { JSONParse, JSONStringify, ObjectPrototypeIsPrototypeOf } = primordials; const { Error, Symbol, @@ -126,10 +126,18 @@ class NodeWorker extends EventEmitter { } this.#name = name; + // One of the most common usages will be to pass `process.env` here, + // but because `process.env` is a Proxy in Deno, we need to get a plain + // object out of it - otherwise we'll run in `DataCloneError`s. + // See https://github.com/denoland/deno/issues/23522. + let env_ = undefined; + if (options?.env) { + env_ = JSONParse(JSONStringify(options?.env)); + } const serializedWorkerMetadata = serializeJsMessageData({ workerData: options?.workerData, environmentData: environmentData, - env: options?.env, + env: env_, }, options?.transferList ?? []); const id = op_create_worker( { |
