From c31a3fe0048953015fc4f69907e27fca71bb04a2 Mon Sep 17 00:00:00 2001 From: godotg Date: Sat, 27 Jul 2024 12:56:21 +0800 Subject: [PATCH] chore[js]: ArrayBuffer slice is deep clone --- protocol/src/main/resources/ecmascript/buffer/ByteBuffer.mjs | 1 + protocol/src/main/resources/javascript/buffer/ByteBuffer.js | 1 + protocol/src/main/resources/typescript/buffer/ByteBuffer.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/protocol/src/main/resources/ecmascript/buffer/ByteBuffer.mjs b/protocol/src/main/resources/ecmascript/buffer/ByteBuffer.mjs index 779879b0..690d0cda 100644 --- a/protocol/src/main/resources/ecmascript/buffer/ByteBuffer.mjs +++ b/protocol/src/main/resources/ecmascript/buffer/ByteBuffer.mjs @@ -64,6 +64,7 @@ class ByteBuffer { this.writeInt(length); this.setWriteOffset(currentWriteIndex); } else { + // ArrayBuffer slice is deep clone const retainedByteBuf = this.buffer.slice(currentWriteIndex - length, currentWriteIndex); this.setWriteOffset(beforeWriteIndex); this.writeInt(length); diff --git a/protocol/src/main/resources/javascript/buffer/ByteBuffer.js b/protocol/src/main/resources/javascript/buffer/ByteBuffer.js index 82b8079e..41622b12 100644 --- a/protocol/src/main/resources/javascript/buffer/ByteBuffer.js +++ b/protocol/src/main/resources/javascript/buffer/ByteBuffer.js @@ -64,6 +64,7 @@ const ByteBuffer = function() { this.writeInt(length); this.setWriteOffset(currentWriteIndex); } else { + // ArrayBuffer slice is deep clone const retainedByteBuf = this.buffer.slice(currentWriteIndex - length, currentWriteIndex); this.setWriteOffset(beforeWriteIndex); this.writeInt(length); diff --git a/protocol/src/main/resources/typescript/buffer/ByteBuffer.ts b/protocol/src/main/resources/typescript/buffer/ByteBuffer.ts index 5bcd181f..6a2e8cb3 100644 --- a/protocol/src/main/resources/typescript/buffer/ByteBuffer.ts +++ b/protocol/src/main/resources/typescript/buffer/ByteBuffer.ts @@ -73,6 +73,7 @@ class ByteBuffer implements IByteBuffer{ this.writeInt(length); this.setWriteOffset(currentWriteIndex); } else { + // ArrayBuffer slice is deep clone const retainedByteBuf = this.buffer.slice(currentWriteIndex - length, currentWriteIndex); this.setWriteOffset(beforeWriteIndex); this.writeInt(length);