* Fixes #9120

* Update buffer.test.js

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2024-02-26 19:15:28 -08:00
committed by GitHub
parent c4a9bdbb81
commit fd6fd78f0f
2 changed files with 36 additions and 6 deletions

View File

@@ -523,17 +523,19 @@ static inline JSC::EncodedJSValue jsBufferConstructorFunction_allocBody(JSC::JSG
auto* start = uint8Array->typedVector();
auto* head = start;
size_t remain = uint8Array->byteLength();
length = std::min(length, remain);
memmove(head, view->vector(), length);
remain -= length;
head += length;
while (remain >= length) {
memcpy(head, start, length);
while (remain >= length && length > 0) {
memmove(head, start, length);
remain -= length;
head += length;
length <<= 1;
}
if (remain > 0) {
memcpy(head, start, remain);
memmove(head, start, remain);
}
} else {
auto value_ = value.toInt32(lexicalGlobalObject) & 0xFF;
@@ -1202,17 +1204,19 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_fillBody(JSC::JSGlob
return JSC::JSValue::encode(jsUndefined());
}
length = std::min(length, remain);
memmove(head, view->vector(), length);
remain -= length;
head += length;
while (remain >= length) {
memcpy(head, startPtr, length);
while (remain >= length && length > 0) {
memmove(head, startPtr, length);
remain -= length;
head += length;
length <<= 1;
}
if (remain > 0) {
memcpy(head, startPtr, remain);
memmove(head, startPtr, remain);
}
} else {
auto value_ = value.toInt32(lexicalGlobalObject) & 0xFF;

View File

@@ -6,6 +6,32 @@ const BufferModule = await import("buffer");
beforeEach(() => gc());
afterEach(() => gc());
it("#9120 fill", () => {
let abBuf = Buffer.alloc(2, "ab");
let x = Buffer.alloc(1);
x.fill(abBuf);
expect(x.toString()).toBe("a");
for (let count = 2; count < 10; count += 2) {
const full = Buffer.from("a".repeat(count) + "b".repeat(count));
const x = Buffer.alloc(count);
x.fill(full);
expect(x.toString()).toBe("a".repeat(count));
}
});
it("#9120 alloc", () => {
let abBuf = Buffer.alloc(2, "ab");
let x = Buffer.alloc(1, abBuf);
expect(x.toString()).toBe("a");
for (let count = 2; count < 10; count += 2) {
const full = Buffer.from("a".repeat(count) + "b".repeat(count));
const x = Buffer.alloc(count, full);
expect(x.toString()).toBe("a".repeat(count));
}
});
it("isAscii", () => {
expect(isAscii(new Buffer("abc"))).toBeTrue();
expect(isAscii(new Buffer(""))).toBeTrue();