mirror of
https://github.com/RGBCube/serenity
synced 2025-10-24 21:52:34 +00:00
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.
60 lines
1.2 KiB
JavaScript
60 lines
1.2 KiB
JavaScript
test("valid 'use strict; directive", () => {
|
|
expect(
|
|
(() => {
|
|
"use strict";
|
|
return isStrictMode();
|
|
})()
|
|
).toBeTrue();
|
|
expect(
|
|
(() => {
|
|
'use strict';
|
|
return isStrictMode();
|
|
})()
|
|
).toBeTrue();
|
|
});
|
|
|
|
test("invalid 'use strict; directive", () => {
|
|
expect(
|
|
(() => {
|
|
" use strict ";
|
|
return isStrictMode();
|
|
})()
|
|
).toBeFalse();
|
|
expect(
|
|
(() => {
|
|
`use strict`;
|
|
return isStrictMode();
|
|
})()
|
|
).toBeFalse();
|
|
expect(
|
|
(() => {
|
|
"use\
|
|
strict";
|
|
return isStrictMode();
|
|
})()
|
|
).toBeFalse();
|
|
expect(
|
|
(() => {
|
|
"use\ strict";
|
|
return isStrictMode();
|
|
})()
|
|
).toBeFalse();
|
|
expect(
|
|
(() => {
|
|
"use \163trict";
|
|
return isStrictMode();
|
|
})()
|
|
).toBeFalse();
|
|
expect(
|
|
(() => {
|
|
`"use strict"`;
|
|
return isStrictMode();
|
|
})()
|
|
).toBeFalse();
|
|
expect(
|
|
(() => {
|
|
"use strict" + 1;
|
|
return isStrictMode();
|
|
})()
|
|
).toBeFalse();
|
|
});
|