fix(ext/node): enable Buffer pool for strings (#29592)

Part 1 towards enabling `parallel/test-buffer-pool-untransferable.js`
This commit is contained in:
Divy Srivastava 2025-06-04 20:04:32 -07:00 committed by GitHub
parent 1e6aca57e8
commit 8b81644b59
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 83 additions and 24 deletions

View file

@ -39,10 +39,15 @@ const {
Symbol,
MathMin,
DataViewPrototypeGetBuffer,
DataViewPrototypeGetByteLength,
DataViewPrototypeGetByteOffset,
ObjectPrototypeIsPrototypeOf,
String,
TypedArrayPrototypeGetBuffer,
TypedArrayPrototypeGetByteLength,
TypedArrayPrototypeGetByteOffset,
StringPrototypeToLowerCase,
Uint8Array,
} = primordials;
const { isTypedArray } = core;
@ -84,10 +89,19 @@ function normalizeBuffer(buf: Buffer) {
if (isBufferType(buf)) {
return buf;
} else {
const isTA = isTypedArray(buf);
return Buffer.from(
isTypedArray(buf)
? TypedArrayPrototypeGetBuffer(buf)
: DataViewPrototypeGetBuffer(buf),
new Uint8Array(
isTA
? TypedArrayPrototypeGetBuffer(buf)
: DataViewPrototypeGetBuffer(buf),
isTA
? TypedArrayPrototypeGetByteOffset(buf)
: DataViewPrototypeGetByteOffset(buf),
isTA
? TypedArrayPrototypeGetByteLength(buf)
: DataViewPrototypeGetByteLength(buf),
),
);
}
}