2021-10-30 04:25:12 +08:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Luau/Common.h"
|
2022-10-28 18:37:29 +08:00
|
|
|
#include "Luau/Error.h"
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
#include <stdexcept>
|
2022-04-15 07:57:43 +08:00
|
|
|
#include <exception>
|
|
|
|
|
2021-10-30 04:25:12 +08:00
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
2022-10-28 18:37:29 +08:00
|
|
|
struct RecursionLimitException : public InternalCompilerError
|
|
|
|
{
|
|
|
|
RecursionLimitException()
|
|
|
|
: InternalCompilerError("Internal recursion counter limit exceeded")
|
|
|
|
{
|
|
|
|
LUAU_ASSERT(FFlag::LuauIceExceptionInheritanceChange);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RecursionLimitException_DEPRECATED : public std::exception
|
2022-04-15 07:57:43 +08:00
|
|
|
{
|
|
|
|
const char* what() const noexcept
|
|
|
|
{
|
2022-10-28 18:37:29 +08:00
|
|
|
LUAU_ASSERT(!FFlag::LuauIceExceptionInheritanceChange);
|
2022-04-15 07:57:43 +08:00
|
|
|
return "Internal recursion counter limit exceeded";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-10-30 04:25:12 +08:00
|
|
|
struct RecursionCounter
|
|
|
|
{
|
|
|
|
RecursionCounter(int* count)
|
|
|
|
: count(count)
|
|
|
|
{
|
|
|
|
++(*count);
|
|
|
|
}
|
|
|
|
|
|
|
|
~RecursionCounter()
|
|
|
|
{
|
|
|
|
LUAU_ASSERT(*count > 0);
|
|
|
|
--(*count);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int* count;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RecursionLimiter : RecursionCounter
|
|
|
|
{
|
2022-06-24 09:56:00 +08:00
|
|
|
RecursionLimiter(int* count, int limit)
|
2021-10-30 04:25:12 +08:00
|
|
|
: RecursionCounter(count)
|
|
|
|
{
|
|
|
|
if (limit > 0 && *count > limit)
|
2022-04-15 07:57:43 +08:00
|
|
|
{
|
2022-10-28 18:37:29 +08:00
|
|
|
if (FFlag::LuauIceExceptionInheritanceChange)
|
|
|
|
{
|
|
|
|
throw RecursionLimitException();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw RecursionLimitException_DEPRECATED();
|
|
|
|
}
|
2022-04-15 07:57:43 +08:00
|
|
|
}
|
2021-10-30 04:25:12 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Luau
|