use super::*;
impl ScriptVm {
pub(crate) fn dynamic_module_import_owner_is_current(
&self,
owner: crate::module_runtime::DynamicModuleImportOwner,
) -> bool {
self._context_host
.borrow()
.dynamic_module_import_owner_is_current(owner)
}
pub(super) fn advance_native_dynamic_module_import_job_with_body
(
&mut self,
mut job: NativeModuleGraphJob,
body: &mut Body,
) -> std::result::Result<(), String>
where
Body: ScriptVmMainNativeModuleTaskBody,
{
if job
.dynamic_import_request()
.and_then(PendingDynamicModuleImport::child_browsing_context_handle)
.is_some()
{
return self.advance_child_native_dynamic_module_import_job(job);
}
let advance = match job.advance_dynamic_import_owner_lane(self) {
Ok(advance) => advance,
Err(error) => {
let mut fanout = NativeDynamicModuleTerminalFanout::default();
fanout.push_graph_advance_failure(job, error);
return self
.handle_dynamic_module_terminal_fanout_for_owner_with_body(fanout, body)
.map(|_| ())
.map_err(|error| error.to_string());
}
};
self.continue_native_dynamic_module_import_after_tree_advance_with_body(job, advance, body)
}
pub(super) fn continue_native_dynamic_module_import_after_tree_advance_with_body(
&mut self,
job: NativeModuleGraphJob,
advance: NativeModuleGraphJobAdvance,
body: &mut Body,
) -> std::result::Result<(), String>
where
Body: ScriptVmMainNativeModuleTaskBody,
{
if job
.dynamic_import_request()
.and_then(PendingDynamicModuleImport::child_browsing_context_handle)
.is_some()
{
return self
.continue_child_native_dynamic_module_import_after_tree_advance(job, advance);
}
self.continue_main_native_dynamic_module_import_after_tree_advance_with_body(
job, advance, body,
)
.map(|_| ())
.map_err(|error| error.to_string())
}
pub(super) fn continue_main_native_dynamic_module_import_after_tree_advance_with_body(
&mut self,
mut job: NativeModuleGraphJob,
advance: NativeModuleGraphJobAdvance,
body: &mut Body,
) -> Result
where
Body: ScriptVmMainNativeModuleTaskBody,
{
let mut outcome = NativeDynamicModuleTerminalFanoutOutcome::default();
let mut fanout = NativeDynamicModuleTerminalFanout::default();
match advance {
NativeModuleGraphJobAdvance::NeedFetches(requests) => {
let joined_clients = job.take_pending_joined_clients();
let owner_module_fetch_starts = vec![None; requests.len()];
let scheduled = self
.document_runtime
.suspend_native_dynamic_module_import_fetches(
requests,
joined_clients,
job,
owner_module_fetch_starts,
);
fanout.extend_scheduled_dynamic_import_fetches(scheduled);
}
NativeModuleGraphJobAdvance::WaitingForFetches => {
let joined_clients = job.take_pending_joined_clients();
if joined_clients.is_empty() {
self.document_runtime
.resume_native_dynamic_module_import_front(job);
outcome.record_dynamic_import_job_resumed();
} else {
self.document_runtime
.suspend_native_dynamic_module_import_fetches(
Vec::new(),
joined_clients,
job,
Vec::new(),
);
outcome.record_dynamic_import_wait_retained();
}
}
NativeModuleGraphJobAdvance::Complete(graph) => {
fanout.push_ready_import(NativeDynamicModuleImportReady { job, graph });
}
}
outcome
.merge(self.handle_dynamic_module_terminal_fanout_for_owner_with_body(fanout, body)?);
Ok(outcome)
}
pub(super) fn run_completed_native_dynamic_module_import_action_with_body(
&mut self,
job: NativeModuleGraphJob,
graph: ModuleGraphHandle,
body: &mut Body,
) -> std::result::Result
where
Body: ScriptVmMainNativeModuleTaskBody,
{
let document_owner = job
.dynamic_import_request()
.expect("completed dynamic import graph must retain its request")
.owner();
if let Some((_child_handle, task_owner, realm_id)) = document_owner.child_parts() {
let owner = task_owner.document_owner();
let followup = self
.child_document_modulator_store
.dynamic_import_ready_followup(
owner,
realm_id,
NativeDynamicModuleImportReady { job, graph },
);
return Ok(
FrameDocumentDynamicImportTerminalOutcome::from_owner_action_queue_followup(
self.apply_child_dynamic_import_followup(followup),
),
);
}
self.run_main_dynamic_import_owner_action_with_body(
FrameDocumentDynamicImportOwnerAction::ready(NativeDynamicModuleImportReady {
job,
graph,
}),
body,
)
}
pub(super) fn run_main_dynamic_import_owner_action_with_body(
&mut self,
action: FrameDocumentDynamicImportOwnerAction,
body: &mut Body,
) -> std::result::Result
where
Body: ScriptVmMainNativeModuleTaskBody,
{
FrameDocumentDynamicImportOwnerActionRunner::new(
ScriptVmMainDynamicImportOwnerActionHooks::new(self, body),
)
.run_owner_action(action)
}
pub(crate) fn has_ready_native_module_owner_actions(&mut self) -> bool {
self.document_runtime.has_ready_native_module_owner_event()
}
#[cfg(test)]
pub(crate) fn drain_ready_native_module_owner_actions(
&mut self,
) -> Result<(
NativeModuleOwnerActions,
FrameDocumentModuleTerminalQueueFollowup,
)> {
self.drain_ready_native_module_owner_actions_with_body(
&mut ScriptVmCheckpointingMainNativeModuleTaskBody,
)
}
pub(super) fn drain_ready_native_module_owner_actions_with_body(
&mut self,
body: &mut Body,
) -> Result<(
NativeModuleOwnerActions,
FrameDocumentModuleTerminalQueueFollowup,
)>
where
Body: ScriptVmMainNativeModuleTaskBody,
{
if !self.has_ready_native_module_owner_actions() {
return Ok((
NativeModuleOwnerActions::empty(),
FrameDocumentModuleTerminalQueueFollowup::none(),
));
}
let Some(event) = self.document_runtime.take_next_native_module_owner_event() else {
return Ok((
NativeModuleOwnerActions::empty(),
FrameDocumentModuleTerminalQueueFollowup::none(),
));
};
self.dispatch_native_module_owner_event_with_body(event, body)
}
pub(super) fn dispatch_native_module_owner_event_with_body(
&mut self,
event: NativeModuleOwnerEvent,
body: &mut Body,
) -> Result<(
NativeModuleOwnerActions,
FrameDocumentModuleTerminalQueueFollowup,
)>
where
Body: ScriptVmMainNativeModuleTaskBody,
{
match event {
NativeModuleOwnerEvent::ModuleMapTerminalNotification(notification) => {
let fanout =
self.dispatch_native_document_modulator_terminal_notification(notification)?;
self.handle_document_modulator_terminal_fanout_for_owner_with_body(fanout, body)
}
NativeModuleOwnerEvent::ModulepreloadLinkError(handle) => {
body.note_page_realm_body_attempted();
self.dispatch_preload_like_link_error_event(handle);
Ok((
NativeModuleOwnerActions::empty(),
FrameDocumentModuleTerminalQueueFollowup::none(),
))
}
}
}
pub(crate) fn has_ready_runtime_owned_module_owner_actions(&mut self) -> bool {
self.document_runtime
.runtime_script_work_mut()
.dynamic_scripts
.has_ready_module_script_continuation()
}
pub(crate) fn register_native_modulepreload_for_owner(
&mut self,
request: NativeModuleSingleFetchRequest,
) -> std::result::Result