mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-27 10:29:23 +00:00
LibJS: Sync additional Import Attributes spec changes
Some steps were not updated with tc39/ecma262#3057. This patch syncs the remaining changes.
This commit is contained in:
parent
f8c4043460
commit
61c36e2865
Notes:
github-actions[bot]
2025-10-22 08:59:25 +00:00
Author: https://github.com/F3n67u
Commit: 61c36e2865
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6276
Reviewed-by: https://github.com/gmta ✅
9 changed files with 120 additions and 66 deletions
|
|
@ -7,17 +7,13 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/Utf16FlyString.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibJS/Module.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
struct ModuleWithSpecifier {
|
||||
Utf16String specifier; // [[Specifier]]
|
||||
GC::Ref<Module> module; // [[Module]]
|
||||
};
|
||||
|
||||
// https://tc39.es/ecma262/#importattribute-record
|
||||
struct ImportAttribute {
|
||||
Utf16String key;
|
||||
|
|
@ -26,6 +22,13 @@ struct ImportAttribute {
|
|||
bool operator==(ImportAttribute const&) const = default;
|
||||
};
|
||||
|
||||
// https://tc39.es/ecma262/#loadedmodulerequest-record
|
||||
struct LoadedModuleRequest {
|
||||
Utf16String specifier; // [[Specifier]]
|
||||
Vector<ImportAttribute> attributes; // [[Attributes]]
|
||||
GC::Ref<Module> module; // [[Module]]
|
||||
};
|
||||
|
||||
// https://tc39.es/ecma262/#modulerequest-record
|
||||
struct ModuleRequest {
|
||||
ModuleRequest() = default;
|
||||
|
|
@ -48,4 +51,39 @@ struct ModuleRequest {
|
|||
bool operator==(ModuleRequest const&) const = default;
|
||||
};
|
||||
|
||||
inline auto const& specifier_of(ModuleRequest const& r) { return r.module_specifier; }
|
||||
inline auto const& specifier_of(LoadedModuleRequest const& r) { return r.specifier; }
|
||||
|
||||
template<typename T>
|
||||
concept ModuleRequestLike = IsOneOf<RemoveCVReference<T>, ModuleRequest, LoadedModuleRequest>;
|
||||
|
||||
// 16.2.1.3.1 ModuleRequestsEqual ( left, right ), https://tc39.es/ecma262/#sec-modulerequestsequal
|
||||
template<ModuleRequestLike L, ModuleRequestLike R>
|
||||
bool module_requests_equal(L const& left, R const& right)
|
||||
{
|
||||
// 1. If left.[[Specifier]] is not right.[[Specifier]], return false.
|
||||
if (specifier_of(left) != specifier_of(right))
|
||||
return false;
|
||||
|
||||
// 2. Let leftAttrs be left.[[Attributes]].
|
||||
// 3. Let rightAttrs be right.[[Attributes]].
|
||||
auto const& left_attrs = left.attributes;
|
||||
auto const& right_attrs = right.attributes;
|
||||
|
||||
// 4. Let leftAttrsCount be the number of elements in leftAttrs.
|
||||
// 5. Let rightAttrsCount be the number of elements in rightAttrs.
|
||||
// 6. If leftAttrsCount ≠ rightAttrsCount, return false.
|
||||
if (left_attrs.size() != right_attrs.size())
|
||||
return false;
|
||||
|
||||
// 7. For each ImportAttribute Record l of leftAttrs
|
||||
// a. If rightAttrs does not contain an ImportAttribute Record r such that l.[[Key]] is r.[[Key]] and l.[[Value]] is r.[[Value]], return false.
|
||||
// 8. Return true.
|
||||
return AK::all_of(left_attrs, [&right_attrs](auto const& l) {
|
||||
return AK::any_of(right_attrs, [&l](auto const& r) {
|
||||
return l.key == r.key && l.value == r.value;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue