1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:17:36 +00:00

LibJS: Make invalid RegExp flags a SyntaxError at parse time

This patch changes the validation of RegExp flags (checking for
invalid and duplicate values) from a SyntaxError at runtime to a
SyntaxError at parse time - it's not something that's supposed to be
catchable.
As a nice side effect, this simplifies the RegExpObject constructor a
bit, as it can no longer throw an exception and doesn't have to validate
the flags itself.
This commit is contained in:
Linus Groh 2021-05-10 12:01:38 +01:00
parent c93c2dc72c
commit 60064e2049
4 changed files with 22 additions and 33 deletions

View file

@ -49,10 +49,10 @@ test("flag and options", () => {
expect(re.unicode).toBe(false);
expect(() => {
/foo/gg;
Function("/foo/gg");
}).toThrowWithMessage(SyntaxError, "Repeated RegExp flag 'g'");
expect(() => {
/foo/x;
Function("/foo/x");
}).toThrowWithMessage(SyntaxError, "Invalid RegExp flag 'x'");
});