mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +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
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -3485,7 +3485,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mozjs"
|
name = "mozjs"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
source = "git+https://github.com/servo/rust-mozjs#8615f86310d2e1021f7f1e5db4a0df98f4c8edb0"
|
source = "git+https://github.com/servo/rust-mozjs#11cabdef2cbf0884a2cc33e3c73719646bd31ce5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
|
|
@ -33,3 +33,4 @@ winapi = { git = "https://github.com/servo/winapi-rs", branch = "patch-1" }
|
||||||
spirv_cross = { git = "https://github.com/servo/spirv_cross", branch = "wgpu-servo" }
|
spirv_cross = { git = "https://github.com/servo/spirv_cross", branch = "wgpu-servo" }
|
||||||
surfman-chains = { git = "https://github.com/asajeffrey/surfman-chains" }
|
surfman-chains = { git = "https://github.com/asajeffrey/surfman-chains" }
|
||||||
surfman = { git = "https://github.com/servo/surfman" }
|
surfman = { git = "https://github.com/servo/surfman" }
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ pub fn handle_evaluate_js(global: &GlobalScope, eval: String, reply: IpcSender<E
|
||||||
let cx = global.get_cx();
|
let cx = global.get_cx();
|
||||||
let _ac = enter_realm(global);
|
let _ac = enter_realm(global);
|
||||||
rooted!(in(*cx) let mut rval = UndefinedValue());
|
rooted!(in(*cx) let mut rval = UndefinedValue());
|
||||||
global.evaluate_js_on_global_with_result(&eval, rval.handle_mut());
|
global.evaluate_script_on_global_with_result(&eval, "<eval>", rval.handle_mut(), 1);
|
||||||
|
|
||||||
if rval.is_undefined() {
|
if rval.is_undefined() {
|
||||||
EvaluateJSReply::VoidValue
|
EvaluateJSReply::VoidValue
|
||||||
|
|
|
@ -7,15 +7,24 @@ use crate::dom::bindings::str::DOMString;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::workerglobalscope::WorkerGlobalScope;
|
use crate::dom::workerglobalscope::WorkerGlobalScope;
|
||||||
use devtools_traits::{ConsoleMessage, LogLevel, ScriptToDevtoolsControlMsg};
|
use devtools_traits::{ConsoleMessage, LogLevel, ScriptToDevtoolsControlMsg};
|
||||||
|
use js::rust::describe_scripted_caller;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/Console
|
// https://developer.mozilla.org/en-US/docs/Web/API/Console
|
||||||
pub struct Console(());
|
pub struct Console(());
|
||||||
|
|
||||||
impl Console {
|
impl Console {
|
||||||
|
#[allow(unsafe_code)]
|
||||||
fn send_to_devtools(global: &GlobalScope, level: LogLevel, message: DOMString) {
|
fn send_to_devtools(global: &GlobalScope, level: LogLevel, message: DOMString) {
|
||||||
if let Some(chan) = global.devtools_chan() {
|
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
|
let worker_id = global
|
||||||
.downcast::<WorkerGlobalScope>()
|
.downcast::<WorkerGlobalScope>()
|
||||||
.map(|worker| worker.get_worker_id());
|
.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