mirror of
https://github.com/lexmount/moli.git
synced 2026-11-22 00:02:21 +00:00
fix(runtime): integrate main event dispatch and font ownership
Preserve shared listener registry identity across document.open, use explicit target/ancestor listener filters, and retain canonical EventTarget inheritance after the main rebase. Drive font and streamed-navigation tests through their native completion queues and align event-order expectations with pinned Chromium 152 observations.
This commit is contained in:
@@ -11,7 +11,7 @@ async fn assert_native_body_consumption(scenario: &str) -> Result<()> {
|
||||
for target in ["window", "child", "worker"] {
|
||||
let observed = tokio::time::timeout(
|
||||
Duration::from_secs(20),
|
||||
super::pipe_disturbed::run_probe(&browser, &server, target, &source),
|
||||
super::event_dispatch::run_probe(&browser, &server, target, &source),
|
||||
)
|
||||
.await??;
|
||||
assert_eq!(
|
||||
@@ -59,7 +59,7 @@ async fn fetch_network_body_rewrapping_avoids_reentrant_source_borrows() -> Resu
|
||||
for target in ["window", "child", "worker"] {
|
||||
let observed = tokio::time::timeout(
|
||||
Duration::from_secs(20),
|
||||
super::pipe_disturbed::run_probe(&browser, &server, target, &source),
|
||||
super::event_dispatch::run_probe(&browser, &server, target, &source),
|
||||
)
|
||||
.await??;
|
||||
assert_eq!(
|
||||
|
||||
@@ -14,7 +14,7 @@ async fn assert_binary_body_realms(scenario: &str, expected_cases: usize) -> Res
|
||||
for target in ["window", "child"] {
|
||||
let observed = tokio::time::timeout(
|
||||
Duration::from_secs(20),
|
||||
super::pipe_disturbed::run_probe(&browser, &server, target, &source),
|
||||
super::event_dispatch::run_probe(&browser, &server, target, &source),
|
||||
)
|
||||
.await??;
|
||||
assert_eq!(
|
||||
|
||||
@@ -12,7 +12,7 @@ async fn assert_request_stream_body(scenario: &str) -> Result<()> {
|
||||
for target in ["window", "child", "worker"] {
|
||||
let observed = tokio::time::timeout(
|
||||
Duration::from_secs(20),
|
||||
super::pipe_disturbed::run_probe(&browser, &server, target, &source),
|
||||
super::event_dispatch::run_probe(&browser, &server, target, &source),
|
||||
)
|
||||
.await??;
|
||||
assert_eq!(
|
||||
@@ -53,7 +53,7 @@ async fn request_stream_consumers_retain_reader_locks_on_success_and_failure() -
|
||||
for target in ["window", "child", "worker"] {
|
||||
let observed = tokio::time::timeout(
|
||||
Duration::from_secs(20),
|
||||
super::pipe_disturbed::run_probe(&browser, &server, target, &source),
|
||||
super::event_dispatch::run_probe(&browser, &server, target, &source),
|
||||
)
|
||||
.await??;
|
||||
assert_eq!(observed, serde_json::json!({"errors": []}), "{target}");
|
||||
|
||||
@@ -630,7 +630,7 @@ async fn handle_scheduler_input(
|
||||
input = input_kind,
|
||||
);
|
||||
}
|
||||
let ok = match input {
|
||||
let mut ok = match input {
|
||||
SchedulerInput::ProtocolWorkCompletion(completion) => {
|
||||
flush_owned_protocol_work(
|
||||
frontend_router,
|
||||
@@ -739,6 +739,16 @@ async fn handle_scheduler_input(
|
||||
.await
|
||||
}
|
||||
};
|
||||
if ok {
|
||||
let output = scheduler.complete_ready_renderer_output_continuations();
|
||||
ok = flush_protocol_output_with_runtime_deferred_reply_routing(
|
||||
frontend_router,
|
||||
scheduler,
|
||||
pending_runtime_deferred_replies,
|
||||
output,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
if let Some(started) = trace_started {
|
||||
tracing::info!(
|
||||
target: "moli_cdp_runtime",
|
||||
@@ -1031,8 +1041,10 @@ async fn flush_protocol_output_with_runtime_deferred_reply_routing(
|
||||
) {
|
||||
Ok(advance) => advance,
|
||||
Err(response) => {
|
||||
let mut routed =
|
||||
route_unmatched_runtime_inspector_response(scheduler, response);
|
||||
let mut routed = prefix;
|
||||
routed.append(route_unmatched_runtime_inspector_response(
|
||||
scheduler, response,
|
||||
));
|
||||
routed.append(output);
|
||||
if !routed.is_empty() {
|
||||
pending_flush
|
||||
@@ -1056,15 +1068,18 @@ async fn flush_protocol_output_with_runtime_deferred_reply_routing(
|
||||
pending_runtime_deferred_replies.push_back(*pending);
|
||||
}
|
||||
RuntimeDeferredReplyAdvance::Complete(completion) => {
|
||||
let completion = (*completion)
|
||||
let mut completion = (*completion)
|
||||
.settle_exact_outputs_before_response(scheduler)
|
||||
.await;
|
||||
let mut remaining_output = prefix;
|
||||
remaining_output.append(output);
|
||||
// This prefix was already ordered before the
|
||||
// renderer response in the same concrete batch.
|
||||
// Keep it before the wire reply when completing
|
||||
// the deferred command, including timer output.
|
||||
completion.output.prepend_protocol_output(prefix);
|
||||
enqueue_runtime_deferred_reply_completion_flush(
|
||||
&mut pending_flush,
|
||||
completion,
|
||||
remaining_output,
|
||||
output,
|
||||
);
|
||||
break;
|
||||
}
|
||||
@@ -2165,6 +2180,7 @@ fn take_internal_command_response(
|
||||
}
|
||||
*output = ProtocolOutputSequence::from_background_events(passthrough);
|
||||
Some((|| {
|
||||
// This control API consumes the structured protocol result.
|
||||
let response = response.context("CDP internal command returned no response")?;
|
||||
let resource = match metadata.method.as_deref() {
|
||||
Some("Target.attachToBrowserTarget" | "Target.attachToTarget") => response
|
||||
|
||||
@@ -14,6 +14,23 @@ mod workflow;
|
||||
pub use task::{CompletedProtocolSchedulerWork, PendingProtocolSchedulerWork};
|
||||
|
||||
impl CdpConnection {
|
||||
pub(crate) fn renderer_output_projection_receipt(
|
||||
&mut self,
|
||||
predecessor: moli_core::RendererOutputFence,
|
||||
target_id: Option<String>,
|
||||
) -> tokio::sync::oneshot::Receiver<()> {
|
||||
let (projected, receipt) = tokio::sync::oneshot::channel();
|
||||
self.publish_protocol_work(move |sequence| {
|
||||
crate::domains::activity::ProtocolSchedulerWork::renderer_projection_receipt(
|
||||
sequence,
|
||||
predecessor,
|
||||
target_id,
|
||||
projected,
|
||||
)
|
||||
});
|
||||
receipt
|
||||
}
|
||||
|
||||
/// Barrier admission and renderer-call registration belong to this same
|
||||
/// connection. The adapter owns only the move-only response permit.
|
||||
pub fn admit_runtime_command_output_barrier(
|
||||
@@ -288,7 +305,7 @@ impl CdpConnection {
|
||||
.all(|fence| self.renderer_output_cursor_is_projected(fence.cursor())),
|
||||
"materialized protocol output cannot cross its concrete renderer predecessor"
|
||||
);
|
||||
output.events
|
||||
output.finish()
|
||||
}
|
||||
ReadyProtocolSchedulerWork::ProtocolObservation(work) => {
|
||||
work.into_background_events(self)
|
||||
|
||||
@@ -31,6 +31,7 @@ fn native_commit_visibility_requires_the_admitted_fact_and_current_attachment()
|
||||
timestamp: 1.0,
|
||||
session_history_position: None,
|
||||
browsing_context_group: None,
|
||||
navigation_policy: None,
|
||||
});
|
||||
assert!(slot.register_renderer_document_commit(&token, attachment, fact.clone(), None));
|
||||
assert_eq!(slot.frame_tree_document_loader_id(), None);
|
||||
|
||||
@@ -5,6 +5,23 @@ use crate::conn::{CommandDispatchContext, CommandOwnerScope};
|
||||
use moli_core::page::CompletedPageCommand;
|
||||
|
||||
impl ProtocolWorkflowState<'_> {
|
||||
pub(crate) fn prepare_before_unload_navigation(
|
||||
self,
|
||||
completed: crate::domains::page::CompletedBeforeUnloadNavigationCommand,
|
||||
context: &mut crate::conn::CommandWorkflowContext,
|
||||
) -> crate::domains::page::PreparedBeforeUnloadNavigation {
|
||||
completed.prepare(self.connection, context)
|
||||
}
|
||||
|
||||
pub(crate) fn resume_before_unload_navigation(
|
||||
self,
|
||||
prepared: crate::domains::page::PreparedBeforeUnloadNavigation,
|
||||
output_mode: crate::domains::page::NavigationCommandOutput,
|
||||
context: &mut crate::conn::CommandWorkflowContext,
|
||||
) -> crate::domains::page::BeforeUnloadNavigationStep {
|
||||
prepared.resume(self.connection, context, output_mode)
|
||||
}
|
||||
|
||||
pub(crate) fn page_query_host_is_current(
|
||||
self,
|
||||
host: &crate::conn::ProtocolPageHostScope,
|
||||
|
||||
@@ -3,10 +3,18 @@ use crate::conn::{
|
||||
CommandOwnerScope, CommandWorkflowContext, DocumentNavigationToken, NavigationDispatchState,
|
||||
NavigationLoadOutcome, TargetRootDocumentProtocolAttachmentIdentity,
|
||||
};
|
||||
use crate::domains::page::PreparedRendererNavigationResult;
|
||||
use crate::domains::page::{PreparedRendererNavigation, PreparedRendererNavigationResult};
|
||||
use anyhow::{Context as _, Result};
|
||||
|
||||
impl ProtocolWorkflowState<'_> {
|
||||
pub(crate) fn prepare_renderer_navigation_step(
|
||||
self,
|
||||
owner: CommandOwnerScope,
|
||||
step: crate::domains::page::PageCommandTaskStep,
|
||||
) -> PreparedRendererNavigation {
|
||||
PreparedRendererNavigation::prepare(self.connection, owner, step)
|
||||
}
|
||||
|
||||
pub(crate) fn resume_initial_document_navigation(
|
||||
self,
|
||||
action: crate::conn::TopLevelNavigationOwnerAction,
|
||||
|
||||
@@ -97,6 +97,16 @@ pub struct RendererFencedProtocolOutput {
|
||||
pub events: Vec<BackgroundProtocolEvent>,
|
||||
pub predecessors: Vec<RendererOutputFence>,
|
||||
target_id: Option<String>,
|
||||
projected: Option<tokio::sync::oneshot::Sender<()>>,
|
||||
}
|
||||
|
||||
impl RendererFencedProtocolOutput {
|
||||
pub(crate) fn finish(self) -> Vec<BackgroundProtocolEvent> {
|
||||
if let Some(projected) = self.projected {
|
||||
let _ = projected.send(());
|
||||
}
|
||||
self.events
|
||||
}
|
||||
}
|
||||
|
||||
enum ProtocolSchedulerWorkPayload {
|
||||
@@ -219,6 +229,32 @@ impl ProtocolSchedulerWork {
|
||||
events,
|
||||
predecessors,
|
||||
target_id,
|
||||
projected: None,
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// A local continuation waits on the same exact projection fence as wire
|
||||
/// output. It produces no wire event and does not acquire a target load
|
||||
/// lane that the continuation itself must release.
|
||||
pub(crate) fn renderer_projection_receipt(
|
||||
publish_sequence: ProtocolWorkPublishSequence,
|
||||
predecessor: RendererOutputFence,
|
||||
target_id: Option<String>,
|
||||
projected: tokio::sync::oneshot::Sender<()>,
|
||||
) -> Self {
|
||||
Self {
|
||||
publish_sequence,
|
||||
renderer_output_source: None,
|
||||
delivery_predecessor: None,
|
||||
execution: ProtocolWorkExecution::ClientTurn,
|
||||
payload: ProtocolSchedulerWorkPayload::RendererFencedOutput(
|
||||
RendererFencedProtocolOutput {
|
||||
events: Vec::new(),
|
||||
predecessors: vec![predecessor],
|
||||
target_id,
|
||||
projected: Some(projected),
|
||||
},
|
||||
),
|
||||
}
|
||||
@@ -233,6 +269,20 @@ impl ProtocolSchedulerWork {
|
||||
}
|
||||
}
|
||||
|
||||
/// Local continuations also follow owner actions emitted by this concrete
|
||||
/// source. The adapter uses its existing source metadata to admit those
|
||||
/// actions before releasing the continuation; no renderer rescan is needed.
|
||||
pub fn renderer_output_continuation_predecessor(&self) -> Option<RendererOutputCursor> {
|
||||
match &self.payload {
|
||||
ProtocolSchedulerWorkPayload::RendererFencedOutput(output)
|
||||
if output.projected.is_some() =>
|
||||
{
|
||||
output.predecessors.first().map(RendererOutputFence::cursor)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// A materialized observation retains its original concrete renderer
|
||||
/// predecessor. It becomes deliverable after projection, without another
|
||||
/// Native wait or a second task registry.
|
||||
@@ -428,14 +478,16 @@ impl ProtocolSchedulerWork {
|
||||
/// crosses the ordinary client-turn predecessor just like activation.
|
||||
pub fn is_command_followup(&self) -> bool {
|
||||
match &self.payload {
|
||||
ProtocolSchedulerWorkPayload::RendererFencedOutput(output) => {
|
||||
output.projected.is_some()
|
||||
}
|
||||
ProtocolSchedulerWorkPayload::BidiChannelOwnerAction(_)
|
||||
| ProtocolSchedulerWorkPayload::TopLevelNavigationOwnerAction(_)
|
||||
| ProtocolSchedulerWorkPayload::PageTargetTerminationOwnerAction(_) => true,
|
||||
ProtocolSchedulerWorkPayload::PopupTargetNavigationOwnerAction(action) => {
|
||||
action.is_command_followup()
|
||||
}
|
||||
ProtocolSchedulerWorkPayload::RendererFencedOutput(_)
|
||||
| ProtocolSchedulerWorkPayload::ProtocolObservation(_)
|
||||
ProtocolSchedulerWorkPayload::ProtocolObservation(_)
|
||||
| ProtocolSchedulerWorkPayload::NavigationRequestContinuation(..)
|
||||
| ProtocolSchedulerWorkPayload::MainDocumentLoadOwnerAction(_)
|
||||
| ProtocolSchedulerWorkPayload::NavigationProtocolCompletion(_) => false,
|
||||
@@ -479,6 +531,13 @@ impl ProtocolSchedulerWork {
|
||||
/// work retains its explicit Page, output and command prerequisites.
|
||||
pub fn navigation_dependency(&self) -> ProtocolNavigationDependency {
|
||||
match &self.payload {
|
||||
ProtocolSchedulerWorkPayload::RendererFencedOutput(output)
|
||||
if output.projected.is_some() =>
|
||||
{
|
||||
// A before-load continuation decides whether that pending load
|
||||
// may begin. Waiting for the load here would create a cycle.
|
||||
ProtocolNavigationDependency::ReplacesPendingLoad
|
||||
}
|
||||
ProtocolSchedulerWorkPayload::TopLevelNavigationOwnerAction(_)
|
||||
| ProtocolSchedulerWorkPayload::NavigationRequestContinuation(..)
|
||||
| ProtocolSchedulerWorkPayload::NavigationProtocolCompletion(_)
|
||||
|
||||
@@ -381,6 +381,12 @@ pub(super) async fn complete_using(
|
||||
let command_id = completed.command_id;
|
||||
let owner = completed.owner_scope;
|
||||
let plan = match *completed.kind {
|
||||
CompletedPageCommandKind::BeforeUnloadNavigation(completed) => {
|
||||
let prepared = context.with_state(driver, move |state, context| {
|
||||
state.prepare_before_unload_navigation(*completed, context)
|
||||
})?;
|
||||
return Box::pin(prepared.run(driver, context, NavigationCommandOutput::Command)).await;
|
||||
}
|
||||
CompletedPageCommandKind::BringToFront { route } => {
|
||||
bring_to_front_using(driver, route).await?
|
||||
}
|
||||
@@ -439,6 +445,7 @@ fn is_composite(kind: &CompletedPageCommandKind) -> bool {
|
||||
| CompletedPageCommandKind::CreateIsolatedWorld(_)
|
||||
| CompletedPageCommandKind::ChildFrameNavigate(_)
|
||||
| CompletedPageCommandKind::Navigate(_)
|
||||
| CompletedPageCommandKind::BeforeUnloadNavigation(_)
|
||||
| CompletedPageCommandKind::ContinueNavigationWithoutRequestPause(_)
|
||||
| CompletedPageCommandKind::Crash(_)
|
||||
| CompletedPageCommandKind::Close(_)
|
||||
@@ -490,6 +497,7 @@ impl PendingPageCommandDispatch {
|
||||
| PendingPageCommandKind::CreateIsolatedWorld(_)
|
||||
| PendingPageCommandKind::ChildFrameNavigate(_)
|
||||
| PendingPageCommandKind::Navigate(_)
|
||||
| PendingPageCommandKind::BeforeUnloadNavigation(_)
|
||||
| PendingPageCommandKind::ContinueNavigationWithoutRequestPause(_)
|
||||
| PendingPageCommandKind::Crash(_)
|
||||
| PendingPageCommandKind::Close(_)
|
||||
|
||||
@@ -75,6 +75,7 @@ struct RecordedDocumentStartScript {
|
||||
}
|
||||
|
||||
enum PendingCreateIsolatedWorldPhase {
|
||||
BeforeUnload(Box<super::navigation::PendingBeforeUnloadNavigationCommand>),
|
||||
InitialDocumentNavigation(Box<super::navigation::PendingNavigateLoadCommand>),
|
||||
InitialDocumentNavigationContinue(
|
||||
Box<super::navigation::PendingContinueNavigationWithoutRequestPauseCommand>,
|
||||
@@ -83,6 +84,7 @@ enum PendingCreateIsolatedWorldPhase {
|
||||
}
|
||||
|
||||
enum CompletedCreateIsolatedWorldPhase {
|
||||
BeforeUnload(Box<super::navigation::CompletedBeforeUnloadNavigationCommand>),
|
||||
InitialDocumentNavigation(Box<super::navigation::CompletedNavigateLoadCommand>),
|
||||
InitialDocumentNavigationContinue(
|
||||
Box<super::navigation::CompletedContinueNavigationWithoutRequestPauseCommand>,
|
||||
@@ -101,6 +103,9 @@ pub(crate) struct CreateIsolatedWorldCommandTask {
|
||||
impl PendingCreateIsolatedWorldCommand {
|
||||
pub(super) async fn wait(self) -> CompletedCreateIsolatedWorldCommand {
|
||||
let completed = match self.pending {
|
||||
PendingCreateIsolatedWorldPhase::BeforeUnload(pending) => {
|
||||
CompletedCreateIsolatedWorldPhase::BeforeUnload(Box::new(pending.wait().await))
|
||||
}
|
||||
PendingCreateIsolatedWorldPhase::InitialDocumentNavigation(pending) => {
|
||||
CompletedCreateIsolatedWorldPhase::InitialDocumentNavigation(Box::new(
|
||||
pending.wait().await,
|
||||
@@ -808,6 +813,14 @@ fn start_create_isolated_world_initial_navigation_or_renderer_phase(
|
||||
Err(plan) => return PageCommandTaskStep::Complete(plan),
|
||||
};
|
||||
match start {
|
||||
super::navigation::NavigateCommandStart::PendingBeforeUnload(pending) => {
|
||||
pending_create_isolated_world_command_for_session(
|
||||
command_id,
|
||||
owner,
|
||||
task,
|
||||
PendingCreateIsolatedWorldPhase::BeforeUnload(pending),
|
||||
)
|
||||
}
|
||||
super::navigation::NavigateCommandStart::CompleteImmediate(plan) => {
|
||||
if plan.command_status().is_some_and(|status| status.is_err()) {
|
||||
return PageCommandTaskStep::Complete(plan);
|
||||
@@ -1044,6 +1057,59 @@ pub(super) async fn complete_create_isolated_world_using(
|
||||
loop {
|
||||
let task = completed.task;
|
||||
let step = match completed.completed {
|
||||
CompletedCreateIsolatedWorldPhase::BeforeUnload(check) => {
|
||||
let prepared = context.with_state(driver, move |state, context| {
|
||||
state.prepare_before_unload_navigation(*check, context)
|
||||
})?;
|
||||
let step = Box::pin(prepared.run(
|
||||
driver,
|
||||
context,
|
||||
super::NavigationCommandOutput::Composite,
|
||||
))
|
||||
.await?;
|
||||
if context.has_retained_terminal() {
|
||||
return Ok(CommandOutputPlan::default());
|
||||
}
|
||||
match step {
|
||||
PageCommandTaskStep::Complete(plan) => {
|
||||
if plan.command_status().is_some_and(|status| status.is_err()) {
|
||||
return Ok(plan);
|
||||
}
|
||||
let mut task = task;
|
||||
task.prefix_output
|
||||
.extend(plan.into_composite_command_prefix());
|
||||
context.materialize_projection_output();
|
||||
let owner = owner.clone();
|
||||
driver.with_state(move |state| {
|
||||
state.start_page_isolated_world(command_id, owner, task)
|
||||
})?
|
||||
}
|
||||
PageCommandTaskStep::Pending(pending) => {
|
||||
let phase = match *pending.kind {
|
||||
PendingPageCommandKind::Navigate(pending) => {
|
||||
CompletedCreateIsolatedWorldPhase::InitialDocumentNavigation(
|
||||
Box::new(pending.wait().await),
|
||||
)
|
||||
}
|
||||
PendingPageCommandKind::ContinueNavigationWithoutRequestPause(
|
||||
pending,
|
||||
) => {
|
||||
CompletedCreateIsolatedWorldPhase::InitialDocumentNavigationContinue(
|
||||
Box::new(pending.wait().await),
|
||||
)
|
||||
}
|
||||
_ => unreachable!(
|
||||
"a checked initial navigation continues only its prepared request"
|
||||
),
|
||||
};
|
||||
completed = CompletedCreateIsolatedWorldCommand {
|
||||
task,
|
||||
completed: phase,
|
||||
};
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
CompletedCreateIsolatedWorldPhase::InitialDocumentNavigation(completed) => {
|
||||
let prepared =
|
||||
driver.with_state(move |state| state.prepare_page_navigation(*completed))?;
|
||||
|
||||
@@ -1849,12 +1849,11 @@ async fn browser_document_navigation_keeps_page_residence_and_replaces_document_
|
||||
take_response_by_id(&mut ctx, id)["error"].is_null(),
|
||||
"navigation {index}"
|
||||
);
|
||||
wait_until_message(
|
||||
&mut ctx,
|
||||
Some(session),
|
||||
"stable Page replacement load",
|
||||
|message| message["method"] == "Page.loadEventFired",
|
||||
)
|
||||
// Streamed replacement advances on real scheduler inputs, independent
|
||||
// of how many idle polling turns fit under concurrent test load.
|
||||
wait_until_scheduler_message(&mut ctx, "stable Page replacement load", |message| {
|
||||
message["method"] == "Page.loadEventFired"
|
||||
})
|
||||
.await;
|
||||
ctx.with_fixture(|conn| {
|
||||
assert_eq!(
|
||||
|
||||
@@ -10,8 +10,8 @@ type Check = dyn Fn(
|
||||
Option<&str>,
|
||||
ContentSecurityPolicyRedirectStatus,
|
||||
) -> (
|
||||
Option<ContentSecurityPolicyUrlViolation>,
|
||||
Option<ContentSecurityPolicyUrlViolation>,
|
||||
Vec<ContentSecurityPolicyUrlViolation>,
|
||||
Vec<ContentSecurityPolicyUrlViolation>,
|
||||
) + Send
|
||||
+ Sync;
|
||||
|
||||
@@ -28,21 +28,23 @@ pub(crate) struct StylesheetFetchCspContext {
|
||||
}
|
||||
|
||||
impl StylesheetFetchCspContext {
|
||||
pub(crate) fn new<C>(capture_check: impl Fn() -> C + Send + Sync + 'static) -> Self
|
||||
pub(crate) fn new<C, R, E>(capture_check: impl Fn() -> C + Send + Sync + 'static) -> Self
|
||||
where
|
||||
C: Fn(
|
||||
&Url,
|
||||
Option<&str>,
|
||||
ContentSecurityPolicyRedirectStatus,
|
||||
) -> (
|
||||
Option<ContentSecurityPolicyUrlViolation>,
|
||||
Option<ContentSecurityPolicyUrlViolation>,
|
||||
) + Send
|
||||
C: Fn(&Url, Option<&str>, ContentSecurityPolicyRedirectStatus) -> (R, E)
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
R: IntoIterator<Item = ContentSecurityPolicyUrlViolation>,
|
||||
E: IntoIterator<Item = ContentSecurityPolicyUrlViolation>,
|
||||
{
|
||||
Self {
|
||||
capture_check: Arc::new(move || Box::new(capture_check())),
|
||||
capture_check: Arc::new(move || {
|
||||
let check = capture_check();
|
||||
Box::new(move |url, nonce, status| {
|
||||
let (report, enforce) = check(url, nonce, status);
|
||||
(report.into_iter().collect(), enforce.into_iter().collect())
|
||||
})
|
||||
}),
|
||||
violations: Arc::default(),
|
||||
}
|
||||
}
|
||||
@@ -62,7 +64,7 @@ impl StylesheetFetchCspContext {
|
||||
ContentSecurityPolicyRedirectStatus::FollowedRedirect
|
||||
},
|
||||
);
|
||||
let error = enforce.as_ref().map(|violation| {
|
||||
let error = enforce.first().map(|violation| {
|
||||
anyhow::anyhow!(
|
||||
"Stylesheet request blocked by Content Security Policy directive `{}`",
|
||||
violation.effective_directive
|
||||
|
||||
@@ -480,14 +480,14 @@ pub(crate) use self::media_queries::SimpleObjectEventListenerInspectorSnapshot;
|
||||
#[cfg(feature = "devtools")]
|
||||
pub(crate) use self::media_queries::simple_event_target_inspector_listener_snapshots;
|
||||
pub(crate) use self::media_queries::{
|
||||
ResolvedSimpleEventTarget, dispatch_media_query_list_change_events,
|
||||
ResolvedSimpleEventTarget, clear_simple_event_target_listeners, dispatch_media_query_list_change_events,
|
||||
dispatch_simple_event_target_event, dispatch_simple_event_target_event_collecting_errors,
|
||||
dispatch_simple_event_target_event_with_ancestors,
|
||||
dispatch_simple_event_target_event_with_checkpoint,
|
||||
dispatch_simple_event_target_event_with_original_target, initialize_simple_event_target,
|
||||
invoke_simple_event_target_listeners, simple_event_target_handler_getter_callback,
|
||||
simple_event_target_handler_setter_callback,
|
||||
simple_object_event_listeners_snapshot, simple_object_event_set_handler,
|
||||
simple_object_event_activate_uncompiled_handler, simple_object_event_listeners_snapshot, simple_object_event_set_handler,
|
||||
simple_object_event_target_register_webidl_listener, simple_object_has_event_listeners,
|
||||
};
|
||||
use self::message_ports::schedule_scope_callback;
|
||||
@@ -1306,3 +1306,6 @@ pub(crate) fn set_event_private_bool<'s>(
|
||||
pub(crate) use self::events::event_trusted;
|
||||
#[cfg(test)]
|
||||
pub(crate) use navigator_runtime::midi_map_for_test;
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) use self::media_queries::install_simple_event_target_handlers;
|
||||
|
||||
@@ -13,13 +13,13 @@ pub(in crate::context_bootstrap) use self::events::dispatch_media_query_list_eve
|
||||
#[cfg(feature = "devtools")]
|
||||
pub(crate) use self::events::simple_event_target_inspector_listener_snapshots;
|
||||
pub(crate) use self::events::{
|
||||
ResolvedSimpleEventTarget, dispatch_simple_event_target_event,
|
||||
dispatch_simple_event_target_event_collecting_errors,
|
||||
ResolvedSimpleEventTarget, clear_simple_event_target_listeners,
|
||||
dispatch_simple_event_target_event, dispatch_simple_event_target_event_collecting_errors,
|
||||
dispatch_simple_event_target_event_with_ancestors,
|
||||
dispatch_simple_event_target_event_with_checkpoint,
|
||||
dispatch_simple_event_target_event_with_original_target, initialize_simple_event_target,
|
||||
invoke_simple_event_target_listeners, simple_event_target_handler_getter_callback,
|
||||
simple_event_target_handler_setter_callback,
|
||||
simple_event_target_handler_setter_callback, simple_object_event_activate_uncompiled_handler,
|
||||
simple_object_event_listeners_snapshot, simple_object_event_set_handler,
|
||||
simple_object_event_target_register_webidl_listener, simple_object_has_event_listeners,
|
||||
};
|
||||
@@ -28,3 +28,6 @@ pub(super) use self::events::{
|
||||
};
|
||||
|
||||
use super::{SIMPLE_EVENT_TARGET_LISTENERS_SLOT, object_string_property_defined, v8str};
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) use self::events::install_simple_event_target_handlers;
|
||||
|
||||
@@ -10,18 +10,18 @@ pub(in crate::context_bootstrap) use media_query_list::{
|
||||
};
|
||||
#[cfg(feature = "devtools")]
|
||||
pub(crate) use simple_event_target::SimpleObjectEventListenerInspectorSnapshot;
|
||||
#[cfg(feature = "devtools")]
|
||||
pub(crate) use simple_event_target::simple_event_target_inspector_listener_snapshots;
|
||||
#[cfg(test)]
|
||||
pub(crate) use simple_event_target::install_simple_event_target_handlers;
|
||||
#[cfg(feature = "devtools")]
|
||||
pub(crate) use simple_event_target::simple_event_target_inspector_listener_snapshots;
|
||||
pub(crate) use simple_event_target::{
|
||||
ResolvedSimpleEventTarget, dispatch_simple_event_target_event,
|
||||
dispatch_simple_event_target_event_collecting_errors,
|
||||
ResolvedSimpleEventTarget, clear_simple_event_target_listeners,
|
||||
dispatch_simple_event_target_event, dispatch_simple_event_target_event_collecting_errors,
|
||||
dispatch_simple_event_target_event_with_ancestors,
|
||||
dispatch_simple_event_target_event_with_checkpoint,
|
||||
dispatch_simple_event_target_event_with_original_target, initialize_simple_event_target,
|
||||
invoke_simple_event_target_listeners, simple_event_target_handler_getter_callback,
|
||||
simple_event_target_handler_setter_callback,
|
||||
simple_event_target_handler_setter_callback, simple_object_event_activate_uncompiled_handler,
|
||||
simple_object_event_listeners_snapshot, simple_object_event_remove_listener_value_for_type,
|
||||
simple_object_event_set_handler, simple_object_event_target_register_webidl_listener,
|
||||
simple_object_has_event_listeners,
|
||||
|
||||
@@ -10,13 +10,12 @@ pub(crate) use dispatch::{
|
||||
dispatch_simple_event_target_event, dispatch_simple_event_target_event_collecting_errors,
|
||||
dispatch_simple_event_target_event_with_ancestors,
|
||||
dispatch_simple_event_target_event_with_checkpoint,
|
||||
dispatch_simple_event_target_event_with_original_target,
|
||||
dispatch_simple_event_target_event_with_original_target, invoke_simple_event_target_listeners,
|
||||
};
|
||||
#[cfg(test)]
|
||||
pub(crate) use handlers::install_simple_event_target_handlers;
|
||||
pub(crate) use handlers::{
|
||||
install_simple_event_target_handlers, simple_event_target_handler_getter_callback,
|
||||
simple_event_target_handler_setter_callback,
|
||||
simple_event_target_handler_getter_callback, simple_event_target_handler_setter_callback,
|
||||
};
|
||||
#[cfg(feature = "devtools")]
|
||||
pub(crate) use listeners::SimpleObjectEventListenerInspectorSnapshot;
|
||||
@@ -25,6 +24,7 @@ use listeners::SimpleObjectEventListenerSnapshot;
|
||||
pub(crate) use listeners::simple_event_target_inspector_listener_snapshots;
|
||||
pub(crate) use listeners::simple_object_event_target_register_webidl_listener;
|
||||
pub(crate) use listeners::{
|
||||
clear_simple_event_target_listeners, simple_object_event_activate_uncompiled_handler,
|
||||
simple_object_event_listeners_snapshot, simple_object_event_remove_listener_value_for_type,
|
||||
simple_object_event_set_handler, simple_object_has_event_listeners,
|
||||
};
|
||||
|
||||
+54
-19
@@ -201,6 +201,7 @@ fn dispatch_resolved_event<'s>(
|
||||
event,
|
||||
None,
|
||||
callback_errors,
|
||||
None,
|
||||
)
|
||||
} else {
|
||||
SimpleEventDispatchResult::default()
|
||||
@@ -209,6 +210,7 @@ fn dispatch_resolved_event<'s>(
|
||||
result
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn invoke_simple_event_listeners<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
target: v8::Local<'s, v8::Object>,
|
||||
@@ -217,6 +219,7 @@ fn invoke_simple_event_listeners<'s>(
|
||||
event: v8::Local<'s, v8::Object>,
|
||||
capture: Option<bool>,
|
||||
mut callback_errors: Option<&mut Vec<crate::exception_reporting::V8ExceptionReport>>,
|
||||
handler_override: Option<(&[v8::Local<'s, v8::Value>], EventHandlerType)>,
|
||||
) -> SimpleEventDispatchResult {
|
||||
let mut dispatched = false;
|
||||
let mut did_listeners_throw = false;
|
||||
@@ -260,9 +263,13 @@ fn invoke_simple_event_listeners<'s>(
|
||||
&listener,
|
||||
callback_target.into(),
|
||||
if listener.handler_slot.is_some() {
|
||||
error_arguments
|
||||
.as_ref()
|
||||
.map_or(callback_arguments.as_slice(), |values| values.as_slice())
|
||||
handler_override
|
||||
.map(|(arguments, _)| arguments)
|
||||
.unwrap_or_else(|| {
|
||||
error_arguments
|
||||
.as_ref()
|
||||
.map_or(callback_arguments.as_slice(), |values| values.as_slice())
|
||||
})
|
||||
} else {
|
||||
&callback_arguments
|
||||
},
|
||||
@@ -274,11 +281,18 @@ fn invoke_simple_event_listeners<'s>(
|
||||
if listener.handler_slot.is_some()
|
||||
&& let Some(returned) = outcome.value
|
||||
{
|
||||
apply_handler_return_value(
|
||||
let handler_type = handler_override.map(|(_, kind)| kind).unwrap_or_else(|| {
|
||||
if error_arguments.is_some() {
|
||||
EventHandlerType::OnErrorEventHandler
|
||||
} else {
|
||||
EventHandlerType::EventHandler
|
||||
}
|
||||
});
|
||||
apply_event_handler_return_value(
|
||||
scope,
|
||||
event,
|
||||
v8::Local::new(scope, &returned),
|
||||
error_arguments.is_some(),
|
||||
handler_type,
|
||||
);
|
||||
}
|
||||
set_event_internal_flag(scope, event, EVENT_PASSIVE_SLOT, false);
|
||||
@@ -294,6 +308,41 @@ fn invoke_simple_event_listeners<'s>(
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn invoke_simple_event_target_listeners<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
target: v8::Local<'s, v8::Object>,
|
||||
event_type: &(impl EventTypeKey + ?Sized),
|
||||
event: v8::Local<'s, v8::Object>,
|
||||
filter: crate::host::ListenerFilter,
|
||||
handler_arguments: &[v8::Local<'s, v8::Value>],
|
||||
handler_type: EventHandlerType,
|
||||
callback_errors: Option<&mut Vec<crate::exception_reporting::V8ExceptionReport>>,
|
||||
) -> SimpleEventDispatchResult {
|
||||
let Some(identity) = resolve_event_target(scope, target) else {
|
||||
return SimpleEventDispatchResult::default();
|
||||
};
|
||||
let Some(registry) = SimpleEventListenerRegistry::from_owner(scope, identity.listener_owner)
|
||||
else {
|
||||
return SimpleEventDispatchResult::default();
|
||||
};
|
||||
let capture = match filter {
|
||||
crate::host::ListenerFilter::Capturing => Some(true),
|
||||
crate::host::ListenerFilter::Bubbling => Some(false),
|
||||
crate::host::ListenerFilter::All => None,
|
||||
};
|
||||
invoke_simple_event_listeners(
|
||||
scope,
|
||||
identity.dispatch_target,
|
||||
registry,
|
||||
event_type,
|
||||
event,
|
||||
capture,
|
||||
callback_errors,
|
||||
Some((handler_arguments, handler_type)),
|
||||
)
|
||||
}
|
||||
|
||||
fn finish_event_dispatch<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
event: v8::Local<'s, v8::Object>,
|
||||
@@ -433,17 +482,3 @@ fn invoke_simple_event_callback_with_invocation<'s>(
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn apply_handler_return_value<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
event: v8::Local<'s, v8::Object>,
|
||||
returned: v8::Local<'s, v8::Value>,
|
||||
error_handler: bool,
|
||||
) {
|
||||
let handler_type = if error_handler {
|
||||
EventHandlerType::OnErrorEventHandler
|
||||
} else {
|
||||
EventHandlerType::EventHandler
|
||||
};
|
||||
apply_event_handler_return_value(scope, event, returned, handler_type);
|
||||
}
|
||||
|
||||
+1
@@ -97,6 +97,7 @@ pub(crate) fn dispatch_simple_event_target_event_with_ancestors<'s>(
|
||||
event,
|
||||
Some(capture),
|
||||
None,
|
||||
None,
|
||||
);
|
||||
result.dispatched |= invoked.dispatched;
|
||||
result.did_listeners_throw |= invoked.did_listeners_throw;
|
||||
|
||||
+23
-1
@@ -1,6 +1,9 @@
|
||||
use super::*;
|
||||
#[cfg(test)]
|
||||
use crate::definitions::define_function_accessor_property;
|
||||
use crate::util::{get_private_value, throw_type_error, v8str};
|
||||
#[cfg(test)]
|
||||
use crate::util::v8str;
|
||||
use crate::util::{get_private_value, throw_type_error};
|
||||
|
||||
// These callbacks are shared by declared EventHandler accessors. Their callback
|
||||
// data is the property name, which also identifies the private handler slot.
|
||||
@@ -12,6 +15,15 @@ pub(crate) fn simple_event_target_handler_getter_callback<'s>(
|
||||
let Some((target, property)) = handler_callback_data(scope, &args) else {
|
||||
return;
|
||||
};
|
||||
if let Some(popup_id) =
|
||||
crate::native_bridge::lightweight_popup_id_from_window(scope, target.identity.handler_owner)
|
||||
&& let Some(host_ptr) = crate::util::context_host_ptr_from_global_bridge(scope)
|
||||
{
|
||||
let value = unsafe { &mut *host_ptr }
|
||||
.lightweight_popup_event_handler_property_value(scope, popup_id, &property);
|
||||
rv.set(value.unwrap_or_else(|| v8::null(scope).into()));
|
||||
return;
|
||||
}
|
||||
rv.set(
|
||||
get_private_value(scope, target.identity.handler_owner, &property)
|
||||
.unwrap_or_else(|| v8::null(scope).into()),
|
||||
@@ -26,6 +38,15 @@ pub(crate) fn simple_event_target_handler_setter_callback<'s>(
|
||||
let Some((target, property)) = handler_callback_data(scope, &args) else {
|
||||
return;
|
||||
};
|
||||
if let Some(popup_id) =
|
||||
crate::native_bridge::lightweight_popup_id_from_window(scope, target.identity.handler_owner)
|
||||
&& let Some(host_ptr) = crate::util::context_host_ptr_from_global_bridge(scope)
|
||||
{
|
||||
let handler = v8::Local::<v8::Object>::try_from(args.get(0)).ok();
|
||||
unsafe { &mut *host_ptr }
|
||||
.set_lightweight_popup_event_handler_property(scope, popup_id, &property, handler);
|
||||
return;
|
||||
}
|
||||
simple_object_event_set_handler_in_registry(
|
||||
scope,
|
||||
target.identity.handler_owner,
|
||||
@@ -51,6 +72,7 @@ fn handler_callback_data<'s>(
|
||||
|
||||
/// Install explicit EventHandler accessors on object-backed Window surfaces.
|
||||
/// Ordinary properties with an `on` prefix never become listeners implicitly.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn install_simple_event_target_handlers<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
target: v8::Local<'s, v8::Object>,
|
||||
|
||||
+148
-64
@@ -78,7 +78,7 @@ struct SimpleObjectEventHandlerEntryDeclaration<'scope> {
|
||||
#[webapi(slot = SIMPLE_EVENT_TARGET_HANDLER_SLOT_FIELD)]
|
||||
handler_slot: v8::Local<'scope, v8::String>,
|
||||
#[webapi(slot = SIMPLE_EVENT_TARGET_LISTENER_CALLBACK_SLOT)]
|
||||
callback: v8::Local<'scope, v8::Object>,
|
||||
callback: v8::Local<'scope, v8::Value>,
|
||||
#[webapi(slot = SIMPLE_EVENT_TARGET_LISTENER_RELEVANT_CONTEXT_ANCHOR_SLOT)]
|
||||
relevant_context_anchor: v8::Local<'scope, v8::Object>,
|
||||
#[webapi(slot = SIMPLE_EVENT_TARGET_LISTENER_INCUMBENT_CONTEXT_ANCHOR_SLOT)]
|
||||
@@ -642,70 +642,15 @@ pub(super) fn simple_object_event_set_handler_in_registry<'s>(
|
||||
registry: SimpleEventListenerRegistry<'s>,
|
||||
) {
|
||||
let callback = store_event_handler_value(scope, target, handler_slot_name, value);
|
||||
let active = callback.is_some();
|
||||
let Some(listeners) = simple_object_event_listener_array(scope, registry, event_type, active)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
if let Some(callback) = callback {
|
||||
let (relevant_context_anchor, incumbent_context_anchor, relevant_identity) =
|
||||
simple_callback_context_anchors(scope, callback);
|
||||
for index in 0..listeners.length() {
|
||||
let Some(candidate) = listeners.get_index(scope, index) else {
|
||||
continue;
|
||||
};
|
||||
if simple_object_event_listener_handler_slot(scope, candidate).as_deref()
|
||||
== Some(handler_slot_name)
|
||||
&& handler_belongs_to_target(scope, candidate, target)
|
||||
{
|
||||
if let Ok(entry) = v8::Local::<v8::Object>::try_from(candidate) {
|
||||
set_private_value(
|
||||
scope,
|
||||
entry,
|
||||
SIMPLE_EVENT_TARGET_LISTENER_CALLBACK_SLOT,
|
||||
callback.into(),
|
||||
);
|
||||
let callable = v8::Boolean::new(scope, callback.is_callable());
|
||||
set_private_value(
|
||||
scope,
|
||||
entry,
|
||||
SIMPLE_EVENT_TARGET_LISTENER_CALLABLE_SLOT,
|
||||
callable.into(),
|
||||
);
|
||||
set_private_value(
|
||||
scope,
|
||||
entry,
|
||||
SIMPLE_EVENT_TARGET_LISTENER_RELEVANT_CONTEXT_ANCHOR_SLOT,
|
||||
relevant_context_anchor.into(),
|
||||
);
|
||||
set_private_value(
|
||||
scope,
|
||||
entry,
|
||||
SIMPLE_EVENT_TARGET_LISTENER_INCUMBENT_CONTEXT_ANCHOR_SLOT,
|
||||
incumbent_context_anchor.into(),
|
||||
);
|
||||
capture_simple_listener_initiator(scope, entry);
|
||||
set_simple_object_event_listener_relevant_identity(
|
||||
scope,
|
||||
entry,
|
||||
relevant_identity,
|
||||
);
|
||||
}
|
||||
ensure_simple_object_event_type_order(scope, registry, event_type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
let entry = simple_object_event_handler_entry_object(
|
||||
if callback.is_some() {
|
||||
set_simple_object_event_ordered_handler_callback(
|
||||
scope,
|
||||
target,
|
||||
event_type,
|
||||
handler_slot_name,
|
||||
callback,
|
||||
relevant_context_anchor,
|
||||
incumbent_context_anchor,
|
||||
relevant_identity,
|
||||
registry,
|
||||
);
|
||||
set_private_value(scope, entry, HANDLER_TARGET_SLOT, target.into());
|
||||
let _ = listeners.set_index(scope, listeners.length(), entry.into());
|
||||
ensure_simple_object_event_type_order(scope, registry, event_type);
|
||||
return;
|
||||
}
|
||||
let Some(listeners) = simple_object_event_listener_array(scope, registry, event_type, false)
|
||||
@@ -750,6 +695,145 @@ fn handler_belongs_to_target<'s>(
|
||||
})
|
||||
}
|
||||
|
||||
/// An uncompiled or failed content handler retains its active listener's
|
||||
/// registration position without inventing a callable value for it.
|
||||
pub(crate) fn simple_object_event_activate_uncompiled_handler<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
target: v8::Local<'s, v8::Object>,
|
||||
event_type: &(impl EventTypeKey + ?Sized),
|
||||
handler_slot_name: &str,
|
||||
) {
|
||||
let Some(registry) = simple_object_event_listener_registry(scope, target) else {
|
||||
return;
|
||||
};
|
||||
set_simple_object_event_ordered_handler_callback(
|
||||
scope,
|
||||
target,
|
||||
event_type,
|
||||
handler_slot_name,
|
||||
None,
|
||||
registry,
|
||||
);
|
||||
}
|
||||
|
||||
fn set_simple_object_event_ordered_handler_callback<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
target: v8::Local<'s, v8::Object>,
|
||||
event_type: &(impl EventTypeKey + ?Sized),
|
||||
handler_slot_name: &str,
|
||||
callback: Option<v8::Local<'s, v8::Object>>,
|
||||
registry: SimpleEventListenerRegistry<'s>,
|
||||
) {
|
||||
let Some(listeners) = simple_object_event_listener_array(scope, registry, event_type, true)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let (relevant_context_anchor, incumbent_context_anchor, relevant_identity) =
|
||||
if let Some(callback) = callback {
|
||||
simple_callback_context_anchors(scope, callback)
|
||||
} else {
|
||||
let context = scope.get_current_context();
|
||||
simple_callback_context_anchors_for_contexts(scope, context, context)
|
||||
};
|
||||
let value = callback
|
||||
.map(v8::Local::<v8::Value>::from)
|
||||
.unwrap_or_else(|| v8::null(scope).into());
|
||||
for index in 0..listeners.length() {
|
||||
let Some(candidate) = listeners.get_index(scope, index) else {
|
||||
continue;
|
||||
};
|
||||
if simple_object_event_listener_handler_slot(scope, candidate).as_deref()
|
||||
== Some(handler_slot_name)
|
||||
&& handler_belongs_to_target(scope, candidate, target)
|
||||
{
|
||||
if let Ok(entry) = v8::Local::<v8::Object>::try_from(candidate) {
|
||||
set_private_value(
|
||||
scope,
|
||||
entry,
|
||||
SIMPLE_EVENT_TARGET_LISTENER_CALLBACK_SLOT,
|
||||
value,
|
||||
);
|
||||
let callable =
|
||||
v8::Boolean::new(scope, callback.is_some_and(|value| value.is_callable()));
|
||||
set_private_value(
|
||||
scope,
|
||||
entry,
|
||||
SIMPLE_EVENT_TARGET_LISTENER_CALLABLE_SLOT,
|
||||
callable.into(),
|
||||
);
|
||||
set_private_value(
|
||||
scope,
|
||||
entry,
|
||||
SIMPLE_EVENT_TARGET_LISTENER_RELEVANT_CONTEXT_ANCHOR_SLOT,
|
||||
relevant_context_anchor.into(),
|
||||
);
|
||||
set_private_value(
|
||||
scope,
|
||||
entry,
|
||||
SIMPLE_EVENT_TARGET_LISTENER_INCUMBENT_CONTEXT_ANCHOR_SLOT,
|
||||
incumbent_context_anchor.into(),
|
||||
);
|
||||
set_simple_object_event_listener_relevant_identity(scope, entry, relevant_identity);
|
||||
capture_simple_listener_initiator(scope, entry);
|
||||
}
|
||||
ensure_simple_object_event_type_order(scope, registry, event_type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
let entry = simple_object_event_handler_entry_object(
|
||||
scope,
|
||||
handler_slot_name,
|
||||
callback,
|
||||
relevant_context_anchor,
|
||||
incumbent_context_anchor,
|
||||
relevant_identity,
|
||||
);
|
||||
set_private_value(scope, entry, HANDLER_TARGET_SLOT, target.into());
|
||||
let _ = listeners.set_index(scope, listeners.length(), entry.into());
|
||||
ensure_simple_object_event_type_order(scope, registry, event_type);
|
||||
}
|
||||
|
||||
pub(crate) fn clear_simple_event_target_listeners<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
target: v8::Local<'s, v8::Object>,
|
||||
) {
|
||||
let Some(registry) = simple_object_event_listener_registry(scope, target) else {
|
||||
return;
|
||||
};
|
||||
let Some(types) = registry
|
||||
.0
|
||||
.get_own_property_names(scope, v8::GetPropertyNamesArgs::default())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
// Keep the registry identity shared with active dispatches and calls that
|
||||
// have already resolved their receiver before argument conversion.
|
||||
for index in 0..types.length() {
|
||||
let Some(key) = types.get_index(scope, index) else {
|
||||
continue;
|
||||
};
|
||||
if let Some(listeners) = registry
|
||||
.0
|
||||
.get(scope, key)
|
||||
.and_then(|value| v8::Local::<v8::Array>::try_from(value).ok())
|
||||
{
|
||||
for index in 0..listeners.length() {
|
||||
if let Some(entry) = listeners.get_index(scope, index) {
|
||||
unregister_simple_object_event_listener_abort_algorithm(scope, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
let _ = registry.0.delete(scope, key);
|
||||
}
|
||||
let order = v8::Array::new(scope, 0);
|
||||
set_private_value(
|
||||
scope,
|
||||
registry.0,
|
||||
SIMPLE_EVENT_TARGET_LISTENER_TYPE_ORDER_SLOT,
|
||||
order.into(),
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn simple_object_event_remove_listener_value_for_type<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
target: v8::Local<'s, v8::Object>,
|
||||
@@ -1016,7 +1100,7 @@ fn simple_object_event_listener_entry_object<'s>(
|
||||
fn simple_object_event_handler_entry_object<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
handler_slot_name: &str,
|
||||
callback: v8::Local<'s, v8::Object>,
|
||||
callback: Option<v8::Local<'s, v8::Object>>,
|
||||
relevant_context_anchor: v8::Local<'s, v8::Object>,
|
||||
incumbent_context_anchor: v8::Local<'s, v8::Object>,
|
||||
relevant_identity: Option<WindowExecutionContextIdentity>,
|
||||
@@ -1028,10 +1112,10 @@ fn simple_object_event_handler_entry_object<'s>(
|
||||
let entry = SimpleObjectEventHandlerEntryDeclaration::new(
|
||||
v8_string(scope, &marker),
|
||||
v8_string(scope, handler_slot_name).expect("event handler slot"),
|
||||
callback,
|
||||
value,
|
||||
relevant_context_anchor,
|
||||
incumbent_context_anchor,
|
||||
callback.is_callable(),
|
||||
callback.is_some_and(|value| value.is_callable()),
|
||||
)
|
||||
.bind(scope)
|
||||
.expect("SimpleObject event handler entry declaration should bind");
|
||||
|
||||
@@ -13,6 +13,11 @@ fn require_window_receiver<'s>(
|
||||
if context_host_ptr_from_window_object(scope, args.this()).is_some() {
|
||||
return true;
|
||||
}
|
||||
if window_event_handler_name_from_data(scope, args.data())
|
||||
.is_some_and(|name| crate::native_bridge::element::legacy_lenient_this_event_handler(&name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
webidl::throw_type_error(
|
||||
scope,
|
||||
"Window event handler called on incompatible receiver.",
|
||||
@@ -36,14 +41,18 @@ fn window_event_handler_value<'s>(
|
||||
) -> Option<v8::Local<'s, v8::Value>> {
|
||||
let host_ptr = context_host_ptr_from_window_object(scope, receiver)
|
||||
.or_else(|| context_host_ptr_from_global_bridge(scope))?;
|
||||
let host = unsafe { &*host_ptr };
|
||||
let host = unsafe { &mut *host_ptr };
|
||||
if let Some(popup_id) = crate::native_bridge::lightweight_popup_id_from_window(scope, receiver)
|
||||
{
|
||||
return host.lightweight_popup_event_handler_property_value(scope, popup_id, property_name);
|
||||
}
|
||||
match window_child_context_handle(scope, receiver) {
|
||||
Some(handle) => {
|
||||
host.child_window_event_handler_property_value(scope, handle, property_name)
|
||||
}
|
||||
None => host.registered_event_handler_property_value(
|
||||
None => crate::native_bridge::element::resolve_window_event_handler_content_attribute(
|
||||
scope,
|
||||
EventTargetHandle::Window,
|
||||
host_ptr,
|
||||
property_name.strip_prefix("on").unwrap_or(property_name),
|
||||
),
|
||||
}
|
||||
@@ -60,8 +69,13 @@ fn set_window_event_handler_value<'s>(
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let handler = v8::Local::<v8::Function>::try_from(value).ok();
|
||||
let handler = v8::Local::<v8::Object>::try_from(value).ok();
|
||||
let host = unsafe { &mut *host_ptr };
|
||||
if let Some(popup_id) = crate::native_bridge::lightweight_popup_id_from_window(scope, receiver)
|
||||
{
|
||||
host.set_lightweight_popup_event_handler_property(scope, popup_id, property_name, handler);
|
||||
return;
|
||||
}
|
||||
match window_child_context_handle(scope, receiver) {
|
||||
Some(handle) => {
|
||||
let relevant_context = handler
|
||||
@@ -171,7 +185,7 @@ fn window_event_value_for_receiver<'s>(
|
||||
} else {
|
||||
crate::native_bridge::OwnerDispatchScope::Top
|
||||
};
|
||||
let host = unsafe { &*host_ptr };
|
||||
let host = unsafe { &mut *host_ptr };
|
||||
let owner = host.current_window_execution_context_owner(dispatch_scope)?;
|
||||
let (_, context) = host.window_execution_context(scope, owner, dispatch_scope)?;
|
||||
let global = context.global(scope);
|
||||
@@ -239,15 +253,10 @@ pub(in crate::context_bootstrap) fn window_onerror_getter_function<'s>(
|
||||
if !require_window_receiver(scope, &args) {
|
||||
return;
|
||||
}
|
||||
if window_child_context_handle(scope, args.this()).is_some() {
|
||||
rv.set(
|
||||
window_event_handler_value(scope, args.this(), "onerror")
|
||||
.unwrap_or_else(|| v8::null(scope).into()),
|
||||
);
|
||||
return;
|
||||
}
|
||||
super::error::ensure_window_reflecting_body_onerror_handler(scope);
|
||||
rv.set(window_event_handler_slot_value(scope, WINDOW_ONERROR_SLOT));
|
||||
rv.set(
|
||||
window_event_handler_value(scope, args.this(), "onerror")
|
||||
.unwrap_or_else(|| v8::null(scope).into()),
|
||||
);
|
||||
}
|
||||
|
||||
pub(in crate::context_bootstrap) fn window_onerror_setter_function<'s>(
|
||||
@@ -258,43 +267,10 @@ pub(in crate::context_bootstrap) fn window_onerror_setter_function<'s>(
|
||||
if !require_window_receiver(scope, &args) {
|
||||
return;
|
||||
}
|
||||
if window_child_context_handle(scope, args.this()).is_some() {
|
||||
set_window_event_handler_value(scope, args.this(), "onerror", args.get(0));
|
||||
rv.set_undefined();
|
||||
return;
|
||||
}
|
||||
set_window_body_onerror_handler_compiled(scope, true);
|
||||
set_window_onerror_handler_value(scope, args.get(0));
|
||||
set_window_event_handler_value(scope, args.this(), "onerror", args.get(0));
|
||||
rv.set_undefined();
|
||||
}
|
||||
|
||||
pub(crate) fn set_window_onerror_handler_value(
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
value: v8::Local<'_, v8::Value>,
|
||||
) {
|
||||
set_window_event_handler_slot(scope, WINDOW_ONERROR_SLOT, value);
|
||||
}
|
||||
|
||||
pub(crate) fn window_body_onerror_handler_is_compiled(scope: &mut v8::PinScope<'_, '_>) -> bool {
|
||||
let global = scope.get_current_context().global(scope);
|
||||
get_private_value(scope, global, WINDOW_BODY_ONERROR_COMPILED_SLOT)
|
||||
.is_some_and(|value| value.boolean_value(scope))
|
||||
}
|
||||
|
||||
pub(crate) fn set_window_body_onerror_handler_compiled(
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
compiled: bool,
|
||||
) {
|
||||
let global = scope.get_current_context().global(scope);
|
||||
let compiled = v8::Boolean::new(scope, compiled);
|
||||
set_private_value(
|
||||
scope,
|
||||
global,
|
||||
WINDOW_BODY_ONERROR_COMPILED_SLOT,
|
||||
compiled.into(),
|
||||
);
|
||||
}
|
||||
|
||||
pub(in crate::context_bootstrap) fn window_onunhandledrejection_getter_function<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
args: v8::FunctionCallbackArguments<'s>,
|
||||
@@ -303,17 +279,10 @@ pub(in crate::context_bootstrap) fn window_onunhandledrejection_getter_function<
|
||||
if !require_window_receiver(scope, &args) {
|
||||
return;
|
||||
}
|
||||
if window_child_context_handle(scope, args.this()).is_some() {
|
||||
rv.set(
|
||||
window_event_handler_value(scope, args.this(), "onunhandledrejection")
|
||||
.unwrap_or_else(|| v8::null(scope).into()),
|
||||
);
|
||||
return;
|
||||
}
|
||||
rv.set(window_event_handler_slot_value(
|
||||
scope,
|
||||
WINDOW_ONUNHANDLEDREJECTION_SLOT,
|
||||
));
|
||||
rv.set(
|
||||
window_event_handler_value(scope, args.this(), "onunhandledrejection")
|
||||
.unwrap_or_else(|| v8::null(scope).into()),
|
||||
);
|
||||
}
|
||||
|
||||
pub(in crate::context_bootstrap) fn window_onunhandledrejection_setter_function<'s>(
|
||||
@@ -324,12 +293,7 @@ pub(in crate::context_bootstrap) fn window_onunhandledrejection_setter_function<
|
||||
if !require_window_receiver(scope, &args) {
|
||||
return;
|
||||
}
|
||||
if window_child_context_handle(scope, args.this()).is_some() {
|
||||
set_window_event_handler_value(scope, args.this(), "onunhandledrejection", args.get(0));
|
||||
rv.set_undefined();
|
||||
return;
|
||||
}
|
||||
set_window_event_handler_slot(scope, WINDOW_ONUNHANDLEDREJECTION_SLOT, args.get(0));
|
||||
set_window_event_handler_value(scope, args.this(), "onunhandledrejection", args.get(0));
|
||||
rv.set_undefined();
|
||||
}
|
||||
|
||||
@@ -341,17 +305,10 @@ pub(in crate::context_bootstrap) fn window_onrejectionhandled_getter_function<'s
|
||||
if !require_window_receiver(scope, &args) {
|
||||
return;
|
||||
}
|
||||
if window_child_context_handle(scope, args.this()).is_some() {
|
||||
rv.set(
|
||||
window_event_handler_value(scope, args.this(), "onrejectionhandled")
|
||||
.unwrap_or_else(|| v8::null(scope).into()),
|
||||
);
|
||||
return;
|
||||
}
|
||||
rv.set(window_event_handler_slot_value(
|
||||
scope,
|
||||
WINDOW_ONREJECTIONHANDLED_SLOT,
|
||||
));
|
||||
rv.set(
|
||||
window_event_handler_value(scope, args.this(), "onrejectionhandled")
|
||||
.unwrap_or_else(|| v8::null(scope).into()),
|
||||
);
|
||||
}
|
||||
|
||||
pub(in crate::context_bootstrap) fn window_onrejectionhandled_setter_function<'s>(
|
||||
@@ -362,42 +319,6 @@ pub(in crate::context_bootstrap) fn window_onrejectionhandled_setter_function<'s
|
||||
if !require_window_receiver(scope, &args) {
|
||||
return;
|
||||
}
|
||||
if window_child_context_handle(scope, args.this()).is_some() {
|
||||
set_window_event_handler_value(scope, args.this(), "onrejectionhandled", args.get(0));
|
||||
rv.set_undefined();
|
||||
return;
|
||||
}
|
||||
set_window_event_handler_slot(scope, WINDOW_ONREJECTIONHANDLED_SLOT, args.get(0));
|
||||
set_window_event_handler_value(scope, args.this(), "onrejectionhandled", args.get(0));
|
||||
rv.set_undefined();
|
||||
}
|
||||
|
||||
fn set_window_event_handler_slot(
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
slot_name: &'static str,
|
||||
value: v8::Local<'_, v8::Value>,
|
||||
) {
|
||||
let global = scope.get_current_context().global(scope);
|
||||
let key = v8str(scope, slot_name);
|
||||
|
||||
if value.is_null_or_undefined() {
|
||||
let _ = global.set(scope, key.into(), v8::null(scope).into());
|
||||
return;
|
||||
}
|
||||
|
||||
if value.is_function() {
|
||||
let _ = global.set(scope, key.into(), value);
|
||||
return;
|
||||
}
|
||||
|
||||
let _ = global.set(scope, key.into(), v8::null(scope).into());
|
||||
}
|
||||
|
||||
fn window_event_handler_slot_value<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
slot_name: &'static str,
|
||||
) -> v8::Local<'s, v8::Value> {
|
||||
match global_hidden_value(scope, slot_name) {
|
||||
Some(value) if !value.is_undefined() => value,
|
||||
_ => v8::null(scope).into(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,8 +69,8 @@ pub(crate) fn install_simple_window_event_handlers<'s>(
|
||||
}
|
||||
}
|
||||
|
||||
// The listener registry is discarded when the lightweight Window navigates.
|
||||
// Clear its handler values too, without invoking author-defined property setters.
|
||||
// Reset handler values alongside listener registrations, without invoking
|
||||
// author-defined property setters.
|
||||
pub(crate) fn clear_simple_window_event_handler_values<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
window: v8::Local<'s, v8::Object>,
|
||||
|
||||
@@ -129,4 +129,15 @@ impl DocumentRuntime {
|
||||
self.pending_connected_style_load_prime_result.extend(prime);
|
||||
}
|
||||
}
|
||||
|
||||
fn reset_non_dirty_textarea_selection_after_child_list_change(&mut self, handle: DomHandle) {
|
||||
let should_reset = self
|
||||
.dom_host
|
||||
.node(handle)
|
||||
.and_then(Node::as_element)
|
||||
.is_some_and(|element| element.is_html_textarea() && !element.input_value_dirty());
|
||||
if should_reset {
|
||||
let _ = self.dom_host.set_selection_range(handle, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use super::*;
|
||||
use crate::event_type::{EventType, EventTypeKey};
|
||||
|
||||
/// Native dispatch inputs, captured before selecting a JavaScript realm. The
|
||||
/// event's wrappers are created only when its path has an actual observer.
|
||||
pub(crate) struct NativeEventDispatch<'event> {
|
||||
event_type: &'event str,
|
||||
pub(crate) struct NativeEventDispatch {
|
||||
event_type: EventType,
|
||||
target: EventTargetHandle,
|
||||
original_target: EventTargetHandle,
|
||||
path: Vec<EventTargetHandle>,
|
||||
@@ -20,7 +21,9 @@ impl DocumentRuntime {
|
||||
handle: DomHandle,
|
||||
attribute: &str,
|
||||
) -> EventTargetHandle {
|
||||
if native_bridge::element::is_body_window_event_handler_attribute(attribute)
|
||||
if attribute
|
||||
.strip_prefix("on")
|
||||
.is_some_and(native_bridge::element::body_or_frameset_reflects_window_event_type)
|
||||
&& self.dom_host.owner_document_handle(handle) == Some(self.document_handle())
|
||||
&& self.dom_host.node(handle).is_some_and(|node| {
|
||||
node.is_html_element_named("body") || node.is_html_element_named("frameset")
|
||||
@@ -32,15 +35,15 @@ impl DocumentRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn prepare_native_event_dispatch<'event>(
|
||||
pub(crate) fn prepare_native_event_dispatch(
|
||||
&self,
|
||||
target: EventTargetHandle,
|
||||
original_target: EventTargetHandle,
|
||||
event_type: &'event str,
|
||||
) -> NativeEventDispatch<'event> {
|
||||
event_type: &(impl EventTypeKey + ?Sized),
|
||||
) -> NativeEventDispatch {
|
||||
let (bubbles, cancelable) = host_event_defaults(event_type);
|
||||
NativeEventDispatch {
|
||||
event_type,
|
||||
event_type: event_type.to_event_type(),
|
||||
target,
|
||||
original_target,
|
||||
path: self.build_propagation_path(target, false),
|
||||
@@ -49,20 +52,20 @@ impl DocumentRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn native_event_has_observers(&self, event: &NativeEventDispatch<'_>) -> bool {
|
||||
pub(crate) fn native_event_has_observers(&self, event: &NativeEventDispatch) -> bool {
|
||||
event.path.iter().enumerate().any(|(index, target)| {
|
||||
self.events.has_listener_in_dispatch_path(
|
||||
*target,
|
||||
event.event_type,
|
||||
&event.event_type,
|
||||
index == 0 || event.bubbles,
|
||||
) || (index == 0 || event.bubbles)
|
||||
&& match self
|
||||
.events
|
||||
.event_handler_property_callback_id(*target, event.event_type)
|
||||
.event_handler_property_callback_id(*target, &event.event_type)
|
||||
{
|
||||
Some(callback) => callback.is_some(),
|
||||
None => self
|
||||
.event_handler_content_attribute_node(*target, event.event_type)
|
||||
.event_handler_content_attribute_node(*target, &event.event_type)
|
||||
.is_some(),
|
||||
}
|
||||
})
|
||||
@@ -72,13 +75,16 @@ impl DocumentRuntime {
|
||||
pub(crate) fn event_handler_content_attribute_node(
|
||||
&self,
|
||||
target: EventTargetHandle,
|
||||
event_type: &str,
|
||||
event_type: &(impl EventTypeKey + ?Sized),
|
||||
) -> Option<DomHandle> {
|
||||
let attribute = native_bridge::element::event_handler_content_attribute_name(event_type)?;
|
||||
let attribute =
|
||||
native_bridge::element::event_handler_content_attribute_name(event_type.as_str()?)?;
|
||||
let handle = match target {
|
||||
EventTargetHandle::Node(handle) => handle,
|
||||
EventTargetHandle::Window => {
|
||||
if !native_bridge::element::is_body_window_event_handler_attribute(&attribute) {
|
||||
if !attribute.strip_prefix("on").is_some_and(
|
||||
native_bridge::element::body_or_frameset_reflects_window_event_type,
|
||||
) {
|
||||
return None;
|
||||
}
|
||||
self.dom_host
|
||||
@@ -87,7 +93,7 @@ impl DocumentRuntime {
|
||||
.as_document()?
|
||||
.body_or_frameset_handle(self.dom_host.dom(), self.document_handle())?
|
||||
}
|
||||
EventTargetHandle::ChildWindow(_) => return None,
|
||||
EventTargetHandle::ChildWindow(_) | EventTargetHandle::PopupWindow(_) => return None,
|
||||
};
|
||||
if self.event_handler_attribute_target(handle, &attribute) != target {
|
||||
return None;
|
||||
@@ -95,7 +101,9 @@ impl DocumentRuntime {
|
||||
let element = self.dom_host.node(handle)?.as_element()?;
|
||||
if matches!(target, EventTargetHandle::Node(_))
|
||||
&& (element.is_html_element("body") || element.is_html_element("frameset"))
|
||||
&& native_bridge::element::is_body_window_event_handler_attribute(&attribute)
|
||||
&& attribute
|
||||
.strip_prefix("on")
|
||||
.is_some_and(native_bridge::element::body_or_frameset_reflects_window_event_type)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
@@ -106,25 +114,22 @@ impl DocumentRuntime {
|
||||
&mut self,
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
host_ptr: *mut PageScriptHost,
|
||||
event: NativeEventDispatch<'_>,
|
||||
event: NativeEventDispatch,
|
||||
) -> std::result::Result<(), String> {
|
||||
let wrapper = if event.target == EventTargetHandle::Window {
|
||||
match event.event_type {
|
||||
"pageshow" | "pagehide" => {
|
||||
context_bootstrap::construct_original_page_transition_event(
|
||||
scope,
|
||||
event.event_type,
|
||||
false,
|
||||
)
|
||||
}
|
||||
_ => context_bootstrap::construct_original_event(scope, event.event_type),
|
||||
}
|
||||
let wrapper = if event.target == EventTargetHandle::Window
|
||||
&& matches!(event.event_type.as_str(), Some("pageshow" | "pagehide"))
|
||||
{
|
||||
context_bootstrap::construct_original_page_transition_event(
|
||||
scope,
|
||||
event.event_type.as_str().expect("page transition name"),
|
||||
false,
|
||||
)
|
||||
.ok_or_else(|| format!("failed to construct native {} event", event.event_type))?
|
||||
} else {
|
||||
let target = event_target_value(scope, host_ptr, event.target)?;
|
||||
create_host_event(
|
||||
scope,
|
||||
event.event_type,
|
||||
&event.event_type,
|
||||
target,
|
||||
target,
|
||||
event.bubbles,
|
||||
|
||||
@@ -39,6 +39,9 @@ pub(super) use self::events::{
|
||||
invoke_prepared_event_callback, report_event_callback_exception,
|
||||
report_event_listener_exception,
|
||||
};
|
||||
pub(crate) use self::events::{
|
||||
EventHandlerCspAdmission, EventHandlerPropertyState, ListenerFilter, UncompiledEventHandler,
|
||||
};
|
||||
pub(super) use self::scripts::{
|
||||
CommittedInlineClassicScript, FailedDynamicScript, HostScriptScheduler, ModuleFailurePolicy,
|
||||
PreparedRuntimeScriptStartCommit, QueuedScriptFailureKind, RuntimeScriptAdmission,
|
||||
|
||||
@@ -31,7 +31,7 @@ struct EventListenerEntry {
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
enum ListenerFilter {
|
||||
pub(crate) enum ListenerFilter {
|
||||
Capturing,
|
||||
Bubbling,
|
||||
All,
|
||||
|
||||
@@ -1428,47 +1428,6 @@ impl PageScriptHost {
|
||||
.map(|record| v8::Local::new(scope, &record.window_proxy))
|
||||
}
|
||||
|
||||
pub(crate) fn lightweight_popup_event_handler_property_value<'s>(
|
||||
&self,
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
popup_id: u64,
|
||||
property_name: &str,
|
||||
) -> Option<v8::Local<'s, v8::Value>> {
|
||||
let window = self.lightweight_popup_window(scope, popup_id)?;
|
||||
Some(
|
||||
get_private_value(scope, window, property_name)
|
||||
.filter(|value| value.is_object())
|
||||
.unwrap_or_else(|| v8::null(scope).into()),
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn set_lightweight_popup_event_handler_property<'s>(
|
||||
&mut self,
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
popup_id: u64,
|
||||
property_name: &str,
|
||||
handler: Option<v8::Local<'s, v8::Object>>,
|
||||
) {
|
||||
let Some(window) = self.lightweight_popup_window(scope, popup_id) else {
|
||||
return;
|
||||
};
|
||||
if !is_window_event_handler_property(property_name) {
|
||||
return;
|
||||
};
|
||||
let value = handler
|
||||
.map(v8::Local::<v8::Value>::from)
|
||||
.unwrap_or_else(|| v8::null(scope).into());
|
||||
crate::context_bootstrap::simple_object_event_set_handler(
|
||||
scope,
|
||||
window,
|
||||
property_name
|
||||
.strip_prefix("on")
|
||||
.expect("Window event handler"),
|
||||
property_name,
|
||||
value,
|
||||
);
|
||||
}
|
||||
|
||||
pub(in crate::native_bridge::context_host) fn lightweight_popup_opener_endpoint(
|
||||
&self,
|
||||
popup_id: u64,
|
||||
@@ -3732,26 +3691,23 @@ impl PageScriptHost {
|
||||
};
|
||||
// The DOM dispatcher owns target, phase, path and cleanup. Invoke only
|
||||
// this Window's listener phase without starting a second dispatch.
|
||||
for capture in [true, false] {
|
||||
if !at_target && capture != capture_only {
|
||||
continue;
|
||||
}
|
||||
crate::context_bootstrap::invoke_simple_event_target_listeners(
|
||||
scope,
|
||||
window,
|
||||
event_type,
|
||||
event,
|
||||
capture,
|
||||
handler_arguments,
|
||||
handler_type,
|
||||
None,
|
||||
);
|
||||
if event_dispatch_status(scope, event) != DispatchStatus::Continue
|
||||
|| !self.popup_window_event_target_is_current(target)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
let filter = if at_target {
|
||||
crate::host::ListenerFilter::All
|
||||
} else if capture_only {
|
||||
crate::host::ListenerFilter::Capturing
|
||||
} else {
|
||||
crate::host::ListenerFilter::Bubbling
|
||||
};
|
||||
crate::context_bootstrap::invoke_simple_event_target_listeners(
|
||||
scope,
|
||||
window,
|
||||
event_type,
|
||||
event,
|
||||
filter,
|
||||
handler_arguments,
|
||||
handler_type,
|
||||
None,
|
||||
);
|
||||
self.restore_window_message_source_scope(previous_message_source);
|
||||
restore_lightweight_popup_event_dispatch(scope, previous);
|
||||
if self.popup_window_event_target_is_current(target) {
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
use super::{PageScriptHost, lightweight_popup_id_from_window};
|
||||
use crate::{
|
||||
context_bootstrap::{
|
||||
WINDOW_EVENT_HANDLER_PROPERTIES, clear_simple_event_target_listeners,
|
||||
clear_simple_window_event_handler_values, simple_object_event_activate_uncompiled_handler,
|
||||
simple_object_event_set_handler, window_event_handler_properties,
|
||||
},
|
||||
host::UncompiledEventHandler,
|
||||
native_bridge::OwnerDispatchScope,
|
||||
util::{context_host_ptr_from_global_bridge, get_private_value, set_private_value},
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct PopupWindowContentEventHandlers {
|
||||
next_revision: u64,
|
||||
attributes: HashMap<&'static str, PopupWindowContentEventHandler>,
|
||||
}
|
||||
|
||||
struct PopupWindowContentEventHandler {
|
||||
revision: u64,
|
||||
uncompiled: Option<PopupWindowEventHandlerSource>,
|
||||
}
|
||||
|
||||
struct PopupWindowEventHandlerSource {
|
||||
handler: UncompiledEventHandler,
|
||||
base_url: url::Url,
|
||||
}
|
||||
|
||||
impl PageScriptHost {
|
||||
pub(crate) fn lightweight_popup_event_handler_property_value<'s>(
|
||||
&mut self,
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
popup_id: u64,
|
||||
property_name: &str,
|
||||
) -> Option<v8::Local<'s, v8::Value>> {
|
||||
let window = self.lightweight_popup_window(scope, popup_id)?;
|
||||
let pending = self
|
||||
.lightweight_popup_document_record_mut(popup_id)
|
||||
.and_then(|document| {
|
||||
document
|
||||
.content_event_handlers
|
||||
.attributes
|
||||
.get_mut(property_name)
|
||||
})
|
||||
.and_then(|entry| {
|
||||
entry
|
||||
.uncompiled
|
||||
.take()
|
||||
.map(|source| (source, entry.revision))
|
||||
});
|
||||
let Some((source, revision)) = pending else {
|
||||
return Some(lightweight_popup_event_handler_value(
|
||||
scope,
|
||||
window,
|
||||
property_name,
|
||||
));
|
||||
};
|
||||
let target = self.current_popup_window_event_target(popup_id)?;
|
||||
let property_name = WINDOW_EVENT_HANDLER_PROPERTIES
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|name| *name == property_name)?;
|
||||
if !self.ensure_lightweight_popup_execution_context(scope, popup_id) {
|
||||
return Some(v8::null(scope).into());
|
||||
}
|
||||
let context = window.get_creation_context(scope)?;
|
||||
let handler = {
|
||||
let scope = &mut v8::ContextScope::new(scope, context);
|
||||
let dispatch_scope = OwnerDispatchScope::LightweightPopup(popup_id);
|
||||
let previous = dispatch_scope.enter(scope);
|
||||
// The pending owner's slot is already null, but its listener is
|
||||
// still active. Error reporting may read it or replace it reentrantly.
|
||||
let handler = crate::native_bridge::element::compile_window_event_attribute_handler(
|
||||
scope,
|
||||
self as *mut PageScriptHost,
|
||||
dispatch_scope,
|
||||
&source.base_url,
|
||||
&source.handler,
|
||||
property_name
|
||||
.strip_prefix("on")
|
||||
.expect("Window handler name"),
|
||||
);
|
||||
let still_current = self.popup_window_event_target_is_current(target)
|
||||
&& self
|
||||
.lightweight_popup_document_record(popup_id)
|
||||
.and_then(|document| {
|
||||
document
|
||||
.content_event_handlers
|
||||
.attributes
|
||||
.get(property_name)
|
||||
})
|
||||
.is_some_and(|entry| entry.revision == revision && entry.uncompiled.is_none());
|
||||
let handler = if let Some(handler) = handler.filter(|_| still_current) {
|
||||
self.lightweight_popup_document_record_mut(popup_id)
|
||||
.expect("current popup Document")
|
||||
.content_event_handlers
|
||||
.attributes
|
||||
.remove(property_name);
|
||||
set_lightweight_popup_event_handler_value(
|
||||
scope,
|
||||
window,
|
||||
property_name,
|
||||
handler.into(),
|
||||
);
|
||||
Some(v8::Global::new(scope, handler))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
dispatch_scope.restore(scope, previous);
|
||||
handler
|
||||
};
|
||||
Some(
|
||||
handler
|
||||
.map(|handler| v8::Local::new(scope, &handler).into())
|
||||
.unwrap_or_else(|| v8::null(scope).into()),
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn set_lightweight_popup_event_handler_property<'s>(
|
||||
&mut self,
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
popup_id: u64,
|
||||
property_name: &str,
|
||||
handler: Option<v8::Local<'s, v8::Object>>,
|
||||
) {
|
||||
let Some(window) = self.lightweight_popup_window(scope, popup_id) else {
|
||||
return;
|
||||
};
|
||||
let Some(property_name) =
|
||||
window_event_handler_properties().find(|name| *name == property_name)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
if let Some(document) = self.lightweight_popup_document_record_mut(popup_id) {
|
||||
document
|
||||
.content_event_handlers
|
||||
.attributes
|
||||
.remove(property_name);
|
||||
}
|
||||
let value = handler
|
||||
.map(v8::Local::<v8::Value>::from)
|
||||
.unwrap_or_else(|| v8::null(scope).into());
|
||||
set_lightweight_popup_event_handler_value(scope, window, property_name, value);
|
||||
}
|
||||
|
||||
pub(crate) fn set_lightweight_popup_event_handler_content_attribute<'s>(
|
||||
&mut self,
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
popup_id: u64,
|
||||
event_type: &str,
|
||||
handler: Option<UncompiledEventHandler>,
|
||||
) {
|
||||
let Some(property_name) = WINDOW_EVENT_HANDLER_PROPERTIES
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|name| name.strip_prefix("on") == Some(event_type))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let Some(handler) = handler else {
|
||||
self.set_lightweight_popup_event_handler_property(scope, popup_id, property_name, None);
|
||||
return;
|
||||
};
|
||||
let Some(window) = self.lightweight_popup_window(scope, popup_id) else {
|
||||
return;
|
||||
};
|
||||
let Some(document) = self.lightweight_popup_document_record_mut(popup_id) else {
|
||||
return;
|
||||
};
|
||||
let source = PopupWindowEventHandlerSource {
|
||||
handler,
|
||||
base_url: document.state.base_url.clone(),
|
||||
};
|
||||
let handlers = &mut document.content_event_handlers;
|
||||
handlers.next_revision = handlers
|
||||
.next_revision
|
||||
.checked_add(1)
|
||||
.expect("popup content handler revision exhausted");
|
||||
handlers.attributes.insert(
|
||||
property_name,
|
||||
PopupWindowContentEventHandler {
|
||||
revision: handlers.next_revision,
|
||||
uncompiled: Some(source),
|
||||
},
|
||||
);
|
||||
let null = v8::null(scope).into();
|
||||
set_private_value(scope, window, property_name, null);
|
||||
simple_object_event_activate_uncompiled_handler(scope, window, event_type, property_name);
|
||||
}
|
||||
}
|
||||
|
||||
fn lightweight_popup_event_handler_value<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
window: v8::Local<'s, v8::Object>,
|
||||
property_name: &str,
|
||||
) -> v8::Local<'s, v8::Value> {
|
||||
get_private_value(scope, window, property_name)
|
||||
.filter(|value| value.is_object())
|
||||
.unwrap_or_else(|| v8::null(scope).into())
|
||||
}
|
||||
|
||||
fn set_lightweight_popup_event_handler_value<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
window: v8::Local<'s, v8::Object>,
|
||||
property_name: &'static str,
|
||||
value: v8::Local<'s, v8::Value>,
|
||||
) {
|
||||
simple_object_event_set_handler(
|
||||
scope,
|
||||
window,
|
||||
property_name.strip_prefix("on").expect("Window handler"),
|
||||
property_name,
|
||||
value,
|
||||
);
|
||||
}
|
||||
|
||||
pub(super) fn clear_lightweight_popup_window_document_event_state<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
window: v8::Local<'s, v8::Object>,
|
||||
) {
|
||||
if let Some(popup_id) = lightweight_popup_id_from_window(scope, window)
|
||||
&& let Some(host_ptr) = context_host_ptr_from_global_bridge(scope)
|
||||
&& let Some(document) =
|
||||
unsafe { &mut *host_ptr }.lightweight_popup_document_record_mut(popup_id)
|
||||
{
|
||||
document.content_event_handlers.attributes.clear();
|
||||
}
|
||||
clear_simple_event_target_listeners(scope, window);
|
||||
clear_simple_window_event_handler_values(scope, window);
|
||||
}
|
||||
@@ -281,7 +281,7 @@ impl PageScriptHost {
|
||||
|
||||
pub(crate) fn child_has_isolated_window_proxies(&self, child_handle: DomHandle) -> bool {
|
||||
let Some(store) = self
|
||||
.child_default_context_bootstrap
|
||||
.window_default_context_bootstrap
|
||||
.as_ref()
|
||||
.and_then(|config| config.pending_contexts.upgrade())
|
||||
else {
|
||||
@@ -318,7 +318,7 @@ impl PageScriptHost {
|
||||
return Ok(None);
|
||||
};
|
||||
let Some(store) = self
|
||||
.child_default_context_bootstrap
|
||||
.window_default_context_bootstrap
|
||||
.as_ref()
|
||||
.and_then(|config| config.pending_contexts.upgrade())
|
||||
else {
|
||||
@@ -363,7 +363,7 @@ impl PageScriptHost {
|
||||
.frame_owner_frame_id_for_child_handle(child_handle)
|
||||
.ok_or_else(|| anyhow::anyhow!("reused isolated proxy lost its frame"))?;
|
||||
let store = self
|
||||
.child_default_context_bootstrap
|
||||
.window_default_context_bootstrap
|
||||
.as_ref()
|
||||
.and_then(|config| config.pending_contexts.upgrade())
|
||||
.ok_or_else(|| anyhow::anyhow!("reused isolated proxy lost its bootstrap owner"))?;
|
||||
@@ -401,7 +401,7 @@ impl PageScriptHost {
|
||||
return Ok(0);
|
||||
};
|
||||
let Some(store) = host
|
||||
.child_default_context_bootstrap
|
||||
.window_default_context_bootstrap
|
||||
.as_ref()
|
||||
.and_then(|config| config.pending_contexts.upgrade())
|
||||
else {
|
||||
@@ -455,7 +455,7 @@ impl PageScriptHost {
|
||||
context: v8::Local<'_, v8::Context>,
|
||||
) {
|
||||
let Some(store) = self
|
||||
.child_default_context_bootstrap
|
||||
.window_default_context_bootstrap
|
||||
.as_ref()
|
||||
.and_then(|config| config.pending_contexts.upgrade())
|
||||
else {
|
||||
@@ -487,7 +487,7 @@ impl PageScriptHost {
|
||||
&self,
|
||||
) -> Vec<(RuntimeObservableContextToken, Rc<v8::Weak<v8::Context>>)> {
|
||||
let Some(store) = self
|
||||
.child_default_context_bootstrap
|
||||
.window_default_context_bootstrap
|
||||
.as_ref()
|
||||
.and_then(|config| config.pending_contexts.upgrade())
|
||||
else {
|
||||
@@ -520,7 +520,7 @@ pub(crate) fn remember_isolated_window_context(
|
||||
.window_execution_context_identity_for_access_check(context)
|
||||
.ok_or_else(|| anyhow::anyhow!("isolated Context has no registered Window Realm"))?;
|
||||
let store = unsafe { &*host_ptr }
|
||||
.child_default_context_bootstrap
|
||||
.window_default_context_bootstrap
|
||||
.as_ref()
|
||||
.and_then(|config| config.pending_contexts.upgrade())
|
||||
.ok_or_else(|| anyhow::anyhow!("Window bootstrap owner was retired"))?;
|
||||
@@ -801,7 +801,7 @@ fn ensure_isolated_window_world_member<'s>(
|
||||
access_policy: WindowExecutionContextAccessPolicy,
|
||||
) -> anyhow::Result<v8::Local<'s, v8::Context>> {
|
||||
let config = unsafe { &*host_ptr }
|
||||
.child_default_context_bootstrap
|
||||
.window_default_context_bootstrap
|
||||
.clone()
|
||||
.ok_or_else(|| anyhow::anyhow!("Window bootstrap is unavailable"))?;
|
||||
let store = config
|
||||
|
||||
@@ -49,7 +49,7 @@ impl ScriptVm {
|
||||
.document_runtime
|
||||
.document_subresource_csp_check(&manifest_url, DocumentSubresourceCspKind::Manifest)
|
||||
.into_violations();
|
||||
if enforced_violation.is_some() {
|
||||
if !enforced_violation.is_empty() {
|
||||
return complete_default_app_manifest(&document_url, Some(&manifest_url));
|
||||
}
|
||||
|
||||
|
||||
@@ -285,7 +285,7 @@ fn clone_selected_node(
|
||||
units.len()
|
||||
}
|
||||
.min(units.len());
|
||||
scratch.create_text_node(&String::from_utf16_lossy(&units[start..end.max(start)]))
|
||||
scratch.create_text_node(String::from_utf16_lossy(&units[start..end.max(start)]))
|
||||
} else {
|
||||
// DomHost's native import reuses the DOM clone machinery without
|
||||
// invoking custom-element constructors or Range/Node JS overrides.
|
||||
|
||||
@@ -140,7 +140,7 @@ impl ScriptVm {
|
||||
.iter()
|
||||
.filter(|event| {
|
||||
self.document_runtime
|
||||
.has_event_listener(EventTargetHandle::Node(handle), event)
|
||||
.has_event_listener(EventTargetHandle::Node(handle), **event)
|
||||
})
|
||||
.map(|event| (*event).to_owned())
|
||||
.collect(),
|
||||
|
||||
@@ -135,6 +135,7 @@ impl ScriptVm {
|
||||
from_cache: false,
|
||||
cache_state: Default::default(),
|
||||
negotiated_http_version: None,
|
||||
preload_state: Default::default(),
|
||||
};
|
||||
let info = pending.info.clone();
|
||||
let activity = self.resolve_pending_subresource_fetch_body(
|
||||
|
||||
@@ -12,7 +12,7 @@ fn event_target_interfaces_inherit_canonical_operations() {
|
||||
vm.eval(
|
||||
r#"(() => {
|
||||
const popup = open('about:blank', 'inherited-event-target');
|
||||
try { __eventTargetInheritance.inspect(popup, 'lightweight popup'); }
|
||||
try { __eventTargetInheritance.inspect(popup, 'popup', popup); }
|
||||
finally { popup.close(); }
|
||||
})()"#,
|
||||
)
|
||||
|
||||
@@ -285,7 +285,11 @@ fn font_set_queries_match_unicode_scalars_and_preserve_family_list_order() {
|
||||
#[test]
|
||||
fn font_query_generic_families_do_not_match_named_font_faces() {
|
||||
for generic in ["serif", "sans-serif", "monospace", "system-ui"] {
|
||||
let mut vm = new_storage_test_vm("https://font-matching.test/");
|
||||
let mut completions = RendererResourceCompletionTestHarness::new();
|
||||
let mut vm = new_storage_test_vm_with_completion_sender(
|
||||
"https://font-matching.test/",
|
||||
completions.sender(),
|
||||
);
|
||||
vm.eval(&format!(r#"
|
||||
globalThis.face=new FontFace('{generic}','url(data:font/ttf;base64,AA==)');
|
||||
face.loaded.catch(()=>{{}});document.fonts.add(face);
|
||||
@@ -305,6 +309,7 @@ fn font_query_generic_families_do_not_match_named_font_faces() {
|
||||
);
|
||||
assert_eq!(vm.eval("face.status").unwrap(), "unloaded", "{generic}");
|
||||
vm.eval(&format!(r#"document.fonts.load('16px "{generic}"','A').then(faces=>results.push(faces.length),error=>results.push(error.name))"#)).unwrap();
|
||||
complete_local_font_resources(&mut vm, &mut completions);
|
||||
assert_eq!(
|
||||
vm.eval("JSON.stringify(results)").unwrap(),
|
||||
r#"[0,"NetworkError"]"#
|
||||
@@ -328,7 +333,11 @@ fn font_query_matches_chromium_unicode_case_folding() {
|
||||
("İ", "i\u{0307}", false),
|
||||
("𐐀", "𐐨", false),
|
||||
] {
|
||||
let mut vm = new_storage_test_vm("https://unicode-font-family.test/");
|
||||
let mut completions = RendererResourceCompletionTestHarness::new();
|
||||
let mut vm = new_storage_test_vm_with_completion_sender(
|
||||
"https://unicode-font-family.test/",
|
||||
completions.sender(),
|
||||
);
|
||||
vm.eval(&format!(
|
||||
r#"
|
||||
globalThis.face=new FontFace('{family}','url(data:font/ttf;base64,AA==)');
|
||||
@@ -345,6 +354,7 @@ fn font_query_matches_chromium_unicode_case_folding() {
|
||||
"{family} / {query}"
|
||||
);
|
||||
vm.eval(&format!("document.fonts.load('{font}','A').then(faces=>result.push(faces.length),error=>result.push(error.name))")).unwrap();
|
||||
complete_local_font_resources(&mut vm, &mut completions);
|
||||
assert_eq!(
|
||||
vm.eval("JSON.stringify(result)").unwrap(),
|
||||
if matches {
|
||||
|
||||
@@ -374,6 +374,7 @@ async fn assert_loaded_promise_lifetime(mode: &str) {
|
||||
let execution_context = pending_contexts[0];
|
||||
let retired = mode.contains("retire-");
|
||||
if retired {
|
||||
let resource_owner_id = vm.resource_owner_id;
|
||||
let mut host = vm._context_host.borrow_mut();
|
||||
if mode.ends_with("retire-realm") {
|
||||
host.retire_window_realm_resources(execution_context.realm_token());
|
||||
@@ -382,7 +383,8 @@ async fn assert_loaded_promise_lifetime(mode: &str) {
|
||||
} else if mode.ends_with("retire-context") {
|
||||
assert_eq!(
|
||||
host.retire_window_execution_contexts_for_context_token(
|
||||
execution_context.realm_token()
|
||||
execution_context.realm_token(),
|
||||
Some(resource_owner_id),
|
||||
),
|
||||
1
|
||||
);
|
||||
|
||||
@@ -33,7 +33,7 @@ async fn detached_css_faces_can_be_registered_manually_before_or_after_native_cl
|
||||
crate::protocol_types::OptionalResourceFetchMask::FONT,
|
||||
);
|
||||
}
|
||||
let (mut vm, _completions) =
|
||||
let (mut vm, mut completions) =
|
||||
new_parsed_test_vm_with_loader_and_resource_completion_queue(
|
||||
"https://font-selection-order.test/",
|
||||
"<!doctype html><span id=probe style='display:inline-block;font:40px OrderFace'>AAAA</span>",
|
||||
@@ -45,6 +45,7 @@ async fn detached_css_faces_can_be_registered_manually_before_or_after_native_cl
|
||||
style.textContent='@font-face{{font-family:OrderFace;src:url(data:font/ttf;base64,{wide})}}';document.head.append(style);
|
||||
globalThis.face=[...document.fonts][0];face.load();
|
||||
"#)).unwrap();
|
||||
complete_local_font_resources(&mut vm, &mut completions);
|
||||
assert_eq!(
|
||||
vm.eval("String(probe.getBoundingClientRect().width)")
|
||||
.unwrap(),
|
||||
@@ -77,11 +78,18 @@ async fn detached_css_faces_can_be_registered_manually_before_or_after_native_cl
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn css_faces_with_shared_sources_keep_independent_mutable_descriptors() {
|
||||
#[tokio::test]
|
||||
async fn css_faces_with_shared_sources_keep_independent_mutable_descriptors() {
|
||||
let (_, wide) = order_font_data();
|
||||
for detached in [false, true] {
|
||||
let mut vm = order_vm();
|
||||
let loader = ResourceRequestClient::new(&moli_fetch::FetchConfig::default()).unwrap();
|
||||
let (mut vm, mut completions) =
|
||||
new_parsed_test_vm_with_loader_and_resource_completion_queue(
|
||||
"https://font-selection-order.test/",
|
||||
ORDER_DOCUMENT,
|
||||
&loader,
|
||||
);
|
||||
vm.set_layout_policy(moli_page_types::LayoutPolicy::OnDemand);
|
||||
vm.eval(&format!(r#"
|
||||
globalThis.style=document.createElement('style');
|
||||
const rule='@font-face{{font-family:OrderFace;src:url(data:font/ttf;base64,{wide})}}';
|
||||
@@ -89,6 +97,7 @@ fn css_faces_with_shared_sources_keep_independent_mutable_descriptors() {
|
||||
globalThis.faces=[...document.fonts];document.fonts.load('40px OrderFace','AAAA');
|
||||
globalThis.moved=document.createElement('span');moved.textContent='AAAA';moved.style.cssText='display:inline-block;font:40px Moved';document.body.append(moved);
|
||||
"#)).unwrap();
|
||||
complete_local_font_resources(&mut vm, &mut completions);
|
||||
assert_eq!(
|
||||
vm.eval("String(probe.getBoundingClientRect().width)")
|
||||
.unwrap(),
|
||||
@@ -346,11 +355,18 @@ fn shared_font_faces_have_independent_selection_order_in_each_document() {
|
||||
assert_eq!(widths(&mut vm), "80,160");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_css_font_declarations_keep_registration_until_last_member_leaves() {
|
||||
#[tokio::test]
|
||||
async fn duplicate_css_font_declarations_keep_registration_until_last_member_leaves() {
|
||||
let (_, wide) = order_font_data();
|
||||
for removed in [0, 1] {
|
||||
let mut vm = order_vm();
|
||||
let loader = ResourceRequestClient::new(&moli_fetch::FetchConfig::default()).unwrap();
|
||||
let (mut vm, mut completions) =
|
||||
new_parsed_test_vm_with_loader_and_resource_completion_queue(
|
||||
"https://font-selection-order.test/",
|
||||
ORDER_DOCUMENT,
|
||||
&loader,
|
||||
);
|
||||
vm.set_layout_policy(moli_page_types::LayoutPolicy::OnDemand);
|
||||
vm.eval(&format!(
|
||||
r#"
|
||||
const style=document.createElement('style');
|
||||
@@ -361,6 +377,7 @@ fn duplicate_css_font_declarations_keep_registration_until_last_member_leaves()
|
||||
"#
|
||||
))
|
||||
.unwrap();
|
||||
complete_local_font_resources(&mut vm, &mut completions);
|
||||
assert_eq!(vm.eval("originalFaces.length===2&&originalFaces[0]!==originalFaces[1]&&originalFaces.every(face=>face.status==='loaded')").unwrap(), "true");
|
||||
assert_eq!(
|
||||
vm.eval("String(probe.getBoundingClientRect().width)")
|
||||
|
||||
@@ -195,14 +195,14 @@ fn simple_event_dispatch_observes_registration_identity_and_current_handler() {
|
||||
),
|
||||
(
|
||||
"capture-add",
|
||||
&["before", "after", "original", "replacement"][..],
|
||||
&["before", "after"][..],
|
||||
&["after", "original", "replacement"][..],
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
),
|
||||
(
|
||||
"capture-readd",
|
||||
&["before", "after", "original"][..],
|
||||
&["before", "after"][..],
|
||||
&["after", "original"][..],
|
||||
true,
|
||||
true,
|
||||
|
||||
@@ -128,6 +128,7 @@ __jsonStream.send();
|
||||
from_cache: false,
|
||||
cache_state: Default::default(),
|
||||
negotiated_http_version: None,
|
||||
preload_state: Default::default(),
|
||||
},
|
||||
network_request_headers: None,
|
||||
})
|
||||
|
||||
@@ -4476,10 +4476,7 @@ fn indexed_db_declared_methods_have_webidl_operation_descriptors() {
|
||||
}
|
||||
}
|
||||
for (const [target, name, length] of methods) {
|
||||
const inherited = ["addEventListener", "removeEventListener", "dispatchEvent"].includes(name);
|
||||
if (inherited && (Object.hasOwn(target, name) || target[name] !== EventTarget.prototype[name]))
|
||||
throw new Error(`${name} should be inherited from EventTarget`);
|
||||
const descriptor = Object.getOwnPropertyDescriptor(inherited ? EventTarget.prototype : target, name);
|
||||
const descriptor = Object.getOwnPropertyDescriptor(target, name);
|
||||
if (!descriptor || typeof descriptor.value !== "function") {
|
||||
throw new Error(`${name} should be a declared function`);
|
||||
}
|
||||
|
||||
@@ -37,8 +37,15 @@ fn isolate() -> v8::OwnedIsolate {
|
||||
|
||||
fn run(scope: &mut v8::PinScope<'_, '_>, source: &str, nonce: Option<&str>) -> String {
|
||||
let url = Url::parse("https://example.test/shared-script.js").unwrap();
|
||||
let origin =
|
||||
create_script_origin_with_base_url_and_nonce(scope, url.as_str(), 0, Some(&url), nonce);
|
||||
let mut metadata = crate::module_runtime::ModuleFetchMetadata::default();
|
||||
metadata.request_metadata.nonce = nonce.map(str::to_owned);
|
||||
let origin = create_script_origin_with_base_url_and_fetch_metadata(
|
||||
scope,
|
||||
url.as_str(),
|
||||
0,
|
||||
Some(&url),
|
||||
&metadata,
|
||||
);
|
||||
let source = v8_string(scope, source).unwrap();
|
||||
let script = v8::Script::compile(scope, source, Some(&origin)).unwrap();
|
||||
let result = crate::script_execution::execute_compiled_script(scope, script)
|
||||
|
||||
@@ -125,6 +125,12 @@ impl module_tree::ModuleScriptTreeHost for WorkerModuleTreeHost<'_, '_, '_> {
|
||||
let key = native_key(&source.request_key)?;
|
||||
let native_source = match source.source {
|
||||
module_tree::ModuleSource::Text(text) => WorkerModuleSource::text(text.to_string()),
|
||||
module_tree::ModuleSource::TextWithOrigin { source, origin } => {
|
||||
WorkerModuleSource::TextWithOrigin {
|
||||
source: source.to_string(),
|
||||
origin,
|
||||
}
|
||||
}
|
||||
module_tree::ModuleSource::Binary(bytes) => WorkerModuleSource::binary(bytes.to_vec()),
|
||||
};
|
||||
let entry = create_worker_module_script(
|
||||
@@ -211,6 +217,15 @@ impl module_tree::ModuleScriptTreeHost for WorkerModuleTreeHost<'_, '_, '_> {
|
||||
})
|
||||
}
|
||||
|
||||
fn cache_module_request_error(
|
||||
&mut self,
|
||||
key: module_tree::ModuleMapKey,
|
||||
error: module_tree::ModuleLoadError,
|
||||
) -> module_tree::ModuleLoadError {
|
||||
let entry = self.mark_module_failed(key.clone(), error.clone());
|
||||
error.with_key(key).with_module_entry(entry)
|
||||
}
|
||||
|
||||
fn mark_module_failed(
|
||||
&mut self,
|
||||
key: module_tree::ModuleMapKey,
|
||||
|
||||
@@ -177,7 +177,7 @@ fn expected_synthetic_onerror() -> serde_json::Value {
|
||||
),
|
||||
(
|
||||
"capture",
|
||||
serde_json::json!(["capture", "before", handler, "after"]),
|
||||
serde_json::json!(["before", handler, "after", "capture"]),
|
||||
false,
|
||||
),
|
||||
] {
|
||||
@@ -269,9 +269,6 @@ async fn worker_onerror_native_errors_use_ordered_handlers_and_intrinsic_event_d
|
||||
let actual: serde_json::Value =
|
||||
serde_json::from_str(&expect_post_json(message)).unwrap();
|
||||
let mut trace = Vec::new();
|
||||
if mode == "capture" {
|
||||
trace.push(serde_json::json!("capture"));
|
||||
}
|
||||
trace.push(serde_json::json!("before"));
|
||||
if mode != "stopImmediate" {
|
||||
if matches!(mode, "replace" | "object") {
|
||||
@@ -281,6 +278,9 @@ async fn worker_onerror_native_errors_use_ordered_handlers_and_intrinsic_event_d
|
||||
}
|
||||
trace.push(serde_json::json!({"after":true,"prevented":!matches!(mode,"clear"|"reactivate"),"errorEvent":true,"trusted":true}));
|
||||
}
|
||||
if mode == "capture" {
|
||||
trace.push(serde_json::json!("capture"));
|
||||
}
|
||||
assert_eq!(
|
||||
actual,
|
||||
serde_json::json!({"trace":trace,"ctorCalls":0,"fieldReads":0}),
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
rows.push([label, !!condition]);
|
||||
if (!condition) throw Error(label);
|
||||
};
|
||||
const inspect = (target, label) => {
|
||||
const inspect = (target, label, realm = globalThis) => {
|
||||
const {EventTarget, Event} = realm;
|
||||
check(target instanceof EventTarget, label + ': native inheritance');
|
||||
for (const name of methods) {
|
||||
check(!Object.hasOwn(target, name), label + ': no own ' + name);
|
||||
|
||||
@@ -97,6 +97,48 @@ async function assert_worker_error_prevent_default_suppresses_window() {
|
||||
}
|
||||
}
|
||||
|
||||
async function assert_false_worker_onerror_suppresses_window() {
|
||||
const previousOnerror = window.onerror;
|
||||
let worker = null;
|
||||
let windowErrorCalled = false;
|
||||
let handlerSeen = false;
|
||||
|
||||
try {
|
||||
window.onerror = function () {
|
||||
windowErrorCalled = true;
|
||||
return true;
|
||||
};
|
||||
|
||||
worker = new Worker(worker_error_url());
|
||||
worker.onerror = function () {
|
||||
handlerSeen = true;
|
||||
return false;
|
||||
};
|
||||
|
||||
const listenerDefaultPrevented = await wait_for(
|
||||
new Promise(function (resolve) {
|
||||
worker.addEventListener(
|
||||
"error",
|
||||
function (event) {
|
||||
resolve(event.defaultPrevented);
|
||||
},
|
||||
{ once: true },
|
||||
);
|
||||
}),
|
||||
"worker error listener after false-returning onerror",
|
||||
);
|
||||
|
||||
assert_true(handlerSeen, "worker.onerror should run before the later listener");
|
||||
assert_true(listenerDefaultPrevented, "false-returning worker.onerror should mark the worker error handled");
|
||||
assert_false(windowErrorCalled, "false-returning worker.onerror should suppress window.onerror");
|
||||
} finally {
|
||||
window.onerror = previousOnerror;
|
||||
if (worker) {
|
||||
worker.terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function assert_non_boolean_truthy_worker_onerror_propagates_to_window() {
|
||||
const previousOnerror = window.onerror;
|
||||
let worker = null;
|
||||
@@ -115,7 +157,7 @@ async function assert_non_boolean_truthy_worker_onerror_propagates_to_window() {
|
||||
worker = new Worker(worker_error_url());
|
||||
worker.onerror = function () {
|
||||
handlerSeen = true;
|
||||
return false;
|
||||
return 1;
|
||||
};
|
||||
|
||||
const listenerDefaultPrevented = await wait_for(
|
||||
|
||||
Reference in New Issue
Block a user