aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/JSBuffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-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) {