Hi all,

In these days I landed quite a few patches to replace the use of
JSAutoStructuredCloneBuffer with something "better": StructuredCloneHelper.

First of all, the reasons why I did it, are:

1. we had many postMessage() methods fully out of sync in terms of which
clonable/transferable objects we were supporting. Now MessagePort,
BroadcastChannel, window and worker and (partially) IPC share the same code
base.

2. We had several regressions about memory management of
clonable/transferrable objects. At least now we have only 1 code base to
maintain and fix.

How it works:

1. StructuredCloneHelperInternal is base class that uses
JSAutoStructuredCloneBuffer internally and exposes the
JSStructuredCloneCallbacks as virtual methods.
For some custom use of JSAutoStructuredCloneBuffer (like Console API in
workers or PromiseWorkerProxy  - bug 1198814) you can use this class.

2. Probably what you really want to use is StructuredCloneHelper. In its
CTOR you must decide if:
a. you want to support the cloning of DOM objects (such as Blob, FileList,
ImageData, FormData, etc...): CloningSupported/CloningNotSupported
b. if you want to support the transferring of DOM objects (currently only
MessagePort): TransferringSupported/TransferringNotSupported
c. what is the most generic context where the "Read" could run. Here we
have 3 options: SameProcessSameThread (window to window for instance),
SameProcessDifferentThread (window to worker), DifferentProcess
(MessagePort? ipc? all that stuff).

3. For IPC communication we have a particular class:
StructuredCloneIPCHelper.

Next steps:

I'm currently (on vacation, but) working on another step: I want to remove
JSAutoStructuredCloneBuffer, OwningSerializedStructuredCloneBuffer and
SerializedStructuredCloneBuffer from IPC serialization. Bug: 1201806.
Please, avoid the use of JSAutoStructuredCloneBuffer in DOM tree. And if
you have a particular use-cases where StructuredCloneHelper doesn't work,
let me know and we can find a solution.

b
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to