aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Ai Hoshino <ambiguous404@gmail.com> 2023-10-19 05:30:53 +0800
committerGravatar GitHub <noreply@github.com> 2023-10-18 14:30:53 -0700
commit0173571b19780ab71772b1efcb9c4e623cab0aca (patch)
treee6223b4ce6e110d0cc5c9403d7b4193247608a9c /src
parent35259c0c1d54f03691d95e7646e7cf368d780652 (diff)
downloadbun-0173571b19780ab71772b1efcb9c4e623cab0aca.tar.gz
bun-0173571b19780ab71772b1efcb9c4e623cab0aca.tar.zst
bun-0173571b19780ab71772b1efcb9c4e623cab0aca.zip
fix(node:buffer): fix the behavior of `totalLength` in `Buffer.concat` (#6574)
* fix(node:buffer): fix the behavior of `totalLength` in `Buffer.concat` Close: #6570 Close: #3639 * fix buffer totalLength type --------- Co-authored-by: Ashcon Partovi <ashcon@partovi.net>
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/bindings/JSBuffer.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/bun.js/bindings/JSBuffer.cpp b/src/bun.js/bindings/JSBuffer.cpp
index 524007f86..543ef2ea3 100644
--- a/src/bun.js/bindings/JSBuffer.cpp
+++ b/src/bun.js/bindings/JSBuffer.cpp
@@ -742,10 +742,16 @@ static inline JSC::EncodedJSValue jsBufferConstructorFunction_concatBody(JSC::JS
byteLength += typedArray->length();
}
- if (callFrame->argumentCount() > 1) {
- auto byteLengthValue = callFrame->uncheckedArgument(1);
- byteLength = std::min(byteLength, byteLengthValue.toTypedArrayIndex(lexicalGlobalObject, "totalLength must be a valid number"_s));
+ JSValue totalLengthValue = callFrame->argument(1);
+ if (!totalLengthValue.isUndefined()) {
+ if (UNLIKELY(!totalLengthValue.isNumber())) {
+ throwTypeError(lexicalGlobalObject, throwScope, "totalLength must be a valid number"_s);
+ return JSValue::encode(jsUndefined());
+ }
+
+ auto totalLength = totalLengthValue.toTypedArrayIndex(lexicalGlobalObject, "totalLength must be a valid number"_s);
RETURN_IF_EXCEPTION(throwScope, {});
+ byteLength = totalLength;
}
if (byteLength == 0) {