Skip to content

armgit / moli

Public Imported from GitHub
0

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

fix(events): expose global touch handlers

ldm04306c48b2464
diff --git a/moli-benchmark/wpt-cross-current/failed-cases.txt b/moli-benchmark/wpt-cross-current/failed-cases.txt
index adccb9740..462b90557 100644
--- a/moli-benchmark/wpt-cross-current/failed-cases.txt
+++ b/moli-benchmark/wpt-cross-current/failed-cases.txt
@@ -3889,7 +3889,6 @@ svg/types/scripted/SVGList-parse-invalid-clears-items.html
svg/types/scripted/SVGMatrix-tentative.html
svg/types/scripted/SVGPoint.html
svg/types/scripted/SVGRect.html
-touch-events/touch-globaleventhandler-interface.html
trusted-types/Document-write-appending-line-feed.html
trusted-types/Document-write.html
trusted-types/Element-setAttribute-respects-Elements-node-documents-globals-CSP-after-adoption-from-TT-realm.html
diff --git a/moli-benchmark/wpt-cross-current/passed-cases.txt b/moli-benchmark/wpt-cross-current/passed-cases.txt
index ba909d7b4..9ce6f0b90 100644
--- a/moli-benchmark/wpt-cross-current/passed-cases.txt
+++ b/moli-benchmark/wpt-cross-current/passed-cases.txt
@@ -7518,6 +7518,7 @@ svg/types/scripted/SVGLengthList-getItem.html
svg/types/scripted/SVGPathElement.getTotalLength-01.html
touch-events/expose-legacy-touch-event-apis.html
touch-events/historical.html
+touch-events/touch-globaleventhandler-interface.html
touch-events/touch-touchevent-constructor.html
trusted-types/DOMParser-parseFromString.html
trusted-types/DedicatedWorker-block-eval-function-constructor.html
diff --git a/moli-renderer-v8/src/context_bootstrap/window_events.rs b/moli-renderer-v8/src/context_bootstrap/window_events.rs
index cc06c72c6..b926a8400 100644
--- a/moli-renderer-v8/src/context_bootstrap/window_events.rs
+++ b/moli-renderer-v8/src/context_bootstrap/window_events.rs
@@ -72,6 +72,10 @@ pub(crate) const WINDOW_EVENT_HANDLER_PROPERTIES: &[&str] = &[
"onsubmit",
"onsuspend",
"ontimeupdate",
+ "ontouchcancel",
+ "ontouchend",
+ "ontouchmove",
+ "ontouchstart",
"onunhandledrejection",
"onunload",
"onvolumechange",
diff --git a/moli-renderer-v8/src/native_bridge/element/event_handlers/generic.rs b/moli-renderer-v8/src/native_bridge/element/event_handlers/generic.rs
index adfd14189..8ca0c6e6d 100644
--- a/moli-renderer-v8/src/native_bridge/element/event_handlers/generic.rs
+++ b/moli-renderer-v8/src/native_bridge/element/event_handlers/generic.rs
@@ -41,6 +41,10 @@ pub(crate) const GENERIC_EVENT_HANDLER_PROPERTIES: &[&str] = &[
"onpointercancel",
"ongotpointercapture",
"onlostpointercapture",
+ "ontouchstart",
+ "ontouchend",
+ "ontouchmove",
+ "ontouchcancel",
"onsubmit",
"onreset",
"onchange",
diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs
index 1314fbb0a..7149fb3af 100644
--- a/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs
+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs
@@ -6500,7 +6500,7 @@ fn zhihu_bot_detection_harness_fixture_matches_stable_moli_baseline() {
assert_eq!(value["screenTouch"]["orientationType"], "landscape-primary");
assert_eq!(value["screenTouch"]["touchType"], "function");
assert_eq!(value["screenTouch"]["touchEventType"], "function");
- assert_eq!(value["screenTouch"]["ontouchstartType"], "undefined");
+ assert_eq!(value["screenTouch"]["ontouchstartType"], "object");
assert_eq!(value["canvasWebgl"]["canvasCtor"], "HTMLCanvasElement");
assert_eq!(value["canvasWebgl"]["canvasTag"], "CANVAS");
diff --git a/moli-renderer-v8/src/script_vm/tests/dom_elements/live_document.rs b/moli-renderer-v8/src/script_vm/tests/dom_elements/live_document.rs
index 51666c8d6..e996e45a0 100644
--- a/moli-renderer-v8/src/script_vm/tests/dom_elements/live_document.rs
+++ b/moli-renderer-v8/src/script_vm/tests/dom_elements/live_document.rs
@@ -4221,6 +4221,56 @@ fn global_drag_event_handlers_cover_window_document_and_elements() {
);
}
+#[test]
+fn global_touch_event_handlers_live_on_mixin_owners() {
+ let mut vm = new_parsed_test_vm(
+ "https://global-touch-event-handlers.test/",
+ "<!doctype html><html><head></head><body></body></html>",
+ );
+
+ let result = vm
+ .eval(
+ r#"
+(() => {
+ const names = ['ontouchstart', 'ontouchend', 'ontouchmove', 'ontouchcancel'];
+ const owners = [window, HTMLElement.prototype, SVGElement.prototype, Document.prototype];
+ const descriptorIsEventHandler = (owner, name) => {
+ const descriptor = Object.getOwnPropertyDescriptor(owner, name);
+ return !!descriptor &&
+ typeof descriptor.get === 'function' &&
+ typeof descriptor.set === 'function' &&
+ descriptor.enumerable && descriptor.configurable;
+ };
+ const ownAccessors = names.every(name =>
+ owners.every(owner => descriptorIsEventHandler(owner, name))
+ );
+ const absentFromElement = names.every(name => !(name in Element.prototype));
+
+ const div = document.createElement('div');
+ const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
+ const calls = [];
+ for (const [label, target] of [
+ ['window', window],
+ ['document', document],
+ ['html', div],
+ ['svg', svg]
+ ]) {
+ target.ontouchstart = event => calls.push(`${label}:${event.type}`);
+ target.dispatchEvent(new Event('touchstart'));
+ }
+
+ return JSON.stringify({ ownAccessors, absentFromElement, calls });
+})()
+"#,
+ )
+ .expect("GlobalEventHandlers touch surface should evaluate");
+
+ assert_eq!(
+ result,
+ r#"{"ownAccessors":true,"absentFromElement":true,"calls":["window:touchstart","document:touchstart","html:touchstart","svg:touchstart"]}"#
+ );
+}
+
#[test]
fn media_accessors_live_on_owner_prototypes() {
let mut vm = new_parsed_test_vm(