File
Blob: src/workerd/api/node/tests/buffer-effective-size-concat-test.js
| 1 | // Copyright (c) 2026 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | import { Buffer } from 'node:buffer'; |
| 5 | import { strictEqual } from 'node:assert'; |
| 6 | |
| 7 | export const BufferConcatResizeDuringGetter = { |
| 8 | async test() { |
| 9 | const ab = new ArrayBuffer(1024, { maxByteLength: 2048 }); |
| 10 | const view = new Uint8Array(ab); |
| 11 | view.fill(0x41); |
| 12 | |
| 13 | const arr = [view, new Uint8Array(0)]; |
| 14 | |
| 15 | Object.defineProperty(arr, '1', { |
| 16 | get() { |
| 17 | ab.resize(0); |
| 18 | return new Uint8Array(0); |
| 19 | }, |
| 20 | enumerable: true, |
| 21 | configurable: true, |
| 22 | }); |
| 23 | |
| 24 | const result = Buffer.concat(arr, 1024); |
| 25 | strictEqual(result.length, 1024); |
| 26 | strictEqual( |
| 27 | result.every((b) => b === 0), |
| 28 | true |
| 29 | ); |
| 30 | }, |
| 31 | }; |