Auto merge of #26668 - CYBAI:fix-module-current-script, r=jdm

Set `currentScript` to `null` for module scripts

I misunderstood the test case when I worked on #23545. That test case is
actually not related to dynamic import; instead, the reason why it
crashes is, `currentScript` should be updated to `null`.

In spec, the step 6 of [execute-the-script-block](https://html.spec.whatwg.org/multipage/scripting.html#execute-the-script-block) only says `Assert: document's currentScript attribute is null.` but doesn't says it should be set to null. Not sure if it can be improved.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)
- [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. -->
This commit is contained in:
bors-servo 2020-05-27 08:58:36 -04:00 committed by GitHub
commit 4094d16323
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View file

@ -756,14 +756,18 @@ impl HTMLScriptElement {
let document = document_from_node(self);
let old_script = document.GetCurrentScript();
match script.type_ {
ScriptType::Classic => document.set_current_script(Some(self)),
ScriptType::Module => document.set_current_script(None),
}
match script.type_ {
ScriptType::Classic => {
document.set_current_script(Some(self));
self.run_a_classic_script(&script);
document.set_current_script(old_script.as_deref());
},
ScriptType::Module => {
assert!(old_script.is_none());
assert!(document.GetCurrentScript().is_none());
self.run_a_module_script(&script, false);
},
}