import from UXP: Issue #2197 - Part 2c: Implement StructuredSerializeOptions for ServiceWorker (4d58139f)

This commit is contained in:
2023-04-10 08:37:15 +08:00
parent e29e66d024
commit b54aa00363
6 changed files with 39 additions and 2 deletions
+3 -1
View File
@@ -15,7 +15,9 @@ interface Client {
readonly attribute DOMString id;
[Throws]
void postMessage(any message, optional sequence<object> transfer = []);
void postMessage(any message, sequence<object> transferable);
[Throws]
void postMessage(any message, optional StructuredSerializeOptions options);
};
[Exposed=ServiceWorker]
+3 -1
View File
@@ -20,7 +20,9 @@ interface ServiceWorker : EventTarget {
attribute EventHandler onstatechange;
[Throws]
void postMessage(any message, optional sequence<object> transferable = []);
void postMessage(any message, sequence<object> transferable);
[Throws]
void postMessage(any message, optional StructuredSerializeOptions options);
};
ServiceWorker implements AbstractWorker;
+10
View File
@@ -15,6 +15,7 @@
#include "mozilla/Preferences.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/MessagePortBinding.h"
#include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h"
#ifdef XP_WIN
@@ -98,6 +99,15 @@ ServiceWorker::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
aRv = workerPrivate->SendMessageEvent(aCx, aMessage, aTransferable, Move(clientInfo));
}
void
ServiceWorker::PostMessage(JSContext* aCx,
JS::Handle<JS::Value> aMessage,
const StructuredSerializeOptions& aOptions,
ErrorResult& aRv)
{
PostMessage(aCx, aMessage, aOptions.mTransfer, aRv);
}
} // namespace workers
} // namespace dom
} // namespace mozilla
+8
View File
@@ -16,6 +16,8 @@ class nsPIDOMWindowInner;
namespace mozilla {
namespace dom {
struct StructuredSerializeOptions;
namespace workers {
class ServiceWorkerInfo;
@@ -67,6 +69,12 @@ public:
const Sequence<JSObject*>& aTransferable,
ErrorResult& aRv);
void
PostMessage(JSContext* aCx,
JS::Handle<JS::Value> aMessage,
const StructuredSerializeOptions& aOptions,
ErrorResult& aRv);
private:
// This class can only be created from ServiceWorkerInfo::GetOrCreateInstance().
ServiceWorker(nsPIDOMWindowInner* aWindow, ServiceWorkerInfo* aInfo);
+9
View File
@@ -12,6 +12,7 @@
#include "mozilla/dom/Navigator.h"
#include "mozilla/dom/ServiceWorkerMessageEvent.h"
#include "mozilla/dom/ServiceWorkerMessageEventBinding.h"
#include "mozilla/dom/MessagePortBinding.h"
#include "nsGlobalWindow.h"
#include "nsIBrowserDOMWindow.h"
#include "nsIDocument.h"
@@ -221,3 +222,11 @@ ServiceWorkerClient::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
}
}
void
ServiceWorkerClient::PostMessage(JSContext* aCx,
JS::Handle<JS::Value> aMessage,
const StructuredSerializeOptions& aOptions,
ErrorResult& aRv)
{
PostMessage(aCx, aMessage, aOptions.mTransfer, aRv);
}
+6
View File
@@ -95,6 +95,12 @@ public:
const Sequence<JSObject*>& aTransferable,
ErrorResult& aRv);
void
PostMessage(JSContext* aCx,
JS::Handle<JS::Value> aMessage,
const StructuredSerializeOptions& aOptions,
ErrorResult& aRv);
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
protected: