diff options
author | 2023-01-12 15:13:05 -0800 | |
---|---|---|
committer | 2023-01-12 15:13:05 -0800 | |
commit | 00773e15f1e776aa6447bd607968623b3923d21a (patch) | |
tree | 54be3ca0eb17ab4f25c9ccde0a7c3ff230a2732f /src/bun.js/bindings/JSStringDecoder.cpp | |
parent | 126809f20c418454651f23959a2e8e070ce216a1 (diff) | |
download | bun-00773e15f1e776aa6447bd607968623b3923d21a.tar.gz bun-00773e15f1e776aa6447bd607968623b3923d21a.tar.zst bun-00773e15f1e776aa6447bd607968623b3923d21a.zip |
reset string decoder on end (#1782)
Diffstat (limited to 'src/bun.js/bindings/JSStringDecoder.cpp')
-rw-r--r-- | src/bun.js/bindings/JSStringDecoder.cpp | 23 |
1 files changed, 22 insertions, 1 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: { |