Diff
Modified: trunk/Source/WebCore/ChangeLog (253811 => 253812)
--- trunk/Source/WebCore/ChangeLog 2019-12-20 10:31:03 UTC (rev 253811)
+++ trunk/Source/WebCore/ChangeLog 2019-12-20 11:52:09 UTC (rev 253812)
@@ -1,3 +1,25 @@
+2019-12-20 youenn fablet <[email protected]>
+
+ Make ServiceWorker::postMessage use the exec state from the JS binding layer
+ https://bugs.webkit.org/show_bug.cgi?id=205395
+
+ Reviewed by Chris Dumez.
+
+ Instead of using ScriptExecutionContext::execState, we can ask the JS binding layer to pass the exec state and use it.
+ Since ServiceWorker is an ActiveDOMObject, we use its scriptExecutionContext() to compute the ServiceWorker source identifier.
+ We do the same for ServiceWorkerClient which is a context destruction observer and which only lives in Service Worker scope so calling ScriptExecutionContext::execState is suboptimal.
+
+ No change of behavior.
+
+ * workers/service/ServiceWorker.cpp:
+ (WebCore::ServiceWorker::postMessage):
+ * workers/service/ServiceWorker.h:
+ * workers/service/ServiceWorker.idl:
+ * workers/service/ServiceWorkerClient.cpp:
+ (WebCore::ServiceWorkerClient::postMessage):
+ * workers/service/ServiceWorkerClient.h:
+ * workers/service/ServiceWorkerClient.idl:
+
2019-12-20 Jiewen Tan <[email protected]>
[WebAuthn] Implement coders for CTAP ClientPIN requests and responses
Modified: trunk/Source/WebCore/workers/service/ServiceWorker.cpp (253811 => 253812)
--- trunk/Source/WebCore/workers/service/ServiceWorker.cpp 2019-12-20 10:31:03 UTC (rev 253811)
+++ trunk/Source/WebCore/workers/service/ServiceWorker.cpp 2019-12-20 11:52:09 UTC (rev 253812)
@@ -99,18 +99,13 @@
return ServiceWorkerProvider::singleton().serviceWorkerConnection();
}
-ExceptionOr<void> ServiceWorker::postMessage(ScriptExecutionContext& context, JSC::JSValue messageValue, PostMessageOptions&& options)
+ExceptionOr<void> ServiceWorker::postMessage(JSC::JSGlobalObject& globalObject, JSC::JSValue messageValue, PostMessageOptions&& options)
{
if (m_isStopped)
return Exception { InvalidStateError };
- auto* execState = context.execState();
- ASSERT(execState);
- if (!execState)
- return Exception { InvalidStateError };
-
Vector<RefPtr<MessagePort>> ports;
- auto messageData = SerializedScriptValue::create(*execState, messageValue, WTFMove(options.transfer), ports, SerializationContext::WorkerPostMessage);
+ auto messageData = SerializedScriptValue::create(globalObject, messageValue, WTFMove(options.transfer), ports, SerializationContext::WorkerPostMessage);
if (messageData.hasException())
return messageData.releaseException();
@@ -119,6 +114,7 @@
if (portsOrException.hasException())
return portsOrException.releaseException();
+ auto& context = *scriptExecutionContext();
ServiceWorkerOrClientIdentifier sourceIdentifier;
if (is<ServiceWorkerGlobalScope>(context))
sourceIdentifier = downcast<ServiceWorkerGlobalScope>(context).thread().identifier();
Modified: trunk/Source/WebCore/workers/service/ServiceWorker.h (253811 => 253812)
--- trunk/Source/WebCore/workers/service/ServiceWorker.h 2019-12-20 10:31:03 UTC (rev 253811)
+++ trunk/Source/WebCore/workers/service/ServiceWorker.h 2019-12-20 11:52:09 UTC (rev 253812)
@@ -37,6 +37,7 @@
#include <wtf/URL.h>
namespace JSC {
+class JSGlobalObject;
class JSValue;
}
@@ -59,7 +60,7 @@
void updateState(State);
- ExceptionOr<void> postMessage(ScriptExecutionContext&, JSC::JSValue message, PostMessageOptions&&);
+ ExceptionOr<void> postMessage(JSC::JSGlobalObject&, JSC::JSValue message, PostMessageOptions&&);
ServiceWorkerIdentifier identifier() const { return m_data.identifier; }
ServiceWorkerRegistrationIdentifier registrationIdentifier() const { return m_data.registrationIdentifier; }
Modified: trunk/Source/WebCore/workers/service/ServiceWorker.idl (253811 => 253812)
--- trunk/Source/WebCore/workers/service/ServiceWorker.idl 2019-12-20 10:31:03 UTC (rev 253811)
+++ trunk/Source/WebCore/workers/service/ServiceWorker.idl 2019-12-20 11:52:09 UTC (rev 253812)
@@ -36,8 +36,8 @@
] interface ServiceWorker : EventTarget {
readonly attribute USVString scriptURL;
readonly attribute ServiceWorkerState state;
- [CallWith=ScriptExecutionContext, MayThrowException] void postMessage(any message, sequence<object> transfer);
- [CallWith=ScriptExecutionContext, MayThrowException] void postMessage(any message, optional PostMessageOptions options);
+ [CallWith=GlobalObject, MayThrowException] void postMessage(any message, sequence<object> transfer);
+ [CallWith=GlobalObject, MayThrowException] void postMessage(any message, optional PostMessageOptions options);
// event
attribute EventHandler onstatechange;
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerClient.cpp (253811 => 253812)
--- trunk/Source/WebCore/workers/service/ServiceWorkerClient.cpp 2019-12-20 10:31:03 UTC (rev 253811)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClient.cpp 2019-12-20 11:52:09 UTC (rev 253812)
@@ -82,13 +82,10 @@
return identifier().toString();
}
-ExceptionOr<void> ServiceWorkerClient::postMessage(ScriptExecutionContext& context, JSC::JSValue messageValue, PostMessageOptions&& options)
+ExceptionOr<void> ServiceWorkerClient::postMessage(JSC::JSGlobalObject& globalObject, JSC::JSValue messageValue, PostMessageOptions&& options)
{
- auto* execState = context.execState();
- ASSERT(execState);
-
Vector<RefPtr<MessagePort>> ports;
- auto messageData = SerializedScriptValue::create(*execState, messageValue, WTFMove(options.transfer), ports, SerializationContext::WorkerPostMessage);
+ auto messageData = SerializedScriptValue::create(globalObject, messageValue, WTFMove(options.transfer), ports, SerializationContext::WorkerPostMessage);
if (messageData.hasException())
return messageData.releaseException();
@@ -98,8 +95,9 @@
return portsOrException.releaseException();
MessageWithMessagePorts message = { messageData.releaseReturnValue(), portsOrException.releaseReturnValue() };
- auto sourceIdentifier = downcast<ServiceWorkerGlobalScope>(context).thread().identifier();
- callOnMainThread([message = WTFMove(message), destinationIdentifier = identifier(), sourceIdentifier, sourceOrigin = context.origin().isolatedCopy()] () mutable {
+ auto& context = downcast<ServiceWorkerGlobalScope>(*scriptExecutionContext());
+ auto sourceIdentifier = context.thread().identifier();
+ callOnMainThread([message = WTFMove(message), destinationIdentifier = identifier(), sourceIdentifier, sourceOrigin = context.origin().isolatedCopy()] {
if (auto* connection = SWContextManager::singleton().connection())
connection->postMessageToServiceWorkerClient(destinationIdentifier, message, sourceIdentifier, sourceOrigin);
});
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerClient.h (253811 => 253812)
--- trunk/Source/WebCore/workers/service/ServiceWorkerClient.h 2019-12-20 10:31:03 UTC (rev 253811)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClient.h 2019-12-20 11:52:09 UTC (rev 253812)
@@ -35,6 +35,7 @@
#include <wtf/RefCounted.h>
namespace JSC {
+class JSGlobalObject;
class JSValue;
}
@@ -60,7 +61,7 @@
Identifier identifier() const { return m_data.identifier; }
- ExceptionOr<void> postMessage(ScriptExecutionContext&, JSC::JSValue message, PostMessageOptions&&);
+ ExceptionOr<void> postMessage(JSC::JSGlobalObject&, JSC::JSValue message, PostMessageOptions&&);
protected:
ServiceWorkerClient(ServiceWorkerGlobalScope&, ServiceWorkerClientData&&);
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerClient.idl (253811 => 253812)
--- trunk/Source/WebCore/workers/service/ServiceWorkerClient.idl 2019-12-20 10:31:03 UTC (rev 253811)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClient.idl 2019-12-20 11:52:09 UTC (rev 253812)
@@ -35,8 +35,8 @@
readonly attribute ServiceWorkerClientType type;
readonly attribute DOMString id;
- [CallWith=ScriptExecutionContext, MayThrowException] void postMessage(any message, sequence<object> transfer);
- [CallWith=ScriptExecutionContext, MayThrowException] void postMessage(any message, optional PostMessageOptions options);
+ [CallWith=GlobalObject, MayThrowException] void postMessage(any message, sequence<object> transfer);
+ [CallWith=GlobalObject, MayThrowException] void postMessage(any message, optional PostMessageOptions options);
};
enum FrameType {