Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
window.postMessage with OffscreenCanvas is broken with isolated world…
… message listener

https://bugs.webkit.org/show_bug.cgi?id=259362
rdar://112618195

Reviewed by Darin Adler.

When constructing a MessageEvent, we would deserialize the `data` SerializedScriptValue
and cache the resulting JSValue. When accessing MessageEvent.data from the main world,
we would return the cached JSValue and everything would work fine.
However, upon accessing MessageEvent.data from a non-main world, the cached JSValue
would not be usable and we would deserialize the original SerializedScriptValue again.

The issue is that a SerializedScriptValue is not meant to be deserialized several times.
This is because the deserialization "consumes" certain internal objects. For examples,
OffscreenCanvas are stored as DetachedOffscreenCanvas internally and consumed upon
deserialization to construct OffscreenCanvas objects again.

To address the issue, this patch makes several changes:
1. MessageEvent::create() now stores the deserialized JSValue inside the MessageEvent
   object instead of the SerializedScriptValue. As a result, when accessing
   MessageEvent.data from the main world, we'll just return the internal JSValue.
   When accessing MessageEvent.data from a non-main world, cachedPropertyValue() will
   detect that the internal JSValue is no compatible with this world and call
   cloneAcrossWorlds() on the internal JSValue to generate one suitable for the non-main
   world. Internally, cloneAcrossWorlds() creates a SerializedScriptValue from the JSValue
   and then deserializes that SerializedScriptValue in the target world.
2. As currently implemented, cloneAcrossWorlds() would drop transferrable objects such
   as OffscreenCanvas and MessagePort. To address the issue, we now introduce a new
   CloneAcrossWorlds SerializationContext. When in this context, SerializedScriptValue
   serialization will store OffscreenCanvas/MessagePort in the JSValue inside internal
   vectors and merely serialize indexes inside those vectors. Upon deserialization, we
   deserialize the index and lookup the OffscreenCanvas/MessagePort from the internal
   vector. Then, we call toJS() on the implementation object to get a JS wrapper for the
   target world.

* Source/WebCore/bindings/js/JSDOMWrapper.cpp:
(WebCore::cloneAcrossWorlds):
* Source/WebCore/bindings/js/SerializedScriptValue.cpp:
(WebCore::isTypeExposedToGlobalObject):
(WebCore::CloneSerializer::serialize):
(WebCore::CloneSerializer::CloneSerializer):
(WebCore::CloneSerializer::dumpOffscreenCanvas):
(WebCore::CloneSerializer::dumpIfTerminal):
(WebCore::CloneDeserializer::deserialize):
(WebCore::CloneDeserializer::CloneDeserializer):
(WebCore::CloneDeserializer::readInMemoryOffscreenCanvas):
(WebCore::CloneDeserializer::readTerminal):
(WebCore::SerializedScriptValue::SerializedScriptValue):
(WebCore::SerializedScriptValue::create):
(WebCore::SerializedScriptValue::deserialize):
* Source/WebCore/bindings/js/SerializedScriptValue.h:
* Source/WebCore/dom/MessageEvent.cpp:
(WebCore::MessageEvent::create):
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/UserContentWorld.mm:
(-[UserContentWorldMessageHandler userContentController:didReceiveScriptMessage:]):
(TEST):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/postMessage-various-types.html: Added.

Canonical link: https://commits.webkit.org/266465@main
  • Loading branch information
cdumez committed Aug 1, 2023
1 parent a347abe commit acece69
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Source/WebCore/bindings/js/JSDOMWrapper.cpp
Expand Up @@ -49,7 +49,7 @@ JSC::JSValue cloneAcrossWorlds(JSC::JSGlobalObject& lexicalGlobalObject, const J
if (isWorldCompatible(lexicalGlobalObject, value))
return value;
// FIXME: Is it best to handle errors by returning null rather than throwing an exception?
auto serializedValue = SerializedScriptValue::create(lexicalGlobalObject, value, SerializationForStorage::No, SerializationErrorMode::NonThrowing);
auto serializedValue = SerializedScriptValue::create(lexicalGlobalObject, value, SerializationForStorage::No, SerializationErrorMode::NonThrowing, SerializationContext::CloneAcrossWorlds);
if (!serializedValue)
return JSC::jsNull();
// FIXME: Why is owner->globalObject() better than lexicalGlobalObject.lexicalGlobalObject() here?
Expand Down
87 changes: 87 additions & 0 deletions Source/WebCore/bindings/js/SerializedScriptValue.cpp
Expand Up @@ -218,6 +218,10 @@ enum SerializationTag {
#endif
ResizableArrayBufferTag = 54,
ErrorInstanceTag = 55,
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
InMemoryOffscreenCanvasTag = 56,
#endif
InMemoryMessagePortTag = 57,
ErrorTag = 255
};

Expand Down Expand Up @@ -306,7 +310,9 @@ static bool isTypeExposedToGlobalObject(JSC::JSGlobalObject& globalObject, Seria
case ImageBitmapTag:
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
case OffscreenCanvasTransferTag:
case InMemoryOffscreenCanvasTag:
#endif
case InMemoryMessagePortTag:
#if ENABLE(WEB_RTC)
case RTCDataChannelTransferTag:
#endif
Expand Down Expand Up @@ -800,7 +806,9 @@ class CloneSerializer : CloneBase {
static SerializationReturnCode serialize(JSGlobalObject* lexicalGlobalObject, JSValue value, Vector<RefPtr<MessagePort>>& messagePorts, Vector<RefPtr<JSC::ArrayBuffer>>& arrayBuffers, const Vector<RefPtr<ImageBitmap>>& imageBitmaps,
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
const Vector<RefPtr<OffscreenCanvas>>& offscreenCanvases,
Vector<RefPtr<OffscreenCanvas>>& inMemoryOffscreenCanvases,
#endif
Vector<RefPtr<MessagePort>>& inMemoryMessagePorts,
#if ENABLE(WEB_RTC)
const Vector<Ref<RTCDataChannel>>& rtcDataChannels,
#endif
Expand All @@ -818,7 +826,9 @@ class CloneSerializer : CloneBase {
CloneSerializer serializer(lexicalGlobalObject, messagePorts, arrayBuffers, imageBitmaps,
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
offscreenCanvases,
inMemoryOffscreenCanvases,
#endif
inMemoryMessagePorts,
#if ENABLE(WEB_RTC)
rtcDataChannels,
#endif
Expand Down Expand Up @@ -856,7 +866,9 @@ class CloneSerializer : CloneBase {
CloneSerializer(JSGlobalObject* lexicalGlobalObject, Vector<RefPtr<MessagePort>>& messagePorts, Vector<RefPtr<JSC::ArrayBuffer>>& arrayBuffers, const Vector<RefPtr<ImageBitmap>>& imageBitmaps,
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
const Vector<RefPtr<OffscreenCanvas>>& offscreenCanvases,
Vector<RefPtr<OffscreenCanvas>>& inMemoryOffscreenCanvases,
#endif
Vector<RefPtr<MessagePort>>& inMemoryMessagePorts,
#if ENABLE(WEB_RTC)
const Vector<Ref<RTCDataChannel>>& rtcDataChannels,
#endif
Expand All @@ -875,6 +887,10 @@ class CloneSerializer : CloneBase {
, m_emptyIdentifier(Identifier::fromString(lexicalGlobalObject->vm(), emptyString()))
, m_context(context)
, m_sharedBuffers(sharedBuffers)
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
, m_inMemoryOffscreenCanvases(inMemoryOffscreenCanvases)
#endif
, m_inMemoryMessagePorts(inMemoryMessagePorts)
#if ENABLE(WEBASSEMBLY)
, m_wasmModules(wasmModules)
, m_wasmMemoryHandles(wasmMemoryHandles)
Expand Down Expand Up @@ -1362,6 +1378,11 @@ class CloneSerializer : CloneBase {
write(OffscreenCanvasTransferTag);
write(index->value);
return;
} else if (m_context == SerializationContext::CloneAcrossWorlds) {
write(InMemoryOffscreenCanvasTag);
write(static_cast<uint32_t>(m_inMemoryOffscreenCanvases.size()));
m_inMemoryOffscreenCanvases.append(&jsCast<JSOffscreenCanvas*>(obj)->wrapped());
return;
}

code = SerializationReturnCode::DataCloneError;
Expand Down Expand Up @@ -1602,6 +1623,12 @@ class CloneSerializer : CloneBase {
write(MessagePortReferenceTag);
write(index->value);
return true;
} else if (m_context == SerializationContext::CloneAcrossWorlds) {
// FIXME: Only in clone accross worlds mode.
write (InMemoryMessagePortTag);
write(static_cast<uint32_t>(m_inMemoryMessagePorts.size()));
m_inMemoryMessagePorts.append(&jsCast<JSMessagePort*>(obj)->wrapped());
return true;
}
// MessagePort object could not be found in transferred message ports
code = SerializationReturnCode::ValidationError;
Expand Down Expand Up @@ -1676,10 +1703,16 @@ class CloneSerializer : CloneBase {
WasmMemoryHandleArray dummyMemoryHandles;
#endif
ArrayBufferContentsArray dummySharedBuffers;
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
Vector<RefPtr<OffscreenCanvas>> dummyInMemoryOffscreenCanvases;
#endif
Vector<RefPtr<MessagePort>> dummyInMemoryMessagePorts;
CloneSerializer rawKeySerializer(m_lexicalGlobalObject, dummyMessagePorts, dummyArrayBuffers, { },
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
{ },
dummyInMemoryOffscreenCanvases,
#endif
dummyInMemoryMessagePorts,
#if ENABLE(WEB_RTC)
{ },
#endif
Expand Down Expand Up @@ -2285,6 +2318,10 @@ class CloneSerializer : CloneBase {
Identifier m_emptyIdentifier;
SerializationContext m_context;
ArrayBufferContentsArray& m_sharedBuffers;
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
Vector<RefPtr<OffscreenCanvas>>& m_inMemoryOffscreenCanvases;
#endif
Vector<RefPtr<MessagePort>>& m_inMemoryMessagePorts;
#if ENABLE(WEBASSEMBLY)
WasmModuleArray& m_wasmModules;
WasmMemoryHandleArray& m_wasmMemoryHandles;
Expand Down Expand Up @@ -2580,7 +2617,9 @@ class CloneDeserializer : CloneBase {
static DeserializationResult deserialize(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, Vector<std::optional<ImageBitmapBacking>>&& backingStores
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
, Vector<std::unique_ptr<DetachedOffscreenCanvas>>&& detachedOffscreenCanvases
, const Vector<RefPtr<OffscreenCanvas>>& inMemoryOffscreenCanvases
#endif
, const Vector<RefPtr<MessagePort>>& inMemoryMessagePorts
#if ENABLE(WEB_RTC)
, Vector<std::unique_ptr<DetachedRTCDataChannel>>&& detachedRTCDataChannels
#endif
Expand All @@ -2600,7 +2639,9 @@ class CloneDeserializer : CloneBase {
CloneDeserializer deserializer(lexicalGlobalObject, globalObject, messagePorts, arrayBufferContentsArray, buffer, blobURLs, blobFilePaths, sharedBuffers, WTFMove(backingStores)
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
, WTFMove(detachedOffscreenCanvases)
, inMemoryOffscreenCanvases
#endif
, inMemoryMessagePorts
#if ENABLE(WEB_RTC)
, WTFMove(detachedRTCDataChannels)
#endif
Expand Down Expand Up @@ -2661,7 +2702,9 @@ class CloneDeserializer : CloneBase {
CloneDeserializer(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, ArrayBufferContentsArray* arrayBufferContents, Vector<std::optional<ImageBitmapBacking>>&& backingStores, const Vector<uint8_t>& buffer
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
, Vector<std::unique_ptr<DetachedOffscreenCanvas>>&& detachedOffscreenCanvases = { }
, const Vector<RefPtr<OffscreenCanvas>>& inMemoryOffscreenCanvases = { }
#endif
, const Vector<RefPtr<MessagePort>>& inMemoryMessagePorts = { }
#if ENABLE(WEB_RTC)
, Vector<std::unique_ptr<DetachedRTCDataChannel>>&& detachedRTCDataChannels = { }
#endif
Expand Down Expand Up @@ -2689,7 +2732,9 @@ class CloneDeserializer : CloneBase {
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
, m_detachedOffscreenCanvases(WTFMove(detachedOffscreenCanvases))
, m_offscreenCanvases(m_detachedOffscreenCanvases.size())
, m_inMemoryOffscreenCanvases(inMemoryOffscreenCanvases)
#endif
, m_inMemoryMessagePorts(inMemoryMessagePorts)
#if ENABLE(WEB_RTC)
, m_detachedRTCDataChannels(WTFMove(detachedRTCDataChannels))
, m_rtcDataChannels(m_detachedRTCDataChannels.size())
Expand All @@ -2712,7 +2757,9 @@ class CloneDeserializer : CloneBase {
CloneDeserializer(JSGlobalObject* lexicalGlobalObject, JSGlobalObject* globalObject, const Vector<RefPtr<MessagePort>>& messagePorts, ArrayBufferContentsArray* arrayBufferContents, const Vector<uint8_t>& buffer, const Vector<String>& blobURLs, const Vector<String> blobFilePaths, ArrayBufferContentsArray* sharedBuffers, Vector<std::optional<ImageBitmapBacking>>&& backingStores
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
, Vector<std::unique_ptr<DetachedOffscreenCanvas>>&& detachedOffscreenCanvases
, const Vector<RefPtr<OffscreenCanvas>>& inMemoryOffscreenCanvases
#endif
, const Vector<RefPtr<MessagePort>>& inMemoryMessagePorts
#if ENABLE(WEB_RTC)
, Vector<std::unique_ptr<DetachedRTCDataChannel>>&& detachedRTCDataChannels
#endif
Expand Down Expand Up @@ -2743,7 +2790,9 @@ class CloneDeserializer : CloneBase {
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
, m_detachedOffscreenCanvases(WTFMove(detachedOffscreenCanvases))
, m_offscreenCanvases(m_detachedOffscreenCanvases.size())
, m_inMemoryOffscreenCanvases(inMemoryOffscreenCanvases)
#endif
, m_inMemoryMessagePorts(inMemoryMessagePorts)
#if ENABLE(WEB_RTC)
, m_detachedRTCDataChannels(WTFMove(detachedRTCDataChannels))
, m_rtcDataChannels(m_detachedRTCDataChannels.size())
Expand Down Expand Up @@ -3847,6 +3896,17 @@ class CloneDeserializer : CloneBase {
auto offscreenCanvas = m_offscreenCanvases[index].get();
return getJSValue(offscreenCanvas);
}

JSValue readInMemoryOffscreenCanvas()
{
uint32_t index;
bool indexSuccessfullyRead = read(index);
if (!indexSuccessfullyRead || index >= m_inMemoryOffscreenCanvases.size()) {
fail();
return JSValue();
}
return getJSValue(m_inMemoryOffscreenCanvases[index].get());
}
#endif

#if ENABLE(WEB_RTC)
Expand Down Expand Up @@ -4329,6 +4389,15 @@ class CloneDeserializer : CloneBase {
}
return getJSValue(m_messagePorts[index].get());
}
case InMemoryMessagePortTag: {
uint32_t index;
bool indexSuccessfullyRead = read(index);
if (!indexSuccessfullyRead || index >= m_inMemoryMessagePorts.size()) {
fail();
return JSValue();
}
return getJSValue(m_inMemoryMessagePorts[index].get());
}
#if ENABLE(WEBASSEMBLY)
case WasmModuleTag: {
if (m_version >= 12) {
Expand Down Expand Up @@ -4517,6 +4586,8 @@ class CloneDeserializer : CloneBase {
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
case OffscreenCanvasTransferTag:
return readOffscreenCanvas();
case InMemoryOffscreenCanvasTag:
return readInMemoryOffscreenCanvas();
#endif
#if ENABLE(WEB_RTC)
case RTCDataChannelTransferTag:
Expand Down Expand Up @@ -4565,7 +4636,9 @@ class CloneDeserializer : CloneBase {
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
Vector<std::unique_ptr<DetachedOffscreenCanvas>> m_detachedOffscreenCanvases;
Vector<RefPtr<OffscreenCanvas>> m_offscreenCanvases;
const Vector<RefPtr<OffscreenCanvas>>& m_inMemoryOffscreenCanvases;
#endif
const Vector<RefPtr<MessagePort>>& m_inMemoryMessagePorts;
#if ENABLE(WEB_RTC)
Vector<std::unique_ptr<DetachedRTCDataChannel>> m_detachedRTCDataChannels;
Vector<RefPtr<RTCDataChannel>> m_rtcDataChannels;
Expand Down Expand Up @@ -4803,7 +4876,9 @@ SerializedScriptValue::SerializedScriptValue(Vector<uint8_t>&& buffer, std::uniq
SerializedScriptValue::SerializedScriptValue(Vector<uint8_t>&& buffer, Vector<URLKeepingBlobAlive>&& blobHandles, std::unique_ptr<ArrayBufferContentsArray> arrayBufferContentsArray, std::unique_ptr<ArrayBufferContentsArray> sharedBufferContentsArray, Vector<std::optional<ImageBitmapBacking>>&& backingStores
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
, Vector<std::unique_ptr<DetachedOffscreenCanvas>>&& detachedOffscreenCanvases
, Vector<RefPtr<OffscreenCanvas>>&& inMemoryOffscreenCanvases
#endif
, Vector<RefPtr<MessagePort>>&& inMemoryMessagePorts
#if ENABLE(WEB_RTC)
, Vector<std::unique_ptr<DetachedRTCDataChannel>>&& detachedRTCDataChannels
#endif
Expand All @@ -4822,7 +4897,9 @@ SerializedScriptValue::SerializedScriptValue(Vector<uint8_t>&& buffer, Vector<UR
, m_backingStores(WTFMove(backingStores))
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
, m_detachedOffscreenCanvases(WTFMove(detachedOffscreenCanvases))
, m_inMemoryOffscreenCanvases(WTFMove(inMemoryOffscreenCanvases))
#endif
, m_inMemoryMessagePorts(WTFMove(inMemoryMessagePorts))
#if ENABLE(WEB_RTC)
, m_detachedRTCDataChannels(WTFMove(detachedRTCDataChannels))
#endif
Expand Down Expand Up @@ -5101,6 +5178,10 @@ ExceptionOr<Ref<SerializedScriptValue>> SerializedScriptValue::create(JSGlobalOb

Vector<uint8_t> buffer;
Vector<URLKeepingBlobAlive> blobHandles;
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
Vector<RefPtr<OffscreenCanvas>> inMemoryOffscreenCanvases;
#endif
Vector<RefPtr<MessagePort>> inMemoryMessagePorts;
#if ENABLE(WEBASSEMBLY)
WasmModuleArray wasmModules;
WasmMemoryHandleArray wasmMemoryHandles;
Expand All @@ -5113,7 +5194,9 @@ ExceptionOr<Ref<SerializedScriptValue>> SerializedScriptValue::create(JSGlobalOb
auto code = CloneSerializer::serialize(&lexicalGlobalObject, value, messagePorts, arrayBuffers, imageBitmaps,
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
offscreenCanvases,
inMemoryOffscreenCanvases,
#endif
inMemoryMessagePorts,
#if ENABLE(WEB_RTC)
dataChannels,
#endif
Expand Down Expand Up @@ -5161,7 +5244,9 @@ ExceptionOr<Ref<SerializedScriptValue>> SerializedScriptValue::create(JSGlobalOb
return adoptRef(*new SerializedScriptValue(WTFMove(buffer), WTFMove(blobHandles), arrayBufferContentsArray.releaseReturnValue(), context == SerializationContext::WorkerPostMessage ? WTFMove(sharedBuffers) : nullptr, WTFMove(backingStores)
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
, WTFMove(detachedCanvases)
, WTFMove(inMemoryOffscreenCanvases)
#endif
, WTFMove(inMemoryMessagePorts)
#if ENABLE(WEB_RTC)
, WTFMove(detachedRTCDataChannels)
#endif
Expand Down Expand Up @@ -5225,7 +5310,9 @@ JSValue SerializedScriptValue::deserialize(JSGlobalObject& lexicalGlobalObject,
DeserializationResult result = CloneDeserializer::deserialize(&lexicalGlobalObject, globalObject, messagePorts, WTFMove(m_backingStores)
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
, WTFMove(m_detachedOffscreenCanvases)
, m_inMemoryOffscreenCanvases
#endif
, m_inMemoryMessagePorts
#if ENABLE(WEB_RTC)
, WTFMove(m_detachedRTCDataChannels)
#endif
Expand Down
7 changes: 6 additions & 1 deletion Source/WebCore/bindings/js/SerializedScriptValue.h
Expand Up @@ -56,6 +56,7 @@ namespace WebCore {

#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
class DetachedOffscreenCanvas;
class OffscreenCanvas;
#endif
class IDBValue;
class MessagePort;
Expand All @@ -64,7 +65,7 @@ class FragmentedSharedBuffer;
enum class SerializationReturnCode;

enum class SerializationErrorMode { NonThrowing, Throwing };
enum class SerializationContext { Default, WorkerPostMessage, WindowPostMessage };
enum class SerializationContext { Default, WorkerPostMessage, WindowPostMessage, CloneAcrossWorlds };
enum class SerializationForStorage : bool { No, Yes };

using ArrayBufferContentsArray = Vector<JSC::ArrayBufferContents>;
Expand Down Expand Up @@ -131,7 +132,9 @@ class SerializedScriptValue : public ThreadSafeRefCounted<SerializedScriptValue>
SerializedScriptValue(Vector<unsigned char>&&, Vector<URLKeepingBlobAlive>&& blobHandles, std::unique_ptr<ArrayBufferContentsArray>, std::unique_ptr<ArrayBufferContentsArray> sharedBuffers, Vector<std::optional<ImageBitmapBacking>>&& backingStores
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
, Vector<std::unique_ptr<DetachedOffscreenCanvas>>&& = { }
, Vector<RefPtr<OffscreenCanvas>>&& = { }
#endif
, Vector<RefPtr<MessagePort>>&& = { }
#if ENABLE(WEB_RTC)
, Vector<std::unique_ptr<DetachedRTCDataChannel>>&& = { }
#endif
Expand All @@ -153,7 +156,9 @@ class SerializedScriptValue : public ThreadSafeRefCounted<SerializedScriptValue>
Vector<std::optional<ImageBitmapBacking>> m_backingStores;
#if ENABLE(OFFSCREEN_CANVAS_IN_WORKERS)
Vector<std::unique_ptr<DetachedOffscreenCanvas>> m_detachedOffscreenCanvases;
Vector<RefPtr<OffscreenCanvas>> m_inMemoryOffscreenCanvases;
#endif
Vector<RefPtr<MessagePort>> m_inMemoryMessagePorts;
#if ENABLE(WEB_RTC)
Vector<std::unique_ptr<DetachedRTCDataChannel>> m_detachedRTCDataChannels;
#endif
Expand Down
6 changes: 2 additions & 4 deletions Source/WebCore/dom/MessageEvent.cpp
Expand Up @@ -74,11 +74,9 @@ auto MessageEvent::create(JSC::JSGlobalObject& globalObject, Ref<SerializedScrip
JSC::Strong<JSC::Unknown> strongData(vm, deserialized);

auto& eventType = didFail ? eventNames().messageerrorEvent : eventNames().messageEvent;
auto event = adoptRef(*new MessageEvent(eventType, WTFMove(data), origin, lastEventId, WTFMove(source), WTFMove(ports)));
auto event = adoptRef(*new MessageEvent(eventType, MessageEvent::JSValueTag { }, origin, lastEventId, WTFMove(source), WTFMove(ports)));
JSC::Strong<JSC::JSObject> strongWrapper(vm, JSC::jsCast<JSC::JSObject*>(toJS(&globalObject, JSC::jsCast<JSDOMGlobalObject*>(&globalObject), event.get())));
// Since we've already deserialized the SerializedScriptValue, cache the result so we don't have to deserialize
// again the next time JSMessageEvent::data() gets called by the main world.
event->cachedData().set(vm, strongWrapper.get(), deserialized);
event->jsData().set(vm, strongWrapper.get(), deserialized);

return MessageEventWithStrongData { event, WTFMove(strongWrapper) };
}
Expand Down

0 comments on commit acece69

Please sign in to comment.