#pragma once
#include "VM.h"
namespace JSC {
class Exception;
#if ENABLE(EXCEPTION_SCOPE_VERIFICATION)
class ExceptionScope {
public:
VM& vm() const { return m_vm; }
unsigned recursionDepth() const { return m_recursionDepth; }
Exception* exception() { return m_vm.exception(); }
ALWAYS_INLINE void assertNoException() { ASSERT_WITH_MESSAGE(!exception(), "%s", unexpectedExceptionMessage().data()); }
ALWAYS_INLINE void releaseAssertNoException() { RELEASE_ASSERT_WITH_MESSAGE(!exception(), "%s", unexpectedExceptionMessage().data()); }
protected:
ExceptionScope(VM&, ExceptionEventLocation);
ExceptionScope(const ExceptionScope&) = delete;
ExceptionScope(ExceptionScope&&) = default;
~ExceptionScope();
JS_EXPORT_PRIVATE CString unexpectedExceptionMessage();
VM& m_vm;
ExceptionScope* m_previousScope;
ExceptionEventLocation m_location;
unsigned m_recursionDepth;
};
#else // not ENABLE(EXCEPTION_SCOPE_VERIFICATION)
class ExceptionScope {
public:
ALWAYS_INLINE VM& vm() const { return m_vm; }
ALWAYS_INLINE Exception* exception() { return m_vm.exception(); }
ALWAYS_INLINE void assertNoException() { ASSERT(!exception()); }
ALWAYS_INLINE void releaseAssertNoException() { RELEASE_ASSERT(!exception()); }
protected:
ALWAYS_INLINE ExceptionScope(VM& vm)
: m_vm(vm)
{ }
ExceptionScope(const ExceptionScope&) = delete;
ExceptionScope(ExceptionScope&&) = default;
ALWAYS_INLINE CString unexpectedExceptionMessage() { return { }; }
VM& m_vm;
};
#endif // ENABLE(EXCEPTION_SCOPE_VERIFICATION)
#define RETURN_IF_EXCEPTION(scope__, value__) do { \
if (UNLIKELY((scope__).exception())) \
return value__; \
} while (false)
}