mirror of
https://github.com/RGBCube/serenity
synced 2025-06-28 21:02:07 +00:00
LibJS: Implement the ImportMeta MetaProperty
This "standard" implementation of this is to do nothing.
This commit is contained in:
parent
7cbf4b90e8
commit
91b3e5b31f
2 changed files with 49 additions and 2 deletions
|
@ -3167,8 +3167,48 @@ Completion MetaProperty::execute(Interpreter& interpreter, GlobalObject& global_
|
|||
|
||||
// ImportMeta : import . meta
|
||||
if (m_type == MetaProperty::Type::ImportMeta) {
|
||||
// TODO: Implement me :^)
|
||||
return interpreter.vm().throw_completion<InternalError>(global_object, ErrorType::NotImplemented, "'import.meta' in modules");
|
||||
// 1. Let module be ! GetActiveScriptOrModule().
|
||||
auto script_or_module = interpreter.vm().get_active_script_or_module();
|
||||
|
||||
// 2. Assert: module is a Source Text Module Record.
|
||||
VERIFY(script_or_module.has<Module*>());
|
||||
VERIFY(is<SourceTextModule>(*script_or_module.get<Module*>()));
|
||||
auto& module = static_cast<SourceTextModule&>(*script_or_module.get<Module*>());
|
||||
|
||||
// 3. Let importMeta be module.[[ImportMeta]].
|
||||
auto* import_meta = module.import_meta();
|
||||
|
||||
// 4. If importMeta is empty, then
|
||||
if (import_meta == nullptr) {
|
||||
// a. Set importMeta to ! OrdinaryObjectCreate(null).
|
||||
import_meta = Object::create(global_object, nullptr);
|
||||
|
||||
// b. Let importMetaValues be ! HostGetImportMetaProperties(module).
|
||||
auto import_meta_values = interpreter.vm().host_get_import_meta_properties(module);
|
||||
|
||||
// c. For each Record { [[Key]], [[Value]] } p of importMetaValues, do
|
||||
for (auto& entry : import_meta_values) {
|
||||
// i. Perform ! CreateDataPropertyOrThrow(importMeta, p.[[Key]], p.[[Value]]).
|
||||
MUST(import_meta->create_data_property_or_throw(entry.key, entry.value));
|
||||
}
|
||||
|
||||
// d. Perform ! HostFinalizeImportMeta(importMeta, module).
|
||||
interpreter.vm().host_finalize_import_meta(import_meta, module);
|
||||
|
||||
// e. Set module.[[ImportMeta]] to importMeta.
|
||||
module.set_import_meta({}, import_meta);
|
||||
|
||||
// f. Return importMeta.
|
||||
return Value { import_meta };
|
||||
}
|
||||
// 5. Else,
|
||||
else {
|
||||
// a. Assert: Type(importMeta) is Object.
|
||||
// Note: This is always true by the type.
|
||||
|
||||
// b. Return importMeta.
|
||||
return Value { import_meta };
|
||||
}
|
||||
}
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue