mirror of
https://github.com/servo/servo.git
synced 2025-07-22 14:53:49 +01:00
Report real caller information for console APIs to devtools.
This commit is contained in:
parent
0540c4a284
commit
ab7ade4efe
4 changed files with 13 additions and 14 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -3481,7 +3481,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "mozjs"
|
||||
version = "0.13.0"
|
||||
source = "git+https://github.com/servo/rust-mozjs#8615f86310d2e1021f7f1e5db4a0df98f4c8edb0"
|
||||
source = "git+https://github.com/servo/rust-mozjs#11cabdef2cbf0884a2cc33e3c73719646bd31ce5"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"lazy_static",
|
||||
|
|
|
@ -34,3 +34,4 @@ spirv_cross = { git = "https://github.com/servo/spirv_cross", branch = "wgpu-ser
|
|||
backtrace = { git = "https://github.com/MeFisto94/backtrace-rs", branch = "fix-strtab-freeing-crash" }
|
||||
surfman-chains = { git = "https://github.com/asajeffrey/surfman-chains" }
|
||||
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 _ac = enter_realm(global);
|
||||
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() {
|
||||
EvaluateJSReply::VoidValue
|
||||
|
|
|
@ -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