diff options
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/Cargo.toml | 2 | ||||
-rw-r--r-- | components/script/dom/webglrenderingcontext.rs | 28 | ||||
-rw-r--r-- | components/script/lib.rs | 2 |
3 files changed, 29 insertions, 3 deletions
diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index 1c8feb0f17e..5ad8c3df8ff 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -16,6 +16,7 @@ debugmozjs = ['mozjs/debugmozjs'] unstable = [] unrooted_must_root_lint = ["script_plugins/unrooted_must_root_lint"] default = ["unrooted_must_root_lint"] +webgl_backtrace = ["backtrace", "canvas_traits/webgl_backtrace"] [build-dependencies] cmake = "0.1" @@ -29,6 +30,7 @@ tinyfiledialogs = "3.0" [dependencies] app_units = "0.7" audio-video-metadata = "0.1.4" +backtrace = {version = "0.3", optional = true} base64 = "0.6" bitflags = "1.0" bluetooth_traits = {path = "../bluetooth_traits"} diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 7367a38fdcf..754637ad52b 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -2,9 +2,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#[cfg(feature = "webgl_backtrace")] +use backtrace::Backtrace; use byteorder::{ByteOrder, NativeEndian, WriteBytesExt}; use canvas_traits::canvas::{byte_swap, multiply_u8_pixel}; -use canvas_traits::webgl::{DOMToTextureCommand, Parameter}; +use canvas_traits::webgl::{DOMToTextureCommand, Parameter, WebGLCommandBacktrace}; use canvas_traits::webgl::{TexParameter, WebGLCommand, WebGLContextShareMode, WebGLError}; use canvas_traits::webgl::{WebGLFramebufferBindingRequest, WebGLMsg, WebGLMsgSender}; use canvas_traits::webgl::{WebGLProgramId, WebGLResult, WebGLSLVersion, WebGLSender}; @@ -316,7 +318,7 @@ impl WebGLRenderingContext { #[inline] pub fn send_command(&self, command: WebGLCommand) { - self.webgl_sender.send(command).unwrap(); + self.webgl_sender.send(command, capture_webgl_backtrace(self)).unwrap(); } #[inline] @@ -1189,6 +1191,25 @@ impl WebGLRenderingContext { } } +#[cfg(not(feature = "webgl_backtrace"))] +#[inline] +pub fn capture_webgl_backtrace<T: DomObject>(_: &T) -> WebGLCommandBacktrace { + WebGLCommandBacktrace {} +} + +#[cfg(feature = "webgl_backtrace")] +#[cfg_attr(feature = "webgl_backtrace", allow(unsafe_code))] +pub fn capture_webgl_backtrace<T: DomObject>(obj: &T) -> WebGLCommandBacktrace { + let bt = Backtrace::new(); + unsafe { + capture_stack!(in(obj.global().get_cx()) let stack); + WebGLCommandBacktrace { + backtrace: format!("{:?}", bt), + js_backtrace: stack.and_then(|s| s.as_string(None)), + } + } +} + impl Drop for WebGLRenderingContext { fn drop(&mut self) { let _ = self.webgl_sender.send_remove(); @@ -1521,9 +1542,10 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { let (sender, receiver) = webgl_channel().unwrap(); // If the send does not succeed, assume context lost + let backtrace = capture_webgl_backtrace(self); if self .webgl_sender - .send(WebGLCommand::GetContextAttributes(sender)) + .send(WebGLCommand::GetContextAttributes(sender), backtrace) .is_err() { return None; diff --git a/components/script/lib.rs b/components/script/lib.rs index f8341323466..66bc4ac40eb 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -19,6 +19,8 @@ extern crate app_units; extern crate audio_video_metadata; +#[cfg(feature = "webgl_backtrace")] +extern crate backtrace; extern crate base64; #[macro_use] extern crate bitflags; |