From 2c27b4e63c20bb82a6e41f6b35efd863ff872651 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Wed, 27 Sep 2023 22:36:50 -0600 Subject: [PATCH] LibWeb: Ensure an ESO is pushed before doing structured deserialization We need to make sure that the given target realm is at the top of the VM's execution context stack before doing any JS object construction based on the data in our serialized buffer. --- Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp b/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp index ca1d70021d..62c4d43625 100644 --- a/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp +++ b/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp @@ -1142,8 +1142,16 @@ WebIDL::ExceptionOr structured_deserialize(JS::VM& vm, SerializationR if (!memory.has_value()) memory = DeserializationMemory { vm.heap() }; + // IMPLEMENTATION DEFINED: We need to make sure there's an execution context for target_realm on the stack before constructing these JS objects + auto& target_settings = Bindings::host_defined_environment_settings_object(target_realm); + target_settings.prepare_to_run_script(); + Deserializer deserializer(vm, target_realm, serialized.span(), *memory); - return deserializer.deserialize(); + + auto result = deserializer.deserialize(); + + target_settings.clean_up_after_running_script(); + return result; } }