1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

LibJS: Implement import.meta for bytecode

This commit is contained in:
Gabriel Dinner-David 2023-07-11 23:07:12 -04:00 committed by Andreas Kling
parent a1692931af
commit d29bd55b48
8 changed files with 78 additions and 49 deletions

View file

@ -2884,10 +2884,8 @@ Bytecode::CodeGenerationErrorOr<void> MetaProperty::generate_bytecode(Bytecode::
// ImportMeta : import . meta
if (m_type == MetaProperty::Type::ImportMeta) {
return Bytecode::CodeGenerationError {
this,
"Unimplemented meta property: import.meta"sv,
};
generator.emit<Bytecode::Op::GetImportMeta>();
return {};
}
VERIFY_NOT_REACHED();

View file

@ -42,6 +42,7 @@
O(GetIterator) \
O(GetMethod) \
O(GetNewTarget) \
O(GetImportMeta) \
O(GetObjectPropertyIterator) \
O(GetPrivateById) \
O(GetVariable) \

View file

@ -26,6 +26,7 @@
#include <LibJS/Runtime/Reference.h>
#include <LibJS/Runtime/RegExpObject.h>
#include <LibJS/Runtime/Value.h>
#include <LibJS/SourceTextModule.h>
namespace JS::Bytecode {
@ -762,6 +763,12 @@ ThrowCompletionOr<void> GetNewTarget::execute_impl(Bytecode::Interpreter& interp
return {};
}
ThrowCompletionOr<void> GetImportMeta::execute_impl(Bytecode::Interpreter& interpreter) const
{
interpreter.accumulator() = interpreter.vm().get_import_meta();
return {};
}
void Jump::replace_references_impl(BasicBlock const& from, BasicBlock const& to)
{
if (m_true_target.has_value() && &m_true_target->block() == &from)
@ -1896,6 +1903,11 @@ DeprecatedString GetNewTarget::to_deprecated_string_impl(Bytecode::Executable co
return "GetNewTarget"sv;
}
DeprecatedString GetImportMeta::to_deprecated_string_impl(Bytecode::Executable const&) const
{
return "GetImportMeta"sv;
}
DeprecatedString TypeofVariable::to_deprecated_string_impl(Bytecode::Executable const& executable) const
{
return DeprecatedString::formatted("TypeofVariable {} ({})", m_identifier, executable.identifier_table->get(m_identifier));

View file

@ -1538,6 +1538,19 @@ public:
void replace_references_impl(Register, Register) { }
};
class GetImportMeta final : public Instruction {
public:
explicit GetImportMeta()
: Instruction(Type::GetImportMeta)
{
}
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
void replace_references_impl(Register, Register) { }
};
class TypeofVariable final : public Instruction {
public:
explicit TypeofVariable(IdentifierTableIndex identifier)