1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

LibJS: Fix "use strict" directive false positives

By having the "is this a use strict directive?" logic in
parse_string_literal() we would apply it to *any* string literal, which
is incorrect and would lead to false positives - e.g.:

    "use strict" + 1
    `"use strict"`
    "\123"; ({"use strict": ...})

Relevant part from the spec which is now implemented properly:

[...] and where each ExpressionStatement in the sequence consists
entirely of a StringLiteral token [...]

I also got rid of UseStrictDirectiveState which is not needed anymore.

Fixes #3903.
This commit is contained in:
Linus Groh 2020-11-01 21:49:25 +00:00 committed by Andreas Kling
parent 21912123c4
commit 9e80c67608
4 changed files with 54 additions and 55 deletions

View file

@ -45,4 +45,16 @@ test("invalid 'use strict; directive", () => {
return isStrictMode();
})()
).toBeFalse();
expect(
(() => {
`"use strict"`;
return isStrictMode();
})()
).toBeFalse();
expect(
(() => {
"use strict" + 1;
return isStrictMode();
})()
).toBeFalse();
});