aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/bindings/JSBuffer.cpp29
-rw-r--r--test/bun.js/buffer.test.js27
2 files changed, 35 insertions, 21 deletions
diff --git a/src/bun.js/bindings/JSBuffer.cpp b/src/bun.js/bindings/JSBuffer.cpp
index 034d237cf..a6f321b21 100644
--- a/src/bun.js/bindings/JSBuffer.cpp
+++ b/src/bun.js/bindings/JSBuffer.cpp
@@ -800,25 +800,23 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_copyBody(JSC::JSGlob
}
size_t targetStart = 0;
- size_t targetEndInit = view->byteLength();
- size_t targetEnd = targetEndInit;
+ size_t targetEnd = view->byteLength();
size_t sourceStart = 0;
size_t sourceEndInit = castedThis->byteLength();
size_t sourceEnd = sourceEndInit;
if (callFrame->argumentCount() > 1) {
- if (auto targetEnd_ = callFrame->uncheckedArgument(1).tryGetAsUint32Index()) {
- targetStart = targetEnd_.value();
+ if (auto targetStart_ = callFrame->uncheckedArgument(1).tryGetAsUint32Index()) {
+ targetStart = targetStart_.value();
} else {
throwVMTypeError(lexicalGlobalObject, throwScope, "Expected number"_s);
return JSValue::encode(jsUndefined());
}
if (callFrame->argumentCount() > 2) {
- auto targetEndArgument = callFrame->uncheckedArgument(2);
- if (auto targetEnd_ = targetEndArgument.tryGetAsUint32Index()) {
- targetEnd = targetEnd_.value();
+ if (auto sourceStart_ = callFrame->uncheckedArgument(2).tryGetAsUint32Index()) {
+ sourceStart = sourceStart_.value();
} else {
throwVMTypeError(lexicalGlobalObject, throwScope, "Expected number"_s);
return JSValue::encode(jsUndefined());
@@ -826,19 +824,8 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_copyBody(JSC::JSGlob
}
if (callFrame->argumentCount() > 3) {
- auto targetEndArgument = callFrame->uncheckedArgument(3);
- if (auto targetEnd_ = targetEndArgument.tryGetAsUint32Index()) {
- sourceStart = targetEnd_.value();
- } else {
- throwVMTypeError(lexicalGlobalObject, throwScope, "Expected number"_s);
- return JSValue::encode(jsUndefined());
- }
- }
-
- if (callFrame->argumentCount() > 4) {
- auto targetEndArgument = callFrame->uncheckedArgument(4);
- if (auto targetEnd_ = targetEndArgument.tryGetAsUint32Index()) {
- sourceEnd = targetEnd_.value();
+ if (auto sourceEnd_ = callFrame->uncheckedArgument(3).tryGetAsUint32Index()) {
+ sourceEnd = sourceEnd_.value();
} else {
throwVMTypeError(lexicalGlobalObject, throwScope, "Expected number"_s);
return JSValue::encode(jsUndefined());
@@ -846,7 +833,7 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_copyBody(JSC::JSGlob
}
}
- targetStart = std::min(targetStart, std::min(targetEnd, targetEndInit));
+ targetStart = std::min(targetStart, targetEnd);
sourceStart = std::min(sourceStart, std::min(sourceEnd, sourceEndInit));
auto sourceLength = sourceEnd - sourceStart;
diff --git a/test/bun.js/buffer.test.js b/test/bun.js/buffer.test.js
index 87937e65e..a7fa539c0 100644
--- a/test/bun.js/buffer.test.js
+++ b/test/bun.js/buffer.test.js
@@ -209,6 +209,33 @@ it("Buffer.copy", () => {
gc();
expect(array1.copy(array2)).toBe(128);
expect(array1.join("")).toBe(array2.join(""));
+
+ {
+ // Create two `Buffer` instances.
+ const buf1 = Buffer.allocUnsafe(26);
+ const buf2 = Buffer.allocUnsafe(26).fill('!');
+
+ for (let i = 0; i < 26; i++) {
+ // 97 is the decimal ASCII value for 'a'.
+ buf1[i] = i + 97;
+ }
+
+ // Copy `buf1` bytes 16 through 19 into `buf2` starting at byte 8 of `buf2`.
+ buf1.copy(buf2, 8, 16, 20);
+ expect(buf2.toString('ascii', 0, 25)).toBe('!!!!!!!!qrst!!!!!!!!!!!!!');
+ }
+
+ {
+ const buf = Buffer.allocUnsafe(26);
+
+ for (let i = 0; i < 26; i++) {
+ // 97 is the decimal ASCII value for 'a'.
+ buf[i] = i + 97;
+ }
+
+ buf.copy(buf, 0, 4, 10);
+ expect(buf.toString()).toBe('efghijghijklmnopqrstuvwxyz');
+ }
});
export function fillRepeating(dstBuffer, start, end) {
rc='//www.gravatar.com/avatar/764ea52180f7f5236744034dd5e1a3c0?s=13&d=retro' width='13' height='13' alt='Gravatar' /> Jarred Sumner 31-56/+2777 * Boilerplate for DNS stuff * Add c-ares * lookup * make * Implement dns.lookup * Create c-ares * wip * normalize * repro * Revert "repro" This reverts commit 8b93e0c295b335b8882a9601da47720348549beb. * Implement macOS `getaddrinfo_async_start` * embiggen * Update string_immutable.zig * Update Makefile * alright * Update .gitignore * Add types * more ccache * Update Dockerfile * Update Dockerfile * Update Dockerfile * Update bun.d.ts Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-07test `BufferList` against surrogate pairsGravatar alexlamsl 1-5/+11 2023-01-06Add missing null checkGravatar Jarred Sumner 1-6/+9 Fixes https://github.com/oven-sh/bun/issues/1739 probably 2023-01-06fix typo in install.sh (#1737)Gravatar Ikko Eltociear Ashimine 1-1/+1 infomation -> information 2023-01-05lazily create buffer/string slices (#1735)Gravatar Alex Lam S.L 3-33/+158 2023-01-05Report unhandled promise rejection on exit and make exit code 1 instead of 0 ↵Gravatar Jarred Sumner 6-54/+108 (#1734) Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-05always report rejected promisesGravatar Jarred Sumner 2-1/+3 2023-01-05Clean up some napi codeGravatar Jarred Sumner 2-70/+79 2023-01-05napi_boolean -> napi_numberGravatar Jarred Sumner 1-1/+1 2023-01-05Fixes #1733Gravatar Jarred Sumner 2-67/+79 2023-01-05[socket] fix double-free in `finalize()` (#1731)Gravatar Alex Lam S.L 3-53/+45 - tidy up `.isEmptyOrUndefinedOrNull()` usage 2023-01-05BumpGravatar Jarred Sumner 1-1/+1 2023-01-05fix `onConnectError()` error propagation (#1730)Gravatar Alex Lam S.L 1-2/+2 * fix `onConnectError()` error propagation suppress extraneous logging messages * Update src/bun.js/api/bun/socket.zig Co-authored-by: Jarred Sumner <jarred@jarredsumner.com> 2023-01-05Update tcp-echo.bun.tsGravatar Jarred Sumner 1-13/+15 2023-01-05Really fix #1722Gravatar Jarred Sumner 2-3/+41 2023-01-05improve `.toThrow()` compatibility with Jest (#1728)Gravatar Alex Lam S.L 2-17/+33 2023-01-04Fix Bun.serve typings (#1714)Gravatar u9g 1-2/+2 2023-01-04implement `expect().toThrow()` (#1727)Gravatar Alex Lam S.L 5-130/+370 - fix bugs in `JSBufferList` - add tests 2023-01-04Add `SharedBuffer` from WebKit to make it easier to import more WebCore stuffGravatar Jarred Sumner 2-0/+1111 2023-01-04Fix default export for streamGravatar Jarred Sumner 1-11/+4 cc @alexlamsl 2023-01-04Fixes #1722Gravatar Jarred Sumner 1-1/+2 2023-01-04split server/client for tcp echo benchmark to better measure net.Socket perfGravatar Jarred Sumner 2-58/+60 2023-01-04buffer list clean-ups (#1721)Gravatar Alex Lam S.L 1-37/+68 2023-01-04Support non-classes in node:net (#1712)Gravatar Jarred Sumner 1-198/+216 * Support non-classes * Update net.exports.js * Make it less observable * Update net.exports.js Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-04Fixes #1716Gravatar Jarred Sumner 1-2/+2 2023-01-0410x faster `new Buffer` (#1717)Gravatar Jarred Sumner 19-520/+480 Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-03Update README.mdGravatar Jarred Sumner 1-2/+2 2023-01-03Add sqlite to vendorGravatar Jarred Sumner 1-4/+8 2023-01-03Fixes https://github.com/oven-sh/bun/issues/1695Gravatar Jarred Sumner 1-1/+1 2023-01-03Remove usages of std.xGravatar Jarred Sumner 7-98/+75 2023-01-03[streams] speed up `Readable` in some cases (#1708)Gravatar Alex Lam S.L 3-14/+140 If `encoding` is set, no `Buffer`s would be exposed thus `Uint8Array` can be used directly. - fix data corruption in `BufferList.concat()` - fix segfaults in `BufferList.join()` 2023-01-03Fix crash in BufferListGravatar Jarred Sumner 1-2/+2