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

Don't crash when calling `nodes_from_point` without a document element #10093

Closed
emilio opened this issue Mar 19, 2016 · 10 comments
Closed

Don't crash when calling `nodes_from_point` without a document element #10093

emilio opened this issue Mar 19, 2016 · 10 comments

Comments

@emilio
Copy link
Member

@emilio emilio commented Mar 19, 2016

Right now, the function Document::nodes_from_point is called when using document.elementsFromPoint.

That function asserts that there should be a document element to run, and crashes if not. It should return an empty vector in that case, preferrably issuing a debug!() message.

Code:

  • components/script/dom/document.rs (the function nodes_from_point).
@rilut
Copy link
Contributor

@rilut rilut commented Mar 19, 2016

I'd love to work on this

@emilio
Copy link
Member Author

@emilio emilio commented Mar 19, 2016

That was fast, it's yours!

Don't forget to mention (in the case I don't review that PR) that there are no new passing tests due to the reasons described in #10091 :)

@emilio emilio added the C-assigned label Mar 19, 2016
@rilut
Copy link
Contributor

@rilut rilut commented Mar 19, 2016

@ecoal95 Hi, actually I think document.elementsFromPoint haven't crashed yet, even with the assertion. Is it better for us to remove the assertion and change it to a check to return an empty vector?

By the way, the error message for the [No viewport available] subtest is:

│ FAIL [expected PASS] No viewport available
│ → assert_array_equals: Should have returned [] lengths differ, expected 0 got 2

rather than frames[1] is undefined or window.frames[1] is undefined

So, I'm not sure whether this subtest is using an iframe. The subtest code:

  test(function () {
        var doc = document.implementation.createHTMLDocument('foo');
        assert_array_equals(doc.elementsFromPoint(0, 0), [],
                      "Should have returned []")
  }, "No viewport available");

If my guess is right that this subtest isn't using an iframe, I'm curious whether it can be fixed without we're worrying about iframes.

EDIT: Never mind my reply above, still reading a documentation on createHTMLDocument.

EDIT 2: I guess the subtest code calls createHTMLDocument without appending the new HTML Document to an iframe? (So the new HTML Document doesn't visible (doesn't have a viewport) ).
Yeah, changing the assertion doesn't fix the subtest result:

pub fn nodes_from_point(&self, page_point: &Point2D<f32>) -> Vec<UntrustedNodeAddress> {
    match self.GetDocumentElement() {
        Some(_) => self.window.layout().nodes_from_point(*page_point),
        None => {
            debug!("No document element available.");
            vec!()
        },
    }
}
@emilio
Copy link
Member Author

@emilio emilio commented Mar 21, 2016

Yes, exactly, createHTMLDocument doesn't create a new iframe, but it does append an <html> node and a <body> node, which are our two nodes.

It seems that we should check if the document is in the viewport before doing hit test.

The spec: https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument

@emilio
Copy link
Member Author

@emilio emilio commented Mar 21, 2016

Note that the assertion should be changed regardless, that's not what that test is testing (no viewport != no document element).

@jdm
Copy link
Member

@jdm jdm commented Mar 21, 2016

You probably want document.browsing_context().is_some() instead.

@jdm
Copy link
Member

@jdm jdm commented Apr 5, 2016

Are you still working on this, @rilut?

@rilut
Copy link
Contributor

@rilut rilut commented Apr 5, 2016

@jdm Yes, I'll get it done on Thursday after exam

@jdm
Copy link
Member

@jdm jdm commented Apr 5, 2016

Ok, thanks! No rush, just wanted to make sure it wasn't abandoned.

@rilut
Copy link
Contributor

@rilut rilut commented Apr 5, 2016

@jdm sure! Thanks for your consideration

bors-servo added a commit that referenced this issue Apr 15, 2016
…ble-test, r=nox

Fix Document#elementsFromPoint no viewport available test

Fixes #10093 and improves #10034.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10426)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.