Skip to content

Implement Range::createContextualFragment - #11496

Merged
bors-servo merged 2 commits into
servo:masterfrom
GuillaumeGomez:range
Jun 3, 2016
Merged

bors-servo merged 2 commits into
servo:masterfrom
GuillaumeGomez:range

Conversation

@GuillaumeGomez

@GuillaumeGomez GuillaumeGomez commented May 29, 2016 •

Copy link
Copy Markdown
Contributor

This change is Reviewable

@highfive

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/element.rs, components/script/dom/webidls/Range.webidl, components/script/dom/range.rs

@highfive

Copy link
Copy Markdown

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 29, 2016
@GuillaumeGomez

Copy link
Copy Markdown
Contributor Author

r? @nox

@highfive highfive assigned nox and unassigned glennw May 29, 2016
Comment thread components/script/dom/range.rs Outdated
elem.root_element()
}
} else {
element.unwrap().downcast::<Element>().unwrap().root_element()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems incorrect but cannot find another way to get the expected type.

@GuillaumeGomez

Copy link
Copy Markdown
Contributor Author

Fixes #11111.

@highfive

Copy link
Copy Markdown

New code was committed to pull request.

@nox nox added C-needs-test An automated test is required. S-needs-code-changes Changes have not yet been made that were requested by a reviewer. S-needs-tests New tests have been requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels May 29, 2016
@nox

nox commented May 29, 2016

Copy link
Copy Markdown
Contributor

Step 3 needs to be rewritten, and there should be tests for this.

-S-awaiting-review +S-needs-code-changes +S-needs-tests +C-needs-test

Previously, highfive wrote…

New code was committed to pull request.


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


components/script/dom/range.rs, line 913 [r1] (raw file):

        // Step 2.
        let elem_copy = element.clone().unwrap();

This is wrong to unwrap, given it could be None if node was a document or a document fragment.


components/script/dom/range.rs, line 916 [r1] (raw file):

        let document = elem_copy.downcast::<Document>().unwrap();
        let element = if element.is_none() {
            Element::new(Atom::from("body"),

Element::new would create an Element instead of the correct HTMLBodyElement. You want Element::create.


components/script/dom/range.rs, line 929 [r1] (raw file):

                             &document)
            } else {
                elem.root_element()

There is no returning the root element in the spec AFAICT.


components/script/dom/range.rs, line 932 [r1] (raw file):

Previously, GuillaumeGomez (Guillaume Gomez) wrote…

This seems incorrect but cannot find another way to get the expected type.

So you just need to create a body element in a specific case when a set of conditions are met. You can do:
let should_create_body = element.map_or(true, |elem| {
    elem.local_name == &atom!("html") && elem.html_element_in_html_document()
});
let element = if should_create_body {
    Root::upcast(HTMLBodyElement::new(atom!("body"), None, &node.owner_doc()))
} else {
    element
};

components/script/dom/range.rs, line 936 [r1] (raw file):

Previously, GuillaumeGomez (Guillaume Gomez) wrote…

It seems strange that I have to upcast to get back a node in order to use this method.

Nope, that's because parsing a fragment is an operation on `Node`, we do that all the time.

components/script/dom/range.rs, line 936 [r1] (raw file):

        // Step 3.
        let fragment_node = element.upcast::<Node>().parse_fragment(fragment);

Please do try!() around the whole call so that fragment_node is actually a Root<Node> and not a Fallible<Root<Node>>, since all the steps haven't been executed yet at this point.


components/script/dom/range.rs, line 939 [r1] (raw file):

        // Step 4.
        // can be ignored

Please write a proper sentence as to why it can be ignored.


components/script/dom/range.rs, line 942 [r1] (raw file):

        // Step 5.
        fragment_node
Ok(fragment_node)

Comments from Reviewable

@jdm jdm removed the C-needs-test An automated test is required. label May 30, 2016
@highfive highfive removed the S-needs-code-changes Changes have not yet been made that were requested by a reviewer. label May 31, 2016
@highfive

Copy link
Copy Markdown

New code was committed to pull request.

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 31, 2016
@nox

nox commented May 31, 2016

Copy link
Copy Markdown
Contributor

Just a few nits, but it still needs tests.

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

Previously, highfive wrote…

New code was committed to pull request.


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


components/script/dom/range.rs, line 913 [r3] (raw file):

        // Step 2.
        let should_create_body = element.clone().map_or(true, |elem| {

Do element.as_ref() instead of element.clone().


components/script/dom/range.rs, line 917 [r3] (raw file):

            elem.local_name() == &atom!("html") && elem.html_element_in_html_document()
        });
        let element: Root<Node> = if should_create_body || element.is_none() {

You can do it this way:

let element = Root::upcast::<Node>(if should_create_body { ... });

This removes the double call to Root::upcast and the Root<Node type annotation, and also the element.is_none() test that is already covered by element.map_or(true, ...).


components/script/dom/range.rs, line 927 [r3] (raw file):

        // Step 4.
        // Can be ignored because at the initialization are supposed to be unmarked as

What are supposed to be unmarked as "already started"? There lack a subject in that sentence.


Comments from Reviewable

@nox nox 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 May 31, 2016
@highfive

highfive commented Jun 1, 2016

Copy link
Copy Markdown

New code was committed to pull request.

@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 Jun 1, 2016
@nox nox removed the S-awaiting-review There is new code that needs to be reviewed. label Jun 1, 2016
@nox

nox commented Jun 1, 2016

Copy link
Copy Markdown
Contributor

-S-awaiting-review -S-needs-tests

Seems like there are tests already in WPT. Let's try.

@bors-servo try

Previously, highfive wrote…

New code was committed to pull request.


Reviewed 1 of 1 files at r4.
Review status: all files reviewed at latest revision, all discussions resolved.


Comments from Reviewable

@nox nox removed the S-needs-tests New tests have been requested by a reviewer. label Jun 1, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit bf8b3d0 with merge 3e724eb...

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit 5ab7f54 with merge fd10ab3...

bors-servo pushed a commit that referenced this pull request Jun 2, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, mac-rel-wpt, windows

@nox

nox commented Jun 3, 2016

Copy link
Copy Markdown
Contributor

@bors-servo r+

I'll file a followup for the <script> issue.

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 5ab7f54 has been approved by nox

@highfive highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jun 3, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 5ab7f54 with merge 51d41c5...

bors-servo pushed a commit that referenced this pull request Jun 3, 2016
Implement Range::createContextualFragment

<!-- 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/11496)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jun 3, 2016
@highfive

highfive commented Jun 3, 2016

Copy link
Copy Markdown
  ▶ FAIL [expected PASS] /css-transforms-1_dev/html/transform-abspos-002.htm
  └   → /css-transforms-1_dev/html/transform-abspos-002.htm 71f0313eedfbfcce0b0fcc5ae55f34b1daa3b8d8
/css-transforms-1_dev/html/reference/transform-abspos-ref.htm 78d197606924062e8dd2a773c977afcecf8940f8
Testing 71f0313eedfbfcce0b0fcc5ae55f34b1daa3b8d8 == 78d197606924062e8dd2a773c977afcecf8940f8

@nox nox removed the S-tests-failed The changes caused existing tests to fail. label Jun 3, 2016
@nox

nox commented Jun 3, 2016

Copy link
Copy Markdown
Contributor

@bors-servo retry #11561

@bors-servo

Copy link
Copy Markdown
Contributor

⚡ Previous build results for android, linux-dev, mac-dev-unit, windows are reusable. Rebuilding only arm32, arm64, linux-rel, mac-rel-css, mac-rel-wpt...

@nox nox added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jun 3, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - mac-rel-css

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jun 3, 2016
@highfive

highfive commented Jun 3, 2016

Copy link
Copy Markdown
  ▶ FAIL [expected PASS] /css-transforms-1_dev/html/transform-abspos-002.htm
  └   → /css-transforms-1_dev/html/transform-abspos-002.htm b8e11894fc87a1b1a2130bc2f522ce5dd20a0b4d
/css-transforms-1_dev/html/reference/transform-abspos-ref.htm 9531333297f9339df08ebd5395fdab407f71a7ef
Testing b8e11894fc87a1b1a2130bc2f522ce5dd20a0b4d == 9531333297f9339df08ebd5395fdab407f71a7ef

  ▶ FAIL [expected PASS] /css-transforms-1_dev/html/transform-table-007.htm
  └   → /css-transforms-1_dev/html/transform-table-007.htm e93c9642827c4e2d15f86f1319d5d92ef443366b
/css-transforms-1_dev/html/reference/transform-blank-ref.htm a4b5a51b35256f1981240981ac8e70bb3f00cde6
Testing e93c9642827c4e2d15f86f1319d5d92ef443366b == a4b5a51b35256f1981240981ac8e70bb3f00cde6

@nox

nox commented Jun 3, 2016

Copy link
Copy Markdown
Contributor

@bors-servo retry #11561 #11574

@nox nox added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Jun 3, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

⚡ Previous build results for android, arm32, arm64, linux-dev, linux-rel, mac-dev-unit, mac-rel-wpt, windows are reusable. Rebuilding only mac-rel-css...

@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, mac-rel-wpt, windows

@bors-servo
bors-servo merged commit 5ab7f54 into servo:master Jun 3, 2016
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jun 3, 2016
@GuillaumeGomez
GuillaumeGomez deleted the range branch June 3, 2016 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants