Skip to content

Commit 1743e81

Browse files
agraciokkoopa
authored andcommitted
updating WriteUtf8V2 method
1 parent 86adbd0 commit 1743e81

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

nan.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,11 @@ template<typename P> class WeakCallbackInfo;
427427

428428
namespace imp {
429429
static const size_t kMaxLength = 0x3fffffff;
430-
// v8::String::REPLACE_INVALID_UTF8 was introduced
431-
// in node.js v0.10.29 and v0.8.27.
432-
#if NODE_MAJOR_VERSION > 0 || \
433-
NODE_MINOR_VERSION > 10 || \
434-
NODE_MINOR_VERSION == 10 && NODE_PATCH_VERSION >= 29 || \
435-
NODE_MINOR_VERSION == 8 && NODE_PATCH_VERSION >= 27
436-
static const unsigned kReplaceInvalidUtf8 = v8::String::REPLACE_INVALID_UTF8;
430+
#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 13 || \
431+
(V8_MAJOR_VERSION == 13 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 4))
432+
static const unsigned kReplaceInvalidUtf8 = v8::String::WriteFlags::kReplaceInvalidUtf8;
437433
#else
438-
static const unsigned kReplaceInvalidUtf8 = 0;
434+
static const unsigned kReplaceInvalidUtf8 = v8::String::REPLACE_INVALID_UTF8;
439435
#endif
440436
} // end of namespace imp
441437

@@ -1167,14 +1163,14 @@ class Utf8String {
11671163
str_ = static_cast<char*>(malloc(len));
11681164
assert(str_ != 0);
11691165
}
1170-
const int flags =
1171-
v8::String::NO_NULL_TERMINATION | imp::kReplaceInvalidUtf8;
11721166
#if NODE_MAJOR_VERSION >= 11
11731167
#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 13 || \
1174-
(V8_MAJOR_VERSION == 13 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION > 3))
1168+
(V8_MAJOR_VERSION == 13 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 4))
11751169
length_ = string->WriteUtf8V2(v8::Isolate::GetCurrent(), str_,
11761170
static_cast<int>(len), imp::kReplaceInvalidUtf8);
11771171
#else
1172+
const int flags =
1173+
v8::String::NO_NULL_TERMINATION | imp::kReplaceInvalidUtf8;
11781174
length_ = string->WriteUtf8(v8::Isolate::GetCurrent(), str_,
11791175
static_cast<int>(len), 0, flags);
11801176
#endif
@@ -1190,7 +1186,9 @@ class Utf8String {
11901186
#pragma GCC diagnostic push
11911187
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
11921188
#endif
1193-
length_ = string->WriteUtf8(str_, static_cast<int>(len), 0, flags);
1189+
const int flags =
1190+
v8::String::NO_NULL_TERMINATION | imp::kReplaceInvalidUtf8;
1191+
length_ = string->WriteUtf8(str_, static_cast<int>(len), 0, flags);
11941192
#ifdef __GNUC__
11951193
#pragma GCC diagnostic pop
11961194
#endif

0 commit comments

Comments
 (0)