From 297732bbb3799c20d86547af42be2bbe8dc3fe15 Mon Sep 17 00:00:00 2001 From: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> Date: Thu, 12 Jan 2023 17:53:58 -0800 Subject: 0 initialize remaining indexes in array (#1783) * 0 initialize remaining indexes in array * switch to memset --- src/bun.js/bindings/JSBufferList.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/bun.js/bindings/JSBufferList.cpp') diff --git a/src/bun.js/bindings/JSBufferList.cpp b/src/bun.js/bindings/JSBufferList.cpp index e54b433e5..0c9815d9e 100644 --- a/src/bun.js/bindings/JSBufferList.cpp +++ b/src/bun.js/bindings/JSBufferList.cpp @@ -75,6 +75,8 @@ JSC::JSValue JSBufferList::concat(JSC::VM& vm, JSC::JSGlobalObject* lexicalGloba i += length; } + memset(uint8Array->typedVector() + i, 0, n - i); + RELEASE_AND_RETURN(throwScope, uint8Array); } -- cgit v1.2.3 From 32f8cb31be6fb5b0b9aea1c6d4e95d118e8ef816 Mon Sep 17 00:00:00 2001 From: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> Date: Thu, 12 Jan 2023 18:44:45 -0800 Subject: set remaining indexes (#1785) --- src/bun.js/bindings/JSBufferList.cpp | 20 ++++++++++++++------ src/bun.js/bindings/JSBufferList.h | 9 +++++---- 2 files changed, 19 insertions(+), 10 deletions(-) (limited to 'src/bun.js/bindings/JSBufferList.cpp') 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(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(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> 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) -- cgit v1.2.3