Bug 1399777 Fprinter directing output to Windows debug console when it outputs to stderr. r=Yoric draft
authorsourav3 <sourav.mukherjee619@gmail.com>
Thu, 21 Sep 2017 17:06:51 +0800
changeset 668246 4da76d1821734932a717c13df4e1e42f9d9b296e
parent 665088 8e818b5e9b6bef0fc1a5c527ecf30b0d56a02f14
child 732652 57921c5072425852d45eefc2dc417fb64b08fe9e
push id80992
push userbmo:sourav.mukherjee619@gmail.com
push dateThu, 21 Sep 2017 12:11:44 +0000
reviewersYoric
bugs1399777
milestone57.0a1
Bug 1399777 Fprinter directing output to Windows debug console when it outputs to stderr. r=Yoric MozReview-Commit-ID: 81ubXofHIlG *** Using PodCopy instead of std::copy and fixing spaces
js/src/vm/Printer.cpp
--- a/js/src/vm/Printer.cpp
+++ b/js/src/vm/Printer.cpp
@@ -13,16 +13,20 @@
 #include <stdarg.h>
 #include <stdio.h>
 
 #include "jscntxt.h"
 #include "jsutil.h"
 
 #include "ds/LifoAlloc.h"
 
+#ifdef XP_WIN32
+#include "jswin.h"
+#endif
+
 using mozilla::PodCopy;
 
 namespace
 {
 
 class GenericPrinterPrintfTarget : public mozilla::PrintfTarget
 {
 public:
@@ -445,16 +449,28 @@ bool
 Fprinter::put(const char* s, size_t len)
 {
     MOZ_ASSERT(file_);
     int i = fwrite(s, /*size=*/ 1, /*nitems=*/ len, file_);
     if (size_t(i) != len) {
         reportOutOfMemory();
         return false;
     }
+#ifdef XP_WIN32
+    if ((file_ == stderr) && (IsDebuggerPresent())) {
+        UniqueChars buf(static_cast<char*>(js_malloc(len + 1)));
+        if (!buf) {
+            reportOutOfMemory();
+            return false;
+        }
+        PodCopy(buf.get(), s, len);
+        buf[len] = '\0';
+        OutputDebugStringA(buf.get());
+    }
+#endif
     return true;
 }
 
 LSprinter::LSprinter(LifoAlloc* lifoAlloc)
   : alloc_(lifoAlloc),
     head_(nullptr),
     tail_(nullptr),
     unused_(0)