mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibJS: Replace invalid escapes in TemplateLiterals with undefined in BC
Also adds a big FIXME, to outline what is still wrong
This commit is contained in:
parent
3a0f7e8eb8
commit
7005a91a1e
Notes:
sideshowbarker
2024-07-17 16:23:55 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/7005a91a1e Pull-request: https://github.com/SerenityOS/serenity/pull/19629
1 changed files with 13 additions and 1 deletions
|
@ -1902,6 +1902,12 @@ Bytecode::CodeGenerationErrorOr<void> TaggedTemplateLiteral::generate_bytecode(B
|
|||
|
||||
// FIXME: We only need to record the first and last register,
|
||||
// due to packing everything in an array, same goes for argument_regs
|
||||
// FIXME: Follow
|
||||
// 13.2.8.3 GetTemplateObject ( templateLiteral ), https://tc39.es/ecma262/#sec-gettemplateobject
|
||||
// more closely, namely:
|
||||
// * cache this somehow
|
||||
// * add a raw object accessor
|
||||
// * freeze array and raw member
|
||||
Vector<Bytecode::Register> string_regs;
|
||||
auto& expressions = m_template_literal->expressions();
|
||||
for (size_t i = 0; i < expressions.size(); ++i) {
|
||||
|
@ -1914,8 +1920,14 @@ Bytecode::CodeGenerationErrorOr<void> TaggedTemplateLiteral::generate_bytecode(B
|
|||
for (size_t i = 0; i < expressions.size(); ++i) {
|
||||
if (i % 2 != 0)
|
||||
continue;
|
||||
// NOTE: If the string contains invalid escapes we get a null expression here,
|
||||
// which we then convert to the expected `undefined` TV. See
|
||||
// 12.9.6.1 Static Semantics: TV, https://tc39.es/ecma262/#sec-static-semantics-tv
|
||||
if (is<NullLiteral>(expressions[i]))
|
||||
generator.emit<Bytecode::Op::LoadImmediate>(js_undefined());
|
||||
else
|
||||
TRY(expressions[i]->generate_bytecode(generator));
|
||||
|
||||
TRY(expressions[i]->generate_bytecode(generator));
|
||||
auto string_reg = string_regs[reg_index++];
|
||||
generator.emit<Bytecode::Op::Store>(string_reg);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue