Reset m_fastModeData of ArrayObject for the case of exception during ArrayObject creation

Signed-off-by: HyukWoo Park <hyukwoo.park@samsung.com>
This commit is contained in:
HyukWoo Park 2024-04-10 17:14:31 +09:00 committed by Patrick Kim
commit fa209656d5
2 changed files with 15 additions and 0 deletions

View file

@ -74,6 +74,15 @@ ArrayObject::ArrayObject(ExecutionState& state, Object* proto, const uint64_t& s
: ArrayObject(state, proto)
{
if (UNLIKELY(size > ((1LL << 32LL) - 1LL))) {
if (UNLIKELY(state.context()->vmInstance()->didSomePrototypeObjectDefineIndexedProperty())) {
// m_fastModeData has the initial value `DummyArrayElement`
// this could trigger an error while destructing of m_fastModeData when an exception thrown right after here
#if defined(ESCARGOT_64) && defined(ESCARGOT_USE_32BIT_IN_64BIT)
m_fastModeData.reset();
#else
m_fastModeData = nullptr;
#endif
}
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, ErrorObject::Messages::GlobalObject_InvalidArrayLength);
}

View file

@ -436,6 +436,12 @@ public:
m_buffer = resetData;
}
// used for specific case
void reset()
{
m_buffer = nullptr;
}
protected:
T* m_buffer;
};