LibJS/Bytecode: Improve export statement handling

This adds support for exporting class expressions, which was previously
TODO'd.

We now correctly set the binding name of exports to `"*default*"` if
they are unnamed. I'm not sure what the difference between the
`InitializationMode` kinds is, but using `Initialize` fixes a bunch of
tests.

Note that some export tests (e.g. `eval-export-dflt-expr-cls-named.js`)
still fail, as we don't set the "name" property of exported classes
correctly.

176 new passes on test262
This commit is contained in:
Daniel Bertalan 2023-06-28 00:53:08 +02:00 committed by Andreas Kling
parent 11a7014b4e
commit fc7de74b12
Notes: sideshowbarker 2024-07-17 20:22:04 +09:00

View file

@ -2857,13 +2857,18 @@ Bytecode::CodeGenerationErrorOr<void> ExportStatement::generate_bytecode(Bytecod
}
if (is<ClassExpression>(*m_statement)) {
TODO();
TRY(m_statement->generate_bytecode(generator));
if (!static_cast<ClassExpression const&>(*m_statement).has_name())
generator.emit<Bytecode::Op::SetVariable>(generator.intern_identifier(ExportStatement::local_name_for_default), Bytecode::Op::SetVariable::InitializationMode::Initialize);
return {};
}
// ExportDeclaration : export default AssignmentExpression ;
VERIFY(is<Expression>(*m_statement));
TRY(generator.emit_named_evaluation_if_anonymous_function(static_cast<Expression const&>(*m_statement), DeprecatedFlyString("default"sv)));
generator.emit<Bytecode::Op::SetVariable>(generator.intern_identifier("default"sv));
generator.emit<Bytecode::Op::SetVariable>(generator.intern_identifier(ExportStatement::local_name_for_default), Bytecode::Op::SetVariable::InitializationMode::Initialize);
return {};
}