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

use return value of invoking event handlers to cancel the event #8707

Closed
wants to merge 1 commit into from

Conversation

jxs
Copy link
Contributor

@jxs jxs commented Nov 28, 2015

Fixes #8490.

@jdm having some questions on the beforeunload event: how can i check if return_value is null?
shoud i also check if "If the Event object E is a BeforeUnloadEvent object, and the Event object E's returnValue attribute's value is the empty string, then set the returnValue attribute's value to return value." ?

thanks!

Review on Reviewable

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Nov 28, 2015
@jdm
Copy link
Member

jdm commented Nov 28, 2015

We don't implement OnBeforeUnloadEventHandler or BeforeUnloadEvent yet; adding the new event interface is straightforward, but adding support for the special event handler will require work similar to #8430. I think doing that in a separate PR would make sense (or a separate commit in this one, if you'd like!), so it could just be a TODO in this one. As for checking whether it's null, there's an is_null_or_undefined method on JSVal: https://github.com/servo/rust-mozjs/blob/master/src/jsval.rs#L219

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 28, 2015
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Nov 28, 2015
@jxs
Copy link
Contributor Author

jxs commented Nov 28, 2015

ok thanks, updated! Yeah i agree on a new PR so that this one can be closed first, what do you think?

@jdm
Copy link
Member

jdm commented Nov 28, 2015

That works for me!

@jdm jdm self-assigned this Nov 28, 2015
@Ms2ger
Copy link
Contributor

Ms2ger commented Nov 28, 2015

is_null_or_undefined does not sound correct; checking for null can be done with the aptly named is_null method.

It may be the case that the return value is never undefined here, but I don't think so. There's a similar issue that the return value is not necessarily a boolean in the other match arms. I would like to see tests for that; if you don't feel up for it, please let me know so I can write them.

Also, there's the problem of

/home/travis/build/servo/servo/components/script/dom/eventtarget.rs:150:35: 150:46 error: no rules expected the token `"mouseover"`
/home/travis/build/servo/servo/components/script/dom/eventtarget.rs:150                             atom!("mouseover") => {

which I assume means we need to add it to the list in the string-cache repo.

@eefriedman
Copy link
Contributor

which I assume means we need to add it to the list in the string-cache repo.

Already done, and landed in Servo; this PR just needs to be rebased.

@jxs jxs force-pushed the master branch 2 times, most recently from 229a083 to d9ecade Compare November 30, 2015 01:17
@jxs
Copy link
Contributor Author

jxs commented Nov 30, 2015

ok, updated to is_null and rebased

@jdm
Copy link
Member

jdm commented Nov 30, 2015

Whoops, we need to update the code to account for #8710 now.

@jxs
Copy link
Contributor Author

jxs commented Nov 30, 2015

ok, updated!

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Dec 2, 2015
@jdm
Copy link
Member

jdm commented Dec 2, 2015

Sorry for the delay!
-S-awaiting-review +S-needs-code-changes


Reviewed 1 of 1 files at r1.
Review status: all files reviewed at latest revision, 10 unresolved discussions.


components/script/dom/eventtarget.rs, line 130 [r1] (raw file):
We should use let return_value = RootedValue::new(cx, handler.Call_(object, or it's a GC hazard.


components/script/dom/eventtarget.rs, line 131 [r1] (raw file):
nit: these lines should be indented to match object on the previous line.


components/script/dom/eventtarget.rs, line 137 [r1] (raw file):
It's cleaner to use if let Ok(value) = return_value here, and we'll need the check to be value.is_boolean() && value.to_boolean() == true or we'll panic if an event handler returns a non-boolean value.


components/script/dom/eventtarget.rs, line 148 [r1] (raw file):
Same comment about RootedValue here.


components/script/dom/eventtarget.rs, line 149 [r1] (raw file):
Let's add a // Step 4 comment here.


components/script/dom/eventtarget.rs, line 151 [r1] (raw file):
Same as previous (if let and is_boolean).


components/script/dom/eventtarget.rs, line 152 [r1] (raw file):
nit: indent by four spaces


components/script/dom/eventtarget.rs, line 156 [r1] (raw file):
if let


components/script/dom/eventtarget.rs, line 161 [r1] (raw file):
if let and is_boolean.


components/script/dom/eventtarget.rs, line 171 [r1] (raw file):
We can remove this now.


Comments from the review on Reviewable.io

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Dec 2, 2015
@jdm
Copy link
Member

jdm commented Dec 2, 2015

Don't forget to run ./mach test-tidy after addressing these review comments!
-S-awaiting-review +S-fails-tidy +S-needs-code-changes


Reviewed 1 of 1 files at r2.
Review status: all files reviewed at latest revision, 9 unresolved discussions, some commit checks failed.


components/script/dom/eventtarget.rs, line 130 [r1] (raw file):
Ah, sorry, I forgot about the Result<> that Call_ returns. We'll need

let return_value = handler.Call_(object, ...);
if let Some(return_value) = return_value {
    let return_value = RootedValue::new(cx, return_value);
    ...
}

components/script/dom/eventtarget.rs, line 156 [r1] (raw file):
This doesn't compile.


components/script/dom/eventtarget.rs, line 139 [r2] (raw file):
This doesn't compile, and doesn't use is_boolean. We'll need

if let Ok(return_value) = return_value {
    ...
    if return_value.is_boolean() && return_value.to_boolean() == true {
        ...
    }
}

components/script/dom/eventtarget.rs, line 149 [r2] (raw file):
This belongs above the match event.type_() line.


Comments from the review on Reviewable.io

@jdm jdm added S-fails-tidy `./mach test-tidy` reported errors. S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Dec 2, 2015
@highfive highfive removed the S-needs-code-changes Changes have not yet been made that were requested by a reviewer. label Dec 4, 2015
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Dec 15, 2015
@jdm
Copy link
Member

jdm commented Dec 16, 2015

-S-awaiting-review +S-needs-code-changes


Reviewed 1 of 1 files at r6.
Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks failed.


tests/wpt/web-platform-tests/html/webappapis/scripting/events/event-handler-processing-algorithm.html, line 15 [r5] (raw file):
I'm pretty sure if we run this test it won't pass now - the actual listener is still returning true.


tests/wpt/web-platform-tests/html/webappapis/scripting/events/event-handler-processing-algorithm.html, line 25 [r5] (raw file):
Same as previous.


Comments from the review on Reviewable.io

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Dec 16, 2015
@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #8903) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Dec 16, 2015
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Dec 17, 2015
@jdm
Copy link
Member

jdm commented Dec 17, 2015

The changes here appear to have reverted to an earlier revision that didn't build.
-S-awaiting-review +S-needs-code-changes -S-needs-rebase


Review status: 0 of 3 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed.


Comments from the review on Reviewable.io

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. S-needs-rebase There are merge conflict errors. labels Dec 17, 2015
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Dec 18, 2015
@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #9062) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Dec 29, 2015
@KiChjang
Copy link
Contributor

@jxs Are you still working on this?

@jdm
Copy link
Member

jdm commented Feb 18, 2016

This is totally waiting on me. The spec issue I filed doesn't really have resolution yet.

@jdm
Copy link
Member

jdm commented Feb 25, 2016

Rebased in #9755.

@jdm jdm closed this Feb 25, 2016
bors-servo pushed a commit that referenced this pull request Feb 25, 2016
use return value of invoking event handlers to cancel the event

Rebased from #8707. Fixes #8490. We can modify the code and test as necessary whenever we make a decision about whatwg/html#423 in the future.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9755)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this pull request Feb 26, 2016
use return value of invoking event handlers to cancel the event

Rebased from #8707. Fixes #8490. We can modify the code and test as necessary whenever we make a decision about whatwg/html#423 in the future.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9755)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this pull request Feb 27, 2016
use return value of invoking event handlers to cancel the event

Rebased from #8707. Fixes #8490. We can modify the code and test as necessary whenever we make a decision about whatwg/html#423 in the future.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9755)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-awaiting-review There is new code that needs to be reviewed. S-needs-rebase There are merge conflict errors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants