Skip to content

Commit

Permalink
Fix build breakage with Node.js 10.0.0-10.9.0. (#833)
Browse files Browse the repository at this point in the history
The five argument WriteUtf8() method was introduced in Node.js v10.0.0,
it doesn't exist in older 10.x releases.

Use the four argument overload and a bunch of pragmas to silence the
compiler warnings.

Fixes: #832
Refs: #825
  • Loading branch information
bnoordhuis authored and kkoopa committed Dec 18, 2018
1 parent e8f8519 commit 625e90e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion nan.h
Original file line number Diff line number Diff line change
Expand Up @@ -1077,11 +1077,27 @@ class Utf8String {
}
const int flags =
v8::String::NO_NULL_TERMINATION | imp::kReplaceInvalidUtf8;
#if NODE_MAJOR_VERSION >= 10
#if NODE_MAJOR_VERSION >= 11
length_ = string->WriteUtf8(v8::Isolate::GetCurrent(), str_, static_cast<int>(len), 0, flags);
#else
// See https://github.com/nodejs/nan/issues/832.
// Disable the warning as there is no way around it.
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996)
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
length_ = string->WriteUtf8(str_, static_cast<int>(len), 0, flags);
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // NODE_MAJOR_VERSION < 11
str_[length_] = '\0';
}
}
Expand Down

0 comments on commit 625e90e

Please sign in to comment.