From 06282ffef5c1e6f19e496c2172b54cd4179048b2 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Sat, 15 Feb 2025 14:07:18 -0500 Subject: [PATCH 1/6] Prevent structuredClone transfer of immutable array buffers (which are not detachable) Ref https://github.com/tc39/proposal-immutable-arraybuffer/issues/30 --- source | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source b/source index 2f6d690e48d..eee040a91d0 100644 --- a/source +++ b/source @@ -3047,6 +3047,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • The IsConstructor abstract operation
  • The IsDataDescriptor abstract operation
  • The IsDetachedBuffer abstract operation
  • +
  • The IsImmutableBuffer abstract operation
  • The IsSharedArrayBuffer abstract operation
  • The NewObjectEnvironment abstract operation
  • The NormalCompletion abstract operation
  • @@ -10463,7 +10464,8 @@ o.myself = o; "DataCloneError" DOMException.

  • If transferable has an [[ArrayBufferData]] internal slot and - IsSharedArrayBuffer(transferable) is true, then throw a + IsSharedArrayBuffer(transferable) is true or + either IsImmutableBuffer(transferable) is true, then throw a "DataCloneError" DOMException.

  • If memory[transferable] exists, From 2f4d3cb4ed91021748eeb0bb96c485199ead0449 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Mon, 17 Feb 2025 15:17:00 -0500 Subject: [PATCH 2/6] Preserve ArrayBuffer immutability in Structured{Serialize,Deserialize} --- source | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/source b/source index eee040a91d0..b73faabdeac 100644 --- a/source +++ b/source @@ -9745,6 +9745,16 @@ interface DOMStringList {

  • +
  • +

    Otherwise, if IsImmutableBuffer(value) is true, then:

    + +
      +
    1. Set serialized to { [[Type]]: "ImmutableArrayBuffer", [[ArrayBufferData]]: + value.[[ArrayBufferData]], [[ArrayBufferByteLength]]: + value.[[ArrayBufferByteLength]] }.

    2. +
    +
  • +
  • Otherwise:

    @@ -9792,7 +9802,8 @@ interface DOMStringList { memory).

  • Assert: bufferSerialized.[[Type]] is "ArrayBuffer", - "ResizableArrayBuffer", "SharedArrayBuffer", or "GrowableSharedArrayBuffer".

  • + "ImmutableArrayBuffer", "ResizableArrayBuffer", "SharedArrayBuffer", or + "GrowableSharedArrayBuffer".

  • If value has a [[DataView]] internal slot, then set serialized to { [[Type]]: "ArrayBufferView", [[Constructor]]: "DataView", [[ArrayBufferSerialized]]: @@ -10187,6 +10198,20 @@ o.myself = o;

  • +
  • +

    Otherwise, if serialized.[[Type]] is "ImmutableArrayBuffer", then:

    + +
      +
    1. Set value to a new ArrayBuffer object in targetRealm whose + [[ArrayBufferData]] internal slot value is serialized.[[ArrayBufferData]], whose + [[ArrayBufferByteLength]] internal slot value is + serialized.[[ArrayBufferByteLength]], and whose [[ArrayBufferIsImmutable]] internal + slot is present.

    2. + +
    3. Assert: IsImmutableBuffer(value) is true.

    4. +
    +
  • +
  • Otherwise, if serialized.[[Type]] is "ArrayBuffer", then set value to a new ArrayBuffer object in targetRealm whose [[ArrayBufferData]] internal slot value From a48c69ae6819743845e13230edf90518ea98efea Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Mon, 17 Feb 2025 19:18:39 -0500 Subject: [PATCH 3/6] Comment on StructuredSerializeInternal for an immutable ArrayBuffer with forStorage true vs. false --- source | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/source b/source index b73faabdeac..426f6e9dda8 100644 --- a/source +++ b/source @@ -9749,9 +9749,17 @@ interface DOMStringList {

    Otherwise, if IsImmutableBuffer(value) is true, then:

      -
    1. Set serialized to { [[Type]]: "ImmutableArrayBuffer", [[ArrayBufferData]]: - value.[[ArrayBufferData]], [[ArrayBufferByteLength]]: - value.[[ArrayBufferByteLength]] }.

    2. +
    3. +

      Set serialized to { [[Type]]: "ImmutableArrayBuffer", [[ArrayBufferData]]: + value.[[ArrayBufferData]], [[ArrayBufferByteLength]]: + value.[[ArrayBufferByteLength]] }.

      + +

      To support deserialization by independent processes at arbitrary points in + the future, the contents of value.[[ArrayBufferData]] + must be preserved when forStorage is true. But otherwise, a + pointer referencing value.[[ArrayBufferData]] is expected to + suffice.

      +
  • From 1c0cf64712039cde6d5a1103da7a0112f5c287a9 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Tue, 18 Feb 2025 13:14:19 -0500 Subject: [PATCH 4/6] fixup! Comment on StructuredSerializeInternal for an immutable ArrayBuffer with forStorage true vs. false --- source | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source b/source index 426f6e9dda8..5b52d803e2c 100644 --- a/source +++ b/source @@ -9755,10 +9755,9 @@ interface DOMStringList { value.[[ArrayBufferByteLength]] }.

    To support deserialization by independent processes at arbitrary points in - the future, the contents of value.[[ArrayBufferData]] - must be preserved when forStorage is true. But otherwise, a - pointer referencing value.[[ArrayBufferData]] is expected to - suffice.

    + the future, the contents of value.[[ArrayBufferData]] need to be + preserved when forStorage is true. But otherwise, a pointer referencing + value.[[ArrayBufferData]] is expected to suffice.

    From 88b5fdf990c7788b02759fbecb360416f3383b4e Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Tue, 18 Feb 2025 13:14:19 -0500 Subject: [PATCH 5/6] fixup! Prevent structuredClone transfer of immutable array buffers (which are not detachable) --- source | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source b/source index 5b52d803e2c..7709fff9ff8 100644 --- a/source +++ b/source @@ -10495,9 +10495,9 @@ o.myself = o; [[Detached]] internal slot, then throw a "DataCloneError" DOMException.

    -
  • If transferable has an [[ArrayBufferData]] internal slot and +

  • If transferable has an [[ArrayBufferData]] internal slot and either IsSharedArrayBuffer(transferable) is true or - either IsImmutableBuffer(transferable) is true, then throw a + IsImmutableBuffer(transferable) is true, then throw a "DataCloneError" DOMException.

  • If memory[transferable] exists, From 56c3332d9deefe8001b2631f8e5a67ea6edc28b4 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Tue, 18 Feb 2025 13:26:39 -0500 Subject: [PATCH 6/6] fixup! Preserve ArrayBuffer immutability in Structured{Serialize,Deserialize} --- source | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source b/source index 7709fff9ff8..4184cf3b7eb 100644 --- a/source +++ b/source @@ -10213,7 +10213,7 @@ o.myself = o; [[ArrayBufferData]] internal slot value is serialized.[[ArrayBufferData]], whose [[ArrayBufferByteLength]] internal slot value is serialized.[[ArrayBufferByteLength]], and whose [[ArrayBufferIsImmutable]] internal - slot is present.

  • + slot value is undefined.

  • Assert: IsImmutableBuffer(value) is true.