summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklinDM <mrmineshafter17@gmail.com>2023-04-07 16:30:32 +0800
committerFranklinDM <mrmineshafter17@gmail.com>2023-04-07 23:41:55 +0800
commit83501c86d2bc9e7b9e12da143204b38f426f20a0 (patch)
tree2e1dfafa9c49e4b4aeac10c8c3198e06bf05c06d
parent5c8599d223fccba1afe68d1cfbfe11ec0231621f (diff)
downloaduxp-83501c86d2bc9e7b9e12da143204b38f426f20a0.tar.gz
Issue #2197 - Part 2b: Implement StructuredSerializeOptions for Worker
Based on https://bugzilla.mozilla.org/show_bug.cgi?id=1502802
-rw-r--r--dom/webidl/DedicatedWorkerGlobalScope.webidl4
-rw-r--r--dom/webidl/Worker.webidl4
-rw-r--r--dom/workers/SharedWorker.cpp10
-rw-r--r--dom/workers/SharedWorker.h6
-rw-r--r--dom/workers/WorkerPrivate.cpp11
-rw-r--r--dom/workers/WorkerPrivate.h7
-rw-r--r--dom/workers/WorkerScope.cpp9
-rw-r--r--dom/workers/WorkerScope.h7
8 files changed, 56 insertions, 2 deletions
diff --git a/dom/webidl/DedicatedWorkerGlobalScope.webidl b/dom/webidl/DedicatedWorkerGlobalScope.webidl
index ad3125fa31..80c7c8decb 100644
--- a/dom/webidl/DedicatedWorkerGlobalScope.webidl
+++ b/dom/webidl/DedicatedWorkerGlobalScope.webidl
@@ -16,7 +16,9 @@
Exposed=DedicatedWorker]
interface DedicatedWorkerGlobalScope : WorkerGlobalScope {
[Throws]
- void postMessage(any message, optional sequence<object> transfer = []);
+ void postMessage(any message, sequence<object> transfer);
+ [Throws]
+ void postMessage(any message, optional StructuredSerializeOptions options);
attribute EventHandler onmessage;
};
diff --git a/dom/webidl/Worker.webidl b/dom/webidl/Worker.webidl
index 44f406d8ce..c13357cd7e 100644
--- a/dom/webidl/Worker.webidl
+++ b/dom/webidl/Worker.webidl
@@ -19,7 +19,9 @@ interface Worker : EventTarget {
void terminate();
[Throws]
- void postMessage(any message, optional sequence<object> transfer = []);
+ void postMessage(any message, sequence<object> transfer);
+ [Throws]
+ void postMessage(any message, optional StructuredSerializeOptions options);
attribute EventHandler onmessage;
};
diff --git a/dom/workers/SharedWorker.cpp b/dom/workers/SharedWorker.cpp
index 03c45c96a1..2fae19f291 100644
--- a/dom/workers/SharedWorker.cpp
+++ b/dom/workers/SharedWorker.cpp
@@ -22,6 +22,7 @@
using mozilla::dom::Optional;
using mozilla::dom::Sequence;
using mozilla::dom::MessagePort;
+using mozilla::dom::StructuredSerializeOptions;
using namespace mozilla;
USING_WORKERS_NAMESPACE
@@ -152,6 +153,15 @@ SharedWorker::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
mMessagePort->PostMessage(aCx, aMessage, aTransferable, aRv);
}
+void
+SharedWorker::PostMessage(JSContext* aCx,
+ JS::Handle<JS::Value> aMessage,
+ const StructuredSerializeOptions& aOptions,
+ ErrorResult& aRv)
+{
+ PostMessage(aCx, aMessage, aOptions.mTransfer, aRv);
+}
+
NS_IMPL_ADDREF_INHERITED(SharedWorker, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(SharedWorker, DOMEventTargetHelper)
diff --git a/dom/workers/SharedWorker.h b/dom/workers/SharedWorker.h
index 6b328811d5..e85fc2609a 100644
--- a/dom/workers/SharedWorker.h
+++ b/dom/workers/SharedWorker.h
@@ -98,6 +98,12 @@ private:
JS::Handle<JS::Value> aMessage,
const Sequence<JSObject*>& aTransferable,
ErrorResult& aRv);
+
+ void
+ PostMessage(JSContext* aCx,
+ JS::Handle<JS::Value> aMessage,
+ const StructuredSerializeOptions& aOptions,
+ ErrorResult& aRv);
};
END_WORKERS_NAMESPACE
diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
index 2c3d439bd8..a7a4929f3b 100644
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -3081,6 +3081,17 @@ WorkerPrivateParent<Derived>::PostMessage(
template <class Derived>
void
+WorkerPrivateParent<Derived>::PostMessage(
+ JSContext* aCx,
+ JS::Handle<JS::Value> aMessage,
+ const StructuredSerializeOptions& aOptions,
+ ErrorResult& aRv)
+{
+ PostMessageInternal(aCx, aMessage, aOptions.mTransfer, nullptr, nullptr, aRv);
+}
+
+template <class Derived>
+void
WorkerPrivateParent<Derived>::PostMessageToServiceWorker(
JSContext* aCx,
JS::Handle<JS::Value> aMessage,
diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h
index cf1a3c22fc..0a71420047 100644
--- a/dom/workers/WorkerPrivate.h
+++ b/dom/workers/WorkerPrivate.h
@@ -68,6 +68,7 @@ class PromiseNativeHandler;
class StructuredCloneHolder;
class WorkerDebuggerGlobalScope;
class WorkerGlobalScope;
+struct StructuredSerializeOptions;
} // namespace dom
namespace ipc {
class PrincipalInfo;
@@ -404,6 +405,12 @@ public:
ErrorResult& aRv);
void
+ PostMessage(JSContext* aCx,
+ JS::Handle<JS::Value> aMessage,
+ const StructuredSerializeOptions& aOptions,
+ ErrorResult& aRv);
+
+ void
PostMessageToServiceWorker(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const Sequence<JSObject*>& aTransferable,
UniquePtr<ServiceWorkerClientInfo>&& aClientInfo,
diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp
index 5469b876c7..4019123c0b 100644
--- a/dom/workers/WorkerScope.cpp
+++ b/dom/workers/WorkerScope.cpp
@@ -542,6 +542,15 @@ DedicatedWorkerGlobalScope::PostMessage(JSContext* aCx,
mWorkerPrivate->PostMessageToParent(aCx, aMessage, aTransferable, aRv);
}
+void
+DedicatedWorkerGlobalScope::PostMessage(JSContext* aCx,
+ JS::Handle<JS::Value> aMessage,
+ const StructuredSerializeOptions& aOptions,
+ ErrorResult& aRv)
+{
+ PostMessage(aCx, aMessage, aOptions.mTransfer, aRv);
+}
+
SharedWorkerGlobalScope::SharedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
const nsCString& aName)
: WorkerGlobalScope(aWorkerPrivate), mName(aName)
diff --git a/dom/workers/WorkerScope.h b/dom/workers/WorkerScope.h
index 8c41d5d279..2b055038fc 100644
--- a/dom/workers/WorkerScope.h
+++ b/dom/workers/WorkerScope.h
@@ -24,6 +24,7 @@ class Function;
class IDBFactory;
enum class ImageBitmapFormat : uint32_t;
class Performance;
+struct StructuredSerializeOptions;
class Promise;
class RequestOrUSVString;
class ServiceWorkerRegistration;
@@ -218,6 +219,12 @@ public:
const Sequence<JSObject*>& aTransferable,
ErrorResult& aRv);
+ void
+ PostMessage(JSContext* aCx,
+ JS::Handle<JS::Value> aMessage,
+ const StructuredSerializeOptions& aOptions,
+ ErrorResult& aRv);
+
IMPL_EVENT_HANDLER(message)
};