Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly cancel event when beforeunload handler returns null #15142

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -15,6 +15,7 @@ use dom::bindings::str::DOMString;
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::window::Window;
use servo_atoms::Atom;
use std::cell::Ref;

// https://html.spec.whatwg.org/multipage/#beforeunloadevent
#[dom_struct]
@@ -49,6 +50,10 @@ impl BeforeUnloadEvent {
}
ev
}

pub fn return_value(&self) -> Ref<DOMString> {
self.return_value.borrow()
}
}

impl BeforeUnloadEventMethods for BeforeUnloadEvent {
@@ -178,20 +178,12 @@ impl CompiledEventListener {
}

CommonEventHandler::BeforeUnloadEventHandler(ref handler) => {
if let Some(event) = event.downcast::<BeforeUnloadEvent>() {
let rv = event.ReturnValue();

if let Ok(value) = handler.Call_(object,
event.upcast::<Event>(),
exception_handle) {
match value {
Some(value) => {
if rv.is_empty() {
event.SetReturnValue(value);
}
}
None => {
event.upcast::<Event>().PreventDefault();
if let Ok(value) = handler.Call_(object, event, exception_handle) {

This comment has been minimized.

@Ms2ger

Ms2ger Jan 23, 2017

Contributor

Can you add some tests for returnValue? Stick them in event-handler-processing-algorithm.html along with the others.

This comment has been minimized.

@nox

nox Jan 23, 2017

Author Member

What do you mean?

This comment has been minimized.

@Ms2ger

Ms2ger Jan 23, 2017

Contributor

We should have a test that uses BeforeUnloadEvent rather than Event.

if let Some(before_unload_event) = event.downcast::<BeforeUnloadEvent>() {
if let Some(return_value) = value {
event.PreventDefault();
if before_unload_event.return_value().is_empty() {
before_unload_event.SetReturnValue(return_value);
}
}
}

This file was deleted.

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.