Fix NetworkInformation event listeners

This commit is contained in:
SGavrl committed 2026-07-22 10:29:51 +00:00
1 parent 730bd01f57
commit fc9f5248f7
2 files changed
+24 -2

No files matched your search

+1
View File
@@ -3108,6 +3108,7 @@ _markNative(MimeTypeArray.prototype.item);
_markNative(MimeTypeArray.prototype.namedItem); _markNative(MimeTypeArray.prototype.namedItem);
class NetworkInformation { class NetworkInformation {
constructor() { _makeListenerBox(this); }
get downlink() { return 10; } get downlink() { return 10; }
get downlinkMax() { return Infinity; } get downlinkMax() { return Infinity; }
get effectiveType() { return '4g'; } get effectiveType() { return '4g'; }
+23 -2
View File
@@ -2689,14 +2689,35 @@ mod tests {
let result = rt let result = rt
.evaluate( .evaluate(
r#" r#"
const connection = navigator.connection;
let calls = 0;
let receiverMatches = false;
function listener(event) {
calls += 1;
receiverMatches = this === connection && event.type === 'change';
}
connection.addEventListener('change', listener);
const dispatchResult = connection.dispatchEvent(new Event('change'));
connection.removeEventListener('change', listener);
connection.dispatchEvent(new Event('change'));
return [ return [
typeof navigator.connection.addEventListener, typeof connection.addEventListener,
typeof connection.removeEventListener,
typeof connection.dispatchEvent,
typeof navigator.serviceWorker.addEventListener, typeof navigator.serviceWorker.addEventListener,
dispatchResult,
calls,
receiverMatches,
]; ];
"#, "#,
) )
.unwrap(); .unwrap();
assert_eq!(result, serde_json::json!(["function", "function"])); assert_eq!(
result,
serde_json::json!([
"function", "function", "function", "function", true, 1, true
])
);
} }
/// Regression test for #285: DDoS-Guard's challenge calls /// Regression test for #285: DDoS-Guard's challenge calls