Bug 1399777 Fprinter directing output to Windows debug console when it outputs to stderr. r=Yoric draft
authorsourav3 <sourav.mukherjee619@gmail.com>
Sun, 17 Sep 2017 18:34:08 +0800
changeset 666059 3cf2a2eda23d94f8107e2f23ca3e0fe273d91239
parent 665088 8e818b5e9b6bef0fc1a5c527ecf30b0d56a02f14
child 731964 7f0845039afacfa0f83fcf6ca097fdee5173f5fd
push id80259
push userbmo:sourav.mukherjee619@gmail.com
push dateSun, 17 Sep 2017 10:36:55 +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 MozReview-Commit-ID: BWecXLjyy1m *** fixing cast in js_malloc MozReview-Commit-ID: 61VEUN63hy2
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 <windows.h>
+#endif
+
 using mozilla::PodCopy;
 
 namespace
 {
 
 class GenericPrinterPrintfTarget : public mozilla::PrintfTarget
 {
 public:
@@ -445,16 +449,25 @@ 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()) ) {
+        char *cpy = (char *) js_malloc(len + 1);
+        PodCopy(cpy, s, len);
+        cpy[len] = '\0';
+        OutputDebugStringA(cpy);
+        js_free(cpy);
+    }
+#endif
     return true;
 }
 
 LSprinter::LSprinter(LifoAlloc* lifoAlloc)
   : alloc_(lifoAlloc),
     head_(nullptr),
     tail_(nullptr),
     unused_(0)