aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-01-12 18:44:45 -0800
committerGravatar GitHub <noreply@github.com> 2023-01-12 18:44:45 -0800
commit32f8cb31be6fb5b0b9aea1c6d4e95d118e8ef816 (patch)
treed9074ac5d655d8bf78d8be06aa2aabbfa82b7f6c /src/bun.js
parent297732bbb3799c20d86547af42be2bbe8dc3fe15 (diff)
downloadbun-32f8cb31be6fb5b0b9aea1c6d4e95d118e8ef816.tar.gz
bun-32f8cb31be6fb5b0b9aea1c6d4e95d118e8ef816.tar.zst
bun-32f8cb31be6fb5b0b9aea1c6d4e95d118e8ef816.zip
set remaining indexes (#1785)
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/bindings/JSBufferList.cpp20
-rw-r--r--src/bun.js/bindings/JSBufferList.h9
2 files changed, 19 insertions, 10 deletions
diff --git a/src/bun.js/bindings/JSBufferList.cpp b/src/bun.js/bindings/JSBufferList.cpp
index 0c9815d9e..9b9990598 100644
--- a/src/bun.js/bindings/JSBufferList.cpp
+++ b/src/bun.js/bindings/JSBufferList.cpp
@@ -32,7 +32,7 @@ void JSBufferList::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject
JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
}
-JSC::JSValue JSBufferList::concat(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, int32_t n)
+JSC::JSValue JSBufferList::concat(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, size_t n)
{
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto* subclassStructure = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject)->JSBufferSubclassStructure();
@@ -102,7 +102,7 @@ JSC::JSValue JSBufferList::join(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalO
RELEASE_AND_RETURN(throwScope, ropeBuilder.release());
}
-JSC::JSValue JSBufferList::consume(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, int32_t n, bool hasString)
+JSC::JSValue JSBufferList::consume(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, size_t n, bool hasString)
{
if (hasString)
return _getString(vm, lexicalGlobalObject, n);
@@ -110,7 +110,7 @@ JSC::JSValue JSBufferList::consume(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlob
return _getBuffer(vm, lexicalGlobalObject, n);
}
-JSC::JSValue JSBufferList::_getString(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, int32_t total)
+JSC::JSValue JSBufferList::_getString(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, size_t total)
{
auto throwScope = DECLARE_THROW_SCOPE(vm);
if (total <= 0 || length() == 0) {
@@ -152,13 +152,14 @@ JSC::JSValue JSBufferList::_getString(JSC::VM& vm, JSC::JSGlobalObject* lexicalG
if (!ropeBuilder.append(str))
return throwOutOfMemoryError(lexicalGlobalObject, throwScope);
m_deque.removeFirst();
- if (n == len) break;
+ if (n == len)
+ break;
n -= len;
}
RELEASE_AND_RETURN(throwScope, ropeBuilder.release());
}
-JSC::JSValue JSBufferList::_getBuffer(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, int32_t total)
+JSC::JSValue JSBufferList::_getBuffer(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, size_t total)
{
auto throwScope = DECLARE_THROW_SCOPE(vm);
auto* subclassStructure = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject)->JSBufferSubclassStructure();
@@ -207,16 +208,23 @@ JSC::JSValue JSBufferList::_getBuffer(JSC::VM& vm, JSC::JSGlobalObject* lexicalG
auto buffer = array->possiblySharedBuffer();
JSC::JSUint8Array* newArray = JSC::JSUint8Array::create(lexicalGlobalObject, subclassStructure, buffer, n, len - n);
iter->set(vm, this, newArray);
+ offset += n;
break;
}
if (UNLIKELY(!uint8Array->setFromTypedArray(lexicalGlobalObject, offset, array, 0, len, JSC::CopyType::Unobservable))) {
return throwOutOfMemoryError(lexicalGlobalObject, throwScope);
}
m_deque.removeFirst();
- if (n == len) break;
+ if (n == len) {
+ offset += len;
+ break;
+ }
n -= len;
offset += len;
}
+
+ memset(uint8Array->typedVector() + offset, 0, total - offset);
+
RELEASE_AND_RETURN(throwScope, uint8Array);
}
diff --git a/src/bun.js/bindings/JSBufferList.h b/src/bun.js/bindings/JSBufferList.h
index a9227e981..94a69c8d1 100644
--- a/src/bun.js/bindings/JSBufferList.h
+++ b/src/bun.js/bindings/JSBufferList.h
@@ -76,11 +76,11 @@ public:
return JSC::JSValue(m_deque.first().get());
}
- JSC::JSValue concat(JSC::VM&, JSC::JSGlobalObject*, int32_t);
+ JSC::JSValue concat(JSC::VM&, JSC::JSGlobalObject*, size_t);
JSC::JSValue join(JSC::VM&, JSC::JSGlobalObject*, JSString*);
- JSC::JSValue consume(JSC::VM&, JSC::JSGlobalObject*, int32_t, bool);
- JSC::JSValue _getBuffer(JSC::VM&, JSC::JSGlobalObject*, int32_t);
- JSC::JSValue _getString(JSC::VM&, JSC::JSGlobalObject*, int32_t);
+ JSC::JSValue consume(JSC::VM&, JSC::JSGlobalObject*, size_t, bool);
+ JSC::JSValue _getBuffer(JSC::VM&, JSC::JSGlobalObject*, size_t);
+ JSC::JSValue _getString(JSC::VM&, JSC::JSGlobalObject*, size_t);
private:
Deque<WriteBarrier<Unknown>> m_deque;
@@ -134,6 +134,7 @@ public:
// Must be defined for each specialization class.
static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*);
DECLARE_EXPORT_INFO;
+
private:
JSBufferListConstructor(JSC::VM& vm, JSC::Structure* structure, JSC::NativeFunction nativeFunction)
: Base(vm, structure, nativeFunction, nativeFunction)