1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:18:11 +00:00

LibJS: Don't use null DFS in {Import,Export}Entry

This commit is contained in:
Dan Klishch 2024-01-24 14:45:11 -05:00 committed by Andrew Kaster
parent 78491204d9
commit fb2c929310
4 changed files with 36 additions and 39 deletions

View file

@ -206,7 +206,7 @@ Result<NonnullGCPtr<SourceTextModule>, Vector<ParserError>> SourceTextModule::pa
auto& import_entry = *in_imported_bound_names;
// 2. If ie.[[ImportName]] is namespace-object, then
if (import_entry.is_namespace) {
if (import_entry.is_namespace()) {
// a. NOTE: This is a re-export of an imported module namespace object.
// b. Append ee to localExportEntries.
local_export_entries.empend(export_entry);
@ -222,7 +222,7 @@ Result<NonnullGCPtr<SourceTextModule>, Vector<ParserError>> SourceTextModule::pa
// b. Else if ee.[[ImportName]] is all-but-default, then
else if (export_entry.kind == ExportEntry::Kind::ModuleRequestAllButDefault) {
// i. Assert: ee.[[ExportName]] is null.
VERIFY(export_entry.export_name.is_null());
VERIFY(!export_entry.export_name.has_value());
// ii. Append ee to starExportEntries.
star_export_entries.empend(export_entry);
}
@ -289,10 +289,10 @@ ThrowCompletionOr<Vector<DeprecatedFlyString>> SourceTextModule::get_exported_na
// FIXME: How do we check that?
// b. Assert: e.[[ExportName]] is not null.
VERIFY(!entry.export_name.is_null());
VERIFY(entry.export_name.has_value());
// c. Append e.[[ExportName]] to exportedNames.
exported_names.empend(entry.export_name);
exported_names.empend(entry.export_name.value());
}
// 7. For each ExportEntry Record e of module.[[IndirectExportEntries]], do
@ -301,10 +301,10 @@ ThrowCompletionOr<Vector<DeprecatedFlyString>> SourceTextModule::get_exported_na
// FIXME: How do we check that?
// b. Assert: e.[[ExportName]] is not null.
VERIFY(!entry.export_name.is_null());
VERIFY(entry.export_name.has_value());
// c. Append e.[[ExportName]] to exportedNames.
exported_names.empend(entry.export_name);
exported_names.empend(entry.export_name.value());
}
// 8. For each ExportEntry Record e of module.[[StarExportEntries]], do
@ -339,7 +339,7 @@ ThrowCompletionOr<void> SourceTextModule::initialize_environment(VM& vm)
// 1. For each ExportEntry Record e of module.[[IndirectExportEntries]], do
for (auto& entry : m_indirect_export_entries) {
// a. Let resolution be ? module.ResolveExport(e.[[ExportName]]).
auto resolution = TRY(resolve_export(vm, entry.export_name));
auto resolution = TRY(resolve_export(vm, entry.export_name.value()));
// b. If resolution is null or ambiguous, throw a SyntaxError exception.
if (!resolution.is_valid())
return vm.throw_completion<SyntaxError>(ErrorType::InvalidOrAmbiguousExportEntry, entry.export_name);
@ -369,7 +369,7 @@ ThrowCompletionOr<void> SourceTextModule::initialize_environment(VM& vm)
// b. NOTE: The above call cannot fail because imported module requests are a subset of module.[[RequestedModules]], and these have been resolved earlier in this algorithm.
// c. If in.[[ImportName]] is namespace-object, then
if (import_entry.is_namespace) {
if (import_entry.is_namespace()) {
// i. Let namespace be ? GetModuleNamespace(importedModule).
auto* namespace_ = TRY(imported_module->get_module_namespace(vm));
@ -382,7 +382,7 @@ ThrowCompletionOr<void> SourceTextModule::initialize_environment(VM& vm)
// d. Else,
else {
// i. Let resolution be ? importedModule.ResolveExport(in.[[ImportName]]).
auto resolution = TRY(imported_module->resolve_export(vm, import_entry.import_name));
auto resolution = TRY(imported_module->resolve_export(vm, import_entry.import_name.value()));
// ii. If resolution is null or ambiguous, throw a SyntaxError exception.
if (!resolution.is_valid())
@ -520,7 +520,7 @@ ThrowCompletionOr<void> SourceTextModule::initialize_environment(VM& vm)
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] Adding default export to lexical declarations: local name: {}, Expression: {}", name, statement.class_name());
// 1. Perform ! env.CreateMutableBinding(dn, false).
MUST(environment->create_mutable_binding(vm, name, false));
MUST(environment->create_mutable_binding(vm, name.value(), false));
// Note: Since this is not a function declaration 24.a.iii never applies
}
@ -569,7 +569,7 @@ ThrowCompletionOr<ResolvedBinding> SourceTextModule::resolve_export(VM& vm, Depr
return ResolvedBinding {
ResolvedBinding::Type::BindingName,
this,
entry.local_or_import_name,
entry.local_or_import_name.value(),
};
}
@ -601,7 +601,7 @@ ThrowCompletionOr<ResolvedBinding> SourceTextModule::resolve_export(VM& vm, Depr
// FIXME: What does this mean? / How do we check this
// 2. Return ? importedModule.ResolveExport(e.[[ImportName]], resolveSet).
return imported_module->resolve_export(vm, entry.local_or_import_name, resolve_set);
return imported_module->resolve_export(vm, entry.local_or_import_name.value(), resolve_set);
}
}