Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Keep cause-free Error serialization on its terminal fast path with byte-identical v14 output; use a distinct v16 Error cause tag and capability negotiation with older IPC peers.

- Avoid an extra payload copy when structured cloning or messaging a Buffer or ArrayBuffer inside a container, without changing serialized bytes.

- Preserve Error cause graphs in structured cloning and worker messages, while retaining v14 bytes for cause-free values and negotiating cause support for advanced IPC with older Bun processes; thanks fuller-stack-dev.

- Sync oven-sh/bun through `ad4089bf49d9f4c3ab7c8d95a58f3e0f0f186054`, including lint, format, binding, WebSocket and SQL updates, while retaining the fork runtime and CI contracts.
Expand Down
15 changes: 13 additions & 2 deletions src/jsc/bindings/webcore/SerializedScriptValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ class CloneSerializer : public CloneBase {
{
if (!startObjectInternal(object))
return false;
m_pendingContainerBytes += sizeof(TerminatorTag);
write(ObjectTag);
return true;
}
Expand All @@ -865,6 +866,7 @@ class CloneSerializer : public CloneBase {
if (!startObjectInternal(array))
return false;

m_pendingContainerBytes += sizeof(TerminatorTag);
unsigned length = array->length();
write(ArrayTag);
write(length);
Expand All @@ -876,6 +878,7 @@ class CloneSerializer : public CloneBase {
if (!startObjectInternal(set))
return false;

m_pendingContainerBytes += sizeof(uint8_t) + sizeof(TerminatorTag);
write(SetObjectTag);
return true;
}
Expand All @@ -885,12 +888,15 @@ class CloneSerializer : public CloneBase {
if (!startObjectInternal(map))
return false;

m_pendingContainerBytes += sizeof(uint8_t) + sizeof(TerminatorTag);
write(MapObjectTag);
return true;
}

void endObject()
{
ASSERT(m_pendingContainerBytes >= sizeof(TerminatorTag));
m_pendingContainerBytes -= sizeof(TerminatorTag);
write(TerminatorTag);
}

Expand Down Expand Up @@ -1386,7 +1392,7 @@ class CloneSerializer : public CloneBase {

if (arrayBuffer->isResizableOrGrowableShared()) {
uint64_t byteLength = arrayBuffer->byteLength();
if (!m_buffer.tryReserveCapacity(static_cast<uint64_t>(m_buffer.size()) + sizeof(uint8_t) + sizeof(uint64_t) * 2 + byteLength)) [[unlikely]] {
if (!m_buffer.tryReserveCapacity(static_cast<uint64_t>(m_buffer.size()) + sizeof(uint8_t) + sizeof(uint64_t) * 2 + byteLength + m_pendingContainerBytes)) [[unlikely]] {
code = SerializationReturnCode::DataCloneError;
return true;
}
Expand All @@ -1399,7 +1405,9 @@ class CloneSerializer : public CloneBase {
}

uint64_t byteLength = arrayBuffer->byteLength();
if (!m_buffer.tryReserveCapacity(static_cast<uint64_t>(m_buffer.size()) + sizeof(uint8_t) + sizeof(uint64_t) + byteLength)) [[unlikely]] {
// Reserve mandatory container trailers before copying the payload so
// closing the containers cannot copy the payload again.
if (!m_buffer.tryReserveCapacity(static_cast<uint64_t>(m_buffer.size()) + sizeof(uint8_t) + sizeof(uint64_t) + byteLength + m_pendingContainerBytes)) [[unlikely]] {
code = SerializationReturnCode::DataCloneError;
return true;
}
Expand Down Expand Up @@ -2144,6 +2152,7 @@ class CloneSerializer : public CloneBase {
ErrorInstance* m_pendingError { nullptr };
JSValue m_pendingErrorCause;
bool m_hasErrorCause { false };
unsigned m_pendingContainerBytes { 0 };
ObjectPool m_objectPool;
ObjectPool m_transferredMessagePorts;
ObjectPool m_transferredArrayBuffers;
Expand Down Expand Up @@ -2330,6 +2339,7 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in)
mapIteratorStack.removeLast();
RETURN_IF_EXCEPTION(scope, SerializationReturnCode::ExistingExceptionError);
// Keep the legacy property-section markers, but clone only Map entries.
m_pendingContainerBytes -= sizeof(uint8_t);
write(NonMapPropertiesTag);
endObject();
inputObjectStack.removeLast();
Expand Down Expand Up @@ -2376,6 +2386,7 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in)
if (!hasNext) {
setIteratorStack.removeLast();
// Older readers still expect an empty own-property section after Set entries.
m_pendingContainerBytes -= sizeof(uint8_t);
write(NonSetPropertiesTag);
endObject();
inputObjectStack.removeLast();
Expand Down
Loading