Skip to content

Truly independent web browser

LibWeb+LibWebCommon: Name the SharedArrayBuffer side table same-agent

Andreas Kling2387cf4aa3e9
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/cpp.rs b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/cpp.rs
index cf9aff62885..859547c0c7a 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/cpp.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/cpp.rs
@@ -100,7 +100,7 @@ impl IPCSerializationRecord {
Self(NonNull::new(record).expect("C++ lends a record"))
}
- /// Sets the record to the bytes, with the SharedArrayBuffers of its same-process side table.
+ /// Sets the record to the bytes, with the SharedArrayBuffers of its same-agent side table.
pub(crate) fn set(self, data: &[u8], shared_array_buffers: &[Gc<ArrayBuffer>]) {
let shared_array_buffers = objects_into_abi(shared_array_buffers);
// SAFETY: The record is lent, the call borrows the bytes, and the buffers are live.
@@ -157,7 +157,7 @@ impl<'a> ReceivedIPCSerializationRecord<'a> {
data.as_slice()
}
- /// The SharedArrayBuffer at the index of the record's same-process side table, if there is one.
+ /// The SharedArrayBuffer at the index of the record's same-agent side table, if there is one.
pub(crate) fn shared_array_buffer(self, side_table_index: u32) -> Option<Gc<ArrayBuffer>> {
// SAFETY: The record is lent. LibWeb returns a live object or null.
let object = unsafe {
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs
index 17ce4a69dd4..2526f8cb7f0 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/mod.rs
@@ -461,10 +461,10 @@ fn serialize_array_buffer(
// 2. If value has an [[ArrayBufferMaxByteLength]] internal slot, then set serialized to { [[Type]]: "GrowableSharedArrayBuffer",
// [[ArrayBufferData]]: value.[[ArrayBufferData]], [[ArrayBufferByteLengthData]]: value.[[ArrayBufferByteLengthData]],
// [[ArrayBufferMaxByteLength]]: value.[[ArrayBufferMaxByteLength]] }.
- // To share with a same-process target, stash the source buffer in the side table. The byte copy keeps the
+ // To share with a same-agent target, stash the source buffer in the side table. The byte copy keeps the
// wire format self-contained for records that cross a process boundary.
// AD-HOC: A growable SharedArrayBuffer isn't backed by cross-process shared memory (its storage is
- // process-local) — so only a same-process target can share it. A record that crosses a process
+ // process-local) — so only a same-agent target can share it. A record that crosses a process
// boundary hands the peer a copy.
// FIXME: Share it across processes too: a max-sized shared mapping with a shared length word (#11682).
data_holder.encode_u8(ValueTag::GrowableSharedArrayBuffer as u8);
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/reader.rs b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/reader.rs
index ea3558de561..fe4dc73456f 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/reader.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/reader.rs
@@ -205,7 +205,7 @@ impl<'a> StructuredSerializeReader<'a> {
)))
}
- /// A new SharedArrayBuffer that shares the storage of the buffer at the index of the record's same-process side
+ /// A new SharedArrayBuffer that shares the storage of the buffer at the index of the record's same-agent side
/// table, if there is such a buffer, and its storage can be shared.
pub(crate) fn array_buffer_sharing_side_table_entry(
&self,
diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/writer.rs b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/writer.rs
index 119c28cfa31..b9d27986628 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/writer.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/html/structured_serialize/writer.rs
@@ -29,8 +29,8 @@ use crate::html::structured_serialize::serializable::serializable_interface_stor
/// The record of a structured serialization, which the serialization writes its values to.
pub(crate) struct StructuredSerializeWriter<'vm> {
encoder: RefCell<RecordEncoder>,
- /// The SharedArrayBuffers that an IPC record shares with a deserialization in the same process, by their index in
- /// this same-process side table.
+ /// The SharedArrayBuffers that an IPC record shares with a deserialization in the same agent, by their index in
+ /// this same-agent side table.
shared_array_buffers: MarkedVec<'vm, Gc<ArrayBuffer>>,
/// The shared memory that a MessageRecord, which may reach agents in other processes, hands over beside its bytes.
shared_memory: Option<RefCell<Vec<SharedMemory>>>,
@@ -145,7 +145,7 @@ impl<'vm> StructuredSerializeWriter<'vm> {
.encode_big_int(big_int.is_negative(), &big_int.magnitude_to_bytes_be());
}
- /// Puts the SharedArrayBuffer in the record's same-process side table, and returns its index there.
+ /// Puts the SharedArrayBuffer in the record's same-agent side table, and returns its index there.
pub(crate) fn add_shared_array_buffer(&self, array_buffer: Gc<ArrayBuffer>) -> u32 {
let index = u32::try_from(self.shared_array_buffers.len()).expect("a record shares fewer than 2^32 buffers");
self.shared_array_buffers.push(array_buffer);
diff --git a/Libraries/LibWeb/HTML/StructuredSerialize.cpp b/Libraries/LibWeb/HTML/StructuredSerialize.cpp
index 9db4b8fac92..eb234d0ad45 100644
--- a/Libraries/LibWeb/HTML/StructuredSerialize.cpp
+++ b/Libraries/LibWeb/HTML/StructuredSerialize.cpp
@@ -17,9 +17,9 @@
namespace Web::HTML {
-// The same-process SharedArrayBuffer aliases of an IPCSerializationRecord. Only this file creates side tables, so a
+// The same-agent SharedArrayBuffer aliases of an IPCSerializationRecord. Only this file creates side tables, so a
// record's side table is one of these.
-class SharedArrayBufferSideTable final : public SameProcessSerializationSideTable {
+class SharedArrayBufferSideTable final : public SameAgentSerializationSideTable {
public:
explicit SharedArrayBufferSideTable(Vector<GC::Root<JS::ArrayBuffer>> array_buffers)
: m_array_buffers(move(array_buffers))
@@ -37,15 +37,15 @@ IPCSerializationRecord create_ipc_serialization_record(ReadonlyBytes data, Vecto
IPCSerializationRecord record;
record.data.append(data.data(), data.size());
if (!shared_array_buffers.is_empty())
- record.same_process_side_table = adopt_ref(*new SharedArrayBufferSideTable(move(shared_array_buffers)));
+ record.same_agent_side_table = adopt_ref(*new SharedArrayBufferSideTable(move(shared_array_buffers)));
return record;
}
-ReadonlySpan<GC::Root<JS::ArrayBuffer>> same_process_shared_array_buffers(IPCSerializationRecord const& record)
+ReadonlySpan<GC::Root<JS::ArrayBuffer>> same_agent_shared_array_buffers(IPCSerializationRecord const& record)
{
- if (!record.same_process_side_table)
+ if (!record.same_agent_side_table)
return {};
- return static_cast<SharedArrayBufferSideTable const&>(*record.same_process_side_table).array_buffers();
+ return static_cast<SharedArrayBufferSideTable const&>(*record.same_agent_side_table).array_buffers();
}
WebIDL::Exception data_clone_error_from_serialization_error(JS::Realm& realm, AK::Error const& error)
diff --git a/Libraries/LibWeb/HTML/StructuredSerialize.h b/Libraries/LibWeb/HTML/StructuredSerialize.h
index c1a46acefd5..53007b57dfa 100644
--- a/Libraries/LibWeb/HTML/StructuredSerialize.h
+++ b/Libraries/LibWeb/HTML/StructuredSerialize.h
@@ -64,7 +64,7 @@ enum class AllowSharedArrayBuffers : u8 {
};
// The SharedArrayBuffers that a record produced in this process aliases instead of copying.
-WEB_API ReadonlySpan<GC::Root<JS::ArrayBuffer>> same_process_shared_array_buffers(IPCSerializationRecord const&);
+WEB_API ReadonlySpan<GC::Root<JS::ArrayBuffer>> same_agent_shared_array_buffers(IPCSerializationRecord const&);
IPCSerializationRecord create_ipc_serialization_record(ReadonlyBytes data, Vector<GC::Root<JS::ArrayBuffer>> shared_array_buffers);
WEB_API WebIDL::ExceptionOr<IPCSerializationRecord> structured_serialize(JS::VM&, JS::Value);
diff --git a/Libraries/LibWeb/HTML/StructuredSerializeRustIntegration.cpp b/Libraries/LibWeb/HTML/StructuredSerializeRustIntegration.cpp
index a1ea1f24f11..bcf2d8cd0e5 100644
--- a/Libraries/LibWeb/HTML/StructuredSerializeRustIntegration.cpp
+++ b/Libraries/LibWeb/HTML/StructuredSerializeRustIntegration.cpp
@@ -139,7 +139,7 @@ void web_structured_serialize_ipc_record_data(IPCSerializationRecord const* reco
JSObject* web_structured_serialize_ipc_record_shared_array_buffer(IPCSerializationRecord const* record, u32 side_table_index)
{
- auto shared_array_buffers = same_process_shared_array_buffers(*record);
+ auto shared_array_buffers = same_agent_shared_array_buffers(*record);
if (side_table_index >= shared_array_buffers.size())
return nullptr;
return JS::HostABI::object_to_abi(shared_array_buffers[side_table_index].ptr());
@@ -264,7 +264,7 @@ void web_structured_serialize_transfer_record_destroy(SerializedTransferRecord*
void web_structured_serialize_transfer_record_take(SerializedTransferRecord* record, void* context, void (*receive)(void*, ReadonlyBytes, JSObject* const*, size_t, int const*, size_t const*, size_t, int), void (*append_holder)(void*, TransferDataEncoder*))
{
Vector<JSObject*> buffers;
- for (auto const& buffer : same_process_shared_array_buffers(record->serialized))
+ for (auto const& buffer : same_agent_shared_array_buffers(record->serialized))
buffers.append(JS::HostABI::object_to_abi(buffer.ptr()));
Vector<int> descriptors;
Vector<size_t> sizes;
diff --git a/Libraries/LibWebCommon/HTML/SerializationRecords.cpp b/Libraries/LibWebCommon/HTML/SerializationRecords.cpp
index 395ada76378..9c8191fd08a 100644
--- a/Libraries/LibWebCommon/HTML/SerializationRecords.cpp
+++ b/Libraries/LibWebCommon/HTML/SerializationRecords.cpp
@@ -14,7 +14,7 @@
namespace Web::HTML {
-SameProcessSerializationSideTable::~SameProcessSerializationSideTable() = default;
+SameAgentSerializationSideTable::~SameAgentSerializationSideTable() = default;
SharedStoreLifeline SharedStoreLifeline::adopting_fd(int fd)
{
@@ -113,7 +113,7 @@ ErrorOr<Web::HTML::TransferDataEncoder> decode(Decoder& decoder)
template<>
ErrorOr<void> encode(Encoder& encoder, Web::HTML::IPCSerializationRecord const& record)
{
- // record.same_process_side_table is deliberately not encoded: it is a same-process aliasing side
+ // record.same_agent_side_table is deliberately not encoded: it is a same-agent aliasing side
// table, so a record that crosses a process boundary arrives with an empty side table by
// construction and deserializes SharedArrayBuffers from the self-contained byte copy in
// record.data instead.
diff --git a/Libraries/LibWebCommon/HTML/SerializationRecords.h b/Libraries/LibWebCommon/HTML/SerializationRecords.h
index c134379269e..197e1b1b4bc 100644
--- a/Libraries/LibWebCommon/HTML/SerializationRecords.h
+++ b/Libraries/LibWebCommon/HTML/SerializationRecords.h
@@ -25,18 +25,18 @@
namespace Web::HTML {
// NB: References that are only meaningful inside the process that produced a serialization record, such as LibWeb's
-// same-process SharedArrayBuffer aliases. It is never IPC-encoded, and is opaque outside of LibWeb.
-class WEBCOMMON_API SameProcessSerializationSideTable : public RefCounted<SameProcessSerializationSideTable> {
+// same-agent SharedArrayBuffer aliases. It is never IPC-encoded, and is opaque outside of LibWeb.
+class WEBCOMMON_API SameAgentSerializationSideTable : public RefCounted<SameAgentSerializationSideTable> {
public:
- virtual ~SameProcessSerializationSideTable();
+ virtual ~SameAgentSerializationSideTable();
};
struct IPCSerializationRecord {
IPC::MessageDataType data;
- // Same-process SharedArrayBuffer aliases. This is intentionally not IPC-encoded; cross-process
+ // Same-agent SharedArrayBuffer aliases. This is intentionally not IPC-encoded; cross-process
// records fall back to the byte copy in `data`.
- RefPtr<SameProcessSerializationSideTable const> same_process_side_table;
+ RefPtr<SameAgentSerializationSideTable const> same_agent_side_table;
IPCSerializationRecord() = default;
explicit IPCSerializationRecord(IPC::MessageDataType data)
diff --git a/Tests/LibWeb/TestStructuredSerializeSharedArrayBuffer.cpp b/Tests/LibWeb/TestStructuredSerializeSharedArrayBuffer.cpp
index ebc74adb95f..57544e82351 100644
--- a/Tests/LibWeb/TestStructuredSerializeSharedArrayBuffer.cpp
+++ b/Tests/LibWeb/TestStructuredSerializeSharedArrayBuffer.cpp
@@ -94,13 +94,13 @@ static Web::HTML::IPCSerializationRecord ipc_round_trip(Web::HTML::IPCSerializat
return MUST(decoder.decode<Web::HTML::IPCSerializationRecord>());
}
-TEST_CASE(same_process_clone_aliases_the_backing_store)
+TEST_CASE(same_agent_clone_aliases_the_backing_store)
{
auto source = make_shared_array_buffer(source_realm(), "shared array buffer"sv.bytes());
auto record = serialize_same_agent(JS::Value { source.ptr() });
- EXPECT_EQ(Web::HTML::same_process_shared_array_buffers(record).size(), 1uz);
- EXPECT_EQ(Web::HTML::same_process_shared_array_buffers(record)[0].ptr(), source.ptr());
+ EXPECT_EQ(Web::HTML::same_agent_shared_array_buffers(record).size(), 1uz);
+ EXPECT_EQ(Web::HTML::same_agent_shared_array_buffers(record)[0].ptr(), source.ptr());
auto& clone = as_array_buffer(deserialize(record, target_realm()));
EXPECT(clone.is_shared_array_buffer());
@@ -184,7 +184,7 @@ TEST_CASE(ipc_round_trip_degrades_to_a_copy)
auto source = make_shared_array_buffer(source_realm(), "copied across processes"sv.bytes());
auto record = ipc_round_trip(serialize_same_agent(JS::Value { source.ptr() }));
- EXPECT(Web::HTML::same_process_shared_array_buffers(record).is_empty());
+ EXPECT(Web::HTML::same_agent_shared_array_buffers(record).is_empty());
auto& clone = as_array_buffer(deserialize(record, target_realm()));
EXPECT(clone.is_shared_array_buffer());
@@ -204,8 +204,8 @@ TEST_CASE(growable_shared_array_buffer_aliases_the_backing_store)
source->set_max_byte_length(128);
auto record = serialize_same_agent(JS::Value { source.ptr() });
- EXPECT_EQ(Web::HTML::same_process_shared_array_buffers(record).size(), 1uz);
- EXPECT_EQ(Web::HTML::same_process_shared_array_buffers(record)[0].ptr(), source.ptr());
+ EXPECT_EQ(Web::HTML::same_agent_shared_array_buffers(record).size(), 1uz);
+ EXPECT_EQ(Web::HTML::same_agent_shared_array_buffers(record)[0].ptr(), source.ptr());
auto& clone = as_array_buffer(deserialize(record, target_realm()));
EXPECT(clone.is_shared_array_buffer());