devtools: Fix source contents tests and fix a race (#38359)

test_sources_list() relied on <https://servo.org/js/load-table.js> to
test scripts loaded from multiple origins, but that file was deleted a
couple of weeks ago. this patch adds a second internal web server, then
replaces that load with scripts loaded from two distinct origins:
<http://127.0.0.1:10000> and <http://127.0.0.1:10001>.

fixing that test revealed an impl bug where inline module scripts
containing `import` statements may never get their source contents
populated. this is because the logic for populating source contents for
inline scripts only applied to source actors created *before* we
finished parsing the page. we assumed that inline scripts always block
the parser, but this is not the case. this patch ensures that inline
source contents can be populated for source actors created after parse.

Testing: adds a new test,
test_source_content_with_inline_module_import_external()
Fixes: part of #36325

Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
This commit is contained in:
shuppy 2025-07-30 19:29:24 +08:00 committed by GitHub
parent 900dd8d191
commit a671c50bc9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 1 deletions

View file

@ -543,11 +543,14 @@ impl DevtoolsInstance {
fn handle_create_source_actor(&mut self, pipeline_id: PipelineId, source_info: SourceInfo) {
let mut actors = self.actors.lock().unwrap();
let source_content = source_info
.content
.or_else(|| actors.inline_source_content(pipeline_id));
let source_actor = SourceActor::new_registered(
&mut actors,
pipeline_id,
source_info.url,
source_info.content,
source_content,
source_info.content_type,
);
let source_actor_name = source_actor.name.clone();
@ -613,6 +616,10 @@ impl DevtoolsInstance {
source_actor.content = Some(source_content.clone());
}
}
// Store the source content separately for any future source actors that get created *after* we finish parsing
// the HTML. For example, adding an `import` to an inline module script can delay it until after parsing.
actors.set_inline_source_content(pipeline_id, source_content);
}
}