diff options
author | davidot <davidot@serenityos.org> | 2022-08-17 02:04:27 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-08-17 23:56:24 +0100 |
commit | e5adc51e272d413fa4f9403aa7899ea63adced95 (patch) | |
tree | a148a64b68c422f6158fb7e0405cfe06592e9dd5 /Userland/Libraries/LibJS/AST.cpp | |
parent | 0f9434a02cb8d3be1d02eacf386839f0ac06cfda (diff) | |
download | serenity-e5adc51e272d413fa4f9403aa7899ea63adced95.zip |
LibJS: Allow invalid string in tagged template literals
Since tagged template literals can inspect the raw string it is not a
syntax error to have invalid escapes. However the cooked value should be
`undefined`.
We accomplish this by tracking whether parse_string_literal
fails and then using a NullLiteral (since UndefinedLiteral is not a
thing) and finally converting null in tagged template execution to
undefined.
Diffstat (limited to 'Userland/Libraries/LibJS/AST.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/AST.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index c6f1fdd106..94e272af9e 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -3545,6 +3545,11 @@ Completion TaggedTemplateLiteral::execute(Interpreter& interpreter, GlobalObject // tag`${foo}` -> "", foo, "" -> tag(["", ""], foo) // tag`foo${bar}baz${qux}` -> "foo", bar, "baz", qux, "" -> tag(["foo", "baz", ""], bar, qux) if (i % 2 == 0) { + // If the string contains invalid escapes we get a null expression here, which we then convert + // to the expected `undefined` TV. + if (value.is_nullish()) + value = js_undefined(); + strings->indexed_properties().append(value); } else { arguments.append(value); |