mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
LibJS: Parse line continuations in string literals properly
Newlines after line continuation were inserted into the string literals. This patch makes the parser ignore the newlines after \ and also makes it so that "use strict" containing a line continuation is not a valid "use strict".
This commit is contained in:
parent
e6505a95f1
commit
e5ddcadd3c
4 changed files with 18 additions and 0 deletions
|
@ -30,6 +30,12 @@ test("use strict with double quotes after statement does not yield strict mode c
|
||||||
expect(isStrictMode()).toBeFalse();
|
expect(isStrictMode()).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("use strict interrupted by a line continuation does not yield strict mode code", () => {
|
||||||
|
"use \
|
||||||
|
strict";
|
||||||
|
expect(isStrictMode()).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
test("strict mode propagates down the scope chain", () => {
|
test("strict mode propagates down the scope chain", () => {
|
||||||
"use strict";
|
"use strict";
|
||||||
expect(isStrictMode()).toBeTrue();
|
expect(isStrictMode()).toBeTrue();
|
||||||
|
|
|
@ -53,6 +53,13 @@ test("newline literals (not characters)", () => {
|
||||||
).toBe("foo\n bar");
|
).toBe("foo\n bar");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("line continuation in literals (not characters)", () => {
|
||||||
|
expect(
|
||||||
|
`foo\
|
||||||
|
bar`
|
||||||
|
).toBe("foo bar");
|
||||||
|
});
|
||||||
|
|
||||||
test("reference error from expressions", () => {
|
test("reference error from expressions", () => {
|
||||||
expect(() => `${b}`).toThrowWithMessage(ReferenceError, "'b' is not defined");
|
expect(() => `${b}`).toThrowWithMessage(ReferenceError, "'b' is not defined");
|
||||||
});
|
});
|
||||||
|
|
|
@ -53,6 +53,9 @@ test("toHaveLength", () => {
|
||||||
expect([1]).toHaveLength(1);
|
expect([1]).toHaveLength(1);
|
||||||
expect({ length: 1 }).toHaveLength(1);
|
expect({ length: 1 }).toHaveLength(1);
|
||||||
|
|
||||||
|
expect("a\
|
||||||
|
b").toHaveLength(2);
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
expect(1).toHaveLength();
|
expect(1).toHaveLength();
|
||||||
}).toThrow(ExpectationError);
|
}).toThrow(ExpectationError);
|
||||||
|
|
|
@ -155,6 +155,8 @@ String Token::string_value(StringValueStatus& status) const
|
||||||
case '\\':
|
case '\\':
|
||||||
builder.append('\\');
|
builder.append('\\');
|
||||||
break;
|
break;
|
||||||
|
case '\n':
|
||||||
|
break;
|
||||||
case 'x': {
|
case 'x': {
|
||||||
if (i + 2 >= m_value.length() - offset)
|
if (i + 2 >= m_value.length() - offset)
|
||||||
return encoding_failure(StringValueStatus::MalformedHexEscape);
|
return encoding_failure(StringValueStatus::MalformedHexEscape);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue