-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Test whether parse document check is done in #prepare-a-script #23162
Test whether parse document check is done in #prepare-a-script #23162
Conversation
This PR adds empty-src tests, which moves <script src=""> elements between Documents before #prepare-a-script. If the parse document check is done in #prepara-a-script, <script>'s error event is not fired, and thus we can test whether the parse document check is done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice stuff. But, can you help me understand it a bit better? Probably we should expand the comment in
Lines 36 to 81 in 959a0d0
// For a script, there are four associated Documents that can | |
// potentially different: | |
// | |
// [1] script's parser document | |
// https://html.spec.whatwg.org/C/#parser-document | |
// | |
// [2] script's preparation-time document | |
// https://html.spec.whatwg.org/C/#preparation-time-document | |
// == script's node document at the beginning of #prepare-a-script | |
// | |
// [3] script's node document at the beginning of | |
// #execute-the-script-block | |
// | |
// This helper is for tests where [1]/[2]/[3] are different. | |
// In the spec, scripts are not executed only if [1]/[2]/[3] are all the same | |
// (or [1] is null and [2]==[3]). | |
// | |
// A check for [1]==[2] is in #prepare-a-script and | |
// a check for [1]==[3] is in #execute-the-script-block, | |
// but these are under debate: https://github.com/whatwg/html/issues/2137 | |
// | |
// A check for [2]==[3] is in #execute-the-script-block, which is added by | |
// https://github.com/whatwg/html/pull/2673 | |
// timing: | |
// "before-prepare": | |
// A <script> is moved during parsing before #prepare-a-script. | |
// [1] != [2] == [3] | |
// | |
// "after-prepare": | |
// A <script> is moved after parsing/#prepare-a-script but | |
// before #execute-the-script-block. | |
// [1] == [2] != [3] | |
// | |
// To move such scripts, #has-a-style-sheet-that-is-blocking-scripts | |
// is utilized to block inline scripts after #prepare-a-script. | |
// Note: this is a corner case in the spec which might be removed | |
// from the spec in the future, e.g. | |
// https://github.com/whatwg/html/issues/1349 | |
// https://github.com/chrishtr/rendering/blob/master/stylesheet-loading-proposal.md | |
// | |
// "parsing but moved back" | |
// A <script> is moved before #prepare-a-script, but moved back again | |
// to the original Document after #prepare-a-script. | |
// [1] == [3] != [2] |
In particular, that comment makes it seem like every combination is captured currently. So what do these tests add?
html/semantics/scripting-1/the-script-element/moving-between-documents/tools/generate.py
Show resolved
Hide resolved
...nt/moving-between-documents/before-prepare-createHTMLDocument-success-empty-src-classic.html
Outdated
Show resolved
Hide resolved
We have tests that assert if a document is moved "before-prepare", then it fails to run. However, imagine an implementation that:
This implementation will accidentally pass all (or some, I haven't checked) of the "before-prepare" tests because the script won't run, but it's because of a different check than we're testing. So in order to see if the algorithm progresses past #prepare-a-script step 2 inappropriately, the tests added here exercise this line. |
// type: "classic" or "module". | ||
async function runTest(timing, destType, result, inlineOrExternal, type) { | ||
if (result === "fetch-error" && inlineOrExternal === "inline") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you just removing this because it's already guarded against in generate.py?
I randomly came across whatwg/html#2137 the other day, from some discussion with @hiroshige-g I was pointed to this PR. I saw it was sitting for a bit so I decided to take a crack at some of the remaining bits. The changes I've made:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes from 5/6 to 4/6 passing in Blink/WebKit make me a bit worried that the refactoring broke something. But, maybe it just made things better? Gecko still passes everything, after all. Have you looked in to why that change happened?
@@ -48,7 +47,7 @@ window.didExecute = undefined; | |||
// | |||
// This helper is for tests where [1]/[2]/[3] are different. | |||
|
|||
// In the spec, scripts are not executed only if [1]/[2]/[3] are all the same | |||
// In the spec, scripts are executed only if [1]/[2]/[3] are all the same | |||
// (or [1] is null and [2]==[3]). | |||
// | |||
// A check for [1]==[2] is in #prepare-a-script and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds like, if the Chromium/spec change lands, we can remove "but these are under debate" (or change it into "these used to be under debate; see link for background"). We can do that in either this PR or in a followup, depending on how the timing works out.
Thanks for the heads up! Just did. So basically before my changed, Chrome / Safari failed tests that executed script inappropriately. We also have a test that should fail whenever the My refactoring creates the variable I've also confirmed that with my Chromium fix, Chromium still passes the tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! This LGTM; will let you decide whether to wait for @hiroshige-g's review or not.
The #prepare-a-script algorithm [1] includes a check asserting that a script element's parser document == its node document, for parser-inserted scripts. Spec discussion has been happening around this at [2], and WPTs have been added for this in [3] and [4] as part of an overall effort to test and better-specify the behavior of script elements that move between documents. Before this CL, Chromium had no concept of a parser document, and therefore would execute scripts that were moved to another document before ScriptLoader::PrepareScript was invoked. This CL introduces a |parser_document_| to ScriptLoader, which is populated from CreateElementFlags::ParserDocument(), similar to the |parser_inserted_| flag. [1]: https://html.spec.whatwg.org/C/#prepare-a-script [2]: whatwg/html#2137 [2]: web-platform-tests/wpt#19632 [3]: web-platform-tests/wpt#23162 Bug: 721914, 1086507 Change-Id: I7a0980afb47be93f8ed9948658b2cc8e4fa04669 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2214301 Commit-Queue: Dominic Farolino <[email protected]> Reviewed-by: Kouhei Ueno <[email protected]> Reviewed-by: Hiroshige Hayashizaki <[email protected]> Cr-Commit-Position: refs/heads/master@{#777203}
The #prepare-a-script algorithm [1] includes a check asserting that a script element's parser document == its node document, for parser-inserted scripts. Spec discussion has been happening around this at [2], and WPTs have been added for this in [3] and [4] as part of an overall effort to test and better-specify the behavior of script elements that move between documents. Before this CL, Chromium had no concept of a parser document, and therefore would execute scripts that were moved to another document before ScriptLoader::PrepareScript was invoked. This CL introduces a |parser_document_| to ScriptLoader, which is populated from CreateElementFlags::ParserDocument(), similar to the |parser_inserted_| flag. [1]: https://html.spec.whatwg.org/C/#prepare-a-script [2]: whatwg/html#2137 [2]: web-platform-tests/wpt#19632 [3]: web-platform-tests/wpt#23162 Bug: 721914, 1086507 Change-Id: I7a0980afb47be93f8ed9948658b2cc8e4fa04669 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2214301 Commit-Queue: Dominic Farolino <[email protected]> Reviewed-by: Kouhei Ueno <[email protected]> Reviewed-by: Hiroshige Hayashizaki <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#777203} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: f104795245d1a32fde965862578baeb6e75961be
This PR adds empty-src tests, which moves <script src=""> elements
<script>'s error event is not fired, and thus we can test whether the parse document check is done.between Documents before #prepare-a-script.
If the parse document check is done in #prepara-a-script,