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

Implement Node::rootNode #10757

Merged
merged 1 commit into from Apr 22, 2016
Merged

Implement Node::rootNode #10757

merged 1 commit into from Apr 22, 2016

Conversation

@ineol
Copy link
Contributor

ineol commented Apr 20, 2016

Fixes #10747.

I don't know whether it's OK to recurse up the tree, though it is a tail call.


This change is Reviewable

@highfive
Copy link

highfive commented Apr 20, 2016

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

@highfive
Copy link

highfive commented Apr 20, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/node.rs, components/script/dom/webidls/Node.webidl
// https://dom.spec.whatwg.org/#dom-node-rootnode
fn RootNode(&self) -> Root<Node> {
match self.GetParentNode() {
Some(parent) => parent.RootNode(),

This comment has been minimized.

Copy link
@aravind-pg

aravind-pg Apr 20, 2016

Contributor

In this case it seems easy enough to make this an explicit loop roughly as follows (since Rust doesn't actually have tail-call optimization):

let mut current = &self;
while let Some(ref parent) = current.GetParentNode() {
    current = parent;
}
Root::from_ref(current)

This comment has been minimized.

Copy link
@dzbarsky

dzbarsky Apr 21, 2016

Member

you should do return self.inclusive_ancestors().last() or something like that

@larsbergstrom
Copy link
Contributor

larsbergstrom commented Apr 21, 2016

r? @Ms2ger (since you opened the original issue)

@highfive highfive assigned Ms2ger and unassigned larsbergstrom Apr 21, 2016
@Ms2ger
Copy link
Contributor

Ms2ger commented Apr 22, 2016

@ineol: can you please use @dzbarsky's suggestion? Looks good otherwise.

@ineol
Copy link
Contributor Author

ineol commented Apr 22, 2016

I made the needed changes.

@@ -1858,6 +1858,12 @@ impl NodeMethods for Node {
}
}

// https://dom.spec.whatwg.org/#dom-node-rootnode
fn RootNode(&self) -> Root<Node> {
let tree_root = self.inclusive_ancestors().last().unwrap();

This comment has been minimized.

Copy link
@nox

nox Apr 22, 2016

Member

This is already a Root<Node>, no need to use Root::from_ref.

@ineol
Copy link
Contributor Author

ineol commented Apr 22, 2016

Oops! fixed

@Ms2ger
Copy link
Contributor

Ms2ger commented Apr 22, 2016

LGTM once you squash into a single commit.

@ineol
Copy link
Contributor Author

ineol commented Apr 22, 2016

Squashed.

@Ms2ger
Copy link
Contributor

Ms2ger commented Apr 22, 2016

@bors-servo r+

Thank you!

@bors-servo
Copy link
Contributor

bors-servo commented Apr 22, 2016

📌 Commit 00b3f79 has been approved by Ms2ger

@bors-servo
Copy link
Contributor

bors-servo commented Apr 22, 2016

Testing commit 00b3f79 with merge 8293854...

bors-servo added a commit that referenced this pull request Apr 22, 2016
Implement Node::rootNode

Fixes #10747.

I don't know whether it's OK to recurse up the tree, though it is a tail call.

<!-- 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/10757)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Apr 22, 2016

@bors-servo bors-servo merged commit 00b3f79 into servo:master Apr 22, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
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.

None yet

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