1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:27:44 +00:00

LibJS: Make RegExp.prototype.source spec-compliant

Basically:
- And edge case for this object being RegExp.prototype.source
- Return "(?:)" for empty pattern
- Escape some things properly
This commit is contained in:
Linus Groh 2020-11-27 23:42:58 +00:00 committed by Andreas Kling
parent b6e5442d55
commit 8a9a7f1677
3 changed files with 36 additions and 5 deletions

View file

@ -1,9 +1,8 @@
test("basic functionality", () => {
// FIXME: update when toString is spec-compliant
expect(RegExp().toString()).toBe("//");
expect(RegExp(undefined).toString()).toBe("//");
expect(RegExp().toString()).toBe("/(?:)/");
expect(RegExp(undefined).toString()).toBe("/(?:)/");
expect(RegExp("foo").toString()).toBe("/foo/");
expect(RegExp("foo", undefined).toString()).toBe("/foo/");
expect(RegExp("foo", "g").toString()).toBe("/foo/g");
expect(RegExp(undefined, "g").toString()).toBe("//g");
expect(RegExp(undefined, "g").toString()).toBe("/(?:)/g");
});