Devtools: initial Debugger > Sources panel (#36164)

This patch adds support for listing scripts in the Sources panel.
Classic scripts, both external and inline, are implemented, but worker
scripts and imported module scripts are not yet implemented.

For example:

```html
<!-- sources.html -->
<!doctype html><meta charset=utf-8>
<script src="classic.js"></script>
<script>
    console.log("inline classic");
    new Worker("worker.js");
</script>
<script type="module">
    import module from "./module.js";
    console.log("inline module");
</script>
<script src="https://servo.org/js/load-table.js"></script>
```

```js
// classic.js
console.log("external classic");
```

```js
// worker.js
console.log("external classic worker");
```

```js
// module.js
export default 1;
console.log("external module");
```


![image](https://github.com/user-attachments/assets/2f1d8d7c-501f-4fe5-bd07-085c95e504f2)

---
<!-- 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 partially implement #36027

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes require tests, but they are blocked on #36325

Signed-off-by: Delan Azabani <dazabani@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
This commit is contained in:
delan azabani 2025-04-08 17:22:53 +08:00 committed by GitHub
parent 40655cc06c
commit 95eedb997a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 143 additions and 7 deletions

View file

@ -19,6 +19,7 @@ use serde::Serialize;
use serde_json::{Map, Value};
use self::network_parent::{NetworkParentActor, NetworkParentActorMsg};
use super::thread::ThreadActor;
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
use crate::actors::browsing_context::{BrowsingContextActor, BrowsingContextActorMsg};
use crate::actors::watcher::target_configuration::{
@ -78,7 +79,7 @@ impl SessionContext {
("network-event-stacktrace", false),
("reflow", false),
("stylesheet", false),
("source", false),
("source", true),
("thread-state", false),
("server-sent-event", false),
("websocket", false),
@ -133,6 +134,18 @@ struct GetThreadConfigurationActorReply {
configuration: ThreadConfigurationActorMsg,
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct GetBreakpointListActorReply {
from: String,
breakpoint_list: GetBreakpointListActorReplyInner,
}
#[derive(Serialize)]
struct GetBreakpointListActorReplyInner {
actor: String,
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct DocumentEvent {
@ -249,6 +262,11 @@ impl Actor for WatcherActor {
target.resource_available(event, "document-event".into());
}
},
"source" => {
let thread_actor = registry.find::<ThreadActor>(&target.thread);
let sources = thread_actor.sources();
target.resources_available(sources.iter().collect(), "source".into());
},
"console-message" | "error-message" => {},
_ => warn!("resource {} not handled yet", resource),
}
@ -295,6 +313,15 @@ impl Actor for WatcherActor {
let _ = stream.write_json_packet(&msg);
ActorMessageStatus::Processed
},
"getBreakpointListActor" => {
let _ = stream.write_json_packet(&GetBreakpointListActorReply {
from: self.name(),
breakpoint_list: GetBreakpointListActorReplyInner {
actor: registry.new_name("breakpoint-list"),
},
});
ActorMessageStatus::Processed
},
_ => ActorMessageStatus::Ignored,
})
}