mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #25625 - pshaughn:errorargs, r=jdm
Make error events only pass the extra error-event arguments to global listeners Error event handlers were getting lineno, etc. arguments even when they weren't on globals, failing two WPT tests; this fixes that. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #25197 <!-- Either: --> - [X] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
388a0f618b
3 changed files with 24 additions and 31 deletions
|
@ -33,6 +33,7 @@ use crate::dom::htmlformelement::FormControlElementHelpers;
|
|||
use crate::dom::node::document_from_node;
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use crate::dom::window::Window;
|
||||
use crate::dom::workerglobalscope::WorkerGlobalScope;
|
||||
use crate::realms::enter_realm;
|
||||
use dom_struct::dom_struct;
|
||||
use fnv::FnvHasher;
|
||||
|
@ -152,9 +153,9 @@ pub enum CompiledEventListener {
|
|||
|
||||
impl CompiledEventListener {
|
||||
// https://html.spec.whatwg.org/multipage/#the-event-handler-processing-algorithm
|
||||
pub fn call_or_handle_event<T: DomObject>(
|
||||
pub fn call_or_handle_event(
|
||||
&self,
|
||||
object: &T,
|
||||
object: &EventTarget,
|
||||
event: &Event,
|
||||
exception_handle: ExceptionHandling,
|
||||
) {
|
||||
|
@ -167,27 +168,29 @@ impl CompiledEventListener {
|
|||
match *handler {
|
||||
CommonEventHandler::ErrorEventHandler(ref handler) => {
|
||||
if let Some(event) = event.downcast::<ErrorEvent>() {
|
||||
let cx = object.global().get_cx();
|
||||
rooted!(in(*cx) let error = event.Error(cx));
|
||||
let return_value = handler.Call_(
|
||||
object,
|
||||
EventOrString::String(event.Message()),
|
||||
Some(event.Filename()),
|
||||
Some(event.Lineno()),
|
||||
Some(event.Colno()),
|
||||
Some(error.handle()),
|
||||
exception_handle,
|
||||
);
|
||||
// Step 4
|
||||
if let Ok(return_value) = return_value {
|
||||
rooted!(in(*cx) let return_value = return_value);
|
||||
if return_value.handle().is_boolean() &&
|
||||
return_value.handle().to_boolean() == true
|
||||
{
|
||||
event.upcast::<Event>().PreventDefault();
|
||||
if object.is::<Window>() || object.is::<WorkerGlobalScope>() {
|
||||
let cx = object.global().get_cx();
|
||||
rooted!(in(*cx) let error = event.Error(cx));
|
||||
let return_value = handler.Call_(
|
||||
object,
|
||||
EventOrString::String(event.Message()),
|
||||
Some(event.Filename()),
|
||||
Some(event.Lineno()),
|
||||
Some(event.Colno()),
|
||||
Some(error.handle()),
|
||||
exception_handle,
|
||||
);
|
||||
// Step 4
|
||||
if let Ok(return_value) = return_value {
|
||||
rooted!(in(*cx) let return_value = return_value);
|
||||
if return_value.handle().is_boolean() &&
|
||||
return_value.handle().to_boolean() == true
|
||||
{
|
||||
event.upcast::<Event>().PreventDefault();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let _ = handler.Call_(
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
[document-synthetic-errorevent.html]
|
||||
type: testharness
|
||||
[error event is normal (return true does not cancel; one arg) on Document, with a synthetic ErrorEvent]
|
||||
expected: FAIL
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
[script-element.html]
|
||||
type: testharness
|
||||
[error event behaves normally (return true does not cancel; one arg) on a script element, with a synthetic ErrorEvent]
|
||||
expected: FAIL
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue