Skip to content

Allow passing FileHandle objects via postMessage

src: introduce BaseObject base FunctionTemplate

(shared with https://github.com/nodejs/node/pull/33360)

worker: allow transferring/cloning generic BaseObjects

Extend support for transferring objects à la MessagePort to other types of BaseObject subclasses, as well as implement cloning support for cases in which destructive transferring is not needed or optional.

(shared with https://github.com/nodejs/node/pull/33360)

fixup! worker: allow transferring/cloning generic BaseObjects

(not shared, hence as a fixup commit)

src: add equality operators for BaseObjectPtr
worker: allow passing JS wrapper objects via postMessage

Enable JS wrapper objects to be used as transferable or cloneable objects in postMessage() calls, by having them extend a C++-backed class.

This requires a few internal changes:

  • This commit adds the possibility for transferred objects to read/write JS values at the end of the serialization/deserialization phases.
  • This commit adds the possibility for transferred objects to list sub-transferables, e.g. typically the public JS wrapper class would list its C++ handle in there.
  • This commit adds usage of BaseObject in a few more places, because now during deserialization weakly held objects can also be involved, in addition to MessagePorts.
worker,fs: make FileHandle transferable

Allow passing FileHandle instances in the transfer list of a .postMessage() call.

worker: emit 'messagerror' events for failed deserialization

This is much nicer than just treating exceptions as uncaught, and enables reporting of exceptions from the internal C++ deserialization machinery.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Merge request reports

Loading