mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #26346 - jdm:console-caller, r=Manishearth
Improve devtools output for console APIs These changes use the new API from https://github.com/servo/rust-mozjs/pull/508 to report meaningful filenames and line numbers for APIs that trigger devtools output. They also cause error messages originating from uncompiled event handlers to report a more relevant filename; this differs from Gecko's behaviour, but provides a more useful debugging experience in my opinion. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #9604 and fix #26344. - [x] These changes do not require tests because devtools aren't tested.
This commit is contained in:
commit
ba0df48d47
4 changed files with 13 additions and 14 deletions
|
@ -7,15 +7,24 @@ use crate::dom::bindings::str::DOMString;
|
|||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::workerglobalscope::WorkerGlobalScope;
|
||||
use devtools_traits::{ConsoleMessage, LogLevel, ScriptToDevtoolsControlMsg};
|
||||
use js::rust::describe_scripted_caller;
|
||||
use std::io;
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Console
|
||||
pub struct Console(());
|
||||
|
||||
impl Console {
|
||||
#[allow(unsafe_code)]
|
||||
fn send_to_devtools(global: &GlobalScope, level: LogLevel, message: DOMString) {
|
||||
if let Some(chan) = global.devtools_chan() {
|
||||
let console_message = prepare_message(level, message);
|
||||
let caller = unsafe { describe_scripted_caller(*global.get_cx()) }.unwrap_or_default();
|
||||
let console_message = ConsoleMessage {
|
||||
message: String::from(message),
|
||||
logLevel: level,
|
||||
filename: caller.filename,
|
||||
lineNumber: caller.line as usize,
|
||||
columnNumber: caller.col as usize,
|
||||
};
|
||||
let worker_id = global
|
||||
.downcast::<WorkerGlobalScope>()
|
||||
.map(|worker| worker.get_worker_id());
|
||||
|
@ -128,14 +137,3 @@ impl Console {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn prepare_message(log_level: LogLevel, message: DOMString) -> ConsoleMessage {
|
||||
// TODO: Sending fake values for filename, lineNumber and columnNumber in LogMessage; adjust later
|
||||
ConsoleMessage {
|
||||
message: String::from(message),
|
||||
logLevel: log_level,
|
||||
filename: "test".to_owned(),
|
||||
lineNumber: 1,
|
||||
columnNumber: 1,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue