From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:35:49 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- dom/workers/Worker.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'dom/workers/Worker.h') diff --git a/dom/workers/Worker.h b/dom/workers/Worker.h index 14d0630f28..6a0e295fc2 100644 --- a/dom/workers/Worker.h +++ b/dom/workers/Worker.h @@ -42,6 +42,31 @@ class Worker : public DOMEventTargetHelper, public SupportsWeakPtr { return Some(EventCallbackDebuggerNotificationType::Worker); } + // True if the worker is not yet closing from the perspective of this, the + // owning thread, and therefore it's okay to post a message to the worker. + // This is not a guarantee that the worker will process the message. + // + // This method will return false if `globalThis.close()` is invoked on the + // worker before that method returns control to the caller and without waiting + // for any task to be queued on this thread and run; this biases us to avoid + // doing wasteful work but does mean if you are exposing something to content + // that is specified to only transition as the result of a task, then you + // should not use this method. + // + // The method name comes from + // https://html.spec.whatwg.org/multipage/web-messaging.html#eligible-for-messaging + // and is intended to convey whether it's okay to begin to take the steps to + // create an `EventWithOptionsRunnable` to pass to `PostEventWithOptions`. + // Note that early returning based on calling this method without performing + // the structured serialization steps that would otherwise run is potentially + // observable to content if content is in control of any of the payload in + // such a way that an object with getters or a proxy could be provided. + // + // There is an identically named method on nsIGlobalObject and the semantics + // are intentionally similar but please make sure you document your + // assumptions when calling either method. + bool IsEligibleForMessaging(); + void PostMessage(JSContext* aCx, JS::Handle aMessage, const Sequence& aTransferable, ErrorResult& aRv); @@ -49,6 +74,8 @@ class Worker : public DOMEventTargetHelper, public SupportsWeakPtr { const StructuredSerializeOptions& aOptions, ErrorResult& aRv); + // Callers must call `IsEligibleForMessaging` before constructing an + // `EventWithOptionsRunnable` subclass. void PostEventWithOptions(JSContext* aCx, JS::Handle aOptions, const Sequence& aTransferable, EventWithOptionsRunnable* aRunnable, -- cgit v1.2.3