mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
* Fixes #9120 * Update buffer.test.js --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user