#ifdef CATCH_TEST_BUILD
-#define DEPTH 65535
-#define MAX_TEMPLATE_NESTING 4
-#define MAX_BRACKET_DEPTH 256
-#define MAX_SCOPE_DEPTH 256
-
-static const std::unordered_set<std::string> s_ignored_ids { "console", "eval", "document" };
-
#define DST_SIZE 512
#define NORMALIZE(src) \
JSIdentifierCtxStub ident_ctx; \
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH); \
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth); \
auto ret = norm.normalize(src, sizeof(src)); \
const char* ptr = norm.get_src_next(); \
int act_len = norm.script_size(); \
#define NORMALIZE_L(src, src_len, dst, dst_len, depth, ret, ptr, len) \
{ \
JSIdentifierCtxStub ident_ctx; \
- JSNormalizer norm(ident_ctx, depth, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH); \
+ JSNormalizer norm(ident_ctx, depth, max_template_nesting, max_bracket_depth); \
ret = norm.normalize(src, src_len); \
ptr = norm.get_src_next(); \
len = norm.script_size(); \
{ \
char dst1[sizeof(exp1)]; \
\
- JSIdentifierCtx ident_ctx(DEPTH, MAX_SCOPE_DEPTH, s_ignored_ids); \
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH); \
+ JSIdentifierCtx ident_ctx(norm_depth, max_scope_depth, s_ignored_ids); \
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth); \
\
DO(src1, sizeof(src1) - 1, dst1, sizeof(dst1) - 1); \
CHECK(!memcmp(exp1, dst1, sizeof(exp1) - 1)); \
char dst1[sizeof(exp1)]; \
char dst2[sizeof(exp2)]; \
\
- JSIdentifierCtx ident_ctx(DEPTH, MAX_SCOPE_DEPTH, s_ignored_ids); \
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH); \
+ JSIdentifierCtx ident_ctx(norm_depth, max_scope_depth, s_ignored_ids); \
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth); \
\
DO(src1, sizeof(src1) - 1, dst1, sizeof(dst1) - 1); \
CHECK(!memcmp(exp1, dst1, sizeof(exp1) - 1)); \
char dst1[sizeof(exp1)]; \
\
JSIdentifierCtxStub ident_ctx; \
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH); \
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth); \
\
DO(src1, sizeof(src1) - 1, dst1, sizeof(dst1) - 1); \
CHECK(!memcmp(exp1, dst1, sizeof(exp1) - 1)); \
char dst2[sizeof(exp2)]; \
\
JSIdentifierCtxStub ident_ctx; \
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH); \
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth); \
\
DO(src1, sizeof(src1) - 1, dst1, sizeof(dst1) - 1); \
CHECK(!memcmp(exp1, dst1, sizeof(exp1) - 1)); \
char dst3[sizeof(exp3)]; \
\
JSIdentifierCtxStub ident_ctx; \
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH); \
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth); \
\
DO(src1, sizeof(src1) - 1, dst1, sizeof(dst1) - 1); \
CHECK(!memcmp(exp1, dst1, sizeof(exp1) - 1)); \
char dst1[sizeof(exp1)]; \
\
JSIdentifierCtxStub ident_ctx; \
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH); \
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth); \
\
TRY(src1, sizeof(src1) - 1, dst1, sizeof(dst1) - 1, code); \
CHECK(!memcmp(exp1, dst1, sizeof(exp1) - 1)); \
char dst2[sizeof(exp2)]; \
\
JSIdentifierCtxStub ident_ctx; \
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH); \
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth); \
\
DO(src1, sizeof(src1) - 1, dst1, sizeof(dst1) - 1); \
CHECK(!memcmp(exp1, dst1, sizeof(exp1) - 1)); \
char dst3[sizeof(exp3)]; \
\
JSIdentifierCtxStub ident_ctx; \
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH); \
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth); \
\
DO(src1, sizeof(src1) - 1, dst1, sizeof(dst1) - 1); \
CHECK(!memcmp(exp1, dst1, sizeof(exp1) - 1)); \
char dst2[sizeof(exp2)]; \
\
JSIdentifierCtxStub ident_ctx; \
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH, limit); \
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth, limit); \
\
DO(src1, sizeof(src1) - 1, dst1, sizeof(dst1) - 1); \
CHECK(!memcmp(exp1, dst1, sizeof(exp1) - 1)); \
CLOSE(); \
}
-#define NORM_COMBINED_2(src1, src2, exp) \
- { \
- JSIdentifierCtxStub ident_ctx; \
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH); \
- \
- auto ret = norm.normalize(src1, sizeof(src1) - 1); \
- REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
- \
- ret = norm.normalize(src2, sizeof(src2) - 1); \
- REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
- \
- const char end[] = "</script>"; \
- ret = norm.normalize(end, sizeof(end) - 1); \
- REQUIRE(ret == JSTokenizer::SCRIPT_ENDED); \
- \
- size_t act_len = norm.script_size(); \
- REQUIRE(act_len == sizeof(exp) - 1); \
- \
- const char* dst = norm.get_script(); \
- CHECK(!memcmp(exp, dst, sizeof(exp) - 1)); \
- }
-
-#define NORM_COMBINED_3(src1, src2, src3, exp) \
- { \
- JSIdentifierCtxStub ident_ctx; \
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH); \
- \
- auto ret = norm.normalize(src1, sizeof(src1) - 1); \
- REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
- \
- ret = norm.normalize(src2, sizeof(src2) - 1); \
- REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
- \
- ret = norm.normalize(src3, sizeof(src3) - 1); \
- REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
- \
- const char end[] = "</script>"; \
- ret = norm.normalize(end, sizeof(end) - 1); \
- REQUIRE(ret == JSTokenizer::SCRIPT_ENDED); \
- \
- size_t act_len = norm.script_size(); \
- REQUIRE(act_len == sizeof(exp) - 1); \
- \
- const char* dst = norm.get_script(); \
- CHECK(!memcmp(exp, dst, sizeof(exp) - 1)); \
- }
-
-#define NORM_COMBINED_BAD_2(src1, src2, exp, eret) \
- { \
- JSIdentifierCtxStub ident_ctx; \
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH); \
- \
- auto ret = norm.normalize(src1, sizeof(src1) - 1); \
- REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
- \
- ret = norm.normalize(src2, sizeof(src2) - 1); \
- REQUIRE(ret == eret); \
- \
- size_t act_len = norm.script_size(); \
- REQUIRE(act_len == sizeof(exp) - 1); \
- \
- const char* dst = norm.get_script(); \
- CHECK(!memcmp(exp, dst, sizeof(exp) - 1)); \
- }
-
-#define NORM_COMBINED_BAD_3(src1, src2, src3, exp, eret) \
- { \
- JSIdentifierCtxStub ident_ctx; \
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH); \
- \
- auto ret = norm.normalize(src1, sizeof(src1) - 1); \
- REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
- \
- ret = norm.normalize(src2, sizeof(src2) - 1); \
- REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
- \
- ret = norm.normalize(src3, sizeof(src3) - 1); \
- REQUIRE(ret == eret); \
- \
- size_t act_len = norm.script_size(); \
- REQUIRE(act_len == sizeof(exp) - 1); \
- \
- const char* dst = norm.get_script(); \
- CHECK(!memcmp(exp, dst, sizeof(exp) - 1)); \
- }
-
-#define NORM_COMBINED_LIMITED_2(limit, src1, src2, exp) \
- { \
- JSIdentifierCtxStub ident_ctx; \
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH, limit); \
- \
- auto ret = norm.normalize(src1, sizeof(src1) - 1); \
- REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
- \
- ret = norm.normalize(src2, sizeof(src2) - 1); \
- REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
- \
- const char end[] = "</script>"; \
- ret = norm.normalize(end, sizeof(end) - 1); \
- REQUIRE(ret == JSTokenizer::SCRIPT_ENDED); \
- \
- size_t act_len = norm.script_size(); \
- REQUIRE(act_len == sizeof(exp) - 1); \
- \
- const char* dst = norm.get_script(); \
- CHECK(!memcmp(exp, dst, sizeof(exp) - 1)); \
- }
-
-#define NORM_COMBINED_S_2(src1, src2, exp) \
- { \
- JSIdentifierCtx ident_ctx(DEPTH, MAX_SCOPE_DEPTH, s_ignored_ids); \
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH); \
- \
- auto ret = norm.normalize(src1, sizeof(src1) - 1); \
- REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
- \
- ret = norm.normalize(src2, sizeof(src2) - 1); \
- REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
- \
- const char end[] = "</script>"; \
- ret = norm.normalize(end, sizeof(end) - 1); \
- REQUIRE(ret == JSTokenizer::SCRIPT_ENDED); \
- \
- size_t act_len = norm.script_size(); \
- REQUIRE(act_len == sizeof(exp) - 1); \
- \
- const char* dst = norm.get_script(); \
- CHECK(!memcmp(exp, dst, sizeof(exp) - 1)); \
+#define NORM_COMBINED_2(src1, src2, exp) \
+ { \
+ JSIdentifierCtxStub ident_ctx; \
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth); \
+ \
+ auto ret = norm.normalize(src1, sizeof(src1) - 1); \
+ REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
+ \
+ ret = norm.normalize(src2, sizeof(src2) - 1); \
+ REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
+ \
+ const char end[] = "</script>"; \
+ ret = norm.normalize(end, sizeof(end) - 1); \
+ REQUIRE(ret == JSTokenizer::SCRIPT_ENDED); \
+ \
+ size_t act_len = norm.script_size(); \
+ REQUIRE(act_len == sizeof(exp) - 1); \
+ \
+ const char* dst = norm.get_script(); \
+ CHECK(!memcmp(exp, dst, sizeof(exp) - 1)); \
+ }
+
+#define NORM_COMBINED_3(src1, src2, src3, exp) \
+ { \
+ JSIdentifierCtxStub ident_ctx; \
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth); \
+ \
+ auto ret = norm.normalize(src1, sizeof(src1) - 1); \
+ REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
+ \
+ ret = norm.normalize(src2, sizeof(src2) - 1); \
+ REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
+ \
+ ret = norm.normalize(src3, sizeof(src3) - 1); \
+ REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
+ \
+ const char end[] = "</script>"; \
+ ret = norm.normalize(end, sizeof(end) - 1); \
+ REQUIRE(ret == JSTokenizer::SCRIPT_ENDED); \
+ \
+ size_t act_len = norm.script_size(); \
+ REQUIRE(act_len == sizeof(exp) - 1); \
+ \
+ const char* dst = norm.get_script(); \
+ CHECK(!memcmp(exp, dst, sizeof(exp) - 1)); \
+ }
+
+#define NORM_COMBINED_BAD_2(src1, src2, exp, eret) \
+ { \
+ JSIdentifierCtxStub ident_ctx; \
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth); \
+ \
+ auto ret = norm.normalize(src1, sizeof(src1) - 1); \
+ REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
+ \
+ ret = norm.normalize(src2, sizeof(src2) - 1); \
+ REQUIRE(ret == eret); \
+ \
+ size_t act_len = norm.script_size(); \
+ REQUIRE(act_len == sizeof(exp) - 1); \
+ \
+ const char* dst = norm.get_script(); \
+ CHECK(!memcmp(exp, dst, sizeof(exp) - 1)); \
+ }
+
+#define NORM_COMBINED_BAD_3(src1, src2, src3, exp, eret) \
+ { \
+ JSIdentifierCtxStub ident_ctx; \
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth); \
+ \
+ auto ret = norm.normalize(src1, sizeof(src1) - 1); \
+ REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
+ \
+ ret = norm.normalize(src2, sizeof(src2) - 1); \
+ REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
+ \
+ ret = norm.normalize(src3, sizeof(src3) - 1); \
+ REQUIRE(ret == eret); \
+ \
+ size_t act_len = norm.script_size(); \
+ REQUIRE(act_len == sizeof(exp) - 1); \
+ \
+ const char* dst = norm.get_script(); \
+ CHECK(!memcmp(exp, dst, sizeof(exp) - 1)); \
+ }
+
+#define NORM_COMBINED_LIMITED_2(limit, src1, src2, exp) \
+ { \
+ JSIdentifierCtxStub ident_ctx; \
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth, limit); \
+ \
+ auto ret = norm.normalize(src1, sizeof(src1) - 1); \
+ REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
+ \
+ ret = norm.normalize(src2, sizeof(src2) - 1); \
+ REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
+ \
+ const char end[] = "</script>"; \
+ ret = norm.normalize(end, sizeof(end) - 1); \
+ REQUIRE(ret == JSTokenizer::SCRIPT_ENDED); \
+ \
+ size_t act_len = norm.script_size(); \
+ REQUIRE(act_len == sizeof(exp) - 1); \
+ \
+ const char* dst = norm.get_script(); \
+ CHECK(!memcmp(exp, dst, sizeof(exp) - 1)); \
+ }
+
+#define NORM_COMBINED_S_2(src1, src2, exp) \
+ { \
+ JSIdentifierCtx ident_ctx(norm_depth, max_scope_depth, s_ignored_ids); \
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth); \
+ \
+ auto ret = norm.normalize(src1, sizeof(src1) - 1); \
+ REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
+ \
+ ret = norm.normalize(src2, sizeof(src2) - 1); \
+ REQUIRE(ret == JSTokenizer::SCRIPT_CONTINUE); \
+ \
+ const char end[] = "</script>"; \
+ ret = norm.normalize(end, sizeof(end) - 1); \
+ REQUIRE(ret == JSTokenizer::SCRIPT_ENDED); \
+ \
+ size_t act_len = norm.script_size(); \
+ REQUIRE(act_len == sizeof(exp) - 1); \
+ \
+ const char* dst = norm.get_script(); \
+ CHECK(!memcmp(exp, dst, sizeof(exp) - 1)); \
}
// ClamAV test vectors from: https://github.com/Cisco-Talos/clamav/blob/main/unit_tests/check_jsnorm.c
const char *ptr0, *ptr1, *ptr2, *ptr3, *ptr4;
int act_len0, act_len1, act_len2, act_len3, act_len4;
- NORMALIZE_L(src0, sizeof(src0), dst0, sizeof(dst0), DEPTH, ret0, ptr0, act_len0);
- NORMALIZE_L(src1, sizeof(src1), dst1, sizeof(dst1), DEPTH, ret1, ptr1, act_len1);
- NORMALIZE_L(src2, sizeof(src2), dst2, sizeof(dst2), DEPTH, ret2, ptr2, act_len2);
- NORMALIZE_L(src3, sizeof(src3), dst3, sizeof(dst3), DEPTH, ret3, ptr3, act_len3);
- NORMALIZE_L(src4, sizeof(src4), dst4, sizeof(dst4), DEPTH, ret4, ptr4, act_len4);
+ NORMALIZE_L(src0, sizeof(src0), dst0, sizeof(dst0), norm_depth, ret0, ptr0, act_len0);
+ NORMALIZE_L(src1, sizeof(src1), dst1, sizeof(dst1), norm_depth, ret1, ptr1, act_len1);
+ NORMALIZE_L(src2, sizeof(src2), dst2, sizeof(dst2), norm_depth, ret2, ptr2, act_len2);
+ NORMALIZE_L(src3, sizeof(src3), dst3, sizeof(dst3), norm_depth, ret3, ptr3, act_len3);
+ NORMALIZE_L(src4, sizeof(src4), dst4, sizeof(dst4), norm_depth, ret4, ptr4, act_len4);
CHECK(ret0 == JSTokenizer::SCRIPT_CONTINUE);
CHECK((ptr0 - src0) == sizeof(src0));
const char* ptr;
int ret;
- NORMALIZE_L(src, sizeof(src), dst, sizeof(dst), DEPTH, ret, ptr, act_len);
+ NORMALIZE_L(src, sizeof(src), dst, sizeof(dst), norm_depth, ret, ptr, act_len);
CHECK(ret == JSTokenizer::SCRIPT_ENDED);
CHECK(act_len == sizeof(expected) - 1);
int ret;
JSIdentifierCtxStub ident_ctx;
- JSNormalizer norm(ident_ctx, 7, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH);
+ JSNormalizer norm(ident_ctx, 7, max_template_nesting, max_bracket_depth);
ret = norm.normalize(src, sizeof(src));
ptr = norm.get_src_next();
int act_len1 = norm.script_size();
char dst3[sizeof(exp3)];
char dst4[sizeof(exp4)];
- JSIdentifierCtx ident_ctx(DEPTH, MAX_SCOPE_DEPTH, s_ignored_ids);
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH);
+ JSIdentifierCtx ident_ctx(norm_depth, max_scope_depth, s_ignored_ids);
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth);
DO(src1, sizeof(src1) - 1, dst1, sizeof(dst1) - 1);
CHECK(!memcmp(exp1, dst1, sizeof(exp1) - 1));
char dst2[sizeof(exp2)];
char dst3[sizeof(exp3)];
- JSIdentifierCtx ident_ctx(DEPTH, MAX_SCOPE_DEPTH, s_ignored_ids);
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH);
+ JSIdentifierCtx ident_ctx(norm_depth, max_scope_depth, s_ignored_ids);
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth);
TRY(src1, sizeof(src1) - 1, dst1, sizeof(dst1) - 1, JSTokenizer::SCRIPT_CONTINUE);
CHECK(!memcmp(exp1, dst1, sizeof(exp1) - 1));
char* act = new char[exp_len];
JSIdentifierCtxStub ident_ctx;
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH);
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth);
DO(dat, dat_len, act, exp_len);
CHECK(!memcmp(exp, act, exp_len));
char* act = new char[exp_len];
JSIdentifierCtxStub ident_ctx;
- JSNormalizer norm(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH);
+ JSNormalizer norm(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth);
TRY(dat, dat_len, act, exp_len, JSTokenizer::BRACKET_NESTING_OVERFLOW);
CHECK(!memcmp(exp, act, exp_len));
const char exp[] = "function(){if";
uint32_t scope_depth = 2;
- JSIdentifierCtx ident_ctx(DEPTH, scope_depth, s_ignored_ids);
- JSNormalizer normalizer(ident_ctx, DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH);
+ JSIdentifierCtx ident_ctx(norm_depth, scope_depth, s_ignored_ids);
+ JSNormalizer normalizer(ident_ctx, norm_depth, max_template_nesting, max_bracket_depth);
auto ret = normalizer.normalize(src, strlen(src));
std::string dst(normalizer.get_script(), normalizer.script_size());
#ifdef BENCHMARK_TEST
-#define UNLIM_DEPTH -1
-
static constexpr const char* s_closing_tag = "</script>";
static const std::string make_input(const char* begin, const char* mid,
TEST_CASE("JS Normalizer, literals by 8 K", "[JSNormalizer]")
{
JSIdentifierCtxStub ident_ctx;
- JSNormalizer normalizer(ident_ctx, UNLIM_DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH);
+ JSNormalizer normalizer(ident_ctx, unlim_depth, max_template_nesting, max_bracket_depth);
char dst[DEPTH];
constexpr size_t size = 1 << 13;
TEST_CASE("JS Normalizer, literals by 64 K", "[JSNormalizer]")
{
JSIdentifierCtxStub ident_ctx;
- JSNormalizer normalizer(ident_ctx, UNLIM_DEPTH, MAX_TEMPLATE_NESTING, MAX_SCOPE_DEPTH);
+ JSNormalizer normalizer(ident_ctx, unlim_depth, max_template_nesting, max_scope_depth);
char dst[DEPTH];
constexpr size_t size = 1 << 16;
input.append(s_closing_tag, strlen(s_closing_tag));
JSIdentifierCtxStub ident_ctx_mock;
- JSNormalizer normalizer_wo_ident(ident_ctx_mock, UNLIM_DEPTH,
- MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH);
+ JSNormalizer normalizer_wo_ident(ident_ctx_mock, unlim_depth,
+ max_template_nesting, max_bracket_depth);
REQUIRE(norm_ret(normalizer_wo_ident, input) == JSTokenizer::SCRIPT_ENDED);
BENCHMARK("without substitution")
};
const std::unordered_set<std::string> ids{};
- JSIdentifierCtx ident_ctx(DEPTH, MAX_SCOPE_DEPTH, ids);
- JSNormalizer normalizer_w_ident(ident_ctx, UNLIM_DEPTH, MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH);
+ JSIdentifierCtx ident_ctx(norm_depth, max_scope_depth, ids);
+ JSNormalizer normalizer_w_ident(ident_ctx, unlim_depth, max_template_nesting, max_bracket_depth);
REQUIRE(norm_ret(normalizer_w_ident, input) == JSTokenizer::SCRIPT_ENDED);
BENCHMARK("with substitution")
};
const std::unordered_set<std::string> ids_n { "n" };
- JSIdentifierCtx ident_ctx_ids_n(DEPTH, MAX_SCOPE_DEPTH, ids_n);
- JSNormalizer normalizer_iids(ident_ctx_ids_n, UNLIM_DEPTH,
- MAX_TEMPLATE_NESTING, MAX_BRACKET_DEPTH);
+ JSIdentifierCtx ident_ctx_ids_n(norm_depth, max_scope_depth, ids_n);
+ JSNormalizer normalizer_iids(ident_ctx_ids_n, unlim_depth,
+ max_template_nesting, max_bracket_depth);
REQUIRE(norm_ret(normalizer_iids, input) == JSTokenizer::SCRIPT_ENDED);
BENCHMARK("with ignored identifiers")
{
constexpr uint32_t depth = 65535;
JSIdentifierCtxStub ident_ctx;
- JSNormalizer normalizer(ident_ctx, UNLIM_DEPTH, MAX_TEMPLATE_NESTING, depth);
+ JSNormalizer normalizer(ident_ctx, unlim_depth, max_template_nesting, depth);
auto src_ws = make_input("", " ", "", depth);
auto src_brace_rep = make_input_repeat("{}", depth);
TEST_CASE("JS Normalizer, automatic semicolon", "[JSNormalizer]")
{
- auto w_semicolons = make_input("", "a;\n", "", DEPTH);
- auto wo_semicolons = make_input("", "a \n", "", DEPTH);
+ auto w_semicolons = make_input("", "a;\n", "", depth);
+ auto wo_semicolons = make_input("", "a \n", "", depth);
const char* src_w_semicolons = w_semicolons.c_str();
const char* src_wo_semicolons = wo_semicolons.c_str();
size_t src_len = w_semicolons.size();
JSIdentifierCtxStub ident_ctx_mock;
- JSNormalizer normalizer_wo_ident(ident_ctx_mock, UNLIM_DEPTH, MAX_TEMPLATE_NESTING, DEPTH);
+ JSNormalizer normalizer_wo_ident(ident_ctx_mock, unlim_depth, max_template_nesting, depth);
REQUIRE(norm_ret(normalizer_wo_ident, w_semicolons) == JSTokenizer::SCRIPT_ENDED);
BENCHMARK("without semicolon insertion")