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

Add microtask checkpoints to script elements and custom elements #25515

Merged
merged 1 commit into from Jan 25, 2020

Conversation

@pshaughn
Copy link
Member

pshaughn commented Jan 13, 2020

Servo had a microtask checkpoint at the end of running a script, but there was also supposed to be one at the end of HTML-parsing a script element before Javascript-parsing the script itself, and there were supposed to be checkpoints immediately after the call to a custom element constructor. This adds those, passing all cases of one WPT test file.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #25016 except for the remaining not-really-about-microtasks case #25514
  • There are tests for these changes
@highfive
Copy link

highfive commented Jan 13, 2020

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/dom/customelementregistry.rs, components/script/dom/servoparser/mod.rs
  • @KiChjang: components/script/dom/customelementregistry.rs, components/script/dom/servoparser/mod.rs
@nox
Copy link
Member

nox commented Jan 14, 2020

@bors-servo
Copy link
Contributor

bors-servo commented Jan 14, 2020

📌 Commit e4a5d8d has been approved by nox

@bors-servo
Copy link
Contributor

bors-servo commented Jan 14, 2020

Testing commit e4a5d8d with merge d8a7ae9...

bors-servo added a commit that referenced this pull request Jan 14, 2020
Add microtask checkpoints to script elements and custom elements

Servo had a microtask checkpoint at the end of running a script, but there was also supposed to be one at the end of HTML-parsing a script element before Javascript-parsing the script itself, and there were supposed to be checkpoints immediately after the call to a custom element constructor. This adds those, passing all cases of one WPT test file.

---
<!-- 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 #25016 except for the remaining not-really-about-microtasks case #25514

<!-- Either: -->
- [X] There are tests for these changes

<!-- 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. -->
@bors-servo
Copy link
Contributor

bors-servo commented Jan 14, 2020

💔 Test failed - status-taskcluster

@jdm
Copy link
Member

jdm commented Jan 14, 2020

  ▶ Unexpected subtest result in /dom/nodes/MutationObserver-document.html:
  └ PASS [expected FAIL] parser insertion mutations
  ▶ Unexpected subtest result in /dom/nodes/MutationObserver-document.html:
  └ PASS [expected FAIL] parser script insertion mutation
  ▶ Unexpected subtest result in /dom/nodes/MutationObserver-document.html:
  └ PASS [expected FAIL] removal of parent during parsing

This also changes the behaviour of a reftest, interestingly:

  ▶ FAIL [expected PASS] /_mozilla/mozilla/FileAPI/blob_url_upload.html
  │   → /_mozilla/mozilla/FileAPI/blob_url_upload.html 072d32c1bd0b78ac1c5af7657d6e5cedfb9ec8d6
  └   → /_mozilla/mozilla/FileAPI/blob_url_upload_ref.html 84f6d3bd2a1b363f32fc2f41c2c8dc78d0dfd881
@pshaughn
Copy link
Member Author

pshaughn commented Jan 14, 2020

That mozilla blob one happens intermittently for me on this branch; I'll see if it also happens intermittently for me on master. My first guess here is that the screenshot has a chance of being taken before the file is done loading.

@pshaughn
Copy link
Member Author

pshaughn commented Jan 14, 2020

It doesn't seem to happen on master.

Hypothesis: The new checkpoint that happens when parsing </script> before compiling the script body fires an ImageMicrotask, that ImageMicrotask does something that tells the document "I'm done being loaded", the document sees that html5ever is done parsing it, and the load event fires even though we're still inside the tokenizer for the final script element.

The one thing I know I didn't follow the exact spec for was that the checkpoint is supposed to happen before "Switch the insertion mode to the original insertion mode", but there wasn't a way to do that with the way Servo and html5ever are connected so I hoped it wasn't observable. I need to look at how the document decides whether it's done being loaded; maybe the insertion mode is part of the problem.

@pshaughn
Copy link
Member Author

pshaughn commented Jan 14, 2020

Nothing is logged from document, servoparser, or htmlimageelement between entering and exiting the suspicious checkpoint; all the interesting action happens after it.

Running it with logs on, in this branch it looks there is a race between "Document got finish_load: Image([blob url])" and "Document got finish_load: PageSource([test url]), and if Image comes first the test fails. Next question I need to look at: in master, do these events always have a strict order (so I need to make sure one waits for the other), or do we pass the test regardless of order (so I need to make something else insensitive to the difference)?

@pshaughn
Copy link
Member Author

pshaughn commented Jan 14, 2020

It looks like with my changes, the document is seeing the finish_load for the the image before the image's process_response has been reached (but after the image has had its blob URL assigned). That then means we have a race between when process_response happens and when the screenshot is taken. In master, the finish_load for the image always happens after process_response. These calls all come later in the timeline than my actual code changes, but I can infer that adding a microtask checkpoint breaks some expectation an image had about its lifecycle, and finding that expectation is the next step.

@pshaughn
Copy link
Member Author

pshaughn commented Jan 14, 2020

// FIXME(nox): According to the spec, setting the current
// request to the broken state is done prior to queuing a
// task, why is this here?
this.abort_request(State::Broken, ImageRequestPhase::Current);
this.abort_request(State::Broken, ImageRequestPhase::Pending);

This seems to be the thing that is firing at the wrong time; moving it out of the task like the comment says, nothing immediately crashes and the one reftest seems to pass consistently. I'm expecting something else to break.

@pshaughn
Copy link
Member Author

pshaughn commented Jan 14, 2020

@bors-servo try=wpt

@bors-servo
Copy link
Contributor

bors-servo commented Jan 14, 2020

Trying commit da0c8c4 with merge 8d585bc...

bors-servo added a commit that referenced this pull request Jan 14, 2020
Add microtask checkpoints to script elements and custom elements

Servo had a microtask checkpoint at the end of running a script, but there was also supposed to be one at the end of HTML-parsing a script element before Javascript-parsing the script itself, and there were supposed to be checkpoints immediately after the call to a custom element constructor. This adds those, passing all cases of one WPT test file.

---
<!-- 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 #25016 except for the remaining not-really-about-microtasks case #25514

<!-- Either: -->
- [X] There are tests for these changes

<!-- 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. -->
@bors-servo
Copy link
Contributor

bors-servo commented Jan 14, 2020

💔 Test failed - status-taskcluster

@pshaughn
Copy link
Member Author

pshaughn commented Jan 14, 2020

Just another one of those background-color intermittents and the new MutationObserver passes. I am surprised that change worked so smoothly.

@pshaughn pshaughn force-pushed the pshaughn:checkpoints branch from da0c8c4 to f5a26a2 Jan 15, 2020
@pshaughn pshaughn force-pushed the pshaughn:checkpoints branch from f5a26a2 to c725f9e Jan 15, 2020
@jdm
Copy link
Member

jdm commented Jan 25, 2020

@bors-servo
Copy link
Contributor

bors-servo commented Jan 25, 2020

📌 Commit c725f9e has been approved by jdm

@highfive highfive assigned jdm and unassigned nox Jan 25, 2020
@bors-servo
Copy link
Contributor

bors-servo commented Jan 25, 2020

Testing commit c725f9e with merge 11bbb25...

bors-servo added a commit that referenced this pull request Jan 25, 2020
Add microtask checkpoints to script elements and custom elements

Servo had a microtask checkpoint at the end of running a script, but there was also supposed to be one at the end of HTML-parsing a script element before Javascript-parsing the script itself, and there were supposed to be checkpoints immediately after the call to a custom element constructor. This adds those, passing all cases of one WPT test file.

---
<!-- 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 #25016 except for the remaining not-really-about-microtasks case #25514

<!-- Either: -->
- [X] There are tests for these changes

<!-- 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. -->
@bors-servo
Copy link
Contributor

bors-servo commented Jan 25, 2020

💔 Test failed - status-taskcluster

@jdm
Copy link
Member

jdm commented Jan 25, 2020

bors-servo added a commit that referenced this pull request Jan 25, 2020
Add microtask checkpoints to script elements and custom elements

Servo had a microtask checkpoint at the end of running a script, but there was also supposed to be one at the end of HTML-parsing a script element before Javascript-parsing the script itself, and there were supposed to be checkpoints immediately after the call to a custom element constructor. This adds those, passing all cases of one WPT test file.

---
<!-- 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 #25016 except for the remaining not-really-about-microtasks case #25514

<!-- Either: -->
- [X] There are tests for these changes

<!-- 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. -->
@bors-servo
Copy link
Contributor

bors-servo commented Jan 25, 2020

Testing commit c725f9e with merge 5387994...

@bors-servo
Copy link
Contributor

bors-servo commented Jan 25, 2020

☀️ Test successful - status-taskcluster
Approved by: jdm
Pushing 5387994 to master...

@bors-servo bors-servo merged commit c725f9e into servo:master Jan 25, 2020
2 checks passed
2 checks passed
Community-TC (pull_request) TaskGroup: success
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.

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