mirror of
https://github.com/denoland/deno
synced 2024-08-24 10:37:00 +00:00
fix: call setIsTrusted for generated events (MessageEvent) (#19919)
This addresses issue #19918. ## Issue description Event messages have the wrong isTrusted value when they are not triggered by user interaction, which differs from the browser. In particular, all MessageEvents created by Deno have isTrusted set to false, even though it should be true. This is my first ever contribution to Deno, so I might be missing something.
This commit is contained in:
parent
aa8078b688
commit
98403691d1
|
@ -8,6 +8,7 @@ import * as webidl from "ext:deno_webidl/00_webidl.js";
|
|||
import {
|
||||
defineEventHandler,
|
||||
EventTarget,
|
||||
setIsTrusted,
|
||||
setTarget,
|
||||
} from "ext:deno_web/02_event.js";
|
||||
import DOMException from "ext:deno_web/01_dom_exception.js";
|
||||
|
@ -56,6 +57,7 @@ function dispatch(source, name, data) {
|
|||
data: core.deserialize(data), // TODO(bnoordhuis) Cache immutables.
|
||||
origin: "http://127.0.0.1",
|
||||
});
|
||||
setIsTrusted(event, true);
|
||||
setTarget(event, channel);
|
||||
channel.dispatchEvent(event);
|
||||
};
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
EventTarget,
|
||||
MessageEvent,
|
||||
setEventTargetData,
|
||||
setIsTrusted,
|
||||
} from "ext:deno_web/02_event.js";
|
||||
import DOMException from "ext:deno_web/01_dom_exception.js";
|
||||
const primordials = globalThis.__bootstrap.primordials;
|
||||
|
@ -155,6 +156,7 @@ class MessagePort extends EventTarget {
|
|||
transferables = v[1];
|
||||
} catch (err) {
|
||||
const event = new MessageEvent("messageerror", { data: err });
|
||||
setIsTrusted(event, true);
|
||||
this.dispatchEvent(event);
|
||||
return;
|
||||
}
|
||||
|
@ -165,6 +167,7 @@ class MessagePort extends EventTarget {
|
|||
(t) => ObjectPrototypeIsPrototypeOf(MessagePortPrototype, t),
|
||||
),
|
||||
});
|
||||
setIsTrusted(event, true);
|
||||
this.dispatchEvent(event);
|
||||
}
|
||||
this[_enabled] = false;
|
||||
|
|
|
@ -17,6 +17,7 @@ import {
|
|||
Event,
|
||||
EventTarget,
|
||||
MessageEvent,
|
||||
setIsTrusted,
|
||||
} from "ext:deno_web/02_event.js";
|
||||
import { Blob, BlobPrototype } from "ext:deno_web/09_file.js";
|
||||
import { getLocationHref } from "ext:deno_web/12_location.js";
|
||||
|
@ -430,6 +431,7 @@ class WebSocket extends EventTarget {
|
|||
data: op_ws_get_buffer_as_string(rid),
|
||||
origin: this[_url],
|
||||
});
|
||||
setIsTrusted(event, true);
|
||||
dispatch(this, event);
|
||||
break;
|
||||
}
|
||||
|
@ -450,6 +452,7 @@ class WebSocket extends EventTarget {
|
|||
origin: this[_url],
|
||||
[_skipInternalInit]: true,
|
||||
});
|
||||
setIsTrusted(event, true);
|
||||
dispatch(this, event);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import {
|
|||
ErrorEvent,
|
||||
EventTarget,
|
||||
MessageEvent,
|
||||
setIsTrusted,
|
||||
} from "ext:deno_web/02_event.js";
|
||||
import {
|
||||
deserializeJsMessageData,
|
||||
|
@ -187,6 +188,7 @@ class Worker extends EventTarget {
|
|||
cancelable: false,
|
||||
data: err,
|
||||
});
|
||||
setIsTrusted(event, true);
|
||||
this.dispatchEvent(event);
|
||||
return;
|
||||
}
|
||||
|
@ -198,6 +200,7 @@ class Worker extends EventTarget {
|
|||
(t) => ObjectPrototypeIsPrototypeOf(MessagePortPrototype, t),
|
||||
),
|
||||
});
|
||||
setIsTrusted(event, true);
|
||||
this.dispatchEvent(event);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -154,6 +154,7 @@ async function pollForMessages() {
|
|||
ObjectPrototypeIsPrototypeOf(messagePort.MessagePortPrototype, t),
|
||||
),
|
||||
});
|
||||
event.setIsTrusted(msgEvent, true);
|
||||
|
||||
try {
|
||||
globalDispatchEvent(msgEvent);
|
||||
|
@ -167,6 +168,7 @@ async function pollForMessages() {
|
|||
error: e,
|
||||
});
|
||||
|
||||
event.setIsTrusted(errorEvent, true);
|
||||
globalDispatchEvent(errorEvent);
|
||||
if (!errorEvent.defaultPrevented) {
|
||||
throw e;
|
||||
|
|
|
@ -6399,8 +6399,8 @@
|
|||
"Channel_postMessage_with_transfer_incoming_messages.any.worker.html": true,
|
||||
"Channel_postMessage_with_transfer_outgoing_messages.any.html": true,
|
||||
"Channel_postMessage_with_transfer_outgoing_messages.any.worker.html": true,
|
||||
"MessageEvent-trusted.any.html": false,
|
||||
"MessageEvent-trusted.any.worker.html": false,
|
||||
"MessageEvent-trusted.any.html": true,
|
||||
"MessageEvent-trusted.any.worker.html": true,
|
||||
"MessageEvent-trusted.window.html": false,
|
||||
"MessageEvent.any.html": true,
|
||||
"MessageEvent.any.worker.html": true,
|
||||
|
@ -9688,4 +9688,4 @@
|
|||
"media-sniff.window.html": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue