Skip to content

armgit / moli

Public Imported from GitHub
0

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

fix(performance): retain ordered worker event handlers

ldm0835c9f602f67
diff --git a/moli-renderer-v8/src/context_bootstrap/performance_runtime/install.rs b/moli-renderer-v8/src/context_bootstrap/performance_runtime/install.rs
index 938af359c..3d1a47415 100644
--- a/moli-renderer-v8/src/context_bootstrap/performance_runtime/install.rs
+++ b/moli-renderer-v8/src/context_bootstrap/performance_runtime/install.rs
@@ -382,6 +382,7 @@ pub(in crate::context_bootstrap) fn install_worker_performance_runtime_state<'s>
PERFORMANCE_EVENT_LISTENERS_SLOT,
false,
);
+ install_simple_event_target_ordered_handlers(scope, performance);
define_global_value(scope, global, WINDOW_PERFORMANCE_SLOT, performance.into())
}
diff --git a/moli-renderer-v8/src/worker/thread/tests/mod.rs b/moli-renderer-v8/src/worker/thread/tests/mod.rs
index b021c5490..f30de5d80 100644
--- a/moli-renderer-v8/src/worker/thread/tests/mod.rs
+++ b/moli-renderer-v8/src/worker/thread/tests/mod.rs
@@ -1545,3 +1545,5 @@ mod canvas_fill_rect;
mod xhr_failure;
mod payment_events;
+
+mod performance_handler_order;
diff --git a/moli-renderer-v8/src/worker/thread/tests/performance_handler_order.rs b/moli-renderer-v8/src/worker/thread/tests/performance_handler_order.rs
new file mode 100644
index 000000000..37e544e29
--- /dev/null
+++ b/moli-renderer-v8/src/worker/thread/tests/performance_handler_order.rs
@@ -0,0 +1,37 @@
+use super::*;
+
+#[tokio::test]
+async fn worker_performance_handlers_keep_their_listener_position_across_replacement() {
+ ensure_v8();
+ for kind in [WorkerScriptKind::Classic, WorkerScriptKind::Module] {
+ let source = r#"
+ const rows = [], target = performance, type = 'resourcetimingbufferfull';
+ target.addEventListener(type, () => rows.push('first'));
+ target.onresourcetimingbufferfull = () => rows.push('handler-one');
+ target.addEventListener(type, () => rows.push('last'));
+ const fire = () => target.dispatchEvent(new Event(type));
+ fire();
+ target.onresourcetimingbufferfull = function(event) {
+ rows.push(this === target && event.currentTarget === target ? 'handler-two' : 'bad receiver');
+ };
+ fire();
+ target.onresourcetimingbufferfull = null;
+ fire();
+ target.onresourcetimingbufferfull = () => rows.push('readded');
+ fire();
+ postMessage(rows);
+ close();
+ "#;
+ let mut handle = spawn_test_worker_with_options(
+ WorkerSpawnOptions::new(
+ source.to_owned(),
+ "https://performance-handler.test/worker.js".to_owned(),
+ )
+ .with_script_kind(kind),
+ );
+ assert_eq!(
+ recv_post_json(&mut handle).await,
+ r#"["first","handler-one","last","first","handler-two","last","first","last","first","last","readded"]"#
+ );
+ }
+}