diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /js/src/vm/Modules.cpp | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/src/vm/Modules.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/js/src/vm/Modules.cpp b/js/src/vm/Modules.cpp index 917083a238..867201baa9 100644 --- a/js/src/vm/Modules.cpp +++ b/js/src/vm/Modules.cpp @@ -310,7 +310,9 @@ JS_PUBLIC_API JSObject* JS::CreateModuleRequest( return nullptr; } - return ModuleRequestObject::create(cx, specifierAtom, nullptr); + Rooted<UniquePtr<ImportAttributeVector>> attributes(cx); + + return ModuleRequestObject::create(cx, specifierAtom, &attributes); } JS_PUBLIC_API JSString* JS::GetModuleRequestSpecifier( @@ -1256,6 +1258,36 @@ static bool ModuleLink(JSContext* cx, Handle<ModuleObject*> module) { return true; } +// https://tc39.es/proposal-import-attributes/#sec-AllImportAttributesSupported +static bool AllImportAttributesSupported( + JSContext* cx, mozilla::Span<const ImportAttribute> attributes) { + // Step 1. Let supported be HostGetSupportedImportAttributes(). + // + // Note: This should be driven by a host hook + // (HostGetSupportedImportAttributes), however the infrastructure of said host + // hook is deeply unclear, and so right now embedders will not have the + // ability to alter or extend the set of supported attributes. See + // https://bugzilla.mozilla.org/show_bug.cgi?id=1840723. + + // Step 2. For each ImportAttribute Record attribute of attributes, do + for (const ImportAttribute& attribute : attributes) { + // Step 2.a. If supported does not contain attribute.[[Key]], return false. + if (attribute.key() != cx->names().type) { + UniqueChars printableKey = AtomToPrintableString(cx, attribute.key()); + if (!printableKey) { + return false; + } + JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, + JSMSG_IMPORT_ATTRIBUTES_UNSUPPORTED_ATTRIBUTE, + printableKey.get()); + return false; + } + } + + // Step 3. Return true. + return true; +} + // https://tc39.es/ecma262/#sec-InnerModuleLinking // ES2023 16.2.1.5.1.1 InnerModuleLinking static bool InnerModuleLinking(JSContext* cx, Handle<ModuleObject*> module, @@ -1312,6 +1344,13 @@ static bool InnerModuleLinking(JSContext* cx, Handle<ModuleObject*> module, for (const RequestedModule& request : module->requestedModules()) { moduleRequest = request.moduleRequest(); + // According to the spec, this should be in InnerModuleLoading, but + // currently, our module code is not aligned with the spec text. + // https://bugzilla.mozilla.org/show_bug.cgi?id=1894729 + if (!AllImportAttributesSupported(cx, moduleRequest->attributes())) { + return false; + } + // Step 9.a. Let requiredModule be ? HostResolveImportedModule(module, // required). requiredModule = HostResolveImportedModule(cx, module, moduleRequest, |