From c98d35ea6b70d341696e72f1d8aeff9dd945f423 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 6 Aug 2015 11:46:58 +0200 Subject: [PATCH] Lock stderr while printing the alert() message. 2a7f262b7df8761261a0fa618394f4e991733a5e was unsufficient for the case where the interleaved output was actually on stderr rather than stdout, such as output from the error macro. --- components/script/dom/window.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index d31eb3d3527..38100d87d16 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -72,7 +72,7 @@ use std::cell::{Cell, Ref, RefMut, RefCell}; use std::collections::HashSet; use std::default::Default; use std::ffi::CString; -use std::io::{stdout, Write}; +use std::io::{stdout, stderr, Write}; use std::mem as std_mem; use std::rc::Rc; use std::sync::Arc; @@ -361,10 +361,15 @@ impl<'a> WindowMethods for &'a Window { // https://html.spec.whatwg.org/#dom-alert fn Alert(self, s: DOMString) { // Right now, just print to the console + // Ensure that stderr doesn't trample through the alert() we use to + // communicate test results. + let stderr = stderr(); + let mut stderr = stderr.lock(); let stdout = stdout(); let mut stdout = stdout.lock(); writeln!(&mut stdout, "ALERT: {}", s).unwrap(); stdout.flush().unwrap(); + stderr.flush().unwrap(); } // https://html.spec.whatwg.org/multipage/#dom-window-close