Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
fix(xhr): order upload startup events and snapshot listeners
ldm0235cdd86ac3e
diff --git a/moli-renderer-v8/src/context_bootstrap.rs b/moli-renderer-v8/src/context_bootstrap.rsindex 85916e183..c646b0c7f 100644--- a/moli-renderer-v8/src/context_bootstrap.rs+++ b/moli-renderer-v8/src/context_bootstrap.rs@@ -322,6 +322,7 @@ pub(crate) use self::media_queries::{simple_event_target_remove_event_listener_callback, simple_event_target_slot_name,simple_object_event_listeners_snapshot, simple_object_event_set_ordered_handler,simple_object_event_target_add_listener, simple_object_event_target_remove_listener,+ simple_object_has_event_listeners,};use self::message_ports::schedule_host_callback;pub(crate) use self::message_ports::{diff --git a/moli-renderer-v8/src/context_bootstrap/media_queries.rs b/moli-renderer-v8/src/context_bootstrap/media_queries.rsindex eae04beb0..52507ef3f 100644--- a/moli-renderer-v8/src/context_bootstrap/media_queries.rs+++ b/moli-renderer-v8/src/context_bootstrap/media_queries.rs@@ -19,6 +19,7 @@ pub(crate) use self::events::{simple_event_target_remove_event_listener_callback, simple_event_target_slot_name,simple_object_event_listeners_snapshot, simple_object_event_set_ordered_handler,simple_object_event_target_add_listener, simple_object_event_target_remove_listener,+ simple_object_has_event_listeners,};pub(super) use self::events::{media_query_list_add_listener_callback, media_query_list_remove_listener_callback,diff --git a/moli-renderer-v8/src/context_bootstrap/media_queries/events.rs b/moli-renderer-v8/src/context_bootstrap/media_queries/events.rsindex 0d8899649..703bbd4fa 100644--- a/moli-renderer-v8/src/context_bootstrap/media_queries/events.rs+++ b/moli-renderer-v8/src/context_bootstrap/media_queries/events.rs@@ -23,5 +23,5 @@ pub(crate) use simple_event_target::{simple_object_event_listeners_snapshot, simple_object_event_remove_listener_value_for_type,simple_object_event_set_ordered_handler, simple_object_event_target_add_listener,simple_object_event_target_register_webidl_listener,- simple_object_event_target_remove_listener,+ simple_object_event_target_remove_listener, simple_object_has_event_listeners,};diff --git a/moli-renderer-v8/src/context_bootstrap/media_queries/events/simple_event_target.rs b/moli-renderer-v8/src/context_bootstrap/media_queries/events/simple_event_target.rsindex 7afbaeec5..9878bbf59 100644--- a/moli-renderer-v8/src/context_bootstrap/media_queries/events/simple_event_target.rs+++ b/moli-renderer-v8/src/context_bootstrap/media_queries/events/simple_event_target.rs@@ -24,6 +24,7 @@ pub(crate) use listeners::{SimpleObjectEventListenerInspectorSnapshot, SimpleObjectEventListenerSnapshot,simple_event_target_inspector_listener_snapshots, simple_object_event_listeners_snapshot,simple_object_event_remove_listener_value_for_type, simple_object_event_set_ordered_handler,+ simple_object_has_event_listeners,};pub(crate) use listeners::{simple_object_event_target_add_listener, simple_object_event_target_register_webidl_listener,diff --git a/moli-renderer-v8/src/context_bootstrap/media_queries/events/simple_event_target/listeners.rs b/moli-renderer-v8/src/context_bootstrap/media_queries/events/simple_event_target/listeners.rsindex 2ccbc364f..b9ae77600 100644--- a/moli-renderer-v8/src/context_bootstrap/media_queries/events/simple_event_target/listeners.rs+++ b/moli-renderer-v8/src/context_bootstrap/media_queries/events/simple_event_target/listeners.rs@@ -499,6 +499,34 @@ pub(crate) fn simple_object_event_listeners_snapshot<'s>(snapshot}+pub(crate) fn simple_object_has_event_listeners<'s>(+ scope: &mut v8::PinScope<'s, '_>,+ target: v8::Local<'s, v8::Object>,+ slot_name: &str,+) -> bool {+ let Some(registry) = simple_object_event_listener_registry(scope, target, slot_name, false)+ else {+ return false;+ };+ let Some(event_types) = simple_object_event_type_order(scope, registry, false) else {+ return false;+ };+ for index in 0..event_types.length() {+ let Some(event_type) = event_types+ .get_index(scope, index)+ .and_then(|value| value.to_string(scope))+ .map(|value| value.to_rust_string_lossy(scope))+ else {+ continue;+ };+ if !simple_object_event_listeners_snapshot(scope, target, slot_name, &event_type).is_empty()+ {+ return true;+ }+ }+ false+}+pub(crate) fn simple_event_target_inspector_listener_snapshots<'s>(scope: &mut v8::PinScope<'s, '_>,target: v8::Local<'s, v8::Object>,diff --git a/moli-renderer-v8/src/network_host.rs b/moli-renderer-v8/src/network_host.rsindex 80a25b4b6..f2c85c135 100644--- a/moli-renderer-v8/src/network_host.rs+++ b/moli-renderer-v8/src/network_host.rs@@ -189,7 +189,7 @@ pub(crate) use self::xhr::{apply_xhr_response_body_source, apply_xhr_response_body_source_with_status_text,apply_xhr_streaming_response_body_source, apply_xhr_streaming_response_chunk,apply_xhr_streaming_response_head, apply_xhr_timeout, convert_xhr_send_body_from_args,- dispatch_xhr_upload_abort_if_in_progress, dispatch_xhr_upload_complete,+ dispatch_xhr_loadstart, dispatch_xhr_upload_abort_if_in_progress, dispatch_xhr_upload_complete,finalize_xml_http_request_event_target_realm_bindings,install_progress_event_template_bindings, install_window_xml_http_request_template_bindings,install_xml_http_request_bindings, install_xml_http_request_event_target_bindings,diff --git a/moli-renderer-v8/src/network_host/xhr.rs b/moli-renderer-v8/src/network_host/xhr.rsindex b2e1dfab8..f87b42166 100644--- a/moli-renderer-v8/src/network_host/xhr.rs+++ b/moli-renderer-v8/src/network_host/xhr.rs@@ -35,6 +35,7 @@ pub(crate) const XHR_ABORTED_SLOT: &str = "__lmXhrAborted";pub(crate) const XHR_ASYNC_SLOT: &str = "__lmXhrAsync";pub(crate) const XHR_SEND_FLAG_SLOT: &str = "__lmXhrSendFlag";pub(crate) const XHR_UPLOAD_IN_PROGRESS_SLOT: &str = "__lmXhrUploadInProgress";+const XHR_UPLOAD_LISTENER_SLOT: &str = "__lmXhrUploadListener";const XHR_PENDING_KIND_SLOT: &str = "__lmXhrPendingKind";const XHR_PENDING_STATUS_SLOT: &str = "__lmXhrPendingStatus";const XHR_PENDING_URL_SLOT: &str = "__lmXhrPendingUrl";@@ -76,8 +77,9 @@ use self::response_type::XmlHttpRequestResponseType;#[cfg(test)]pub(crate) use self::send::prepare_xhr_send_body;pub(crate) use self::send::{- PreparedXhrSendBody, convert_xhr_send_body_from_args, dispatch_xhr_upload_abort_if_in_progress,- dispatch_xhr_upload_complete, xhr_author_request_headers,+ PreparedXhrSendBody, convert_xhr_send_body_from_args, dispatch_xhr_loadstart,+ dispatch_xhr_upload_abort_if_in_progress, dispatch_xhr_upload_complete,+ xhr_author_request_headers,};pub(crate) fn install_progress_event_template_bindings<'s>(diff --git a/moli-renderer-v8/src/network_host/xhr/bindings/open.rs b/moli-renderer-v8/src/network_host/xhr/bindings/open.rsindex a8c88a2ca..00f2c67d9 100644--- a/moli-renderer-v8/src/network_host/xhr/bindings/open.rs+++ b/moli-renderer-v8/src/network_host/xhr/bindings/open.rs@@ -94,6 +94,7 @@ pub(super) fn xhr_open_callback<'s>(set_xhr_state_number(scope, xhr, XHR_PENDING_STATUS_SLOT, 0.0);set_xhr_state_bool(scope, xhr, XHR_ABORTED_SLOT, false);set_xhr_state_bool(scope, xhr, XHR_SEND_FLAG_SLOT, false);+ set_xhr_state_bool(scope, xhr, XHR_UPLOAD_LISTENER_SLOT, false);let empty_response: v8::Local<'_, v8::Value> = v8_string(scope, "").map(|s| s.into()).unwrap_or_else(|| v8::undefined(scope).into());diff --git a/moli-renderer-v8/src/network_host/xhr/events/dispatch.rs b/moli-renderer-v8/src/network_host/xhr/events/dispatch.rsindex be7c04f73..7776e965c 100644--- a/moli-renderer-v8/src/network_host/xhr/events/dispatch.rs+++ b/moli-renderer-v8/src/network_host/xhr/events/dispatch.rs@@ -140,15 +140,17 @@ pub(crate) fn xhr_dispatch_upload_progress_event(loaded: f64,total: f64,) {+ if !xhr_state_bool_property(scope, xhr, XHR_UPLOAD_LISTENER_SLOT).unwrap_or(false) {+ return;+ }let Some(upload) = xhr_upload_object(scope, xhr) else {return;};if !xhr_has_event_observers(scope, upload, event_type) {return;}- // Upload dispatch always knows the request body length, including zero-byte bodies.let event =- super::progress::make_progress_event(scope, event_type, upload, true, loaded, total);+ super::progress::make_progress_event(scope, event_type, upload, total > 0.0, loaded, total);let handler_name = format!("on{event_type}");xhr_invoke_handler(scope, upload, &handler_name, event);}diff --git a/moli-renderer-v8/src/network_host/xhr/instance_state.rs b/moli-renderer-v8/src/network_host/xhr/instance_state.rsindex 2dbed91d3..02f988957 100644--- a/moli-renderer-v8/src/network_host/xhr/instance_state.rs+++ b/moli-renderer-v8/src/network_host/xhr/instance_state.rs@@ -83,6 +83,8 @@ struct XmlHttpRequestStateDeclaration {send_flag: (),#[webapi(slot = XHR_UPLOAD_IN_PROGRESS_SLOT, init = false)]upload_in_progress: (),+ #[webapi(slot = XHR_UPLOAD_LISTENER_SLOT, init = false)]+ upload_listener: (),#[webapi(slot = XHR_ACTIVE_INTERNAL_ID_SLOT, init = 0)]active_internal_id: (),#[webapi(slot = XHR_PENDING_STATUS_SLOT, init = 0)]diff --git a/moli-renderer-v8/src/network_host/xhr/send.rs b/moli-renderer-v8/src/network_host/xhr/send.rsindex 04cc88d45..174bf75e8 100644--- a/moli-renderer-v8/src/network_host/xhr/send.rs+++ b/moli-renderer-v8/src/network_host/xhr/send.rs@@ -105,11 +105,10 @@ pub(super) fn xhr_send_callback<'s>(let open_generation =xhr_state_number_property(scope, xhr, XHR_OPEN_GENERATION_SLOT).unwrap_or(0.0);if async_request {- dispatch_xhr_upload_complete(scope, xhr, prepared.send_body.as_deref());- if xhr_is_aborted(scope, xhr) || xhr_open_generation_changed(scope, xhr, open_generation) {+ if !dispatch_xhr_loadstart(scope, xhr, prepared.send_body.as_deref()) {return;}- xhr_dispatch_progress_event(scope, xhr, "loadstart", 0.0, 0.0);+ dispatch_xhr_upload_complete(scope, xhr, prepared.send_body.as_deref());if xhr_is_aborted(scope, xhr) || xhr_open_generation_changed(scope, xhr, open_generation) {return;}@@ -251,6 +250,33 @@ fn xhr_open_generation_changed(.is_some_and(|current| current != expected)}+pub(crate) fn dispatch_xhr_loadstart(+ scope: &mut v8::PinScope<'_, '_>,+ xhr: v8::Local<'_, v8::Object>,+ send_body: Option<&[u8]>,+) -> bool {+ let open_generation =+ xhr_state_number_property(scope, xhr, XHR_OPEN_GENERATION_SLOT).unwrap_or(0.0);+ // The XHR loadstart listener can abort before upload.loadstart runs.+ let has_upload_listeners = xhr_upload_object(scope, xhr).is_some_and(|upload| {+ crate::context_bootstrap::simple_object_has_event_listeners(+ scope,+ upload,+ XHR_SIMPLE_EVENT_TARGET_LISTENERS_SLOT,+ )+ });+ set_xhr_state_bool(scope, xhr, XHR_UPLOAD_LISTENER_SLOT, has_upload_listeners);+ set_xhr_state_bool(scope, xhr, XHR_UPLOAD_IN_PROGRESS_SLOT, send_body.is_some());+ xhr_dispatch_progress_event(scope, xhr, "loadstart", 0.0, 0.0);+ if xhr_is_aborted(scope, xhr) || xhr_open_generation_changed(scope, xhr, open_generation) {+ return false;+ }+ if let Some(send_body) = send_body {+ xhr_dispatch_upload_progress_event(scope, xhr, "loadstart", 0.0, send_body.len() as f64);+ }+ !xhr_is_aborted(scope, xhr) && !xhr_open_generation_changed(scope, xhr, open_generation)+}+pub(crate) fn dispatch_xhr_upload_complete(scope: &mut v8::PinScope<'_, '_>,xhr: v8::Local<'_, v8::Object>,@@ -260,8 +286,7 @@ pub(crate) fn dispatch_xhr_upload_complete(return;};let total = send_body.len() as f64;- set_xhr_state_bool(scope, xhr, XHR_UPLOAD_IN_PROGRESS_SLOT, true);- for event_type in ["loadstart", "progress", "load", "loadend"] {+ for event_type in ["progress", "load", "loadend"] {if xhr_is_aborted(scope, xhr) {set_xhr_state_bool(scope, xhr, XHR_UPLOAD_IN_PROGRESS_SLOT, false);return;diff --git a/moli-renderer-v8/src/script_vm/tests/dom_xhr/xhr.rs b/moli-renderer-v8/src/script_vm/tests/dom_xhr/xhr.rsindex 3d0d5a593..11b4e4c27 100644--- a/moli-renderer-v8/src/script_vm/tests/dom_xhr/xhr.rs+++ b/moli-renderer-v8/src/script_vm/tests/dom_xhr/xhr.rs@@ -3754,3 +3754,123 @@ fn xhr_response_documents_keep_distinct_source_modification_times() {}}}++#[test]+fn xml_http_request_loadstart_orders_upload_events_and_handles_abort() {+ let mut vm = new_storage_test_vm("https://xhr-upload-start.test/");+ let result = vm+ .eval(+ r#"+JSON.stringify(["xhr", "upload", "empty"].map(abortAt => {+ const xhr = new XMLHttpRequest();+ const events = [];+ xhr.onloadstart = event => {+ events.push(`xhr-start:${event.loaded}:${event.total}:${event.lengthComputable}`);+ if (abortAt === "xhr") xhr.abort();+ };+ xhr.upload.onloadstart = event => {+ events.push(`upload-start:${event.loaded}:${event.total}:${event.lengthComputable}`);+ if (abortAt !== "xhr") xhr.abort();+ };+ for (const type of ["progress", "load", "abort", "loadend"]) {+ xhr.upload.addEventListener(type, event => events.push(+ `upload-${type}:${xhr.readyState}:${event.loaded}:${event.total}:${event.lengthComputable}`));+ }+ xhr.onabort = () => events.push(`xhr-abort:${xhr.readyState}`);+ xhr.onloadend = () => events.push(`xhr-loadend:${xhr.readyState}`);+ xhr.open("POST", "/unused");+ xhr.send(abortAt === "empty" ? "" : "é");+ events.push(`after-send:${xhr.readyState}:${xhr.status}`);+ return events;+}))+"#,+ )+ .expect("abort during either loadstart should end the pending upload");+ assert_eq!(+ result,+ r#"[["xhr-start:0:0:false","upload-abort:4:0:0:false","upload-loadend:4:0:0:false","xhr-abort:4","xhr-loadend:4","after-send:0:0"],["xhr-start:0:0:false","upload-start:0:2:true","upload-abort:4:0:0:false","upload-loadend:4:0:0:false","xhr-abort:4","xhr-loadend:4","after-send:0:0"],["xhr-start:0:0:false","upload-start:0:0:false","upload-abort:4:0:0:false","upload-loadend:4:0:0:false","xhr-abort:4","xhr-loadend:4","after-send:0:0"]]"#+ );+}++#[test]+fn xml_http_request_upload_listener_flag_is_captured_before_loadstart() {+ let mut vm = new_storage_test_vm("https://xhr-upload-listeners.test/");+ let result = vm+ .eval(+ r#"+["none", "removed", "cleared", "signal", "custom", "handler", "getter"].map(mode => {+ const xhr = new XMLHttpRequest();+ const upload = xhr.upload;+ const listener = () => {};+ const events = [];+ if (mode === "removed") {+ upload.addEventListener("custom", listener);+ upload.removeEventListener("custom", listener);+ } else if (mode === "cleared") {+ upload.onprogress = listener;+ upload.onprogress = null;+ } else if (mode === "signal") {+ const controller = new AbortController();+ upload.addEventListener("custom", listener, {signal: controller.signal});+ controller.abort();+ } else if (mode === "custom") {+ upload.addEventListener("custom", {handleEvent() {}});+ } else if (mode === "handler") {+ upload.onprogress = listener;+ } else if (mode === "getter") {+ Object.defineProperty(upload, "onprogress", {get() {throw new Error("public handler read");}});+ }+ xhr.onloadstart = () => {+ upload.onloadstart = event => {+ events.push(`${event.loaded}:${event.total}`);+ xhr.abort();+ };+ };+ xhr.open("POST", "/unused");+ xhr.send("é");+ xhr.abort();+ return `${mode}:${events.join()}`;+}).join("|")+"#,+ )+ .expect("only listeners registered before send should enable upload events");+ assert_eq!(+ result,+ "none:|removed:|cleared:|signal:|custom:0:2|handler:0:2|getter:"+ );+}++#[test]+fn xml_http_request_upload_loadstart_preserves_reopened_request() {+ let mut vm = new_storage_test_vm("https://xhr-upload-reopen.test/");+ vm.eval(+ r#"+(() => {+ const xhr = new XMLHttpRequest();+ const events = globalThis.__xhrUploadReopenEvents = [];+ xhr.onloadstart = () => events.push(`xhr-start:${xhr.readyState}`);+ xhr.upload.onloadstart = event => {+ events.push(`upload-start:${event.loaded}:${event.total}`);+ xhr.open("GET", "data:text/plain,replacement");+ xhr.send();+ events.push(`after-reopen:${xhr.readyState}`);+ };+ for (const type of ["progress", "load", "abort", "loadend"]) {+ xhr.upload.addEventListener(type, () => events.push(`unexpected-upload-${type}`));+ }+ xhr.onload = () => events.push(`load:${xhr.responseText}`);+ xhr.onloadend = () => events.push(`loadend:${xhr.readyState}`);+ xhr.open("POST", "/unused");+ xhr.send("é");+})()+"#,+ )+ .expect("upload loadstart should be able to reopen and send another request");+ vm.eval("0")+ .expect("replacement request should complete at the following checkpoint");+ assert_eq!(+ vm.eval("__xhrUploadReopenEvents.join('|')")+ .expect("replacement request event trace"),+ "xhr-start:1|upload-start:0:2|xhr-start:1|after-reopen:1|load:replacement|loadend:4"+ );+}diff --git a/moli-renderer-v8/src/worker/global_scope/mod.rs b/moli-renderer-v8/src/worker/global_scope/mod.rsindex ae1ee0abc..290e3833a 100644--- a/moli-renderer-v8/src/worker/global_scope/mod.rs+++ b/moli-renderer-v8/src/worker/global_scope/mod.rs@@ -68,7 +68,7 @@ use crate::network_host::{build_fetch_response_object_from_body_source_for_request_mode,build_fetch_response_object_from_stream_for_request_mode,build_fetch_response_object_from_subresource_body_for_request_mode,- close_pending_network_body_stream, convert_xhr_send_body_from_args,+ close_pending_network_body_stream, convert_xhr_send_body_from_args, dispatch_xhr_loadstart,dispatch_xhr_upload_abort_if_in_progress, dispatch_xhr_upload_complete,enqueue_pending_network_body_chunk, error_pending_network_body_stream_with_reason,extract_subresource_auth_challenge,diff --git a/moli-renderer-v8/src/worker/global_scope/xhr.rs b/moli-renderer-v8/src/worker/global_scope/xhr.rsindex 53710ce10..5ad0faf54 100644--- a/moli-renderer-v8/src/worker/global_scope/xhr.rs+++ b/moli-renderer-v8/src/worker/global_scope/xhr.rs@@ -331,13 +331,10 @@ pub(crate) fn try_worker_xhr_send_callback<'s>(let request_url = prepared.resolved_url.to_string();if async_request {- dispatch_xhr_upload_complete(scope, xhr, prepared.send_body.as_deref());- if xhr_state_bool_property(scope, xhr, XHR_ABORTED_SLOT).unwrap_or(false)- || worker_xhr_open_generation_changed(scope, xhr, open_generation)- {+ if !dispatch_xhr_loadstart(scope, xhr, prepared.send_body.as_deref()) {return true;}- xhr_dispatch_progress_event(scope, xhr, "loadstart", 0.0, 0.0);+ dispatch_xhr_upload_complete(scope, xhr, prepared.send_body.as_deref());if xhr_state_bool_property(scope, xhr, XHR_ABORTED_SLOT).unwrap_or(false)|| worker_xhr_open_generation_changed(scope, xhr, open_generation){diff --git a/moli-renderer-v8/src/worker/thread/tests/lifecycle/background_apis_and_worker_events.rs b/moli-renderer-v8/src/worker/thread/tests/lifecycle/background_apis_and_worker_events.rsindex 70cfee802..430000024 100644--- a/moli-renderer-v8/src/worker/thread/tests/lifecycle/background_apis_and_worker_events.rs+++ b/moli-renderer-v8/src/worker/thread/tests/lifecycle/background_apis_and_worker_events.rs@@ -1724,3 +1724,63 @@ async fn worker_message_port_listener_errors_use_worker_error_reporting() {.expect("channel closed");assert_eq!(expect_post_json(msg), r#"{"isMessagePortError":true}"#);}++#[tokio::test]+async fn worker_xmlhttprequest_loadstart_handles_upload_abort_and_reopen() {+ ensure_v8();+ let mut handle = spawn_worker(+ r#"+ (() => {+ const aborted = ["xhr", "upload", "empty"].map(abortAt => {+ const xhr = new XMLHttpRequest();+ const events = [];+ xhr.onloadstart = event => {+ events.push(`xhr-start:${event.loaded}:${event.total}:${event.lengthComputable}`);+ if (abortAt === "xhr") xhr.abort();+ };+ xhr.upload.onloadstart = event => {+ events.push(`upload-start:${event.loaded}:${event.total}:${event.lengthComputable}`);+ if (abortAt !== "xhr") xhr.abort();+ };+ for (const type of ["progress", "load", "abort", "loadend"]) {+ xhr.upload.addEventListener(type, event => events.push(+ `upload-${type}:${xhr.readyState}:${event.loaded}:${event.total}:${event.lengthComputable}`));+ }+ xhr.onabort = () => events.push(`xhr-abort:${xhr.readyState}`);+ xhr.onloadend = () => events.push(`xhr-loadend:${xhr.readyState}`);+ xhr.open("POST", "/unused");+ xhr.send(abortAt === "empty" ? "" : "é");+ events.push(`after-send:${xhr.readyState}:${xhr.status}`);+ return events;+ });++ const xhr = new XMLHttpRequest();+ const reopened = [];+ xhr.onloadstart = () => reopened.push(`xhr-start:${xhr.readyState}`);+ xhr.upload.onloadstart = event => {+ reopened.push(`upload-start:${event.loaded}:${event.total}`);+ xhr.open("GET", "data:text/plain,replacement");+ xhr.send();+ reopened.push(`after-reopen:${xhr.readyState}`);+ };+ for (const type of ["progress", "load", "abort", "loadend"]) {+ xhr.upload.addEventListener(type, () => reopened.push(`unexpected-upload-${type}`));+ }+ xhr.onload = () => reopened.push(`load:${xhr.responseText}`);+ xhr.onloadend = () => {+ reopened.push(`loadend:${xhr.readyState}`);+ postMessage({ aborted, reopened });+ close();+ };+ xhr.open("POST", "/unused");+ xhr.send("é");+ })();+ "#+ .into(),+ "https://worker-xhr-upload-start.test/main.js".into(),+ );+ assert_eq!(+ recv_post_json(&mut handle).await,+ r#"{"aborted":[["xhr-start:0:0:false","upload-abort:4:0:0:false","upload-loadend:4:0:0:false","xhr-abort:4","xhr-loadend:4","after-send:0:0"],["xhr-start:0:0:false","upload-start:0:2:true","upload-abort:4:0:0:false","upload-loadend:4:0:0:false","xhr-abort:4","xhr-loadend:4","after-send:0:0"],["xhr-start:0:0:false","upload-start:0:0:false","upload-abort:4:0:0:false","upload-loadend:4:0:0:false","xhr-abort:4","xhr-loadend:4","after-send:0:0"]],"reopened":["xhr-start:1","upload-start:0:2","xhr-start:1","after-reopen:1","load:replacement","loadend:4"]}"#+ );+}diff --git a/moli-renderer-v8/src/worker/thread/tests/network/file_and_xhr.rs b/moli-renderer-v8/src/worker/thread/tests/network/file_and_xhr.rsindex abc35a594..39329ef5c 100644--- a/moli-renderer-v8/src/worker/thread/tests/network/file_and_xhr.rs+++ b/moli-renderer-v8/src/worker/thread/tests/network/file_and_xhr.rs@@ -1015,6 +1015,7 @@ async fn worker_xmlhttprequest_upload_dispatches_completion_events() {const payload = "upload=alpha&count=2";const uploadEvents = [];const uploadOrder = [];+ xhr.onloadstart = () => uploadOrder.push("xhr:loadstart");["loadstart", "progress", "load", "loadend"].forEach((type) => {xhr.upload.addEventListener(type, (event) => {uploadOrder.push(`listener-before:${event.type}`);@@ -1059,7 +1060,7 @@ async fn worker_xmlhttprequest_upload_dispatches_completion_events() {.expect("channel closed");assert_eq!(expect_post_json(msg),- r#"{"status":200,"response":"{\"ok\":true}","uploadEvents":["loadstart:true:true:true:20:20","progress:true:true:true:20:20","load:true:true:true:20:20","loadend:true:true:true:20:20"],"uploadOrder":["listener-before:loadstart","handler:loadstart","listener-after:loadstart","listener-before:progress","handler:progress","listener-after:progress","listener-before:load","handler:load","listener-after:load","listener-before:loadend","handler:loadend","listener-after:loadend"]}"#+ r#"{"status":200,"response":"{\"ok\":true}","uploadEvents":["loadstart:true:true:true:0:20","progress:true:true:true:20:20","load:true:true:true:20:20","loadend:true:true:true:20:20"],"uploadOrder":["xhr:loadstart","listener-before:loadstart","handler:loadstart","listener-after:loadstart","listener-before:progress","handler:progress","listener-after:progress","listener-before:load","handler:load","listener-after:load","listener-before:loadend","handler:loadend","listener-after:loadend"]}"#);server.awaitdiff --git a/moli-wpt-compat/fixtures/wpt/ported/worker/worker-xhr-upload-basic.html b/moli-wpt-compat/fixtures/wpt/ported/worker/worker-xhr-upload-basic.htmlindex dd70d7490..3789d42c5 100644--- a/moli-wpt-compat/fixtures/wpt/ported/worker/worker-xhr-upload-basic.html+++ b/moli-wpt-compat/fixtures/wpt/ported/worker/worker-xhr-upload-basic.html@@ -10,7 +10,7 @@ function byteLength(value) {function uploadCompletionEvents(size) {return [- `loadstart:true:true:true:${size}:${size}`,+ `loadstart:true:true:true:0:${size}`,`progress:true:true:true:${size}:${size}`,`load:true:true:true:${size}:${size}`,`loadend:true:true:true:${size}:${size}`,@@ -69,7 +69,7 @@ promise_test(async function () {assert_array_equals(result.uploadEvents,[- "loadstart:true:true:true:20:20",+ "loadstart:true:true:true:0:20","progress:true:true:true:20:20","load:true:true:true:20:20","loadend:true:true:true:20:20",@@ -164,10 +164,10 @@ promise_test(async function () {assert_array_equals(result.uploadEvents,[- "loadstart:true:true:true:0:0",- "progress:true:true:true:0:0",- "load:true:true:true:0:0",- "loadend:true:true:true:0:0",+ "loadstart:true:true:false:0:0",+ "progress:true:true:false:0:0",+ "load:true:true:false:0:0",+ "loadend:true:true:false:0:0",],"worker XHR send(\"\") should dispatch upload completion events with zero-byte totals",);@@ -180,9 +180,9 @@ promise_test(async function () {assert_array_equals(result.uploadEvents,[- "loadstart:true:true:true:12:12",- "abort:true:true:true:0:0",- "loadend:true:true:true:0:0",+ "loadstart:true:true:true:0:12",+ "abort:true:true:false:0:0",+ "loadend:true:true:false:0:0",],"worker XHR upload abort should stop completion progress and emit upload abort/loadend",);@@ -215,10 +215,10 @@ promise_test(async function () {assert_array_equals(result.uploadEvents,[- "loadstart:true:true:true:12:12",+ "loadstart:true:true:true:0:12","progress:true:true:true:12:12",- "abort:true:true:true:0:0",- "loadend:true:true:true:0:0",+ "abort:true:true:false:0:0",+ "loadend:true:true:false:0:0",],"worker XHR upload abort from progress should stop completion and emit upload abort/loadend",);diff --git a/moli-wpt-compat/fixtures/wpt/ported/xhr/xmlhttprequest-upload-basic.html b/moli-wpt-compat/fixtures/wpt/ported/xhr/xmlhttprequest-upload-basic.htmlindex 345e63d9e..2fa7b0f81 100644--- a/moli-wpt-compat/fixtures/wpt/ported/xhr/xmlhttprequest-upload-basic.html+++ b/moli-wpt-compat/fixtures/wpt/ported/xhr/xmlhttprequest-upload-basic.html@@ -12,7 +12,7 @@ function byteLength(value) {function uploadCompletionEvents(size) {return [- `loadstart:true:true:true:${size}:${size}`,+ `loadstart:true:true:true:0:${size}`,`progress:true:true:true:${size}:${size}`,`load:true:true:true:${size}:${size}`,`loadend:true:true:true:${size}:${size}`,@@ -136,7 +136,7 @@ promise_test(async function () {assert_array_equals(result.uploadEvents,[- "loadstart:true:true:true:20:20",+ "loadstart:true:true:true:0:20","progress:true:true:true:20:20","load:true:true:true:20:20","loadend:true:true:true:20:20",@@ -234,10 +234,10 @@ promise_test(async function () {assert_array_equals(result.uploadEvents,[- "loadstart:true:true:true:0:0",- "progress:true:true:true:0:0",- "load:true:true:true:0:0",- "loadend:true:true:true:0:0",+ "loadstart:true:true:false:0:0",+ "progress:true:true:false:0:0",+ "load:true:true:false:0:0",+ "loadend:true:true:false:0:0",],"send(\"\") should dispatch upload completion events with zero-byte totals",);@@ -252,9 +252,9 @@ promise_test(async function () {assert_array_equals(result.uploadEvents,[- "loadstart:true:true:true:12:12",- "abort:true:true:true:0:0",- "loadend:true:true:true:0:0",+ "loadstart:true:true:true:0:12",+ "abort:true:true:false:0:0",+ "loadend:true:true:false:0:0",],"aborting from upload loadstart should stop upload completion and emit upload abort/loadend",);@@ -273,10 +273,10 @@ promise_test(async function () {assert_array_equals(result.uploadEvents,[- "loadstart:true:true:true:12:12",+ "loadstart:true:true:true:0:12","progress:true:true:true:12:12",- "abort:true:true:true:0:0",- "loadend:true:true:true:0:0",+ "abort:true:true:false:0:0",+ "loadend:true:true:false:0:0",],"aborting from upload progress should stop upload completion and emit upload abort/loadend",);