diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-08-12 11:02:46 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-08-15 11:43:45 +0100 |
commit | 9509433e25455bf8ee98a9ea718c9b4d4c84c7f6 (patch) | |
tree | a33cd40c3c050454143e79004b27d1c3263e0a12 /Tests | |
parent | a0b72f5ad35e853db3a6b2cb36bb6ccfaa1557b2 (diff) | |
download | serenity-9509433e25455bf8ee98a9ea718c9b4d4c84c7f6.zip |
LibRegex: Implement and use a REPEAT operation for bytecode repetition
Currently, when we need to repeat an instruction N times, we simply add
that instruction N times in a for-loop. This doesn't scale well with
extremely large values of N, and ECMA-262 allows up to N = 2^53 - 1.
Instead, add a new REPEAT bytecode operation to defer this loop from the
parser to the runtime executor. This allows the parser to complete sans
any loops (for this instruction), and allows the executor to bail early
if the repeated bytecode fails.
Note: The templated ByteCode methods are to allow the Posix parsers to
continue using u32 because they are limited to N = 2^20.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/LibRegex/Regex.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Tests/LibRegex/Regex.cpp b/Tests/LibRegex/Regex.cpp index ea8707ccf7..bcbfa545f9 100644 --- a/Tests/LibRegex/Regex.cpp +++ b/Tests/LibRegex/Regex.cpp @@ -569,6 +569,14 @@ TEST_CASE(ECMA262_parse) { "}"sv, regex::Error::NoError, ECMAScriptFlags::BrowserExtended }, { "}"sv, regex::Error::InvalidPattern, ECMAScriptFlags::Unicode }, { "\\}"sv, regex::Error::NoError, ECMAScriptFlags::Unicode }, + { "a{9007199254740991}"sv }, // 2^53 - 1 + { "a{9007199254740991,}"sv }, + { "a{9007199254740991,9007199254740991}"sv }, + { "a{9007199254740992}"sv, regex::Error::InvalidBraceContent }, + { "a{9007199254740992,}"sv, regex::Error::InvalidBraceContent }, + { "a{9007199254740991,9007199254740992}"sv, regex::Error::InvalidBraceContent }, + { "a{9007199254740992,9007199254740991}"sv, regex::Error::InvalidBraceContent }, + { "a{9007199254740992,9007199254740992}"sv, regex::Error::InvalidBraceContent }, }; for (auto& test : tests) { @@ -619,6 +627,14 @@ TEST_CASE(ECMA262_match) { "\\^"sv, "^"sv }, { "\\^\\$\\\\\\.\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|\\/"sv, "^$\\.*+?()[]{}|/"sv, true, ECMAScriptFlags::Unicode }, { "[\\^\\$\\\\\\.\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|\\/]{15}"sv, "^$\\.*+?()[]{}|/"sv, true, ECMAScriptFlags::Unicode }, + { "(a{2}){3}"sv, "aaaaaa"sv }, + { "(a{2}){3}"sv, "aaaabaa"sv, false }, + { "(a{2}){4}"sv, "aaaaaaaa"sv }, + { "(a{2}){4}"sv, "aaaaaabaa"sv, false }, + { "(a{3}){2}"sv, "aaaaaa"sv }, + { "(a{3}){2}"sv, "aaaabaa"sv, false }, + { "(a{4}){2}"sv, "aaaaaaaa"sv }, + { "(a{4}){2}"sv, "aaaaaabaa"sv, false }, // ECMA262, B.1.4. Regular Expression Pattern extensions for browsers { "{"sv, "{"sv, true, ECMAScriptFlags::BrowserExtended }, { "\\5"sv, "\5"sv, true, ECMAScriptFlags::BrowserExtended }, |