Skip to content

Introduce VirtualMethods::children_changed() - #6660

Merged
bors-servo merged 2 commits into
servo:masterfrom
nox:children-changed
Jul 25, 2015
Merged

bors-servo merged 2 commits into
servo:masterfrom
nox:children-changed

Conversation

@nox

@nox nox commented Jul 18, 2015

Copy link
Copy Markdown
Contributor

This virtual method mimics the behaviour of mutation observers and make it more viable than the older child_inserted(), which didn't cover removed nodes and was called as many times as there were inserted nodes.

A few other shortcomings where remove_child() was called directly instead of Node::remove() were also fixed while at it.

Review on Reviewable

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jul 18, 2015
@hoppipolla-critic-bot

Copy link
Copy Markdown

Critic review: https://critic.hoppipolla.co.uk/r/5593

This is an external review system which you may optionally use for the code review of your pull request.

In order to help critic track your changes, please do not make in-place history rewrites (e.g. via git rebase -i or git commit --amend) when updating this pull request.

@Ms2ger

Ms2ger commented Jul 18, 2015

Copy link
Copy Markdown
Contributor

@pcwalton removed the vector allocation in the non-DocumentFragment case in 8ab354a; I expect he'll have something to say about bringing it back.

@bzbarsky: do you have any thoughts on the best approach here?

@nox

nox commented Jul 18, 2015

Copy link
Copy Markdown
Contributor Author

@pcwalton I don't see how we can afford to not bring it back if we ever support mutation observers.

Maybe an enum Zero, One(&Node), Many(&RootedVec<JS<Node>>)?

@nox

nox commented Jul 20, 2015

Copy link
Copy Markdown
Contributor Author

Seems like I forgot to fix Node.replaceChild().

@nox
nox force-pushed the children-changed branch from fbf22e7 to bfe1f06 Compare July 20, 2015 10:15
@nox

nox commented Jul 20, 2015

Copy link
Copy Markdown
Contributor Author

I think we are better off passing around an enumeration representing each kind of changes that can happen to children of a node, instead of 2 vectors and 2 nodes.

With the 2 vectors and 2 nodes, implementors have to handle cases that don't exist, like removing n out of m children of a node, while the only removal cases that exist are removing a single node or all of them.

@pcwalton

Copy link
Copy Markdown
Contributor

Maybe use a SmallVec?

@nox

nox commented Jul 20, 2015

Copy link
Copy Markdown
Contributor Author

@pcwalton So I should make a RootedSmallVec I guess?

@bors-servo

Copy link
Copy Markdown
Contributor

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

@nox
nox force-pushed the children-changed branch from 97a8497 to 3c1ccff Compare July 23, 2015 19:44
@nox

nox commented Jul 24, 2015

Copy link
Copy Markdown
Contributor Author

There is a problem on insertion, children_changed() isn't called when the nodes are removed from their original parents.

@nox
nox force-pushed the children-changed branch from 3c1ccff to edad2c2 Compare July 24, 2015 13:33
@nox

nox commented Jul 24, 2015

Copy link
Copy Markdown
Contributor Author

Misunderstood the problem, children_changed() was called too many times because remove() didn't check whether the suppress observers flag was set or not.

@jdm jdm self-assigned this Jul 24, 2015
@nox
nox force-pushed the children-changed branch from edad2c2 to e0faeef Compare July 24, 2015 19:37
@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 Jul 25, 2015
@jdm

jdm commented Jul 25, 2015

Copy link
Copy Markdown
Member

I've looked through node.rs and cross-checked the various node manipulation algorithms in the spec against our implementation. It appears as though in the cases in which we execute an algorithm with observers suppressed (and therefore don't call children_changed), we later explicitly call children_changed for the same set of affected nodes. Accordingly, these changes look good to me with a couple small considerations.

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


Reviewed 4 of 4 files at r1, 7 of 7 files at r2.
Review status: all files reviewed at latest revision, 2 unresolved discussions, all commit checks successful.


components/script/dom/node.rs, line 2605 [r2] (raw file):
I'm inclined to recommend struct variants here so we can name these fields clearly.


components/script/dom/node.rs, line 2622 [r2] (raw file):
nit: move added_nodes to a new line.

Why is removed_node &&?


Comments from the review on Reviewable.io

This virtual method mimics the behaviour of mutation observers and make it more
viable than the older child_inserted(), which didn't cover removed nodes and
was called as many times as there were inserted nodes.

A few other shortcomings where remove_child() was called directly instead of
Node::remove() were also fixed while at it.
@nox
nox force-pushed the children-changed branch from e0faeef to 7b40cc9 Compare July 25, 2015 17:20
@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 Jul 25, 2015
@nox

nox commented Jul 25, 2015

Copy link
Copy Markdown
Contributor Author

Review status: 10 of 11 files reviewed at latest revision, 1 unresolved discussion, all commit checks successful.


components/script/dom/node.rs, line 2622 [r2] (raw file):
Will move it, but removed_node is a && so that I can call ref_slice() on it.


Comments from the review on Reviewable.io

@jdm

jdm commented Jul 25, 2015

Copy link
Copy Markdown
Member

@bors-servo: r+
-S-awaiting-review +S-awaiting-merge


Reviewed 1 of 1 files at r3.
Review status: :shipit: all files reviewed at latest revision, all discussions resolved, all commit checks successful.


Comments from the review on Reviewable.io

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 7b40cc9 has been approved by jdm

@jdm jdm added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jul 25, 2015
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 7b40cc9 with merge 705c95d...

bors-servo pushed a commit that referenced this pull request Jul 25, 2015
Introduce VirtualMethods::children_changed()

This virtual method mimics the behaviour of mutation observers and make it more viable than the older child_inserted(), which didn't cover removed nodes and was called as many times as there were inserted nodes.

A few other shortcomings where remove_child() was called directly instead of Node::remove() were also fixed while at it.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6660)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, gonk, linux1, linux2, linux3, mac1, mac2, mac3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants