dom: Add Window.js_backtrace debugging extension method.

This commit is contained in:
Josh Matthews 2020-07-14 12:17:05 -04:00
parent e6cdfddea6
commit 4dd7387799
3 changed files with 21 additions and 4 deletions

View file

@ -18,8 +18,8 @@ jitspew = ['js/jitspew']
profilemozjs = ['js/profilemozjs'] profilemozjs = ['js/profilemozjs']
unrooted_must_root_lint = ["script_plugins/unrooted_must_root_lint"] unrooted_must_root_lint = ["script_plugins/unrooted_must_root_lint"]
default = ["unrooted_must_root_lint"] default = ["unrooted_must_root_lint"]
webgl_backtrace = ["backtrace", "canvas_traits/webgl_backtrace"] webgl_backtrace = ["canvas_traits/webgl_backtrace"]
js_backtrace = ["backtrace"] js_backtrace = []
refcell_backtrace = ["accountable-refcell"] refcell_backtrace = ["accountable-refcell"]
uwp = ["js/uwp"] uwp = ["js/uwp"]
xr-profile = ["webxr-api/profile"] xr-profile = ["webxr-api/profile"]
@ -33,7 +33,7 @@ serde_json = "1.0"
accountable-refcell = { version = "0.2.0", optional = true } accountable-refcell = { version = "0.2.0", optional = true }
app_units = "0.7" app_units = "0.7"
arrayvec = "0.5.1" arrayvec = "0.5.1"
backtrace = { version = "0.3", optional = true } backtrace = "0.3"
base64 = "0.10.1" base64 = "0.10.1"
bitflags = "1.0" bitflags = "1.0"
bluetooth_traits = { path = "../bluetooth_traits" } bluetooth_traits = { path = "../bluetooth_traits" }

View file

@ -142,6 +142,8 @@ partial interface Window {
void gc(); void gc();
[Pref="dom.servo_helpers.enabled"] [Pref="dom.servo_helpers.enabled"]
void trap(); void trap();
[Pref="dom.servo_helpers.enabled"]
void js_backtrace();
}; };
// WebDriver extensions // WebDriver extensions

View file

@ -72,6 +72,7 @@ use crate::task_source::{TaskSource, TaskSourceName};
use crate::timers::{IsInterval, TimerCallback}; use crate::timers::{IsInterval, TimerCallback};
use crate::webdriver_handlers::jsval_to_webdriver; use crate::webdriver_handlers::jsval_to_webdriver;
use app_units::Au; use app_units::Au;
use backtrace::Backtrace;
use base64; use base64;
use bluetooth_traits::BluetoothRequest; use bluetooth_traits::BluetoothRequest;
use canvas_traits::webgl::WebGLChan; use canvas_traits::webgl::WebGLChan;
@ -89,7 +90,7 @@ use js::jsapi::Heap;
use js::jsapi::JSAutoRealm; use js::jsapi::JSAutoRealm;
use js::jsapi::JSObject; use js::jsapi::JSObject;
use js::jsapi::JSPROP_ENUMERATE; use js::jsapi::JSPROP_ENUMERATE;
use js::jsapi::{GCReason, JS_GC}; use js::jsapi::{GCReason, StackFormat, JS_GC};
use js::jsval::UndefinedValue; use js::jsval::UndefinedValue;
use js::jsval::{JSVal, NullValue}; use js::jsval::{JSVal, NullValue};
use js::rust::wrappers::JS_DefineProperty; use js::rust::wrappers::JS_DefineProperty;
@ -1081,6 +1082,20 @@ impl WindowMethods for Window {
unsafe { ::std::intrinsics::breakpoint() } unsafe { ::std::intrinsics::breakpoint() }
} }
#[allow(unsafe_code)]
fn Js_backtrace(&self) {
unsafe {
capture_stack!(in(*self.get_cx()) let stack);
let js_stack = stack.and_then(|s| s.as_string(None, StackFormat::SpiderMonkey));
let rust_stack = Backtrace::new();
println!(
"Current JS stack:\n{}\nCurrent Rust stack:\n{:?}",
js_stack.unwrap_or(String::new()),
rust_stack
);
}
}
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn WebdriverCallback(&self, cx: JSContext, val: HandleValue) { fn WebdriverCallback(&self, cx: JSContext, val: HandleValue) {
let rv = unsafe { jsval_to_webdriver(*cx, &self.globalscope, val) }; let rv = unsafe { jsval_to_webdriver(*cx, &self.globalscope, val) };