Skip to content

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

Closed

Description

@emilio

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).

Activity

  1. added
    A-content/dom
    E-less-complex
    on Mar 19, 2016
  2. luthfianto commented on Mar 19, 2016

    @luthfianto
    Contributor

    I'd love to work on this

  3. emilio commented on Mar 19, 2016

    @emilio
    MemberAuthor

    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 :)

  4. added
    C-assigned
    on Mar 19, 2016
  5. luthfianto commented on Mar 19, 2016

    @luthfianto
    Contributor

    @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!()
            },
        }
    }
    
  6. emilio commented on Mar 21, 2016

    @emilio
    MemberAuthor

    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

  7. emilio commented on Mar 21, 2016

    @emilio
    MemberAuthor

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

  8. jdm commented on Mar 21, 2016

    @jdm
    Member

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

  9. jdm commented on Apr 5, 2016

    @jdm
    Member

    Are you still working on this, @rilut?

  10. luthfianto commented on Apr 5, 2016

    @luthfianto
    Contributor

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

  11. jdm commented on Apr 5, 2016

    @jdm
    Member

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

  12. luthfianto commented on Apr 5, 2016

    @luthfianto
    Contributor

    @jdm sure! Thanks for your consideration

  13. added a commit that references this issue on Apr 15, 2016
    44d7657
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-content/domC-assignedE-less-complex

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions