Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

Remove legacy inspector command routing

ldm091bfa0b4410c
diff --git a/moli-core/src/page/command_dispatch.rs b/moli-core/src/page/command_dispatch.rs
index f6f54fbf0..e8722e194 100644
--- a/moli-core/src/page/command_dispatch.rs
+++ b/moli-core/src/page/command_dispatch.rs
@@ -1,7 +1,7 @@
use super::{
Page, RendererAgentAttachmentId, RendererCommandTurnOutput, RendererPageCommand,
- RendererPageCommandPending, RendererPageReply, RendererRuntimeInspectorCommandClaim,
- RendererRuntimeInspectorCommandRoute, RendererRuntimeInspectorMainCommandCompletion,
+ RendererPageCommandPending, RendererPageReply, RendererRuntimeInspectorIoCommandClaim,
+ RendererRuntimeInspectorIoCommandRoute, RendererRuntimeInspectorMainCommandCompletion,
RendererRuntimeInspectorMainCommandRoute, RendererRuntimeInspectorMessage,
};
use crate::RendererOutputFence;
@@ -18,7 +18,7 @@ pub struct PendingRuntimeInspectorCommandDispatch {
enum PendingRuntimeInspectorCommandDispatchKind {
MainIngress(Box<RendererRuntimeInspectorMainCommandRoute>),
- Io(RendererRuntimeInspectorCommandRoute),
+ Io(RendererRuntimeInspectorIoCommandRoute),
}
/// Identifies which execution owner consumed one routable Inspector command.
@@ -129,7 +129,7 @@ impl Page {
}
pub(crate) fn pending_io_runtime_inspector_command_dispatch(
- route: RendererRuntimeInspectorCommandRoute,
+ route: RendererRuntimeInspectorIoCommandRoute,
) -> PendingRuntimeInspectorCommandDispatch {
Self::pending_runtime_inspector_command_dispatch(
PendingRuntimeInspectorCommandDispatchKind::Io(route),
@@ -390,10 +390,10 @@ impl PendingRuntimeInspectorCommandDispatch {
}
PendingRuntimeInspectorCommandDispatchKind::Io(route) => {
match route.wait_for_claim().await.map_err(anyhow::Error::msg)? {
- RendererRuntimeInspectorCommandClaim::Inspector => {
+ RendererRuntimeInspectorIoCommandClaim::Inspector => {
Ok(CompletedRuntimeInspectorCommandDispatch::Inspector)
}
- RendererRuntimeInspectorCommandClaim::Canceled => {
+ RendererRuntimeInspectorIoCommandClaim::Canceled => {
Ok(CompletedRuntimeInspectorCommandDispatch::Canceled)
}
}
diff --git a/moli-core/src/page/js_evaluation.rs b/moli-core/src/page/js_evaluation.rs
index 6c4f056d7..97af0fc60 100644
--- a/moli-core/src/page/js_evaluation.rs
+++ b/moli-core/src/page/js_evaluation.rs
@@ -477,7 +477,6 @@ impl Page {
) -> Result<PendingPageCommand> {
self.start_page_command(RendererPageCommand::dispatch_runtime_protocol_message(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
raw_json,
))
}
@@ -503,7 +502,6 @@ impl Page {
self.start_page_command(
RendererPageCommand::dispatch_runtime_protocol_message_with_deferred_response(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
raw_json,
deferred_response,
),
@@ -598,7 +596,6 @@ impl Page {
self.start_page_command(
RendererPageCommand::dispatch_runtime_protocol_message_with_context_resolution(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
action,
raw_json,
),
@@ -629,7 +626,6 @@ impl Page {
self.start_page_command(
RendererPageCommand::dispatch_runtime_protocol_message_with_context_resolution_and_deferred_response(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
action,
raw_json,
deferred_response,
diff --git a/moli-core/src/page/mod.rs b/moli-core/src/page/mod.rs
index b9a9e4005..c3ea274a3 100644
--- a/moli-core/src/page/mod.rs
+++ b/moli-core/src/page/mod.rs
@@ -113,7 +113,7 @@ pub use moli_renderer_v8::{
RendererPendingWindowOpenEvent, RendererPerformanceMetricSnapshot,
RendererPointerEventProperties, RendererPopupActivationSource,
RendererResourceTextSearchOutcome, RendererRuntimeCommandOutput, RendererRuntimeHeapUsage,
- RendererRuntimeInspectorCommandClaim, RendererRuntimeInspectorCommandRoute,
+ RendererRuntimeInspectorIoCommandClaim, RendererRuntimeInspectorIoCommandRoute,
RendererRuntimeInspectorMainCommandCompletion, RendererRuntimeInspectorMainCommandRoute,
RendererRuntimeInspectorMessage, RendererRuntimeInspectorMessageBatch,
RendererRuntimeInspectorProtocolMessage, RendererRuntimeInspectorProtocolMessageValueMut,
diff --git a/moli-protocol-cdp/src/wire.rs b/moli-protocol-cdp/src/wire.rs
index 036945b0e..1f27ed0a8 100644
--- a/moli-protocol-cdp/src/wire.rs
+++ b/moli-protocol-cdp/src/wire.rs
@@ -157,7 +157,7 @@ impl CdpRequest {
/// Renderer access required by one parsed CDP command.
///
-/// Chromium physically separates renderer main-thread and interruptible IO
+/// Chromium physically separates renderer main-thread and IO
/// DevTools routes. Moli keeps one protocol actor, so the parsed command
/// carries the equivalent scheduling fact explicitly instead of asking later
/// layers to reinterpret the wire method string.
@@ -170,7 +170,7 @@ pub enum CdpRendererCommandAccess {
MainThread,
/// The command may address the suspended renderer in order to inspect,
/// interrupt, or release it while navigation is in flight.
- Interruptible,
+ Io,
}
/// Fate of an in-flight renderer command when navigation replaces its
@@ -547,21 +547,21 @@ impl CdpRendererCommandPolicy {
let renderer_access = match domain {
CdpMethodDomain::Runtime => {
if runtime_action == Some(RuntimeWireAction::TerminateExecution) {
- CdpRendererCommandAccess::Interruptible
+ CdpRendererCommandAccess::Io
} else {
CdpRendererCommandAccess::MainThread
}
}
CdpMethodDomain::Debugger => {
if debugger_action.is_some_and(DebuggerWireAction::is_interruptible) {
- CdpRendererCommandAccess::Interruptible
+ CdpRendererCommandAccess::Io
} else {
CdpRendererCommandAccess::MainThread
}
}
CdpMethodDomain::Performance => {
if PerformanceWireAction::parse(action) == PerformanceWireAction::GetMetrics {
- CdpRendererCommandAccess::Interruptible
+ CdpRendererCommandAccess::Io
} else {
CdpRendererCommandAccess::MainThread
}
@@ -570,14 +570,14 @@ impl CdpRendererCommandPolicy {
if EmulationWireAction::parse(action)
== EmulationWireAction::SetScriptExecutionDisabled
{
- CdpRendererCommandAccess::Interruptible
+ CdpRendererCommandAccess::Io
} else {
CdpRendererCommandAccess::OwnerIndependent
}
}
CdpMethodDomain::Page => match PageWireAction::parse(action) {
PageWireAction::MainThread => CdpRendererCommandAccess::MainThread,
- PageWireAction::Crash => CdpRendererCommandAccess::Interruptible,
+ PageWireAction::Crash => CdpRendererCommandAccess::Io,
PageWireAction::Other => CdpRendererCommandAccess::OwnerIndependent,
},
CdpMethodDomain::Accessibility
@@ -690,7 +690,7 @@ mod tests {
] {
let command = parse(format!(r#"{{"id":12,"method":"{method}"}}"#));
assert!(
- command.renderer_access() == CdpRendererCommandAccess::Interruptible,
+ command.renderer_access() == CdpRendererCommandAccess::Io,
"{method} must remain dispatchable while the renderer attachment is suspended"
);
}
@@ -849,10 +849,7 @@ mod tests {
assert_eq!(command.request().id(), 14);
assert_eq!(command.session_id(), Some("s2"));
- assert_eq!(
- command.renderer_access(),
- CdpRendererCommandAccess::Interruptible
- );
+ assert_eq!(command.renderer_access(), CdpRendererCommandAccess::Io);
assert!(!command.runtime_command_executes_page_javascript());
}
diff --git a/moli-protocol/src/conn/runtime_eval.rs b/moli-protocol/src/conn/runtime_eval.rs
index fa5ee3b36..df1e3f6a5 100644
--- a/moli-protocol/src/conn/runtime_eval.rs
+++ b/moli-protocol/src/conn/runtime_eval.rs
@@ -4252,7 +4252,7 @@ impl CdpConnection {
)
}
- pub(crate) fn start_runtime_interrupt_protocol_message_for_session_owner(
+ pub(crate) fn start_runtime_io_protocol_message_for_session_owner(
&mut self,
session_id: Option<&str>,
raw_json: String,
@@ -4317,7 +4317,7 @@ impl CdpConnection {
)
}
- pub(crate) fn start_runtime_interrupt_protocol_message_for_session_owner_with_deferred_response(
+ pub(crate) fn start_runtime_io_protocol_message_for_session_owner_with_deferred_response(
&mut self,
session_id: Option<&str>,
descriptor: RendererCommandDescriptor,
diff --git a/moli-protocol/src/domains/performance.rs b/moli-protocol/src/domains/performance.rs
index dffd7a61c..c58627dc1 100644
--- a/moli-protocol/src/domains/performance.rs
+++ b/moli-protocol/src/domains/performance.rs
@@ -78,7 +78,7 @@ fn loaded_page_mut_for_renderer_access<'a>(
CdpRendererCommandAccess::MainThread => {
conn.loaded_page_mut_for_protocol_access(session_id)
}
- CdpRendererCommandAccess::Interruptible => {
+ CdpRendererCommandAccess::Io => {
conn.loaded_page_mut_for_interruptible_protocol_access(session_id)
}
CdpRendererCommandAccess::OwnerIndependent => {
diff --git a/moli-protocol/src/domains/runtime/command_classification.rs b/moli-protocol/src/domains/runtime/command_classification.rs
index 9c20ebec8..31363ca8e 100644
--- a/moli-protocol/src/domains/runtime/command_classification.rs
+++ b/moli-protocol/src/domains/runtime/command_classification.rs
@@ -14,28 +14,19 @@ pub(super) enum RuntimeInspectorPayloadPreparation {
PrepareCallFunctionOn,
}
-#[derive(Clone, Copy, Debug, Eq, PartialEq)]
-pub(super) enum RuntimeInspectorDispatchRoute {
- Direct,
- Interruptible,
-}
-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(super) struct MainRuntimeInspectorCommand {
action: RuntimeAction,
- route: RuntimeInspectorDispatchRoute,
payload_preparation: RuntimeInspectorPayloadPreparation,
}
impl MainRuntimeInspectorCommand {
const fn new(
action: RuntimeAction,
- route: RuntimeInspectorDispatchRoute,
payload_preparation: RuntimeInspectorPayloadPreparation,
) -> Self {
Self {
action,
- route,
payload_preparation,
}
}
@@ -44,10 +35,6 @@ impl MainRuntimeInspectorCommand {
self.action
}
- pub(super) const fn route(self) -> RuntimeInspectorDispatchRoute {
- self.route
- }
-
pub(super) const fn payload_preparation(self) -> RuntimeInspectorPayloadPreparation {
self.payload_preparation
}
@@ -101,7 +88,6 @@ pub(super) enum MainRuntimeCommand {
impl MainRuntimeCommand {
pub(super) const fn classify(action: RuntimeAction) -> Self {
- use RuntimeInspectorDispatchRoute::{Direct, Interruptible};
use RuntimeInspectorPayloadPreparation::{
Passthrough, ValidateObjectOwner, ValidatePrototypeOwner,
};
@@ -117,22 +103,18 @@ impl MainRuntimeCommand {
RuntimeAction::CallFunctionOn => {
Self::DevToolsScript(RuntimeDevToolsScriptCommand::CallFunctionOn)
}
- RuntimeAction::TerminateExecution => Self::Inspector(MainRuntimeInspectorCommand::new(
- action,
- Interruptible,
- Passthrough,
- )),
+ RuntimeAction::TerminateExecution => {
+ Self::Inspector(MainRuntimeInspectorCommand::new(action, Passthrough))
+ }
RuntimeAction::GetProperties
| RuntimeAction::AwaitPromise
| RuntimeAction::GetExceptionDetails
| RuntimeAction::ReleaseObject => Self::Inspector(MainRuntimeInspectorCommand::new(
action,
- Direct,
ValidateObjectOwner,
)),
RuntimeAction::QueryObjects => Self::Inspector(MainRuntimeInspectorCommand::new(
action,
- Direct,
ValidatePrototypeOwner,
)),
RuntimeAction::CompileScript
@@ -143,9 +125,9 @@ impl MainRuntimeCommand {
| RuntimeAction::ReleaseObjectGroup
| RuntimeAction::SetAsyncCallStackDepth
| RuntimeAction::SetCustomObjectFormatterEnabled
- | RuntimeAction::SetMaxCallStackSizeToCapture => Self::Inspector(
- MainRuntimeInspectorCommand::new(action, Direct, Passthrough),
- ),
+ | RuntimeAction::SetMaxCallStackSizeToCapture => {
+ Self::Inspector(MainRuntimeInspectorCommand::new(action, Passthrough))
+ }
}
}
@@ -262,16 +244,13 @@ mod tests {
}
#[test]
- fn main_interruptible_and_owned_object_commands_have_explicit_preparation() {
+ fn main_owned_object_commands_have_explicit_preparation() {
let MainRuntimeCommand::Inspector(terminate) =
MainRuntimeCommand::classify(RuntimeAction::TerminateExecution)
else {
panic!("terminateExecution must be an Inspector command");
};
- assert_eq!(
- terminate.route(),
- RuntimeInspectorDispatchRoute::Interruptible
- );
+ assert_eq!(terminate.action(), RuntimeAction::TerminateExecution);
let MainRuntimeCommand::Inspector(get_properties) =
MainRuntimeCommand::classify(RuntimeAction::GetProperties)
diff --git a/moli-protocol/src/domains/runtime/dispatcher.rs b/moli-protocol/src/domains/runtime/dispatcher.rs
index 6eda9354d..1251740e0 100644
--- a/moli-protocol/src/domains/runtime/dispatcher.rs
+++ b/moli-protocol/src/domains/runtime/dispatcher.rs
@@ -81,8 +81,8 @@ use super::{
},
command_classification::{
MainRuntimeCommand, MainRuntimeInspectorCommand, RuntimeBindingCommand,
- RuntimeDevToolsScriptCommand, RuntimeInspectorDispatchRoute,
- RuntimeInspectorPayloadPreparation, WorkerRuntimeCommand, WorkerRuntimeCommandKind,
+ RuntimeDevToolsScriptCommand, RuntimeInspectorPayloadPreparation, WorkerRuntimeCommand,
+ WorkerRuntimeCommandKind,
},
evaluate::can_dispatch,
};
@@ -1030,12 +1030,8 @@ fn start_main_runtime_inspector_command(
));
}
};
- let pending = match start_pending_runtime_inspector_dispatch_with_route(
- conn,
- cmd,
- command.route(),
- inspector_json,
- ) {
+ let pending = match start_pending_runtime_routable_inspector_dispatch(conn, cmd, inspector_json)
+ {
Ok(pending) => pending,
Err(message) => {
forget_pre_registered_runtime_await(conn, pre_registered_await, cmd.session_id);
@@ -1225,8 +1221,8 @@ pub(crate) fn start_debugger_inspector_command_dispatch(
CdpRendererCommandAccess::MainThread => {
start_pending_runtime_inspector_dispatch(conn, cmd, inspector_json)
}
- CdpRendererCommandAccess::Interruptible => {
- start_pending_runtime_interrupt_inspector_dispatch(conn, cmd, inspector_json)
+ CdpRendererCommandAccess::Io => {
+ start_pending_runtime_io_inspector_dispatch(conn, cmd, inspector_json)
}
CdpRendererCommandAccess::OwnerIndependent => Err(
"an owner-independent command cannot enter the Debugger Inspector dispatcher"
@@ -1850,23 +1846,25 @@ fn try_start_pending_runtime_binding_command(
)))
}
-fn start_pending_runtime_inspector_dispatch_with_route(
+fn start_pending_runtime_routable_inspector_dispatch(
conn: &mut CdpConnection,
cmd: &Cmd<'_>,
- route: RuntimeInspectorDispatchRoute,
inspector_json: String,
) -> Result<PendingRuntimeProtocolMessageDispatch, String> {
- match route {
- RuntimeInspectorDispatchRoute::Interruptible => {
- start_pending_runtime_interrupt_inspector_dispatch(conn, cmd, inspector_json)
- }
- RuntimeInspectorDispatchRoute::Direct => {
+ match cmd.renderer_policy().access() {
+ CdpRendererCommandAccess::MainThread => {
start_pending_runtime_inspector_dispatch(conn, cmd, inspector_json)
}
+ CdpRendererCommandAccess::Io => {
+ start_pending_runtime_io_inspector_dispatch(conn, cmd, inspector_json)
+ }
+ CdpRendererCommandAccess::OwnerIndependent => Err(
+ "an owner-independent command cannot enter the Runtime Inspector dispatcher".to_owned(),
+ ),
}
}
-fn start_pending_runtime_interrupt_inspector_dispatch(
+fn start_pending_runtime_io_inspector_dispatch(
conn: &mut CdpConnection,
cmd: &Cmd<'_>,
inspector_json: String,
@@ -1874,16 +1872,13 @@ fn start_pending_runtime_interrupt_inspector_dispatch(
if let Some(command_id) = cmd.id {
let descriptor =
RendererCommandDescriptor::from_policy(inspector_json, cmd.renderer_policy());
- conn.start_runtime_interrupt_protocol_message_for_session_owner_with_deferred_response(
+ conn.start_runtime_io_protocol_message_for_session_owner_with_deferred_response(
cmd.session_id,
descriptor,
command_id,
)
} else {
- conn.start_runtime_interrupt_protocol_message_for_session_owner(
- cmd.session_id,
- inspector_json,
- )
+ conn.start_runtime_io_protocol_message_for_session_owner(cmd.session_id, inspector_json)
}
}
diff --git a/moli-renderer-v8/src/lib.rs b/moli-renderer-v8/src/lib.rs
index 0abecfad1..69c7d295f 100644
--- a/moli-renderer-v8/src/lib.rs
+++ b/moli-renderer-v8/src/lib.rs
@@ -280,7 +280,7 @@ pub use runtime::{
RendererResourceTextSearchOutcome, RendererRuntimeCommandCausalIdentity,
RendererRuntimeCommandOutput, RendererRuntimeEvaluationResult, RendererRuntimeHeapSpaceUsage,
RendererRuntimeHeapUsage, RendererRuntimeInspectorAsyncCompletion,
- RendererRuntimeInspectorCommandClaim, RendererRuntimeInspectorCommandRoute,
+ RendererRuntimeInspectorIoCommandClaim, RendererRuntimeInspectorIoCommandRoute,
RendererRuntimeInspectorMainCommandCompletion, RendererRuntimeInspectorMainCommandRoute,
RendererRuntimeInspectorMessage, RendererRuntimeInspectorMessageBatch,
RendererRuntimeInspectorProtocolMessage, RendererRuntimeInspectorProtocolMessageValueMut,
diff --git a/moli-renderer-v8/src/render_runtime.rs b/moli-renderer-v8/src/render_runtime.rs
index 0b8b05831..4c9f9a602 100644
--- a/moli-renderer-v8/src/render_runtime.rs
+++ b/moli-renderer-v8/src/render_runtime.rs
@@ -6,7 +6,9 @@ use tokio::runtime::LocalOptions;
use tokio::sync::{mpsc, oneshot};
use super::page_task_queue::RendererOwnerWake;
-use super::runtime::{RendererOwnerCommand, RendererOwnerHandle, RendererOwnerReply};
+use super::runtime::{
+ RendererOwnerCommand, RendererOwnerHandle, RendererOwnerReply, RendererPageCommand,
+};
use super::script_vm::inspector_io::RendererInspectorIoOwnerWake;
use super::script_vm::inspector_main::RendererInspectorMainOwnerWake;
use super::service_worker_runtime::ServiceWorkerRuntimeOwnerWake;
@@ -153,6 +155,23 @@ impl RenderRuntimeHandle {
command: RendererOwnerCommand,
) -> std::result::Result<oneshot::Receiver<Result<RendererOwnerReply>>, RenderRuntimeEnqueueError>
{
+ if matches!(
+ &command,
+ RendererOwnerCommand::RunAsyncPageCommand {
+ command: RendererPageCommand::Inspector(_),
+ ..
+ } | RendererOwnerCommand::RunProtocolPageCommand {
+ command: RendererPageCommand::Inspector(_),
+ ..
+ }
+ ) {
+ return Err(RenderRuntimeEnqueueError {
+ command: Box::new(command),
+ error: anyhow!(
+ "Inspector Page commands must enter through RendererPageHandle ingress"
+ ),
+ });
+ }
if moli_trace::cdp_nav_timing_enabled() {
let page_command = match &command {
RendererOwnerCommand::RunAsyncPageCommand { command, .. }
@@ -283,6 +302,28 @@ mod tests {
use super::*;
+ #[test]
+ fn raw_owner_admission_rejects_inspector_page_commands() {
+ let handle = RenderRuntimeHandle::disconnected();
+ let result = handle.enqueue(RendererOwnerCommand::RunProtocolPageCommand {
+ token: crate::runtime::RendererPageToken::new_for_testing(
+ crate::runtime::PageId::new_for_testing(1),
+ ),
+ command: RendererPageCommand::dispatch_runtime_protocol_message(
+ None,
+ r#"{"id":1,"method":"Runtime.getProperties","params":{"objectId":"1"}}"#.to_owned(),
+ ),
+ });
+ let error = match result {
+ Ok(_) => panic!("raw owner Inspector admission must be rejected"),
+ Err(error) => error,
+ };
+ assert_eq!(
+ error.to_string(),
+ "Inspector Page commands must enter through RendererPageHandle ingress"
+ );
+ }
+
#[test]
fn dropping_render_runtime_owner_closes_and_joins_render_thread() {
let render_exited = Arc::new(AtomicBool::new(false));
diff --git a/moli-renderer-v8/src/runtime/mod.rs b/moli-renderer-v8/src/runtime/mod.rs
index 6646dd41b..1a1737299 100644
--- a/moli-renderer-v8/src/runtime/mod.rs
+++ b/moli-renderer-v8/src/runtime/mod.rs
@@ -54,7 +54,6 @@ mod owner_local;
mod owner_local_store;
mod owner_maintenance;
mod page;
-mod page_command_residence;
mod page_commands;
mod page_context_cancel;
mod page_css;
@@ -363,8 +362,9 @@ pub use self::page_surface::{
RendererTouchPoint, RendererWindowDocumentSource, RuntimeConsoleMessageSnapshot,
};
pub(crate) use self::page_surface::{
- RendererCommandTurnOutputRecorder, RendererRuntimeCommandOutputRecorder,
- RendererRuntimeInspectorResponsePublication, RendererRuntimeObservableSourceQueue,
+ RendererCommandTurnOutputRecorder, RendererInspectorPauseCommandEffect,
+ RendererRuntimeCommandOutputRecorder, RendererRuntimeInspectorResponsePublication,
+ RendererRuntimeObservableSourceQueue,
};
pub(crate) use self::page_vm::PageVm;
use self::page_vm::PageVmDropTracker;
@@ -404,7 +404,7 @@ pub use self::protocol_output::{
pub use self::service_worker_run::RendererServiceWorkerRunIdentity;
pub(crate) use crate::renderer::PageVmInitStage;
pub use crate::script_vm::inspector_io::{
- RendererRuntimeInspectorCommandClaim, RendererRuntimeInspectorCommandRoute,
+ RendererRuntimeInspectorIoCommandClaim, RendererRuntimeInspectorIoCommandRoute,
};
pub use crate::script_vm::inspector_main::{
RendererRuntimeInspectorMainCommandCompletion, RendererRuntimeInspectorMainCommandRoute,
diff --git a/moli-renderer-v8/src/runtime/owner.rs b/moli-renderer-v8/src/runtime/owner.rs
index 259fec947..e2514c596 100644
--- a/moli-renderer-v8/src/runtime/owner.rs
+++ b/moli-renderer-v8/src/runtime/owner.rs
@@ -13,7 +13,6 @@ use super::owner_local_store::{
RendererPageCreationResolution, RendererPageLocalEntry, RendererPageLocalEntryCheckoutError,
RendererPageScheduledTurn, RendererPageToken, RendererPageTurnAdmission,
RendererPageTurnCheckoutError, RendererPendingPageCreation, RendererPreparedDocumentResidence,
- admit_page_command_first_dispatch_on_bound_owner_local_store,
advance_document_lifecycle_one_page_turn_via_local_task,
advance_dom_stable_wait_turn_on_entry_via_local_task,
advance_network_idle_wait_turn_on_entry_via_local_task,
@@ -30,7 +29,6 @@ use super::owner_local_store::{
claim_due_owner_maintenance_task_on_bound_owner_local_store,
commit_page_state_on_entry_via_local_task,
commit_page_state_on_entry_via_local_task_with_policy,
- complete_page_command_first_dispatch_on_bound_owner_local_store,
dispatch_async_command_on_entry_via_local_task,
finalize_pending_page_creation_on_bound_owner_local_store,
follow_pending_location_navigation_one_turn_on_entry_via_local_task,
@@ -380,17 +378,6 @@ pub(super) struct RenderRuntimePendingTurn {
command_admission_output_predecessor: Option<RendererOutputFence>,
}
-#[derive(Clone, Debug, Eq, PartialEq)]
-struct PageCommandFirstDispatchIdentity {
- token: RendererPageToken,
- lane: PageCommandFirstDispatchLane,
-}
-
-#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
-pub(super) struct PageCommandFirstDispatchLane {
- inspector_session: DevToolsSessionKey,
-}
-
impl RenderRuntimePendingTurn {
const fn is_page_owner_turn(&self) -> bool {
matches!(&self.turn, RenderRuntimeTurn::RunPageTurn { .. })
@@ -406,15 +393,6 @@ impl RenderRuntimePendingTurn {
const fn is_owner_maintenance_turn(&self) -> bool {
matches!(&self.turn, RenderRuntimeTurn::RunOwnerMaintenance { .. })
}
-
- pub(super) fn reject_page_command_admission(self, page_id: PageId) {
- if let Some(reply_tx) = self.reply_tx {
- let _ = reply_tx.send(Err(anyhow!(
- "renderer page {} was retired while a command waited for first dispatch",
- page_id.as_u64()
- )));
- }
- }
}
#[derive(Default)]
@@ -685,36 +663,6 @@ impl RenderRuntimeTurn {
)
}
- fn live_page_command_first_dispatch_identity(
- &self,
- ) -> Option<PageCommandFirstDispatchIdentity> {
- match self {
- Self::RunLivePageCommand { token, command, .. } => {
- if command.uses_main_inspector_ingress_admission() {
- return None;
- }
- command.inspector_ticket().map(|ticket| {
- debug_assert_eq!(
- ticket.route(),
- RendererInspectorCommandRoute::MainThread,
- "IO Inspector commands must bypass owner admission",
- );
- debug_assert_eq!(
- command.inspector_first_dispatch_lifecycle(),
- Some(RendererInspectorFirstDispatchLifecycle::OrderedUntilFirstDispatch,),
- );
- PageCommandFirstDispatchIdentity {
- token: *token,
- lane: PageCommandFirstDispatchLane {
- inspector_session: ticket.session().clone(),
- },
- }
- })
- }
- _ => None,
- }
- }
-
/// Return the Page whose committed view this host-facing command needs.
///
/// A same-Page cross-document navigation installs its replacement PageVm
@@ -873,26 +821,6 @@ fn owner_command_timing_label(command: &RendererOwnerCommand) -> Option<&'static
}
}
-impl RenderRuntimeDispatchOutcome {
- fn deferred_live_page_command_first_dispatch_identity(
- &self,
- ) -> Option<PageCommandFirstDispatchIdentity> {
- match self {
- Self::ContinueNextTurn(turn)
- | Self::ContinueAfterPageWakeOrDeadline { turn, .. }
- | Self::ContinueAfterPageWake { turn, .. }
- | Self::ContinueCommittedDocumentParserAfterPageWake { turn, .. } => {
- turn.live_page_command_first_dispatch_identity()
- }
- Self::Reply(_)
- | Self::InspectorMainCommandClaimed { .. }
- | Self::PageCreatedAndContinueNavigation { .. }
- | Self::BackgroundComplete(_)
- | Self::PageCreationNavigationFailurePublished { .. } => None,
- }
- }
-}
-
impl From<Result<RendererOwnerReply>> for RenderRuntimeDispatchOutcome {
fn from(value: Result<RendererOwnerReply>) -> Self {
Self::Reply(Box::new(value))
@@ -2497,40 +2425,6 @@ impl RendererOwnerHandle {
}
}
- /// The stable Page slot owns each MainThread Inspector session's arrival
- /// order. IO commands use their physically separate ingress and never
- /// enter this owner admission structure. Only the command that owns the
- /// session lane enters the owner-wide runnable queue; other sessions and
- /// non-Inspector Page commands remain independent.
- fn admit_page_command_first_dispatch(
- turn: RenderRuntimePendingTurn,
- pending_turns: &mut RenderRuntimePendingTurnQueue,
- ) {
- let Some(identity) = turn.turn.live_page_command_first_dispatch_identity() else {
- pending_turns.push_back(turn);
- return;
- };
- if let Some(admitted) = admit_page_command_first_dispatch_on_bound_owner_local_store(
- identity.token,
- identity.lane,
- turn,
- ) {
- pending_turns.push_back(admitted);
- }
- }
-
- fn complete_page_command_first_dispatch(
- identity: &PageCommandFirstDispatchIdentity,
- pending_turns: &mut RenderRuntimePendingTurnQueue,
- ) {
- if let Some(next) = complete_page_command_first_dispatch_on_bound_owner_local_store(
- identity.token,
- &identity.lane,
- ) {
- pending_turns.push_back(next);
- }
- }
-
fn enqueue_inspector_main_receiver_wake(
wake: RendererInspectorMainOwnerWake,
pending_turns: &mut RenderRuntimePendingTurnQueue,
@@ -2655,19 +2549,10 @@ impl RendererOwnerHandle {
.as_ref()
.is_some_and(|tx| tx.is_closed())
{
- let first_dispatch_identity = pending_turn
- .turn
- .live_page_command_first_dispatch_identity();
self.detach_navigation_or_cancel_pending_turn(
pending_turn.turn,
&mut pending_turns,
);
- if let Some(identity) = first_dispatch_identity.as_ref() {
- Self::complete_page_command_first_dispatch(
- identity,
- &mut pending_turns,
- );
- }
continue;
}
if let Some(token) = pending_turn.turn.committed_page_view_command_token()
@@ -2728,14 +2613,9 @@ impl RendererOwnerHandle {
continue;
}
let completed_page_turn_token = pending_turn.page_owner_token();
- let first_dispatch_identity = pending_turn
- .turn
- .live_page_command_first_dispatch_identity();
let outcome = self
.run_pending_turn_on_owner_local_store(pending_turn.turn)
.await;
- let deferred_first_dispatch_identity =
- outcome.deferred_live_page_command_first_dispatch_identity();
match outcome {
RenderRuntimeDispatchOutcome::Reply(result) => {
let result = merge_command_admission_output_predecessor(
@@ -2933,11 +2813,6 @@ impl RendererOwnerHandle {
&mut pending_turns,
);
}
- if let Some(identity) = first_dispatch_identity.as_ref()
- && deferred_first_dispatch_identity.as_ref() != Some(identity)
- {
- Self::complete_page_command_first_dispatch(identity, &mut pending_turns);
- }
continue;
}
@@ -3156,21 +3031,18 @@ impl RendererOwnerHandle {
if reply_tx.is_closed() {
self.detach_navigation_or_cancel_pending_turn(*turn, pending_turns);
} else {
- Self::admit_page_command_first_dispatch(
- RenderRuntimePendingTurn {
- reply_tx: Some(reply_tx),
- turn: *turn,
- // This is the command's first owner turn, not a
- // continuation returning to the queue. Run it before
- // admitting another envelope so a Page wake produced
- // by the command cannot inherit an already-pending
- // command and then yield to a second one.
- allow_command_overtake: false,
- command_admission_output_predecessor:
- command_admission_output_predecessor.take(),
- },
- pending_turns,
- );
+ pending_turns.push_back(RenderRuntimePendingTurn {
+ reply_tx: Some(reply_tx),
+ turn: *turn,
+ // This is the command's first owner turn, not a
+ // continuation returning to the queue. Run it before
+ // admitting another envelope so a Page wake produced
+ // by the command cannot inherit an already-pending
+ // command and then yield to a second one.
+ allow_command_overtake: false,
+ command_admission_output_predecessor: command_admission_output_predecessor
+ .take(),
+ });
}
}
RenderRuntimeDispatchOutcome::ContinueAfterPageWakeOrDeadline {
@@ -3425,11 +3297,7 @@ impl RendererOwnerHandle {
pending_turns: &mut RenderRuntimePendingTurnQueue,
) {
if reply_tx.as_ref().is_some_and(|tx| tx.is_closed()) {
- let first_dispatch_identity = turn.live_page_command_first_dispatch_identity();
self.detach_navigation_or_cancel_pending_turn(turn, pending_turns);
- if let Some(identity) = first_dispatch_identity.as_ref() {
- Self::complete_page_command_first_dispatch(identity, pending_turns);
- }
return;
}
parked_turns.push_back(RenderRuntimeParkedTurn {
@@ -3854,12 +3722,7 @@ impl RendererOwnerHandle {
.as_ref()
.is_some_and(|tx| tx.is_closed())
{
- let first_dispatch_identity =
- parked_turn.turn.live_page_command_first_dispatch_identity();
self.detach_navigation_or_cancel_pending_turn(parked_turn.turn, pending_turns);
- if let Some(identity) = first_dispatch_identity.as_ref() {
- Self::complete_page_command_first_dispatch(identity, pending_turns);
- }
None
} else {
let allow_command_overtake = parked_turn.condition.allows_command_overtake();
@@ -7195,84 +7058,6 @@ mod tests {
);
}
- #[test]
- fn first_dispatch_identity_uses_the_exact_main_thread_inspector_session() {
- let token = RendererPageToken::new_for_testing(PageId::new_for_testing(8));
- let attached = RenderRuntimeTurn::RunLivePageCommand {
- token,
- command: RendererPageCommand::dispatch_runtime_protocol_message(
- Some("SID-aux".to_owned()),
- RendererInspectorCommandRoute::MainThread,
- r#"{"id":1,"method":"Runtime.evaluate","params":{"expression":"1"}}"#.to_owned(),
- ),
- capture_policy: RendererPageStateCapturePolicy::ProtocolTurn,
- };
- assert_eq!(
- attached.live_page_command_first_dispatch_identity(),
- Some(PageCommandFirstDispatchIdentity {
- token,
- lane: PageCommandFirstDispatchLane {
- inspector_session: DevToolsSessionKey::Attached("SID-aux".to_owned()),
- },
- })
- );
-
- let primary = RenderRuntimeTurn::RunLivePageCommand {
- token,
- command: RendererPageCommand::dispatch_runtime_protocol_message(
- None,
- RendererInspectorCommandRoute::MainThread,
- r#"{"id":2,"method":"Runtime.evaluate","params":{"expression":"2"}}"#.to_owned(),
- ),
- capture_policy: RendererPageStateCapturePolicy::ProtocolTurn,
- };
- assert_eq!(
- primary.live_page_command_first_dispatch_identity(),
- Some(PageCommandFirstDispatchIdentity {
- token,
- lane: PageCommandFirstDispatchLane {
- inspector_session: DevToolsSessionKey::Primary,
- },
- })
- );
-
- let ordinary_page_command = RenderRuntimeTurn::RunLivePageCommand {
- token,
- command: RendererPageCommand::PageDiagnosticsSnapshot,
- capture_policy: RendererPageStateCapturePolicy::ProtocolTurn,
- };
- assert_eq!(
- ordinary_page_command.live_page_command_first_dispatch_identity(),
- None,
- "non-Inspector Page commands must not join an unrelated session lane"
- );
- }
-
- #[test]
- fn special_inspector_commands_join_raw_commands_at_the_structural_boundary() {
- let token = RendererPageToken::new_for_testing(PageId::new_for_testing(9));
- let turn_for = |command| RenderRuntimeTurn::RunLivePageCommand {
- token,
- command,
- capture_policy: RendererPageStateCapturePolicy::ProtocolTurn,
- };
- let enable = turn_for(RendererPageCommand::runtime_enable_events(Some(
- "SID-shared-lane".to_owned(),
- )));
- let raw_main = turn_for(RendererPageCommand::dispatch_runtime_protocol_message(
- Some("SID-shared-lane".to_owned()),
- RendererInspectorCommandRoute::MainThread,
- r#"{"id":1,"method":"Runtime.disable"}"#.to_owned(),
- ));
- let enable_identity = enable
- .live_page_command_first_dispatch_identity()
- .expect("Runtime.enable must enter the Inspector boundary");
- let main_identity = raw_main
- .live_page_command_first_dispatch_identity()
- .expect("raw main-thread dispatch must enter the Inspector boundary");
- assert_eq!(enable_identity, main_identity);
- }
-
#[test]
fn replacement_view_waiter_ignores_generic_activity_and_wrong_document_settlement() {
let condition = RenderRuntimeParkCondition::ReplacementDocumentViewSettlement {
diff --git a/moli-renderer-v8/src/runtime/owner_local.rs b/moli-renderer-v8/src/runtime/owner_local.rs
index 2b9d96926..63212a096 100644
--- a/moli-renderer-v8/src/runtime/owner_local.rs
+++ b/moli-renderer-v8/src/runtime/owner_local.rs
@@ -178,7 +178,7 @@ impl RendererPageHandle {
pub fn enqueue_runtime_inspector_io_command(
&self,
envelope: RendererInspectorCommandEnvelope,
- ) -> RendererRuntimeInspectorCommandRoute {
+ ) -> RendererRuntimeInspectorIoCommandRoute {
self.inspector_io_ingress
.enqueue_command(self.devtools_agent_token, envelope)
}
diff --git a/moli-renderer-v8/src/runtime/owner_local_store.rs b/moli-renderer-v8/src/runtime/owner_local_store.rs
index 58ac1b300..c17021bad 100644
--- a/moli-renderer-v8/src/runtime/owner_local_store.rs
+++ b/moli-renderer-v8/src/runtime/owner_local_store.rs
@@ -17,15 +17,12 @@ use super::navigation::{
PageCreationNavigationFailurePublisher, PageCreationResolution, PageCreationRetirement,
PageNavigationOwnerFailure, page_creation_navigation_failure_scope,
};
-use super::owner::{
- PageCommandFirstDispatchLane, RenderRuntimePendingTurn, RendererCreateStreamingRawPageRequest,
-};
+use super::owner::RendererCreateStreamingRawPageRequest;
use super::owner_deadline_index::OwnerDeadlineIndex;
use super::owner_local::RendererAttachedPage;
use super::owner_maintenance::{
RendererOwnerMaintenanceTask, RendererPageOwnerMaintenanceResidence,
};
-use super::page_command_residence::PageCommandFirstDispatchResidence;
use super::page_entry_residence::{RendererPageEntryCheckout, RendererPageEntryRestore};
use super::page_turn_scheduler::{
DocumentLifecycleClassReadiness, PageTurnAdmission, PageTurnClass, PageTurnScheduler,
@@ -656,8 +653,6 @@ impl RendererPageScriptEnvironmentPin {
struct RendererOwnerLocalPageSlot {
owner_slot: RendererPageSlotHandle,
turn_scheduler: PageTurnScheduler<RendererPageLocalEntry>,
- page_command_first_dispatch:
- PageCommandFirstDispatchResidence<PageCommandFirstDispatchLane, RenderRuntimePendingTurn>,
owner_maintenance: RendererPageOwnerMaintenanceResidence,
task_sources: RendererPageOwnedTaskSources,
lifecycle_gate: Option<LifecycleGate>,
@@ -677,7 +672,6 @@ impl RendererOwnerLocalPageSlot {
Self {
owner_slot,
turn_scheduler: PageTurnScheduler::new(entry),
- page_command_first_dispatch: PageCommandFirstDispatchResidence::default(),
owner_maintenance: RendererPageOwnerMaintenanceResidence::new(std::time::Instant::now()),
task_sources,
lifecycle_gate: lifecycle_gate.map(LifecycleGate::new),
@@ -738,9 +732,6 @@ impl Drop for RendererOwnerLocalPageSlot {
// This is the stable Page lifetime boundary. A replacement PageVm
// drops only Document-owned queues; retiring the slot also discards
// V8 foreground work and typed Page source payloads.
- for waiting in self.page_command_first_dispatch.drain_waiting() {
- waiting.reject_page_command_admission(self.owner_slot.page_id());
- }
self.task_sources.clear();
self.script_environment_pin
.environment
@@ -1560,29 +1551,6 @@ pub(super) fn take_entry_for_command_on_bound_owner_local_store(
})
}
-pub(super) fn admit_page_command_first_dispatch_on_bound_owner_local_store(
- token: RendererPageToken,
- lane: PageCommandFirstDispatchLane,
- turn: RenderRuntimePendingTurn,
-) -> Option<RenderRuntimePendingTurn> {
- with_bound_render_runtime_owner_local_store_session(|session| {
- session
- .store
- .admit_page_command_first_dispatch(token, lane, turn)
- })
-}
-
-pub(super) fn complete_page_command_first_dispatch_on_bound_owner_local_store(
- token: RendererPageToken,
- lane: &PageCommandFirstDispatchLane,
-) -> Option<RenderRuntimePendingTurn> {
- with_bound_render_runtime_owner_local_store_session(|session| {
- session
- .store
- .complete_page_command_first_dispatch(token, lane)
- })
-}
-
pub(super) fn checkout_entry_for_owner_turn_on_bound_owner_local_store(
token: RendererPageToken,
) -> RendererPageLocalEntryCheckout {
@@ -2907,35 +2875,6 @@ impl RendererOwnerLocalStore {
.and_then(RendererPageLocalEntry::uncommitted_page_vm_creation_id)
}
- fn admit_page_command_first_dispatch(
- &mut self,
- token: RendererPageToken,
- lane: PageCommandFirstDispatchLane,
- turn: RenderRuntimePendingTurn,
- ) -> Option<RenderRuntimePendingTurn> {
- let Some(page_slot) = self
- .page_hosts
- .get_mut(&token.local_host_id)
- .and_then(|host| host.pages.get_mut(&token.page_id))
- else {
- // Let the command run once so the ordinary stale-Page error path
- // remains responsible for its protocol reply.
- return Some(turn);
- };
- page_slot.page_command_first_dispatch.admit(lane, turn)
- }
-
- fn complete_page_command_first_dispatch(
- &mut self,
- token: RendererPageToken,
- lane: &PageCommandFirstDispatchLane,
- ) -> Option<RenderRuntimePendingTurn> {
- self.page_hosts
- .get_mut(&token.local_host_id)
- .and_then(|host| host.pages.get_mut(&token.page_id))
- .and_then(|slot| slot.page_command_first_dispatch.complete(lane))
- }
-
fn checkout_entry_for_owner_turn(
&mut self,
token: RendererPageToken,
diff --git a/moli-renderer-v8/src/runtime/page_command_residence.rs b/moli-renderer-v8/src/runtime/page_command_residence.rs
deleted file mode 100644
index 699ab33cb..000000000
--- a/moli-renderer-v8/src/runtime/page_command_residence.rs
+++ /dev/null
@@ -1,139 +0,0 @@
-//! Stable per-Page admission state for renderer Inspector commands.
-//!
-//! A Page entry is temporarily checked out while an owner turn runs, so
-//! Inspector-session ordering cannot live in `RendererPageLocalEntry`. This
-//! residence stays in the stable Page slot and admits each `(session, route)`
-//! stream in arrival order until commands reach their first V8 dispatch.
-//! Independent sessions and Chromium-style main-thread/IO routes on the same
-//! Page have independent lanes.
-
-use std::collections::{BTreeMap, VecDeque};
-
-pub(super) struct PageCommandFirstDispatchResidence<Key, Command> {
- /// Presence of a lane is the stable marker for its active command, which
- /// has already moved to the renderer owner. The deque retains only later
- /// same-lane commands.
- lanes: BTreeMap<Key, VecDeque<Command>>,
-}
-
-impl<Key, Command> std::fmt::Debug for PageCommandFirstDispatchResidence<Key, Command> {
- fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- formatter
- .debug_struct("PageCommandFirstDispatchResidence")
- .field("active_session_count", &self.lanes.len())
- .field(
- "waiting_count",
- &self.lanes.values().map(VecDeque::len).sum::<usize>(),
- )
- .finish()
- }
-}
-
-impl<Key, Command> Default for PageCommandFirstDispatchResidence<Key, Command> {
- fn default() -> Self {
- Self {
- lanes: BTreeMap::new(),
- }
- }
-}
-
-impl<Key: Ord, Command> PageCommandFirstDispatchResidence<Key, Command> {
- /// Returns the command when it owns its lane's active dispatch slot. A
- /// `None` result means the Page residence retained it behind a predecessor
- /// from the same lane.
- pub(super) fn admit(&mut self, key: Key, command: Command) -> Option<Command> {
- match self.lanes.entry(key) {
- std::collections::btree_map::Entry::Vacant(entry) => {
- entry.insert(VecDeque::new());
- Some(command)
- }
- std::collections::btree_map::Entry::Occupied(mut entry) => {
- entry.get_mut().push_back(command);
- None
- }
- }
- }
-
- /// Releases one lane's active command and returns its next FIFO waiter,
- /// which inherits the lane without an intermediate idle state.
- pub(super) fn complete(&mut self, key: &Key) -> Option<Command> {
- debug_assert!(
- self.lanes.contains_key(key),
- "an Inspector session dispatch lane must be active"
- );
- let waiting = self.lanes.get_mut(key)?;
- if let Some(next) = waiting.pop_front() {
- return Some(next);
- }
- self.lanes.remove(key);
- None
- }
-
- pub(super) fn drain_waiting(&mut self) -> Vec<Command> {
- std::mem::take(&mut self.lanes)
- .into_values()
- .flatten()
- .collect()
- }
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- type Lane = &'static str;
-
- #[test]
- fn each_main_thread_inspector_session_owns_an_independent_fifo_dispatch_lane() {
- let mut first_page = PageCommandFirstDispatchResidence::default();
- let mut other_page = PageCommandFirstDispatchResidence::default();
- let session_a: Lane = "session-a";
- let session_b: Lane = "session-b";
-
- assert_eq!(
- first_page.admit(session_a, "a-main-first"),
- Some("a-main-first")
- );
- assert_eq!(first_page.admit(session_a, "a-main-second"), None);
- assert_eq!(
- first_page.admit(session_b, "b-first"),
- Some("b-first"),
- "a parked command must not block a different Inspector session"
- );
- assert_eq!(first_page.admit(session_b, "b-second"), None);
-
- assert_eq!(other_page.admit(session_a, "other"), Some("other"));
- assert_eq!(other_page.complete(&session_a), None);
-
- assert_eq!(first_page.complete(&session_b), Some("b-second"));
- assert_eq!(first_page.complete(&session_b), None);
- assert_eq!(first_page.complete(&session_a), Some("a-main-second"));
- assert_eq!(first_page.complete(&session_a), None);
-
- assert_eq!(
- first_page.admit(session_a, "a-after-idle"),
- Some("a-after-idle")
- );
- }
-
- #[test]
- fn retiring_a_page_drains_waiters_and_resets_every_lane() {
- let mut residence = PageCommandFirstDispatchResidence::default();
- let main: Lane = "session-a";
- let other: Lane = "session-b";
-
- assert_eq!(residence.admit(main, "main-active"), Some("main-active"));
- assert_eq!(residence.admit(main, "main-waiting"), None);
- assert_eq!(residence.admit(other, "other-active"), Some("other-active"));
- assert_eq!(residence.admit(other, "other-waiting"), None);
-
- let mut drained = residence.drain_waiting();
- drained.sort_unstable();
- assert_eq!(drained, ["main-waiting", "other-waiting"]);
- assert_eq!(
- residence.admit(main, "main-after-retirement"),
- Some("main-after-retirement"),
- "retirement must not leave a stale active-lane marker"
- );
- }
-}
diff --git a/moli-renderer-v8/src/runtime/page_surface.rs b/moli-renderer-v8/src/runtime/page_surface.rs
index 9c36cba1b..87c6b5739 100644
--- a/moli-renderer-v8/src/runtime/page_surface.rs
+++ b/moli-renderer-v8/src/runtime/page_surface.rs
@@ -3548,6 +3548,41 @@ pub enum RendererInspectorFirstDispatchLifecycle {
OrderedUntilFirstDispatch,
}
+/// Pause-loop transition owned by an Inspector command. This is derived once
+/// when the ingress envelope is created so executors do not need to reparse
+/// protocol JSON to decide how resumed/paused notifications are attributed.
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+pub(crate) enum RendererInspectorPauseCommandEffect {
+ None,
+ Resume,
+ Step,
+}
+
+impl RendererInspectorPauseCommandEffect {
+ fn from_message(message: Option<&Value>) -> Self {
+ match message
+ .and_then(|message| message.get("method"))
+ .and_then(Value::as_str)
+ {
+ Some("Debugger.resume") => Self::Resume,
+ Some(
+ "Debugger.continueToLocation"
+ | "Debugger.restartFrame"
+ | "Debugger.stepInto"
+ | "Debugger.stepOut"
+ | "Debugger.stepOver",
+ ) => Self::Step,
+ _ => Self::None,
+ }
+ }
+}
+
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+enum RendererInspectorMainDispatchBoundary {
+ InspectorSession,
+ PageOwner,
+}
+
static NEXT_RENDERER_INSPECTOR_INGRESS_SEQUENCE: AtomicU64 = AtomicU64::new(1);
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -3615,6 +3650,8 @@ impl RendererInspectorIngressTicket {
pub struct RendererInspectorCommandEnvelope {
ticket: RendererInspectorIngressTicket,
first_dispatch: RendererInspectorFirstDispatchLifecycle,
+ pause_effect: RendererInspectorPauseCommandEffect,
+ main_dispatch_boundary: RendererInspectorMainDispatchBoundary,
payload: RendererInspectorCommandPayload,
main_ingress_first_dispatch:
Option<crate::script_vm::inspector_main::RendererInspectorMainFirstDispatchGuard>,
@@ -3629,19 +3666,16 @@ enum RendererInspectorCommandPayload {
}
impl RendererInspectorCommandEnvelope {
- fn new(
- inspector_session_id: Option<String>,
- route: RendererInspectorCommandRoute,
- command: RendererInspectorPageCommand,
- ) -> Self {
- assert_eq!(
- route,
- RendererInspectorCommandRoute::MainThread,
- "a Page-owned Inspector payload must use the MainThread route"
- );
+ fn new(inspector_session_id: Option<String>, command: RendererInspectorPageCommand) -> Self {
Self {
- ticket: RendererInspectorIngressTicket::new(None, inspector_session_id, route),
+ ticket: RendererInspectorIngressTicket::new(
+ None,
+ inspector_session_id,
+ RendererInspectorCommandRoute::MainThread,
+ ),
first_dispatch: RendererInspectorFirstDispatchLifecycle::OrderedUntilFirstDispatch,
+ pause_effect: RendererInspectorPauseCommandEffect::None,
+ main_dispatch_boundary: RendererInspectorMainDispatchBoundary::PageOwner,
payload: RendererInspectorCommandPayload::MainThread(command),
main_ingress_first_dispatch: None,
}
@@ -3659,6 +3693,15 @@ impl RendererInspectorCommandEnvelope {
RendererInspectorCommandRoute::MainThread,
"a Main Inspector protocol payload must use the MainThread route"
);
+ let message = serde_json::from_str::<Value>(&raw_json).ok();
+ let main_dispatch_boundary = if main_protocol_can_dispatch_at_inspector_session_boundary(
+ owner_context_resolution_action.as_deref(),
+ message.as_ref(),
+ ) {
+ RendererInspectorMainDispatchBoundary::InspectorSession
+ } else {
+ RendererInspectorMainDispatchBoundary::PageOwner
+ };
let command = match owner_context_resolution_action {
Some(action) => RendererInspectorPageCommand::DispatchRuntimeProtocolMessageWithContextResolutionAndDeferredResponse {
action,
@@ -3673,6 +3716,8 @@ impl RendererInspectorCommandEnvelope {
Self {
ticket,
first_dispatch: RendererInspectorFirstDispatchLifecycle::OrderedUntilFirstDispatch,
+ pause_effect: RendererInspectorPauseCommandEffect::from_message(message.as_ref()),
+ main_dispatch_boundary,
payload: RendererInspectorCommandPayload::MainThread(command),
main_ingress_first_dispatch: None,
}
@@ -3689,9 +3734,12 @@ impl RendererInspectorCommandEnvelope {
RendererInspectorCommandRoute::Io,
"an Inspector IO payload must use the IO route"
);
+ let message = serde_json::from_str::<Value>(&raw_json).ok();
Self {
ticket,
first_dispatch: RendererInspectorFirstDispatchLifecycle::OrderedUntilFirstDispatch,
+ pause_effect: RendererInspectorPauseCommandEffect::from_message(message.as_ref()),
+ main_dispatch_boundary: RendererInspectorMainDispatchBoundary::InspectorSession,
payload: RendererInspectorCommandPayload::Io { raw_json, response },
main_ingress_first_dispatch: None,
}
@@ -3705,6 +3753,14 @@ impl RendererInspectorCommandEnvelope {
self.first_dispatch
}
+ pub(crate) fn pause_effect(&self) -> RendererInspectorPauseCommandEffect {
+ self.pause_effect
+ }
+
+ pub(crate) fn can_dispatch_at_nested_inspector_session_boundary(&self) -> bool {
+ self.main_dispatch_boundary == RendererInspectorMainDispatchBoundary::InspectorSession
+ }
+
fn bind_attachment(&mut self, attachment: RendererAgentAttachmentId) {
self.ticket.bind_attachment(attachment);
}
@@ -3732,10 +3788,6 @@ impl RendererInspectorCommandEnvelope {
self.main_ingress_first_dispatch = Some(first_dispatch);
}
- pub(crate) fn uses_main_ingress_admission(&self) -> bool {
- self.main_ingress_first_dispatch.is_some()
- }
-
fn main_thread_payload(&self) -> &RendererInspectorPageCommand {
let RendererInspectorCommandPayload::MainThread(command) = &self.payload else {
panic!("an Inspector IO envelope cannot enter Page owner dispatch");
@@ -3754,6 +3806,7 @@ impl RendererInspectorCommandEnvelope {
)
}
+ #[cfg(test)]
pub(crate) fn main_protocol_raw_json(&self) -> &str {
match self.main_thread_payload() {
RendererInspectorPageCommand::DispatchRuntimeProtocolMessageWithDeferredResponse {
@@ -3793,6 +3846,11 @@ impl RendererInspectorCommandEnvelope {
self.main_ingress_first_dispatch.is_none(),
"a direct nested Main dispatch must keep its first-dispatch guard outside the envelope"
);
+ assert_eq!(
+ self.main_dispatch_boundary,
+ RendererInspectorMainDispatchBoundary::InspectorSession,
+ "a Page-owner-dependent Main command cannot enter direct nested Inspector dispatch"
+ );
match self.payload {
RendererInspectorCommandPayload::MainThread(
RendererInspectorPageCommand::DispatchRuntimeProtocolMessageWithDeferredResponse {
@@ -3897,6 +3955,61 @@ impl RendererInspectorCommandEnvelope {
}
}
+fn main_protocol_can_dispatch_at_inspector_session_boundary(
+ owner_context_resolution_action: Option<&str>,
+ message: Option<&Value>,
+) -> bool {
+ let Some(message) = message else {
+ return false;
+ };
+ let method = message.get("method").and_then(Value::as_str);
+ let params = message.get("params").and_then(Value::as_object);
+
+ // These transitions have renderer-owned restore state and must therefore
+ // pass through PageVm even though their final sink is V8InspectorSession.
+ if matches!(
+ method,
+ Some("Runtime.enable" | "Runtime.disable" | "Console.enable" | "Console.disable")
+ ) {
+ return false;
+ }
+
+ let has_owner_scoped_runtime_semantics = params.is_some_and(|params| {
+ params.get("userGesture").and_then(Value::as_bool) == Some(true)
+ || params.contains_key(crate::script_vm::WEBDRIVER_BIDI_FILE_PROMPT_HANDLER_PARAM)
+ });
+ if has_owner_scoped_runtime_semantics {
+ return false;
+ }
+
+ if matches!(method, Some("Runtime.compileScript"))
+ && params.is_some_and(|params| {
+ params.contains_key("contextId") || params.contains_key("executionContextId")
+ })
+ || matches!(method, Some("Runtime.runScript"))
+ && params.is_some_and(|params| params.contains_key("executionContextId"))
+ {
+ return false;
+ }
+
+ match owner_context_resolution_action {
+ // A default-world evaluate needs no renderer context-id rewrite. It is
+ // the useful Chromium-style nested Main case while JavaScript is
+ // paused. Explicit context targeting remains an owner operation.
+ Some("evaluate") => !params.is_some_and(|params| {
+ params.contains_key("contextId") || params.contains_key("executionContextId")
+ }),
+ // An object/unique-context target is already complete. A missing or
+ // numeric executionContextId requires PageVm to choose/rewrite it.
+ Some("callFunctionOn") => params.is_some_and(|params| {
+ !params.contains_key("executionContextId")
+ && (params.contains_key("objectId") || params.contains_key("uniqueContextId"))
+ }),
+ Some(_) => false,
+ None => true,
+ }
+}
+
pub(crate) enum RendererInspectorPageCommand {
DispatchRuntimeProtocolMessage {
raw_json: String,
@@ -4520,42 +4633,31 @@ impl RendererPageCommand {
fn inspector_command(
inspector_session_id: Option<String>,
- route: RendererInspectorCommandRoute,
command: RendererInspectorPageCommand,
) -> Self {
- assert_eq!(
- route,
- RendererInspectorCommandRoute::MainThread,
- "IO Inspector commands must enter RendererInspectorIoIngress"
- );
Self::Inspector(RendererInspectorCommandEnvelope::new(
inspector_session_id,
- route,
command,
))
}
pub fn dispatch_runtime_protocol_message(
inspector_session_id: Option<String>,
- route: RendererInspectorCommandRoute,
raw_json: String,
) -> Self {
Self::inspector_command(
inspector_session_id,
- route,
RendererInspectorPageCommand::DispatchRuntimeProtocolMessage { raw_json },
)
}
pub fn dispatch_runtime_protocol_message_with_deferred_response(
inspector_session_id: Option<String>,
- route: RendererInspectorCommandRoute,
raw_json: String,
deferred_response: RendererRuntimeInspectorResponseSender,
) -> Self {
Self::inspector_command(
inspector_session_id,
- route,
RendererInspectorPageCommand::DispatchRuntimeProtocolMessageWithDeferredResponse {
raw_json,
deferred_response,
@@ -4565,13 +4667,11 @@ impl RendererPageCommand {
pub fn dispatch_runtime_protocol_message_with_context_resolution(
inspector_session_id: Option<String>,
- route: RendererInspectorCommandRoute,
action: String,
raw_json: String,
) -> Self {
Self::inspector_command(
inspector_session_id,
- route,
RendererInspectorPageCommand::DispatchRuntimeProtocolMessageWithContextResolution {
action,
raw_json,
@@ -4581,14 +4681,12 @@ impl RendererPageCommand {
pub fn dispatch_runtime_protocol_message_with_context_resolution_and_deferred_response(
inspector_session_id: Option<String>,
- route: RendererInspectorCommandRoute,
action: String,
raw_json: String,
deferred_response: RendererRuntimeInspectorResponseSender,
) -> Self {
Self::inspector_command(
inspector_session_id,
- route,
RendererInspectorPageCommand::DispatchRuntimeProtocolMessageWithContextResolutionAndDeferredResponse {
action,
raw_json,
@@ -4600,7 +4698,6 @@ impl RendererPageCommand {
pub fn runtime_enable_events(inspector_session_id: Option<String>) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::RuntimeEnableEvents,
)
}
@@ -4614,7 +4711,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::ApplyRuntimeProtocolState {
session_restore_snapshots,
isolated_worlds,
@@ -4630,7 +4726,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::DetachRuntimeInspectorSession { pause_guard },
)
}
@@ -4643,7 +4738,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::AddRuntimeBinding {
name,
execution_context_name,
@@ -4660,7 +4754,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::DomDebuggerGetEventListeners {
object_id,
depth,
@@ -4675,7 +4768,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::ComputedStylePropertiesForObjectId { object_id },
)
}
@@ -4687,7 +4779,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::ScrollObjectNodeIntoViewIfNeeded { object_id, rect },
)
}
@@ -4698,7 +4789,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::ClientRectForObjectId { object_id },
)
}
@@ -4709,7 +4799,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::DocumentGeometryForObjectId { object_id },
)
}
@@ -4720,7 +4809,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::NodeHasGeometryForObjectId { object_id },
)
}
@@ -4731,7 +4819,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::FocusDocumentNodeForObjectId { object_id },
)
}
@@ -4744,7 +4831,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::SetFileInputFilesForObjectId {
object_id,
files,
@@ -4762,7 +4848,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::DocumentNodeSnapshotForObjectId {
include_whitespace,
object_id,
@@ -4778,7 +4863,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::AccessibilityTreePayloadsForObjectId { object_id },
)
}
@@ -4789,7 +4873,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::AccessibilityNodeAndAncestorPayloadsForObjectId {
object_id,
},
@@ -4803,7 +4886,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::AccessibilityPartialTreePayloadsForObjectId {
object_id,
fetch_relatives,
@@ -4818,7 +4900,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::OuterHtmlForObjectId {
object_id,
include_shadow_dom,
@@ -4834,7 +4915,6 @@ impl RendererPageCommand {
) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::ResolveRuntimeObjectForBackendNodeId {
backend_node_id,
execution_context_id,
@@ -4846,21 +4926,22 @@ impl RendererPageCommand {
pub fn resolve_blob_object(inspector_session_id: Option<String>, object_id: String) -> Self {
Self::inspector_command(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
RendererInspectorPageCommand::ResolveBlobObject { object_id },
)
}
/// Metadata is structurally present for every command that can access a
/// frontend V8 Inspector session; no command-variant allowlist is involved.
- pub fn inspector_ticket(&self) -> Option<&RendererInspectorIngressTicket> {
+ #[cfg(test)]
+ pub(crate) fn inspector_ticket(&self) -> Option<&RendererInspectorIngressTicket> {
match self {
Self::Inspector(envelope) => Some(envelope.ticket()),
_ => None,
}
}
- pub fn inspector_first_dispatch_lifecycle(
+ #[cfg(test)]
+ pub(crate) fn inspector_first_dispatch_lifecycle(
&self,
) -> Option<RendererInspectorFirstDispatchLifecycle> {
match self {
@@ -4869,10 +4950,6 @@ impl RendererPageCommand {
}
}
- pub(crate) fn uses_main_inspector_ingress_admission(&self) -> bool {
- matches!(self, Self::Inspector(envelope) if envelope.uses_main_ingress_admission())
- }
-
pub fn bind_inspector_attachment(&mut self, attachment: RendererAgentAttachmentId) {
if let Self::Inspector(envelope) = self {
envelope.bind_attachment(attachment);
@@ -5087,16 +5164,6 @@ mod renderer_inspector_command_envelope_tests {
);
}
- #[test]
- #[should_panic(expected = "IO Inspector commands must enter RendererInspectorIoIngress")]
- fn io_command_cannot_use_the_main_thread_page_envelope() {
- let _ = RendererPageCommand::dispatch_runtime_protocol_message(
- None,
- RendererInspectorCommandRoute::Io,
- r#"{"id":1,"method":"Runtime.terminateExecution"}"#.to_owned(),
- );
- }
-
#[test]
fn empty_wire_session_id_normalizes_to_the_primary_session() {
let command = RendererPageCommand::runtime_enable_events(Some(String::new()));
diff --git a/moli-renderer-v8/src/runtime/tests.rs b/moli-renderer-v8/src/runtime/tests.rs
index 3e50a27db..94d723c55 100644
--- a/moli-renderer-v8/src/runtime/tests.rs
+++ b/moli-renderer-v8/src/runtime/tests.rs
@@ -1,14 +1,13 @@
use super::{
ExternalRawDocumentBodyStream, JsLocalExecutor, JsRuntime, JsRuntimeOwner, PageVmInitStage,
PreparedRendererDocument, RendererCaptureScreenshotReply, RendererDragData,
- RendererDraggedDirectory, RendererDraggedFile, RendererInspectorCommandRoute,
- RendererInspectorProtocolConfiguration, RendererInspectorSessionRestoreSnapshot,
- RendererOutputItem, RendererOutputPublication, RendererOutputResidenceIdentity,
- RendererOutputTransportMessage, RendererOutputTransportReceiver, RendererOutputTransportSender,
- RendererOwnerAction, RendererPageCommand, RendererPageHandle, RendererPageReply,
- RendererPageTestingHandle, RendererPendingPopupActivation,
- RendererPreparedDocumentCommitConfiguration, RendererProtocolObservation,
- RendererRuntimeCommandOutput, RendererRuntimeInspectorMessage,
+ RendererDraggedDirectory, RendererDraggedFile, RendererInspectorProtocolConfiguration,
+ RendererInspectorSessionRestoreSnapshot, RendererOutputItem, RendererOutputPublication,
+ RendererOutputResidenceIdentity, RendererOutputTransportMessage,
+ RendererOutputTransportReceiver, RendererOutputTransportSender, RendererOwnerAction,
+ RendererPageCommand, RendererPageHandle, RendererPageReply, RendererPageTestingHandle,
+ RendererPendingPopupActivation, RendererPreparedDocumentCommitConfiguration,
+ RendererProtocolObservation, RendererRuntimeCommandOutput, RendererRuntimeInspectorMessage,
RendererRuntimeInspectorResponseSender,
};
use crate::local_executor::{is_on_script_execution_lane_for, scope_on_scaffold_js_local_executor};
@@ -3756,7 +3755,6 @@ async fn replacement_navigation_releases_old_inspector_deferred_response_callbac
.run_async_command(
RendererPageCommand::dispatch_runtime_protocol_message_with_deferred_response(
inspector_session_id,
- RendererInspectorCommandRoute::MainThread,
serde_json::json!({
"id": call_id,
"method": "Runtime.evaluate",
@@ -3820,7 +3818,6 @@ async fn replacement_navigation_releases_old_inspector_deferred_response_callbac
.enqueue_async_command(
RendererPageCommand::dispatch_runtime_protocol_message_with_deferred_response(
Some("session-a".to_owned()),
- RendererInspectorCommandRoute::MainThread,
serde_json::json!({
"id": reused_call_id,
"method": "Runtime.evaluate",
@@ -3885,7 +3882,6 @@ async fn runtime_binding_replay_cannot_consume_same_id_frontend_deferred_respons
.run_async_command(
RendererPageCommand::dispatch_runtime_protocol_message_with_deferred_response(
None,
- RendererInspectorCommandRoute::MainThread,
serde_json::json!({
"id": colliding_call_id,
"method": "Runtime.evaluate",
@@ -16183,7 +16179,6 @@ async fn command_turn_output_scope_is_removed_after_command_error() {
.enqueue_async_command(
RendererPageCommand::dispatch_runtime_protocol_message_with_context_resolution_and_deferred_response(
None,
- RendererInspectorCommandRoute::MainThread,
"evaluate".to_owned(),
"{".to_owned(),
RendererRuntimeInspectorResponseSender::new(
@@ -16206,7 +16201,6 @@ async fn command_turn_output_scope_is_removed_after_command_error() {
.enqueue_async_command(
RendererPageCommand::dispatch_runtime_protocol_message_with_deferred_response(
None,
- RendererInspectorCommandRoute::MainThread,
serde_json::json!({
"id": call_id,
"method": "Runtime.evaluate",
@@ -16265,7 +16259,6 @@ async fn runtime_document_close_completion_parks_lifecycle_until_capability_rele
.enqueue_async_command(
RendererPageCommand::dispatch_runtime_protocol_message_with_deferred_response(
None,
- RendererInspectorCommandRoute::MainThread,
serde_json::json!({
"id": call_id,
"method": "Runtime.evaluate",
@@ -17201,9 +17194,7 @@ async fn dispatch_runtime_protocol_with_output_for_test(
let raw_json = serde_json::to_string(&request)?;
let output = page
.enqueue_async_command(RendererPageCommand::dispatch_runtime_protocol_message(
- None,
- RendererInspectorCommandRoute::MainThread,
- raw_json,
+ None, raw_json,
))
.expect("runtime protocol command should enqueue")
.wait()
@@ -17231,7 +17222,6 @@ async fn dispatch_runtime_protocol_with_context_resolution_for_test(
.run_async_command(
RendererPageCommand::dispatch_runtime_protocol_message_with_context_resolution(
None,
- RendererInspectorCommandRoute::MainThread,
action.to_owned(),
raw_json,
),
diff --git a/moli-renderer-v8/src/script_vm/inspector/outbound.rs b/moli-renderer-v8/src/script_vm/inspector/outbound.rs
index 3e0835b70..d41388f9b 100644
--- a/moli-renderer-v8/src/script_vm/inspector/outbound.rs
+++ b/moli-renderer-v8/src/script_vm/inspector/outbound.rs
@@ -5,8 +5,8 @@ use crate::runtime::{
RendererTurnOutputJournal,
};
use crate::script_vm::inspector_pause::{
- RendererInspectorPauseNotificationRoute, RendererInspectorPauseOutboundRoute,
- RendererInspectorPausePrefaceGuard,
+ RendererInspectorPauseNotificationRoute, RendererInspectorPausePrefaceGuard,
+ RendererInspectorSessionOutboundRoute,
};
use anyhow::Result;
use moli_page_types::{DevToolsSessionKey, RendererDevToolsAgentToken};
@@ -64,7 +64,7 @@ pub(in crate::script_vm) struct InspectorOutbound {
output_journal: Option<RendererTurnOutputJournal>,
messages: SharedInspectorOutboundMessageState,
response_routing: SharedInspectorResponseRoutingState,
- pause_route: Rc<RefCell<Option<RendererInspectorPauseOutboundRoute>>>,
+ session_route: Rc<RefCell<Option<RendererInspectorSessionOutboundRoute>>>,
}
impl Default for InspectorOutbound {
@@ -81,20 +81,20 @@ impl InspectorOutbound {
output_journal: None,
messages: Rc::new(RefCell::new(InspectorOutboundMessageState::default())),
response_routing: Rc::new(RefCell::new(InspectorResponseRoutingState::default())),
- pause_route: Rc::new(RefCell::new(None)),
+ session_route: Rc::new(RefCell::new(None)),
}
}
pub(super) fn for_frontend(
agent_token: RendererDevToolsAgentToken,
session: DevToolsSessionKey,
- pause_route: RendererInspectorPauseOutboundRoute,
+ session_route: RendererInspectorSessionOutboundRoute,
output_journal: Option<RendererTurnOutputJournal>,
) -> Self {
let mut outbound = Self::for_agent(agent_token);
outbound.session = Some(session);
outbound.output_journal = output_journal;
- *outbound.pause_route.borrow_mut() = Some(pause_route);
+ *outbound.session_route.borrow_mut() = Some(session_route);
outbound
}
@@ -142,7 +142,7 @@ impl InspectorOutbound {
}
let mut messages = self.messages.borrow_mut();
messages.messages.clear();
- if let Some(route) = self.pause_route.borrow_mut().take() {
+ if let Some(route) = self.session_route.borrow_mut().take() {
route.detach_session();
}
}
@@ -188,8 +188,8 @@ impl InspectorOutbound {
}
pub(super) fn push_value(&self, value: Value) {
- if let Some(pause_route) = self.pause_route.borrow().clone() {
- match pause_route.route_notification(&value) {
+ if let Some(session_route) = self.session_route.borrow().clone() {
+ match session_route.route_notification(&value) {
RendererInspectorPauseNotificationRoute::OrdinaryTurn => {
return self.push_local_value(value);
}
@@ -273,7 +273,7 @@ impl InspectorOutbound {
&self,
messages: Vec<RendererRuntimeInspectorMessage>,
) -> Option<RendererInspectorPausePrefaceGuard> {
- self.pause_route
+ self.session_route
.borrow()
.as_ref()
.and_then(|route| route.stage_pause_preface(messages))
@@ -336,8 +336,8 @@ impl InspectorOutbound {
}
pub(super) fn push_response_value(&self, call_id: i32, value: Value) {
- if let Some(pause_route) = self.pause_route.borrow().as_ref() {
- pause_route.mark_command_response(call_id, value.get("error").is_none());
+ if let Some(session_route) = self.session_route.borrow().as_ref() {
+ session_route.mark_command_response(call_id, value.get("error").is_none());
}
let mut guard = self.response_routing.borrow_mut();
if guard
diff --git a/moli-renderer-v8/src/script_vm/inspector/v8_backend.rs b/moli-renderer-v8/src/script_vm/inspector/v8_backend.rs
index f019f014e..100796ec5 100644
--- a/moli-renderer-v8/src/script_vm/inspector/v8_backend.rs
+++ b/moli-renderer-v8/src/script_vm/inspector/v8_backend.rs
@@ -292,7 +292,7 @@ impl RendererInspectorSessionExecutorLocal {
let _command_dispatch = self.bridge.begin_command_dispatch(
command.command_id(),
command.ticket(),
- command.raw_json(),
+ command.pause_effect(),
Some(command.response().call_id()),
);
let (_, raw_json, response) = command.into_protocol_parts();
@@ -329,7 +329,7 @@ impl RendererInspectorSessionExecutorLocal {
let _command_dispatch = self.bridge.begin_command_dispatch(
command.command_id(),
command.ticket(),
- command.raw_json(),
+ command.pause_effect(),
command.response().map(|response| response.call_id()),
);
if let Some(response) = command.take_response() {
diff --git a/moli-renderer-v8/src/script_vm/inspector_io.rs b/moli-renderer-v8/src/script_vm/inspector_io.rs
index 0d92802fa..a514993c5 100644
--- a/moli-renderer-v8/src/script_vm/inspector_io.rs
+++ b/moli-renderer-v8/src/script_vm/inspector_io.rs
@@ -14,7 +14,8 @@ use serde_json::json;
use crate::{
runtime::{
RendererInspectorCommandEnvelope, RendererInspectorCommandRoute,
- RendererInspectorIngressTicket, RendererRuntimeInspectorResponseSender,
+ RendererInspectorIngressTicket, RendererInspectorPauseCommandEffect,
+ RendererRuntimeInspectorResponseSender,
},
script_vm::{
inspector_pause::RendererInspectorPauseLoopWake,
@@ -46,7 +47,7 @@ pub(crate) struct RendererInspectorIoCommand {
command_id: u64,
pub(crate) agent_token: RendererDevToolsAgentToken,
envelope: RendererInspectorCommandEnvelope,
- claim_tx: Option<tokio::sync::oneshot::Sender<RendererRuntimeInspectorCommandClaim>>,
+ claim_tx: Option<tokio::sync::oneshot::Sender<RendererRuntimeInspectorIoCommandClaim>>,
claimed_by: Option<RendererInspectorIoCommandConsumer>,
}
@@ -73,6 +74,10 @@ impl RendererInspectorIoCommand {
self.envelope.io_response()
}
+ pub(crate) fn pause_effect(&self) -> RendererInspectorPauseCommandEffect {
+ self.envelope.pause_effect()
+ }
+
pub(crate) fn take_response(&mut self) -> Option<RendererRuntimeInspectorResponseSender> {
self.envelope.take_io_response()
}
@@ -84,19 +89,19 @@ impl RendererInspectorIoCommand {
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
-pub enum RendererRuntimeInspectorCommandClaim {
+pub enum RendererRuntimeInspectorIoCommandClaim {
Inspector,
Canceled,
}
-pub struct RendererRuntimeInspectorCommandRoute {
+pub struct RendererRuntimeInspectorIoCommandRoute {
command_id: u64,
ticket: RendererInspectorIngressTicket,
- claim_rx: Option<tokio::sync::oneshot::Receiver<RendererRuntimeInspectorCommandClaim>>,
+ claim_rx: Option<tokio::sync::oneshot::Receiver<RendererRuntimeInspectorIoCommandClaim>>,
ingress: RendererInspectorIoIngress,
}
-impl RendererRuntimeInspectorCommandRoute {
+impl RendererRuntimeInspectorIoCommandRoute {
pub fn command_id(&self) -> u64 {
self.command_id
}
@@ -107,7 +112,7 @@ impl RendererRuntimeInspectorCommandRoute {
pub async fn wait_for_claim(
mut self,
- ) -> Result<RendererRuntimeInspectorCommandClaim, &'static str> {
+ ) -> Result<RendererRuntimeInspectorIoCommandClaim, &'static str> {
self.claim_rx
.take()
.expect("runtime inspector IO command claim receiver should only be awaited once")
@@ -116,7 +121,7 @@ impl RendererRuntimeInspectorCommandRoute {
}
}
-impl Drop for RendererRuntimeInspectorCommandRoute {
+impl Drop for RendererRuntimeInspectorIoCommandRoute {
fn drop(&mut self) {
self.ingress.cancel_queued_command(
self.command_id,
@@ -133,6 +138,7 @@ pub(crate) struct RendererInspectorIoIngress {
struct RendererInspectorIoShared {
state: Mutex<RendererInspectorIoState>,
interrupt_armed: AtomicBool,
+ owner_wake_armed: AtomicBool,
interrupt_route: Option<RendererInspectorInterruptRoute>,
pause_wake: RendererInspectorPauseLoopWake,
}
@@ -169,7 +175,6 @@ struct RendererInspectorIoSessionLane {
}
struct RendererInspectorIoState {
- next_command_id: u64,
sessions: BTreeMap<RendererInspectorIoSessionLaneKey, RendererInspectorIoSessionLane>,
ready_sessions: VecDeque<RendererInspectorIoSessionLaneKey>,
owner_wake_tx: Option<tokio::sync::mpsc::UnboundedSender<RendererInspectorIoOwnerWake>>,
@@ -245,13 +250,13 @@ impl RendererInspectorIoIngress {
Self {
shared: Arc::new(RendererInspectorIoShared {
state: Mutex::new(RendererInspectorIoState {
- next_command_id: 1,
sessions: BTreeMap::new(),
ready_sessions: VecDeque::new(),
owner_wake_tx: None,
closed: false,
}),
interrupt_armed: AtomicBool::new(false),
+ owner_wake_armed: AtomicBool::new(false),
interrupt_route: interrupt_route.map(|(isolate, callback, route_id)| {
RendererInspectorInterruptRoute {
isolate,
@@ -289,7 +294,7 @@ impl RendererInspectorIoIngress {
&self,
agent_token: RendererDevToolsAgentToken,
envelope: RendererInspectorCommandEnvelope,
- ) -> RendererRuntimeInspectorCommandRoute {
+ ) -> RendererRuntimeInspectorIoCommandRoute {
assert_eq!(
envelope.ticket().route(),
RendererInspectorCommandRoute::Io,
@@ -298,11 +303,7 @@ impl RendererInspectorIoIngress {
let ticket = envelope.ticket().clone();
let (claim_tx, claim_rx) = tokio::sync::oneshot::channel();
let mut state = self.shared.state.lock();
- let command_id = state.next_command_id;
- state.next_command_id = state
- .next_command_id
- .checked_add(1)
- .expect("runtime inspector IO command ID overflow");
+ let command_id = ticket.sequence();
let lane_key = RendererInspectorIoSessionLaneKey {
agent_token,
session: ticket.session().clone(),
@@ -317,7 +318,7 @@ impl RendererInspectorIoIngress {
if state.closed {
drop(state);
fail_io_command(command, "Inspector IO target is closed");
- return RendererRuntimeInspectorCommandRoute {
+ return RendererRuntimeInspectorIoCommandRoute {
command_id,
ticket,
claim_rx: Some(claim_rx),
@@ -328,7 +329,7 @@ impl RendererInspectorIoIngress {
if lane.detached {
drop(state);
fail_io_command(command, "Inspector IO session was detached");
- return RendererRuntimeInspectorCommandRoute {
+ return RendererRuntimeInspectorIoCommandRoute {
command_id,
ticket,
claim_rx: Some(claim_rx),
@@ -342,7 +343,7 @@ impl RendererInspectorIoIngress {
}
drop(state);
self.notify_execution_opportunities();
- RendererRuntimeInspectorCommandRoute {
+ RendererRuntimeInspectorIoCommandRoute {
command_id,
ticket,
claim_rx: Some(claim_rx),
@@ -351,7 +352,12 @@ impl RendererInspectorIoIngress {
}
pub(crate) fn claim_for_owner(&self) -> Option<RendererInspectorIoCommand> {
- self.claim_next(RendererInspectorIoCommandConsumer::Owner)
+ self.shared.owner_wake_armed.store(false, Ordering::Release);
+ let command = self.claim_next(RendererInspectorIoCommandConsumer::Owner);
+ if command.is_none() && !self.shared.state.lock().ready_sessions.is_empty() {
+ self.notify_execution_opportunities();
+ }
+ command
}
pub(crate) fn claim_for_interrupt(&self) -> Option<RendererInspectorIoCommand> {
@@ -400,7 +406,7 @@ impl RendererInspectorIoIngress {
lane.active_command_id = Some(command.command_id);
command.claimed_by = Some(consumer);
if let Some(claim_tx) = command.claim_tx.take() {
- let _ = claim_tx.send(RendererRuntimeInspectorCommandClaim::Inspector);
+ let _ = claim_tx.send(RendererRuntimeInspectorIoCommandClaim::Inspector);
}
return Some(command);
}
@@ -566,8 +572,17 @@ impl RendererInspectorIoIngress {
let state = self.shared.state.lock();
state.owner_wake_tx.clone().zip(self.route_id())
};
- if let Some((owner_wake_tx, route_id)) = owner_wake {
- let _ = owner_wake_tx.send(RendererInspectorIoOwnerWake { route_id });
+ if let Some((owner_wake_tx, route_id)) = owner_wake
+ && self
+ .shared
+ .owner_wake_armed
+ .compare_exchange(false, true, Ordering::AcqRel, Ordering::Acquire)
+ .is_ok()
+ && owner_wake_tx
+ .send(RendererInspectorIoOwnerWake { route_id })
+ .is_err()
+ {
+ self.shared.owner_wake_armed.store(false, Ordering::Release);
}
self.request_interrupt();
self.shared.pause_wake.notify_one();
@@ -636,7 +651,7 @@ impl std::fmt::Debug for RendererInspectorIoIngress {
fn fail_io_command(mut command: RendererInspectorIoCommand, message: &str) {
if let Some(claim_tx) = command.claim_tx.take() {
- let _ = claim_tx.send(RendererRuntimeInspectorCommandClaim::Canceled);
+ let _ = claim_tx.send(RendererRuntimeInspectorIoCommandClaim::Canceled);
}
let Some(response) = command.take_response() else {
return;
@@ -669,7 +684,7 @@ mod tests {
agent_token: RendererDevToolsAgentToken,
session: Option<&str>,
raw_json: &str,
- ) -> RendererRuntimeInspectorCommandRoute {
+ ) -> RendererRuntimeInspectorIoCommandRoute {
ingress.enqueue_command(
agent_token,
RendererInspectorCommandEnvelope::new_io(
@@ -739,13 +754,13 @@ mod tests {
let mut first_dispatch = ingress.first_dispatch_guard(&first);
assert_eq!(
first_route.wait_for_claim().await,
- Ok(RendererRuntimeInspectorCommandClaim::Inspector)
+ Ok(RendererRuntimeInspectorIoCommandClaim::Inspector)
);
ingress.detach_session(agent, &DevToolsSessionKey::Attached("session-a".to_owned()));
assert_eq!(
second_route.wait_for_claim().await,
- Ok(RendererRuntimeInspectorCommandClaim::Canceled),
+ Ok(RendererRuntimeInspectorIoCommandClaim::Canceled),
"detach must cancel commands that have not been claimed"
);
@@ -762,7 +777,6 @@ mod tests {
let ingress = ingress();
let page_command = crate::runtime::RendererPageCommand::dispatch_runtime_protocol_message(
Some("session-a".to_owned()),
- RendererInspectorCommandRoute::MainThread,
"main".to_owned(),
);
let crate::runtime::RendererPageCommand::Inspector(envelope) = page_command else {
diff --git a/moli-renderer-v8/src/script_vm/inspector_main.rs b/moli-renderer-v8/src/script_vm/inspector_main.rs
index e0e95d5e6..5616bd126 100644
--- a/moli-renderer-v8/src/script_vm/inspector_main.rs
+++ b/moli-renderer-v8/src/script_vm/inspector_main.rs
@@ -14,8 +14,8 @@ use crate::{
render_runtime::RenderRuntimeHandle,
runtime::{
RendererCommandTurnOutput, RendererInspectorCommandEnvelope, RendererInspectorCommandRoute,
- RendererInspectorIngressTicket, RendererOwnerReply, RendererPageStateCapturePolicy,
- RendererPageToken, RendererRuntimeInspectorResponseSender,
+ RendererInspectorIngressTicket, RendererInspectorPauseCommandEffect, RendererOwnerReply,
+ RendererPageStateCapturePolicy, RendererPageToken, RendererRuntimeInspectorResponseSender,
},
script_vm::{
inspector_pause::RendererInspectorPauseLoopWake,
@@ -47,7 +47,6 @@ pub(crate) struct RendererInspectorMainCommand {
page_token: RendererPageToken,
pub(crate) agent_token: RendererDevToolsAgentToken,
capture_policy: RendererPageStateCapturePolicy,
- pause_dispatch_allowed: bool,
envelope: RendererInspectorCommandEnvelope,
claim_tx: Option<tokio::sync::oneshot::Sender<RendererInspectorMainCommandClaim>>,
owner_reply_tx: Option<tokio::sync::oneshot::Sender<anyhow::Result<RendererOwnerReply>>>,
@@ -69,6 +68,7 @@ impl RendererInspectorMainCommand {
self.envelope.first_dispatch_lifecycle()
}
+ #[cfg(test)]
pub(crate) fn raw_json(&self) -> &str {
self.envelope.main_protocol_raw_json()
}
@@ -77,6 +77,10 @@ impl RendererInspectorMainCommand {
self.envelope.main_protocol_response()
}
+ pub(crate) fn pause_effect(&self) -> RendererInspectorPauseCommandEffect {
+ self.envelope.pause_effect()
+ }
+
pub(crate) fn into_protocol_parts(
self,
) -> (
@@ -191,7 +195,6 @@ struct RendererInspectorMainSessionLane {
}
struct RendererInspectorMainState {
- next_command_id: u64,
sessions: BTreeMap<RendererInspectorMainSessionLaneKey, RendererInspectorMainSessionLane>,
ready_sessions: VecDeque<RendererInspectorMainSessionLaneKey>,
owner_runtime: Option<RenderRuntimeHandle>,
@@ -276,7 +279,6 @@ impl RendererInspectorMainIngress {
Self {
shared: Arc::new(RendererInspectorMainShared {
state: Mutex::new(RendererInspectorMainState {
- next_command_id: 1,
sessions: BTreeMap::new(),
ready_sessions: VecDeque::new(),
owner_runtime: None,
@@ -311,7 +313,6 @@ impl RendererInspectorMainIngress {
agent_token,
envelope,
RendererPageStateCapturePolicy::ProtocolTurn,
- true,
)
}
@@ -322,7 +323,7 @@ impl RendererInspectorMainIngress {
envelope: RendererInspectorCommandEnvelope,
capture_policy: RendererPageStateCapturePolicy,
) -> RendererRuntimeInspectorMainCommandRoute {
- self.enqueue_with_policy(page_token, agent_token, envelope, capture_policy, false)
+ self.enqueue_with_policy(page_token, agent_token, envelope, capture_policy)
}
fn enqueue_with_policy(
@@ -331,26 +332,17 @@ impl RendererInspectorMainIngress {
agent_token: RendererDevToolsAgentToken,
envelope: RendererInspectorCommandEnvelope,
capture_policy: RendererPageStateCapturePolicy,
- pause_dispatch_allowed: bool,
) -> RendererRuntimeInspectorMainCommandRoute {
assert_eq!(
envelope.ticket().route(),
RendererInspectorCommandRoute::MainThread,
"only MainThread Inspector commands may enter RendererInspectorMainIngress"
);
- assert!(
- !pause_dispatch_allowed || envelope.is_main_protocol_command_with_deferred_response(),
- "only deferred frontend protocol commands may use nested Main dispatch"
- );
let ticket = envelope.ticket().clone();
let (claim_tx, claim_rx) = tokio::sync::oneshot::channel();
let (owner_reply_tx, owner_reply_rx) = tokio::sync::oneshot::channel();
let mut state = self.shared.state.lock();
- let command_id = state.next_command_id;
- state.next_command_id = state
- .next_command_id
- .checked_add(1)
- .expect("runtime inspector Main command ID overflow");
+ let command_id = ticket.sequence();
let lane_key = RendererInspectorMainSessionLaneKey {
agent_token,
session: ticket.session().clone(),
@@ -360,7 +352,6 @@ impl RendererInspectorMainIngress {
page_token,
agent_token,
capture_policy,
- pause_dispatch_allowed,
envelope,
claim_tx: Some(claim_tx),
owner_reply_tx: Some(owner_reply_tx),
@@ -437,7 +428,11 @@ impl RendererInspectorMainIngress {
.sessions
.get(&lane_key)
.and_then(|lane| lane.queued.front())
- .is_some_and(|command| !command.pause_dispatch_allowed);
+ .is_some_and(|command| {
+ !command
+ .envelope
+ .can_dispatch_at_nested_inspector_session_boundary()
+ });
if pause_dispatch_blocked {
state.ready_sessions.push_back(lane_key);
continue;
@@ -747,6 +742,16 @@ mod tests {
agent_token: RendererDevToolsAgentToken,
session: Option<&str>,
raw_json: &str,
+ ) -> RendererRuntimeInspectorMainCommandRoute {
+ enqueue_with_action(ingress, agent_token, session, None, raw_json)
+ }
+
+ fn enqueue_with_action(
+ ingress: &RendererInspectorMainIngress,
+ agent_token: RendererDevToolsAgentToken,
+ session: Option<&str>,
+ action: Option<&str>,
+ raw_json: &str,
) -> RendererRuntimeInspectorMainCommandRoute {
let (response_tx, _response_rx) =
tokio::sync::oneshot::channel::<RendererRuntimeInspectorAsyncCompletion>();
@@ -759,7 +764,7 @@ mod tests {
session.map(str::to_owned),
RendererInspectorCommandRoute::MainThread,
),
- None,
+ action.map(str::to_owned),
raw_json.to_owned(),
RendererRuntimeInspectorResponseSender::new(1, response_tx),
),
@@ -770,7 +775,12 @@ mod tests {
fn owner_and_pause_can_claim_one_main_command_only_once() {
let ingress = ingress();
let agent = RendererDevToolsAgentToken::allocate();
- let _route = enqueue(&ingress, agent, Some("session-a"), "first");
+ let _route = enqueue(
+ &ingress,
+ agent,
+ Some("session-a"),
+ r#"{"id":1,"method":"Runtime.getProperties","params":{"objectId":"first"}}"#,
+ );
let pause = ingress.claim_for_pause();
let owner = ingress.claim_for_owner();
@@ -788,21 +798,69 @@ mod tests {
fn main_ingress_is_fifo_per_session_and_independent_across_sessions() {
let ingress = ingress();
let agent = RendererDevToolsAgentToken::allocate();
- let _a1 = enqueue(&ingress, agent, Some("session-a"), "a1");
- let _a2 = enqueue(&ingress, agent, Some("session-a"), "a2");
- let _b1 = enqueue(&ingress, agent, Some("session-b"), "b1");
+ let _a1 = enqueue(
+ &ingress,
+ agent,
+ Some("session-a"),
+ r#"{"id":1,"method":"Runtime.getProperties","params":{"objectId":"a1"}}"#,
+ );
+ let _a2 = enqueue(
+ &ingress,
+ agent,
+ Some("session-a"),
+ r#"{"id":2,"method":"Runtime.getProperties","params":{"objectId":"a2"}}"#,
+ );
+ let _b1 = enqueue(
+ &ingress,
+ agent,
+ Some("session-b"),
+ r#"{"id":3,"method":"Runtime.getProperties","params":{"objectId":"b1"}}"#,
+ );
let first = ingress.claim_for_owner().expect("first ready Main session");
- assert_eq!(first.raw_json(), "a1");
+ assert!(first.raw_json().contains(r#""a1""#));
let second = ingress
.claim_for_pause()
.expect("the other Main session remains independently ready");
- assert_eq!(second.raw_json(), "b1");
+ assert!(second.raw_json().contains(r#""b1""#));
assert!(ingress.claim_for_owner().is_none());
ingress.first_dispatch_guard(&first).release();
let third = ingress.claim_for_pause().expect("a2 after a1 dispatch");
- assert_eq!(third.raw_json(), "a2");
+ assert!(third.raw_json().contains(r#""a2""#));
+ }
+
+ #[test]
+ fn nested_main_accepts_runtime_evaluation_but_not_page_owner_context_rewrite() {
+ let ingress = ingress();
+ let agent = RendererDevToolsAgentToken::allocate();
+ let _default_evaluate = enqueue_with_action(
+ &ingress,
+ agent,
+ Some("session-default"),
+ Some("evaluate"),
+ r#"{"id":1,"method":"Runtime.evaluate","params":{"expression":"1 + 1"}}"#,
+ );
+ let nested = ingress
+ .claim_for_pause()
+ .expect("default-world Runtime.evaluate should be pumpable by nested Main");
+ assert_eq!(
+ nested.claimed_by(),
+ Some(RendererInspectorMainCommandConsumer::Pause)
+ );
+
+ let _context_evaluate = enqueue_with_action(
+ &ingress,
+ agent,
+ Some("session-context"),
+ Some("evaluate"),
+ r#"{"id":2,"method":"Runtime.evaluate","params":{"contextId":41,"expression":"2 + 2"}}"#,
+ );
+ assert!(
+ ingress.claim_for_pause().is_none(),
+ "context-id rewriting belongs to Page owner dispatch"
+ );
+ assert!(ingress.claim_for_owner().is_some());
}
#[test]
diff --git a/moli-renderer-v8/src/script_vm/inspector_pause.rs b/moli-renderer-v8/src/script_vm/inspector_pause.rs
index cd1e8d840..401cd8a75 100644
--- a/moli-renderer-v8/src/script_vm/inspector_pause.rs
+++ b/moli-renderer-v8/src/script_vm/inspector_pause.rs
@@ -13,9 +13,10 @@ use serde_json::json;
use crate::runtime::RendererRuntimeInspectorResponseSender;
use crate::runtime::{
PageId, PendingRendererOutputRecord, RendererInspectorIngressTicket,
- RendererOutputResidenceIdentity, RendererProtocolObservation,
- RendererRuntimeCommandCausalIdentity, RendererRuntimeInspectorMessage,
- RendererRuntimeInspectorMessageBatch, RendererTurnOutputJournal,
+ RendererInspectorPauseCommandEffect, RendererOutputResidenceIdentity,
+ RendererProtocolObservation, RendererRuntimeCommandCausalIdentity,
+ RendererRuntimeInspectorMessage, RendererRuntimeInspectorMessageBatch,
+ RendererTurnOutputJournal,
};
use crate::script_vm::inspector_io::RendererInspectorIoIngress;
use crate::script_vm::inspector_main::RendererInspectorMainIngress;
@@ -60,32 +61,6 @@ struct RendererInspectorPauseBridgeState {
route: Option<RendererInspectorPauseRoute>,
}
-#[derive(Clone, Copy, Debug, Eq, PartialEq)]
-enum RendererInspectorPauseCommandEffect {
- None,
- Resume,
- Step,
-}
-
-impl RendererInspectorPauseCommandEffect {
- fn from_raw_json(raw_json: &str) -> Self {
- let Ok(message) = serde_json::from_str::<Value>(raw_json) else {
- return Self::None;
- };
- match message.get("method").and_then(Value::as_str) {
- Some("Debugger.resume") => Self::Resume,
- Some(
- "Debugger.continueToLocation"
- | "Debugger.restartFrame"
- | "Debugger.stepInto"
- | "Debugger.stepOut"
- | "Debugger.stepOver",
- ) => Self::Step,
- _ => Self::None,
- }
- }
-}
-
struct RendererInspectorPauseCommandDispatch {
command_id: u64,
transition: RendererInspectorPauseCommandTransition,
@@ -184,7 +159,7 @@ impl Drop for RendererInspectorPausePrefaceGuard {
}
}
#[derive(Clone)]
-pub(super) struct RendererInspectorPauseOutboundRoute {
+pub(super) struct RendererInspectorSessionOutboundRoute {
bridge: RendererInspectorPauseBridge,
main_ingress: RendererInspectorMainIngress,
io_ingress: RendererInspectorIoIngress,
@@ -258,8 +233,8 @@ impl RendererInspectorPauseBridge {
io_ingress: RendererInspectorIoIngress,
agent_token: RendererDevToolsAgentToken,
session: DevToolsSessionKey,
- ) -> RendererInspectorPauseOutboundRoute {
- RendererInspectorPauseOutboundRoute {
+ ) -> RendererInspectorSessionOutboundRoute {
+ RendererInspectorSessionOutboundRoute {
bridge: self.clone(),
main_ingress,
io_ingress,
@@ -284,10 +259,9 @@ impl RendererInspectorPauseBridge {
&self,
command_id: u64,
ticket: &RendererInspectorIngressTicket,
- raw_json: &str,
+ effect: RendererInspectorPauseCommandEffect,
response_call_id: Option<i32>,
) -> RendererInspectorPauseCommandDispatchGuard {
- let effect = RendererInspectorPauseCommandEffect::from_raw_json(raw_json);
if effect == RendererInspectorPauseCommandEffect::None {
return RendererInspectorPauseCommandDispatchGuard {
bridge: self.clone(),
@@ -653,7 +627,7 @@ pub(super) enum RendererInspectorPauseNotificationRoute {
Drop,
}
-impl RendererInspectorPauseOutboundRoute {
+impl RendererInspectorSessionOutboundRoute {
pub(super) fn route_notification(
&self,
message: &Value,
@@ -732,14 +706,14 @@ mod tests {
fn outbound_route(
bridge: &RendererInspectorPauseBridge,
- ) -> RendererInspectorPauseOutboundRoute {
+ ) -> RendererInspectorSessionOutboundRoute {
outbound_route_with_io(bridge, io_ingress(bridge))
}
fn outbound_route_with_io(
bridge: &RendererInspectorPauseBridge,
io_ingress: crate::script_vm::inspector_io::RendererInspectorIoIngress,
- ) -> RendererInspectorPauseOutboundRoute {
+ ) -> RendererInspectorSessionOutboundRoute {
bridge.outbound_route(
main_ingress(bridge),
io_ingress,
@@ -754,7 +728,7 @@ mod tests {
inspector_session_id: Option<String>,
raw_json: String,
response: RendererRuntimeInspectorResponseSender,
- ) -> crate::script_vm::inspector_io::RendererRuntimeInspectorCommandRoute {
+ ) -> crate::script_vm::inspector_io::RendererRuntimeInspectorIoCommandRoute {
ingress.enqueue_command(
agent_token,
crate::runtime::RendererInspectorCommandEnvelope::new_io(
@@ -843,7 +817,7 @@ mod tests {
let dispatch = bridge.begin_command_dispatch(
command.command_id(),
command.ticket(),
- command.raw_json(),
+ command.pause_effect(),
command.response().map(|response| response.call_id()),
);
outbound.mark_command_response(41, true);
@@ -906,7 +880,7 @@ mod tests {
let dispatch = bridge.begin_command_dispatch(
command.command_id(),
command.ticket(),
- command.raw_json(),
+ command.pause_effect(),
command.response().map(|response| response.call_id()),
);
outbound.mark_command_response(43, true);
@@ -962,7 +936,7 @@ mod tests {
let dispatch = bridge.begin_command_dispatch(
command.command_id(),
command.ticket(),
- command.raw_json(),
+ command.pause_effect(),
command.response().map(|response| response.call_id()),
);
outbound.mark_command_response(42, false);