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

Return an enum instead of a boolean from dispatch_event #13397

Merged
merged 1 commit into from Sep 26, 2016

Conversation

@aochagavia
Copy link
Contributor

aochagavia commented Sep 23, 2016

Fixes #13196


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #13196.
  • These changes do not require tests because the functionality hasn't changed

This change is Reviewable

@highfive
Copy link

highfive commented Sep 23, 2016

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @emilio (or someone else) soon.

@highfive
Copy link

highfive commented Sep 23, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/worker.rs, components/script/dom/document.rs, components/script/dom/eventtarget.rs, components/script/dom/eventdispatcher.rs, components/script/dom/event.rs, components/script/dom/dedicatedworkerglobalscope.rs, components/script/dom/htmlscriptelement.rs
@highfive
Copy link

highfive commented Sep 23, 2016

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!
@aochagavia
Copy link
Contributor Author

aochagavia commented Sep 23, 2016

An unresolved question is whether handle_touch_event should use EventStatus as the return value instead of bool. The function has some early returns that seem unrelated to Event::fire, so I am unsure if they all mean the same. The current implementation converts the EventStatus back into a bool.

@aochagavia
Copy link
Contributor Author

aochagavia commented Sep 23, 2016

There is something wrong with the (Windows, GNU) build, but it seems unrelated to this PR

@aochagavia
Copy link
Contributor Author

aochagavia commented Sep 23, 2016

r? @Ms2ger

@highfive highfive assigned Ms2ger and unassigned emilio Sep 23, 2016
@@ -103,10 +103,15 @@ fn dispatch_to_listeners(event: &Event, target: &EventTarget, event_path: &[&Eve
}
}

pub enum EventStatus {

This comment has been minimized.

@KiChjang

KiChjang Sep 23, 2016

Member

You can derive PartialEq here so that you don't need if let to match for it.

This comment has been minimized.

@aochagavia

aochagavia Sep 24, 2016

Author Contributor

I actually like if let, but if you think it is necessary I could change the code to use ==

This comment has been minimized.

@Ms2ger

Ms2ger Sep 26, 2016

Contributor

I agree with @KiChjang here; please do use == rather than if let.

Copy link
Contributor

Ms2ger left a comment

Looking good, just needs a few small changes.

@@ -103,10 +103,15 @@ fn dispatch_to_listeners(event: &Event, target: &EventTarget, event_path: &[&Eve
}
}

pub enum EventStatus {

This comment has been minimized.

@Ms2ger

Ms2ger Sep 26, 2016

Contributor

I agree with @KiChjang here; please do use == rather than if let.

// Step 13.
!event.DefaultPrevented()
// Step 14.
match event.DefaultPrevented() {

This comment has been minimized.

@Ms2ger

Ms2ger Sep 26, 2016

Contributor

I would suggest adding a method on Event that returned this.

@@ -560,7 +560,10 @@ impl EventTargetMethods for EventTarget {
return Err(Error::InvalidState);
}
event.set_trusted(false);
Ok(self.dispatch_event(event))
match self.dispatch_event(event) {

This comment has been minimized.

@Ms2ger

Ms2ger Sep 26, 2016

Contributor

Nit: you can use Ok(match ...).

@aochagavia
Copy link
Contributor Author

aochagavia commented Sep 26, 2016

@Ms2ger Thanks for your feedback! I have pushed the changes.

@@ -153,6 +154,14 @@ impl Event {
self.cancelable.set(cancelable);
}

pub fn status(&self) -> EventStatus
{

This comment has been minimized.

@Ms2ger

Ms2ger Sep 26, 2016

Contributor

{ should go on the previous line

This comment has been minimized.

@aochagavia

aochagavia Sep 26, 2016

Author Contributor

Nice catch... Too much C# programming these days...

let event_status = event.upcast::<Event>().fire(self.upcast::<EventTarget>());

// Step 15
if EventStatus::NotCanceled == event_status {

This comment has been minimized.

@Ms2ger

Ms2ger Sep 26, 2016

Contributor

If you want to swap around the left-hand and right-hand sides of these comparisons, I think that would read better. r+ either way, if you fix the other comment below.

@aochagavia
Copy link
Contributor Author

aochagavia commented Sep 26, 2016

@Ms2ger I pushed new changes, including swapping the comparisons.

@Ms2ger
Copy link
Contributor

Ms2ger commented Sep 26, 2016

Thanks a lot!

@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Sep 26, 2016

📌 Commit 6c8bfdb has been approved by Ms2ger

@bors-servo
Copy link
Contributor

bors-servo commented Sep 26, 2016

Testing commit 6c8bfdb with merge 9b77080...

bors-servo added a commit that referenced this pull request Sep 26, 2016
Return an enum instead of a boolean from dispatch_event

Fixes #13196

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #13196.
- [X] These changes do not require tests because the functionality hasn't changed

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13397)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Sep 26, 2016

@bors-servo bors-servo merged commit 6c8bfdb into servo:master Sep 26, 2016
2 of 3 checks passed
2 of 3 checks passed
continuous-integration/travis-ci/pr The Travis CI build failed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

7 participants
You can’t perform that action at this time.