Skip to content

Truly independent web browser

LibJS+LibWeb: Root the import.meta properties returned by the host

Shannon Booth9642dfad02de
diff --git a/Libraries/LibJS/Runtime/VM.cpp b/Libraries/LibJS/Runtime/VM.cpp
index 1b80f72acef..65cb2d34c92 100644
--- a/Libraries/LibJS/Runtime/VM.cpp
+++ b/Libraries/LibJS/Runtime/VM.cpp
@@ -6,7 +6,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <LibGC/RootVector.h>
#include <LibJS/CyclicModule.h>
#include <LibJS/EmbeddingABIConversions.h>
#include <LibJS/Runtime/ArrayBufferABIConversions.h>
@@ -207,12 +206,6 @@ struct HostHookThunks {
{
auto& vm = vm_of(data);
auto import_meta_properties = vm.host_get_import_meta_properties(module_from_abi<SourceTextModule>(module));
-
- // The values have to stay alive until they are appended, and appending one can collect garbage.
- GC::RootVector<Value> values_being_appended;
- for (auto const& property : import_meta_properties)
- values_being_appended.append(property.value);
-
for (auto const& property : import_meta_properties)
properties->append(properties->context, *property_key_to_abi(property.key), value_to_abi(property.value));
}
@@ -350,7 +343,7 @@ void VM::install_default_host_hooks()
js_vm_default_host_load_imported_module(vm_abi(*this), imported_module_referrer_to_abi(referrer), abi_module_request.ptr(), load_state.ptr(), imported_module_payload_to_abi(payload));
};
- host_get_import_meta_properties = [](SourceTextModule&) -> HashMap<PropertyKey, Value> {
+ host_get_import_meta_properties = [](SourceTextModule&) -> GC::RootHashMap<PropertyKey, Value> {
return {};
};
diff --git a/Libraries/LibJS/Runtime/VM.h b/Libraries/LibJS/Runtime/VM.h
index 740f498c7bc..145e76b5bce 100644
--- a/Libraries/LibJS/Runtime/VM.h
+++ b/Libraries/LibJS/Runtime/VM.h
@@ -29,6 +29,7 @@
#include <LibCrypto/Forward.h>
#include <LibGC/Function.h>
#include <LibGC/Heap.h>
+#include <LibGC/RootHashMap.h>
#include <LibGC/RootVector.h>
#include <LibJS/Breakpoint.h>
#include <LibJS/CyclicModule.h>
@@ -429,7 +430,7 @@ public:
// 16.2.1.10 HostLoadImportedModule ( referrer, moduleRequest, hostDefined, payload ), https://tc39.es/ecma262/#sec-HostLoadImportedModule
Function<void(ImportedModuleReferrer, ModuleRequest const&, GC::Ptr<GC::Cell> load_state, ImportedModulePayload)> host_load_imported_module;
- Function<HashMap<PropertyKey, Value>(SourceTextModule&)> host_get_import_meta_properties;
+ Function<GC::RootHashMap<PropertyKey, Value>(SourceTextModule&)> host_get_import_meta_properties;
Function<Vector<Utf16String>()> host_get_supported_import_attributes;
diff --git a/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Libraries/LibWeb/Bindings/MainThreadVM.cpp
index a965b6c1dca..945a711a98f 100644
--- a/Libraries/LibWeb/Bindings/MainThreadVM.cpp
+++ b/Libraries/LibWeb/Bindings/MainThreadVM.cpp
@@ -464,7 +464,7 @@ void initialize_main_thread_vm(HTML::AgentType type)
auto resolve_function = JS::NativeFunction::create(realm, move(steps), 1, vm.names.resolve);
// 5. Return « Record { [[Key]]: "url", [[Value]]: urlString }, Record { [[Key]]: "resolve", [[Value]]: resolveFunction } ».
- HashMap<JS::PropertyKey, JS::Value> meta;
+ GC::RootHashMap<JS::PropertyKey, JS::Value> meta;
meta.set("url"_utf16_fly_string, JS::PrimitiveString::create(vm, Utf16String::from_utf8(url_string)));
meta.set("resolve"_utf16_fly_string, resolve_function);