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
--- 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)