From b25876355888158167ebdefe50c0a88a2d33a38f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 16 Mar 2023 09:27:16 -0400 Subject: refactor(core): op initialization and snapshot creator (#18221) This PR cleans up APIs related to snapshot creation and how ops are initialized. Prerequisite for #18080 --------- Co-authored-by: Divy Srivastava --- core/modules.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'core/modules.rs') diff --git a/core/modules.rs b/core/modules.rs index ee5f72d9d..e03f86c01 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -6,6 +6,7 @@ use crate::extensions::ExtensionFileSource; use crate::module_specifier::ModuleSpecifier; use crate::resolve_import; use crate::resolve_url; +use crate::snapshot_util::SnapshottedData; use crate::JsRuntime; use crate::OpState; use anyhow::Error; @@ -1030,7 +1031,7 @@ impl ModuleMap { pub fn serialize_for_snapshotting( &self, scope: &mut v8::HandleScope, - ) -> (v8::Global, Vec>) { + ) -> SnapshottedData { let array = v8::Array::new(scope, 3); let next_load_id = v8::Integer::new(scope, self.next_load_id); @@ -1105,16 +1106,19 @@ impl ModuleMap { let array_global = v8::Global::new(scope, array); let handles = self.handles.clone(); - (array_global, handles) + SnapshottedData { + module_map_data: array_global, + module_handles: handles, + } } - pub fn update_with_snapshot_data( + pub fn update_with_snapshotted_data( &mut self, scope: &mut v8::HandleScope, - data: v8::Global, - module_handles: Vec>, + snapshotted_data: SnapshottedData, ) { - let local_data: v8::Local = v8::Local::new(scope, data); + let local_data: v8::Local = + v8::Local::new(scope, snapshotted_data.module_map_data); { let next_load_id = local_data.get_index(scope, 0).unwrap(); @@ -1258,7 +1262,7 @@ impl ModuleMap { self.by_name = by_name; } - self.handles = module_handles; + self.handles = snapshotted_data.module_handles; } pub(crate) fn new( -- cgit v1.2.3