mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
9e80c67608
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();
|
|
});
|