aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-01-12 15:13:05 -0800
committerGravatar GitHub <noreply@github.com> 2023-01-12 15:13:05 -0800
commit00773e15f1e776aa6447bd607968623b3923d21a (patch)
tree54be3ca0eb17ab4f25c9ccde0a7c3ff230a2732f
parent126809f20c418454651f23959a2e8e070ce216a1 (diff)
downloadbun-00773e15f1e776aa6447bd607968623b3923d21a.tar.gz
bun-00773e15f1e776aa6447bd607968623b3923d21a.tar.zst
bun-00773e15f1e776aa6447bd607968623b3923d21a.zip
reset string decoder on end (#1782)
-rw-r--r--src/bun.js/bindings/JSStringDecoder.cpp23
-rw-r--r--src/bun.js/bindings/JSStringDecoder.h6
2 files changed, 27 insertions, 2 deletions
diff --git a/src/bun.js/bindings/JSStringDecoder.cpp b/src/bun.js/bindings/JSStringDecoder.cpp
index 66f9cb654..ca79e9e1c 100644
--- a/src/bun.js/bindings/JSStringDecoder.cpp
+++ b/src/bun.js/bindings/JSStringDecoder.cpp
@@ -206,9 +206,30 @@ JSC::JSValue JSStringDecoder::write(JSC::VM& vm, JSC::JSGlobalObject* globalObje
}
}
-JSC::JSValue JSStringDecoder::end(JSC::VM& vm, JSC::JSGlobalObject* globalObject, uint8_t* bufPtr, uint32_t length)
+class ResetScope final {
+public:
+ ResetScope(JSStringDecoder* decoder);
+ ~ResetScope();
+ JSStringDecoder* m_decoder;
+};
+
+ResetScope::ResetScope(JSStringDecoder* decoder)
+{
+ m_decoder = decoder;
+}
+
+ResetScope::~ResetScope()
+{
+ m_decoder->m_lastTotal = 0;
+ m_decoder->m_lastNeed = 0;
+ memset(m_decoder->m_lastChar, 0, 4);
+}
+
+JSC::JSValue
+JSStringDecoder::end(JSC::VM& vm, JSC::JSGlobalObject* globalObject, uint8_t* bufPtr, uint32_t length)
{
auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto resetScope = ResetScope(this);
switch (m_encoding) {
case BufferEncodingType::ucs2:
case BufferEncodingType::utf16le: {
diff --git a/src/bun.js/bindings/JSStringDecoder.h b/src/bun.js/bindings/JSStringDecoder.h
index 299c2fb96..bce1ae05d 100644
--- a/src/bun.js/bindings/JSStringDecoder.h
+++ b/src/bun.js/bindings/JSStringDecoder.h
@@ -11,7 +11,10 @@ class JSStringDecoder : public JSC::JSDestructibleObject {
public:
JSStringDecoder(JSC::VM& vm, JSC::Structure* structure, BufferEncodingType encoding)
- : Base(vm, structure), m_lastNeed(0), m_lastTotal(0), m_encoding(encoding)
+ : Base(vm, structure)
+ , m_lastNeed(0)
+ , m_lastTotal(0)
+ , m_encoding(encoding)
{
}
@@ -108,6 +111,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:
JSStringDecoderConstructor(JSC::VM& vm, JSC::Structure* structure, JSC::NativeFunction nativeFunction)
: Base(vm, structure, nativeFunction, nativeFunction)