diff options
author | 2023-07-01 17:07:37 -0700 | |
---|---|---|
committer | 2023-07-01 17:07:37 -0700 | |
commit | f3833376e75a2353285fc884f31a5be97a917b6e (patch) | |
tree | 536634ee3cbe5ece86bc9767add70711e4db67d9 /src/bun.js/bindings/JSBuffer.cpp | |
parent | 4720fa1207d374a2447d457ad478f9f8911b959a (diff) | |
download | bun-f3833376e75a2353285fc884f31a5be97a917b6e.tar.gz bun-f3833376e75a2353285fc884f31a5be97a917b6e.tar.zst bun-f3833376e75a2353285fc884f31a5be97a917b6e.zip |
small cleanup
Diffstat (limited to 'src/bun.js/bindings/JSBuffer.cpp')
-rw-r--r-- | src/bun.js/bindings/JSBuffer.cpp | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/bun.js/bindings/JSBuffer.cpp b/src/bun.js/bindings/JSBuffer.cpp index 4b0e058dd..10f9aab5a 100644 --- a/src/bun.js/bindings/JSBuffer.cpp +++ b/src/bun.js/bindings/JSBuffer.cpp @@ -1453,23 +1453,32 @@ static inline JSC::EncodedJSValue jsBufferPrototypeFunction_toStringBody(JSC::JS return jsBufferToString(vm, lexicalGlobalObject, castedThis, offset, length, encoding); if (arg1.isString()) { - encoding = parseEncoding(lexicalGlobalObject, scope, arg1); + encoding = parseEncoding(lexicalGlobalObject, scope, arg1); + RETURN_IF_EXCEPTION(scope, JSC::JSValue::encode(jsUndefined())); + + if (!arg3.isUndefined()) { + // length is end + length = std::min(byteLength, static_cast<uint32_t>(arg3.toInt32(lexicalGlobalObject))); RETURN_IF_EXCEPTION(scope, JSC::JSValue::encode(jsUndefined())); + } - if (!arg3.isUndefined()) { - // length is end - length = std::min(byteLength, static_cast<uint32_t>(arg3.toInt32(lexicalGlobalObject))); - } + int32_t istart = 0; - int32_t istart = arg2.toInt32(lexicalGlobalObject); - if (istart < 0) { - throwTypeError(lexicalGlobalObject, scope, "Start must be a positive integer"_s); - return JSC::JSValue::encode(jsUndefined()); - } - offset = static_cast<uint32_t>(istart); - length = (length > offset) ? (length - offset) : 0; + if (!arg2.isUndefined()) { + istart = arg2.toInt32(lexicalGlobalObject); + RETURN_IF_EXCEPTION(scope, JSC::JSValue::encode(jsUndefined())); + } + + if (istart < 0) { + throwTypeError(lexicalGlobalObject, scope, "Start must be a positive integer"_s); + return JSC::JSValue::encode(jsUndefined()); + } + offset = static_cast<uint32_t>(istart); + length = (length > offset) ? (length - offset) : 0; } else { int32_t ioffset = arg1.toInt32(lexicalGlobalObject); + RETURN_IF_EXCEPTION(scope, JSC::JSValue::encode(jsUndefined())); + if (ioffset < 0) { throwTypeError(lexicalGlobalObject, scope, "Offset must be a positive integer"_s); return JSC::JSValue::encode(jsUndefined()); |