Truly independent web browser
LibJS: Move what describes nested functions into their shared data
Andreas Kling56d5ebb307af
diff --git a/Libraries/LibJS/Rust/src/bytecode/executable.rs b/Libraries/LibJS/Rust/src/bytecode/executable.rsindex ade22adab02..34b3929ff8a 100644--- a/Libraries/LibJS/Rust/src/bytecode/executable.rs+++ b/Libraries/LibJS/Rust/src/bytecode/executable.rs@@ -1391,20 +1391,30 @@ impl Executable {/// into any realm. Without another holder nothing can link it again, so what only linking reads goes away.pub fn create_with_source_code(vm: &Vm,- data: Arc<ExecutableData>,+ mut data: Arc<ExecutableData>,source_code: Option<&Rc<SourceCode>>,) -> Gc<Executable> {let executable = DeferGc::scope(vm, |_| {let mut tables = SliceBlock::builder(Self::size_of_tables(&data));let is_strict = data.is_strict;- let shared_function_data = tables.slice(data.shared_function_data.iter().map(|pending| {- SharedFunctionInstanceData::create_from_pending_shared_function_data(- vm,- pending,- is_strict,- source_code,- )- }));+ let shared_function_data = match Arc::get_mut(&mut data) {+ Some(code) => tables.slice(code.shared_function_data.take_elements().map(|pending| {+ SharedFunctionInstanceData::create_from_owned_pending_shared_function_data(+ vm,+ pending,+ is_strict,+ source_code,+ )+ })),+ None => tables.slice(data.shared_function_data.iter().map(|pending| {+ SharedFunctionInstanceData::create_from_pending_shared_function_data(+ vm,+ pending,+ is_strict,+ source_code,+ )+ })),+ };vm.heap().allocate(|defer_gc| Self::build(vm, data, tables, shared_function_data, source_code, defer_gc))});diff --git a/Libraries/LibJS/Rust/src/compile.rs b/Libraries/LibJS/Rust/src/compile.rsindex 31a337a17ce..43fa5dea535 100644--- a/Libraries/LibJS/Rust/src/compile.rs+++ b/Libraries/LibJS/Rust/src/compile.rs@@ -1144,6 +1144,7 @@ pub struct FunctionPayload {/// What a runtime needs to create a SharedFunctionInstanceData for one function, none of which takes the function's own/// tree to know. `payload` is what compile_function() turns into bytecode when the function is first called.+#[derive(Clone)]pub struct SharedFunctionDescription {/// Empty for an anonymous function.pub name: ak::Utf16FlyString,diff --git a/Libraries/LibJS/Rust/src/runtime/shared_function_instance_data.rs b/Libraries/LibJS/Rust/src/runtime/shared_function_instance_data.rsindex 91d56fd50e5..37f788c44ac 100644--- a/Libraries/LibJS/Rust/src/runtime/shared_function_instance_data.rs+++ b/Libraries/LibJS/Rust/src/runtime/shared_function_instance_data.rs@@ -354,34 +354,57 @@ impl SharedFunctionInstanceData {strict: bool,source_code: Option<&Rc<SourceCode>>,) -> Gc<SharedFunctionInstanceData> {+ Self::create_from_owned_description(vm, description.clone(), strict, source_code)+ }++ fn create_from_owned_description(+ vm: &Vm,+ description: SharedFunctionDescription,+ strict: bool,+ source_code: Option<&Rc<SourceCode>>,+ ) -> Gc<SharedFunctionInstanceData> {+ let SharedFunctionDescription {+ name,+ function_kind,+ function_length,+ formal_parameter_count,+ is_arrow,+ has_simple_parameter_list,+ source_text_offset,+ source_text_length,+ uses_this,+ uses_this_from_environment,+ payload,+ ..+ } = description;let shared = vm.heap().allocate(|defer| {Self::new(defer,- description.function_kind,- description.name.clone(),- description.function_length,- description.formal_parameter_count,+ function_kind,+ name,+ function_length,+ formal_parameter_count,strict,- description.is_arrow,- description.has_simple_parameter_list,+ is_arrow,+ has_simple_parameter_list,Vec::new(),- Some(description.payload.clone()),+ Some(payload),)});shared.update_can_inline_call();// Set parsing insights that must be available before lazy compilation.- shared.set_uses_this(description.uses_this);+ shared.set_uses_this(uses_this);shared.set_metadata_bit(asm_call_metadata::THIS_VALUE_NEEDS_ENVIRONMENT_RESOLUTION,- description.uses_this_from_environment,+ uses_this_from_environment,);- if description.uses_this_from_environment && !description.is_arrow {+ if uses_this_from_environment && !is_arrow {shared.set_function_environment_needed(true);}shared.storage.source_code.set(source_code.cloned());- shared.initialize_source_text_range(description.source_text_offset, description.source_text_length);+ shared.initialize_source_text_range(source_text_offset, source_text_length);shared}@@ -446,6 +469,24 @@ impl SharedFunctionInstanceData {shared}+ /// create_from_pending_shared_function_data() for what nothing links again, which moves into the shared data.+ pub fn create_from_owned_pending_shared_function_data(+ vm: &Vm,+ pending: PendingSharedFunctionData,+ is_strict: bool,+ source_code: Option<&Rc<SourceCode>>,+ ) -> Gc<SharedFunctionInstanceData> {+ let strict = pending.is_strict_in(is_strict);+ let shared = Self::create_from_owned_description(vm, pending.description, strict, source_code);+ if let Some((name, is_private)) = &pending.class_field_initializer_name {+ shared.set_class_field_initializer_name_from_utf16(&name.to_utf16(), *is_private);+ }+ if let Some(precompiled) = pending.precompiled_function {+ shared.set_precompiled_bytecode_executable(precompiled);+ }+ shared+ }+pub fn executable(&self) -> Option<Gc<Executable>> {self.executable.get().map(Executable::from_head)}