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

Iterative serialization of nodes #16749

Closed
wants to merge 1 commit into from
Closed

Iterative serialization of nodes #16749

wants to merge 1 commit into from

Conversation

@ghost
Copy link

ghost commented May 5, 2017

This serializes the nodes in an iterative way and now it doesn't crash when serializing a deep tree

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #16696 (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

highfive commented May 5, 2017

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/dom/servoparser/html.rs
  • @KiChjang: components/script/dom/servoparser/html.rs
@jdm
Copy link
Member

jdm commented May 10, 2017

@nox review ping!

@nox nox added the S-needs-squash label May 12, 2017
Copy link
Member

nox left a comment

This looks correct, but the commits need to be squashed together, and I would appreciate if you would write a proper explanation in the commit, specifically how stack works, and how the children count in its items is handled.

if stack.is_empty() {
Ok(())
} else {
Err(io::Error::new(io::ErrorKind::Other, "Stack is not empty!!!!"))

This comment has been minimized.

Copy link
@nox

nox May 12, 2017

Member

What's that for? If this isn't empty, this is a logic error and should probably panic instead.

This comment has been minimized.

Copy link
@ghost
roots.next().unwrap();
}
'traversal: for root in roots {
let node = root.r();

This comment has been minimized.

Copy link
@nox

nox May 12, 2017

Member

I don't think you need this here, just do for node in roots.

This comment has been minimized.

Copy link
@ghost
}
'traversal: for root in roots {
let node = root.r();
match node.type_id() {

This comment has been minimized.

Copy link
@nox

nox May 12, 2017

Member

Nit: there is one space too many here, after match.

This comment has been minimized.

Copy link
@ghost
over the tree generated by the node in preorder using a vector as a
stack. When we call the serializer's method start_elem, we add a
tuple with the node's name and the total number of children. We
substract one from the number of children of the last element of
the vector when we serialize a node or when we call the serializer's
method end_elem. The purpose of this stack is to take into account
which nodes need to be ended by the serializer and when they need to
be ended. If the last element of the vector has no children left,
it is removed from the vector and ended by the serializer using
end_elem. Another way to think about this, is that the last element
of the vector always contains the name of the parent of the current
node during the iteration over the tree.
@ghost
Copy link
Author

ghost commented May 13, 2017

OK @nox I believe it's ready

@nox
Copy link
Member

nox commented May 15, 2017

@bors-servo
Copy link
Contributor

bors-servo commented May 15, 2017

📌 Commit f61c07f has been approved by nox

@bors-servo
Copy link
Contributor

bors-servo commented May 15, 2017

Testing commit f61c07f with merge e175826...

bors-servo added a commit that referenced this pull request May 15, 2017
Iterative serialization of nodes

<!-- Please describe your changes on the following line: -->
This serializes the nodes in an iterative way and now it doesn't crash when serializing a deep tree
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #16696 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16749)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented May 15, 2017

💔 Test failed - linux-rel-wpt

@nox
Copy link
Member

nox commented May 15, 2017

  ▶ Unexpected subtest result in /html/semantics/scripting-1/the-template-element/serializing-html-templates/outerhtml.html:
  │ FAIL [expected PASS] Template contents should be serialized instead of template element if serializing template element. Test serializing whole document
  │   → assert_equals: template element is serialized incorrectly expected "<html><head><title>Test Document</title></head><body><template><div id=\"div1\">some text</div></template></body></html>" but got "<html><head><title>Test Document</title></head><body><template></template></body></html>"
  │ 
  │ @http://web-platform.test:8000/html/semantics/scripting-1/the-template-element/serializing-html-templates/outerhtml.html:62:5
  │ Test.prototype.step@http://web-platform.test:8000/resources/testharness.js:1406:20
  │ test@http://web-platform.test:8000/resources/testharness.js:497:9
  └ @http://web-platform.test:8000/html/semantics/scripting-1/the-template-element/serializing-html-templates/outerhtml.html:52:1

  ▶ Unexpected subtest result in /html/semantics/scripting-1/the-template-element/serializing-html-templates/outerhtml.html:
  │ FAIL [expected PASS] Template contents should be serialized instead of template element if serializing template element. Test nested template
  │   → assert_equals: template element is serialized incorrectly expected "<template><template><div id=\"div1\">some text</div></template></template>" but got "<template></template>"
  │ 
  │ @http://web-platform.test:8000/html/semantics/scripting-1/the-template-element/serializing-html-templates/outerhtml.html:44:5
  │ Test.prototype.step@http://web-platform.test:8000/resources/testharness.js:1406:20
  │ test@http://web-platform.test:8000/resources/testharness.js:497:9
  └ @http://web-platform.test:8000/html/semantics/scripting-1/the-template-element/serializing-html-templates/outerhtml.html:32:1

  ▶ Unexpected subtest result in /html/semantics/scripting-1/the-template-element/serializing-html-templates/outerhtml.html:
  │ FAIL [expected PASS] Template contents should be serialized instead of template element if serializing template element
  │   → assert_equals: template element is serialized incorrectly expected "<template><div id=\"div1\">some text</div></template>" but got "<template></template>"
  │ 
  │ @http://web-platform.test:8000/html/semantics/scripting-1/the-template-element/serializing-html-templates/outerhtml.html:25:5
  │ Test.prototype.step@http://web-platform.test:8000/resources/testharness.js:1406:20
  │ test@http://web-platform.test:8000/resources/testharness.js:497:9
  └ @http://web-platform.test:8000/html/semantics/scripting-1/the-template-element/serializing-html-templates/outerhtml.html:16:1

You broke serialization of templates.

@nox
nox approved these changes May 15, 2017
@ghost
Copy link
Author

ghost commented May 15, 2017

Ok the problem is that I didn't include this part: https://github.com/servo/servo/blob/master/components/script/dom/servoparser/html.rs#L141

The thing is, We are traversing the tree in preorder and then we don't know which nodes are the children of the current node. should I try to downcast to HTMLTemplateElement and upcast to Node every node?

@nox
Copy link
Member

nox commented May 15, 2017

I would make stack a Vec<(Root<Node>, usize)>, and store in that the DocumentFragment associated with the template, instead of the template itself. Then when it's time to print the end tag of these nodes, write </template> if the node is a DocumentFragment.

@nox
Copy link
Member

nox commented May 15, 2017

Oh never mind, I see what the problem is. You probably want to make a new iterator, somehow.

@ghost
Copy link
Author

ghost commented May 15, 2017

could you tell me what do you have in mind?

@nox
Copy link
Member

nox commented May 15, 2017

You need a new iterator, that does exactly the same traversal as the one returned by traverse_preorder, but which traverse the template's contents instead of its children.

@ghost ghost deleted the serialize_nodes_preorder branch Jun 21, 2017
@ghost ghost restored the serialize_nodes_preorder branch Jun 21, 2017
This issue was closed.
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.

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