Skip to content

Example snippet does not behave like it should #60504

@davidebombelli

Description

@davidebombelli

Affected URL(s)

https://nodejs.org/api/worker_threads.html#considerations-when-cloning-objects-with-prototypes-classes-and-accessors

Description of the problem

The following code is supposed to print {}:

const { port1, port2 } = new MessageChannel();

port1.onmessage = ({ data }) => console.log(data);

port2.postMessage(new URL('https://example.org'));

// Prints: { } 

However, when running it, it gives the following:

node:internal/per_context/domexception:76
    const self = new Error();
                 ^

DOMException [DataCloneError]: Cannot clone object of unsupported type.
    at new DOMException (node:internal/per_context/domexception:76:18)
    at file:///my-folder-structure/test.mjs:6:7
    at ModuleJob.run (node:internal/modules/esm/module_job:377:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:691:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5)

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions