From d68a5c7bca3775881b903129f484cd01172dad97 Mon Sep 17 00:00:00 2001 From: Mattias Buelens Date: Wed, 13 Aug 2025 20:36:05 +0200 Subject: [PATCH 1/4] Implement `TransferArrayBuffer` correctly in reference implementation --- .../lib/abstract-ops/ecmascript.js | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/reference-implementation/lib/abstract-ops/ecmascript.js b/reference-implementation/lib/abstract-ops/ecmascript.js index 731b38c0c..682200786 100644 --- a/reference-implementation/lib/abstract-ops/ecmascript.js +++ b/reference-implementation/lib/abstract-ops/ecmascript.js @@ -1,7 +1,8 @@ 'use strict'; const assert = require('assert'); -const isFakeDetached = Symbol('is "detached" for our purposes'); +const ArrayBufferPrototypeTransferToFixedLength = ArrayBuffer.prototype.transferToFixedLength; +const ArrayBufferPrototypeDetachedGetter = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'detached').get; exports.typeIsObject = x => (typeof x === 'object' && x !== null) || typeof x === 'function'; @@ -15,31 +16,17 @@ exports.CopyDataBlockBytes = (dest, destOffset, src, srcOffset, n) => { new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset); }; -// Not implemented correctly exports.TransferArrayBuffer = O => { assert(!exports.IsDetachedBuffer(O)); - const transferredIshVersion = O.slice(); - - // This is specifically to fool tests that test "is transferred" by taking a non-zero-length - // ArrayBuffer and checking if its byteLength starts returning 0. - Object.defineProperty(O, 'byteLength', { - get() { - return 0; - } - }); - O[isFakeDetached] = true; - - return transferredIshVersion; + return ArrayBufferPrototypeTransferToFixedLength.call(O); }; -// Not implemented correctly exports.CanTransferArrayBuffer = O => { return !exports.IsDetachedBuffer(O); }; -// Not implemented correctly exports.IsDetachedBuffer = O => { - return isFakeDetached in O; + return ArrayBufferPrototypeDetachedGetter.call(O) === true; }; exports.Call = (F, V, args = []) => { From 3ea6daff3f765437e911ae6ac663cf454f05fb0a Mon Sep 17 00:00:00 2001 From: Mattias Buelens Date: Wed, 13 Aug 2025 20:57:07 +0200 Subject: [PATCH 2/4] Fix `PullInto()` reading stale `byteLength` after transferring --- .../lib/abstract-ops/readable-streams.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/reference-implementation/lib/abstract-ops/readable-streams.js b/reference-implementation/lib/abstract-ops/readable-streams.js index cbbb31404..0a7cfaffa 100644 --- a/reference-implementation/lib/abstract-ops/readable-streams.js +++ b/reference-implementation/lib/abstract-ops/readable-streams.js @@ -1584,6 +1584,8 @@ function ReadableByteStreamControllerPullInto(controller, view, min, readIntoReq assert(minimumFill >= elementSize && minimumFill <= view.byteLength); assert(minimumFill % elementSize === 0); + const byteOffset = view.byteOffset; + const byteLength = view.byteLength; const ctor = view.constructor; let buffer; @@ -1597,8 +1599,8 @@ function ReadableByteStreamControllerPullInto(controller, view, min, readIntoReq const pullIntoDescriptor = { buffer, bufferByteLength: buffer.byteLength, - byteOffset: view.byteOffset, - byteLength: view.byteLength, + byteOffset, + byteLength, bytesFilled: 0, minimumFill, elementSize, From 5cde2af74d534a9b25b807894d14b0e305cd0746 Mon Sep 17 00:00:00 2001 From: Mattias Buelens Date: Fri, 15 Aug 2025 12:49:09 +0200 Subject: [PATCH 3/4] Roll WPT --- reference-implementation/web-platform-tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference-implementation/web-platform-tests b/reference-implementation/web-platform-tests index 186a9fd7a..6bece402f 160000 --- a/reference-implementation/web-platform-tests +++ b/reference-implementation/web-platform-tests @@ -1 +1 @@ -Subproject commit 186a9fd7abc3d9c31e2b37680be757e992af9e3a +Subproject commit 6bece402fea763af59646e66cea2ad38218ce36d From ea326f9b1323f92a2b9da241c8d2fc701540f44c Mon Sep 17 00:00:00 2001 From: Mattias Buelens Date: Tue, 19 Aug 2025 09:43:27 +0200 Subject: [PATCH 4/4] Roll WPT again --- reference-implementation/web-platform-tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference-implementation/web-platform-tests b/reference-implementation/web-platform-tests index 6bece402f..ad6c0aa10 160000 --- a/reference-implementation/web-platform-tests +++ b/reference-implementation/web-platform-tests @@ -1 +1 @@ -Subproject commit 6bece402fea763af59646e66cea2ad38218ce36d +Subproject commit ad6c0aa100e1fc9d88c8967d55dca004a46a73bd