aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/bindings/JSBuffer.cpp65
1 files changed, 51 insertions, 14 deletions
diff --git a/src/bun.js/bindings/JSBuffer.cpp b/src/bun.js/bindings/JSBuffer.cpp
index 0ff8b76a5..f77cffac3 100644
--- a/src/bun.js/bindings/JSBuffer.cpp
+++ b/src/bun.js/bindings/JSBuffer.cpp
@@ -865,28 +865,49 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_compareBody(JSC::JSG
size_t sourceEndInit = castedThis->byteLength();
size_t sourceEnd = sourceEndInit;
+ JSValue targetStartValue = jsUndefined();
+ JSValue targetEndValue = jsUndefined();
+ JSValue sourceStartValue = jsUndefined();
+ JSValue sourceEndValue = jsUndefined();
+
switch (callFrame->argumentCount()) {
default:
- sourceEnd = parseIndex(lexicalGlobalObject, throwScope, callFrame->uncheckedArgument(4));
- RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
+ sourceEndValue = callFrame->uncheckedArgument(4);
FALLTHROUGH;
case 4:
- sourceStart = parseIndex(lexicalGlobalObject, throwScope, callFrame->uncheckedArgument(3));
- RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
+ sourceStartValue = callFrame->uncheckedArgument(3);
FALLTHROUGH;
case 3:
- targetEnd = parseIndex(lexicalGlobalObject, throwScope, callFrame->uncheckedArgument(2));
- RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
+ targetEndValue = callFrame->uncheckedArgument(2);
FALLTHROUGH;
case 2:
- targetStart = parseIndex(lexicalGlobalObject, throwScope, callFrame->uncheckedArgument(1));
- RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
+ targetStartValue = callFrame->uncheckedArgument(1);
break;
case 1:
case 0:
break;
}
+ if (!targetStartValue.isUndefined()) {
+ targetStart = parseIndex(lexicalGlobalObject, throwScope, callFrame->uncheckedArgument(1));
+ RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
+ }
+
+ if (!targetEndValue.isUndefined()) {
+ targetEnd = parseIndex(lexicalGlobalObject, throwScope, callFrame->uncheckedArgument(2));
+ RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
+ }
+
+ if (!sourceStartValue.isUndefined()) {
+ sourceStart = parseIndex(lexicalGlobalObject, throwScope, callFrame->uncheckedArgument(3));
+ RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
+ }
+
+ if (!sourceEndValue.isUndefined()) {
+ sourceEnd = parseIndex(lexicalGlobalObject, throwScope, callFrame->uncheckedArgument(4));
+ RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
+ }
+
targetStart = std::min(targetStart, std::min(targetEnd, targetEndInit));
sourceStart = std::min(sourceStart, std::min(sourceEnd, sourceEndInit));
@@ -931,24 +952,40 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_copyBody(JSC::JSGlob
size_t sourceEndInit = castedThis->byteLength();
size_t sourceEnd = sourceEndInit;
+ JSValue targetStartValue = jsUndefined();
+ JSValue sourceStartValue = jsUndefined();
+ JSValue sourceEndValue = jsUndefined();
+
switch (callFrame->argumentCount()) {
default:
- sourceEnd = parseIndex(lexicalGlobalObject, throwScope, callFrame->uncheckedArgument(3));
- RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
+ sourceEndValue = callFrame->uncheckedArgument(3);
FALLTHROUGH;
case 3:
- sourceStart = parseIndex(lexicalGlobalObject, throwScope, callFrame->uncheckedArgument(2));
- RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
+ sourceStartValue = callFrame->uncheckedArgument(2);
FALLTHROUGH;
case 2:
- targetStart = parseIndex(lexicalGlobalObject, throwScope, callFrame->uncheckedArgument(1));
- RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
+ targetStartValue = callFrame->uncheckedArgument(1);
break;
case 1:
case 0:
break;
}
+ if (!targetStartValue.isUndefined()) {
+ targetStart = parseIndex(lexicalGlobalObject, throwScope, callFrame->uncheckedArgument(1));
+ RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
+ }
+
+ if (!sourceStartValue.isUndefined()) {
+ sourceStart = parseIndex(lexicalGlobalObject, throwScope, callFrame->uncheckedArgument(2));
+ RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
+ }
+
+ if (!sourceEndValue.isUndefined()) {
+ sourceEnd = parseIndex(lexicalGlobalObject, throwScope, callFrame->uncheckedArgument(3));
+ RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
+ }
+
targetStart = std::min(targetStart, targetEnd);
sourceEnd = std::min(sourceEnd, sourceEndInit);
sourceStart = std::min(sourceStart, sourceEnd);