Issue #2197 - Part 2a: Implement StructuredSerializeOptions for MessagePort

Based on https://bugzilla.mozilla.org/show_bug.cgi?id=1502802
This commit is contained in:
FranklinDM 2023-04-07 15:55:27 +08:00 committed by roytam1
commit fd982fd298
3 changed files with 22 additions and 1 deletions

View file

@ -495,6 +495,14 @@ MessagePort::PostMessage(JSContext* aCx,
mActor->SendPostMessages(messages);
}
void
MessagePort::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const StructuredSerializeOptions& aOptions,
ErrorResult& aRv)
{
PostMessage(aCx, aMessage, aOptions.mTransfer, aRv);
}
void
MessagePort::Start()
{

View file

@ -26,6 +26,7 @@ class MessagePortIdentifier;
class MessagePortMessage;
class PostMessageRunnable;
class SharedMessagePortMessage;
struct StructuredSerializeOptions;
namespace workers {
class WorkerHolder;
@ -65,6 +66,11 @@ public:
const Sequence<JSObject*>& aTransferable,
ErrorResult& aRv);
void
PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const StructuredSerializeOptions& aOptions,
ErrorResult& aRv);
void Start();
void Close();

View file

@ -10,7 +10,9 @@
[Exposed=(Window,Worker,System)]
interface MessagePort : EventTarget {
[Throws]
void postMessage(any message, optional sequence<object> transferable = []);
void postMessage(any message, sequence<object> transferable);
[Throws]
void postMessage(any message, optional StructuredSerializeOptions options);
void start();
void close();
@ -19,3 +21,8 @@ interface MessagePort : EventTarget {
attribute EventHandler onmessage;
};
// MessagePort implements Transferable;
// Used to declare which objects should be transferred.
dictionary StructuredSerializeOptions {
sequence<object> transfer = [];
};