From cd0f3ed299ec736909dc810014183b003f9b280e Mon Sep 17 00:00:00 2001 From: Luke Street Date: Thu, 2 Jan 2025 17:11:34 -0700 Subject: [PATCH] byml: Fix GrowableBuffer (#741) Issues introduced in 89aa596b15f39a13b2e52b2d3ba99991fc729fe4 --- src/byml.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/byml.ts b/src/byml.ts index 3cbc9137d..d6a277d42 100644 --- a/src/byml.ts +++ b/src/byml.ts @@ -278,8 +278,8 @@ export function parse(buffer: ArrayBufferSlice, fileType: FileType = FileType } class GrowableBuffer { - public buffer: ArrayBuffer; - public view: DataView; + public buffer = new ArrayBuffer(); + public view = new DataView(this.buffer); public userSize: number = 0; public bufferSize: number = 0; @@ -293,16 +293,13 @@ class GrowableBuffer { if (newBufferSize > this.bufferSize) { this.bufferSize = align(newBufferSize, this.growAmount); - this.buffer = this.buffer.transfer(newBufferSize); + this.buffer = this.buffer.transfer(this.bufferSize); this.view = new DataView(this.buffer); } } public finalize(): ArrayBuffer { - const buffer = this.buffer; - // Clear out to avoid GC. - (this as any).buffer = null; - return buffer.slice(0x00, this.userSize); + return this.buffer.transfer(this.userSize); } }