15#define snprintf sprintf_s
19#if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
21#include <android/log.h>
33 if (!IsDebuggerPresent()) {
40 if (pbase() == epptr()) {
41 auto as_char =
static_cast<char>(c);
42 OutputDebugStringA(&as_char);
44 sputc(
static_cast<char>(c));
53 if (!IsDebuggerPresent()) {
57 if (pbase() != pptr()) {
58 OutputDebugStringA(std::string(pbase(),
static_cast<std::string::size_type
>(
61 setp(pbase(), epptr());
77 return (c != EOF) ? std::fputc(c,
f_) : c;
81 return static_cast<std::streamsize
>(
82 std::fwrite(s, 1,
static_cast<size_t>(n),
f_));
90#if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
91AndroidLogStream::~AndroidLogStream() {
94 if (!line_buffer_.empty()) {
95 __android_log_write(ANDROID_LOG_INFO, LOG_TAG, line_buffer_.c_str());
99std::streamsize AndroidLogStream::xsputn(
const char* s, std::streamsize n) {
100 const char*
const e = s +
n;
102 const char* newline =
reinterpret_cast<const char*
>(memchr(s,
'\n', e - s));
103 size_t line_chars = (newline ? newline : e) - s;
104 line_buffer_.append(s, line_chars);
109 __android_log_write(ANDROID_LOG_INFO, LOG_TAG, line_buffer_.c_str());
110 line_buffer_.clear();
123bool IsPrint(uint16_t c) {
return 0x20 <= c && c <= 0x7E; }
124bool IsSpace(uint16_t c) {
return (0x9 <= c && c <= 0xD) || c == 0x20; }
125bool IsOK(uint16_t c) {
return (IsPrint(c) || IsSpace(c)) && c !=
'\\'; }
127std::ostream& PrintUC16(std::ostream& os, uint16_t c,
bool (*pred)(uint16_t)) {
129 const char* format = pred(c) ?
"%c" : (c <= 0xFF) ?
"\\x%02x" :
"\\u%04x";
130 snprintf(buf,
sizeof(buf), format, c);
134std::ostream& PrintUC16ForJSON(std::ostream& os, uint16_t c,
135 bool (*pred)(uint16_t)) {
138 const char* format = pred(c) ?
"%c" :
"\\u%04x";
139 snprintf(buf,
sizeof(buf), format, c);
143std::ostream& PrintUC32(std::ostream& os, int32_t c,
bool (*pred)(uint16_t)) {
145 return PrintUC16(os,
static_cast<uint16_t
>(c), pred);
148 snprintf(buf,
sizeof(buf),
"\\u{%06x}", c);
155 return PrintUC16(os, c.
value, IsOK);
159 if (c.
value ==
'\n')
return os <<
"\\n";
160 if (c.
value ==
'\r')
return os <<
"\\r";
161 if (c.
value ==
'\t')
return os <<
"\\t";
162 if (c.
value ==
'\"')
return os <<
"\\\"";
163 return PrintUC16ForJSON(os, c.
value, IsOK);
167 return PrintUC16(os, c.
value, IsPrint);
171 return PrintUC32(os, c.
value, IsPrint);
178 static constexpr size_t kMaxHexLength = 3 +
sizeof(hex.
value) * 2;
179 char buf[kMaxHexLength];
180 snprintf(buf, kMaxHexLength,
"%s%.*" PRIx64, hex.
with_prefix ?
"0x" :
"",
187 while (bytes <
sizeof(hex.
value) && (hex.
value >> (bytes * 8) != 0)) ++bytes;
188 for (uint8_t b = 0; b < bytes; ++b) {
190 uint8_t printed_byte =
192 os <<
AsHex((hex.
value >> (8 * printed_byte)) & 0xFF, 2);
int overflow(int c) override
int_type overflow(int_type c) override
std::streamsize xsputn(const char *s, std::streamsize n) override
static V8_EXPORT_PRIVATE base::RecursiveMutex * GetStdoutMutex()
static const int kMaxUtf16CodeUnit
#define DEFINE_LAZY_LEAKY_OBJECT_GETTER(T, FunctionName,...)
std::ostream & operator<<(std::ostream &os, AtomicMemoryOrder order)
#define DCHECK_NOT_NULL(val)
#define DCHECK_GE(v1, v2)