Skip to content

Fix Node.js v10.12.0 deprecation warnings. #825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions nan.h
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,10 @@ class Utf8String {
length_(0), str_(str_st_) {
HandleScope scope;
if (!from.IsEmpty()) {
#if V8_MAJOR_VERSION >= 7
v8::Local<v8::String> string = from->ToString(v8::Isolate::GetCurrent());
#if NODE_MAJOR_VERSION >= 10
v8::Local<v8::Context> context = GetCurrentContext();
v8::Local<v8::String> string =
from->ToString(context).FromMaybe(v8::Local<v8::String>());
#else
v8::Local<v8::String> string = from->ToString();
#endif
Expand All @@ -1074,7 +1076,7 @@ class Utf8String {
}
const int flags =
v8::String::NO_NULL_TERMINATION | imp::kReplaceInvalidUtf8;
#if V8_MAJOR_VERSION >= 7
#if NODE_MAJOR_VERSION >= 10
length_ = string->WriteUtf8(v8::Isolate::GetCurrent(), str_, static_cast<int>(len), 0, flags);
#else
length_ = string->WriteUtf8(str_, static_cast<int>(len), 0, flags);
Expand Down Expand Up @@ -1852,36 +1854,41 @@ inline MaybeLocal<v8::Value> Call(
inline void SaveToPersistent(
const char *key, const v8::Local<v8::Value> &value) {
HandleScope scope;
New(persistentHandle)->Set(New(key).ToLocalChecked(), value);
Set(New(persistentHandle), New(key).ToLocalChecked(), value).FromJust();
}

inline void SaveToPersistent(
const v8::Local<v8::String> &key, const v8::Local<v8::Value> &value) {
HandleScope scope;
New(persistentHandle)->Set(key, value);
Set(New(persistentHandle), key, value).FromJust();
}

inline void SaveToPersistent(
uint32_t index, const v8::Local<v8::Value> &value) {
HandleScope scope;
New(persistentHandle)->Set(index, value);
Set(New(persistentHandle), index, value).FromJust();
}

inline v8::Local<v8::Value> GetFromPersistent(const char *key) const {
EscapableHandleScope scope;
return scope.Escape(
New(persistentHandle)->Get(New(key).ToLocalChecked()));
Get(New(persistentHandle), New(key).ToLocalChecked())
.FromMaybe(v8::Local<v8::Value>()));
}

inline v8::Local<v8::Value>
GetFromPersistent(const v8::Local<v8::String> &key) const {
EscapableHandleScope scope;
return scope.Escape(New(persistentHandle)->Get(key));
return scope.Escape(
Get(New(persistentHandle), key)
.FromMaybe(v8::Local<v8::Value>()));
}

inline v8::Local<v8::Value> GetFromPersistent(uint32_t index) const {
EscapableHandleScope scope;
return scope.Escape(New(persistentHandle)->Get(index));
return scope.Escape(
Get(New(persistentHandle), index)
.FromMaybe(v8::Local<v8::Value>()));
}

virtual void Execute() = 0;
Expand Down Expand Up @@ -2375,7 +2382,7 @@ SetMethodAux(T recv,
v8::Local<v8::String> name,
v8::Local<v8::FunctionTemplate> tpl,
...) {
recv->Set(name, GetFunction(tpl).ToLocalChecked());
Set(recv, name, GetFunction(tpl).ToLocalChecked());
}

} // end of namespace imp
Expand Down
33 changes: 27 additions & 6 deletions nan_implementation_12_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,17 @@ Factory<v8::Function>::New( FunctionCallback callback
obj->SetInternalField(imp::kDataIndex, val);
}

return scope.Escape(v8::Function::New( isolate
, imp::FunctionCallbackWrapper
, obj));
#if NODE_MAJOR_VERSION >= 10
v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::Local<v8::Function> function =
v8::Function::New(context, imp::FunctionCallbackWrapper, obj)
.ToLocalChecked();
#else
v8::Local<v8::Function> function =
v8::Function::New(isolate, imp::FunctionCallbackWrapper, obj);
#endif

return scope.Escape(function);
}

//=== Function Template ========================================================
Expand Down Expand Up @@ -332,12 +340,25 @@ Factory<v8::String>::New(ExternalOneByteStringResource * value) {

//=== String Object ============================================================

// See https://github.com/nodejs/nan/pull/811#discussion_r224594980.
// Disable the warning as there is no way around it.
// TODO(bnoordhuis) Use isolate-based version in Node.js v12.
Factory<v8::StringObject>::return_t
Factory<v8::StringObject>::New(v8::Local<v8::String> value) {
#if V8_MAJOR_VERSION >= 7
return v8::StringObject::New(v8::Isolate::GetCurrent(), value).As<v8::StringObject>();
#else
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996)
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
return v8::StringObject::New(value).As<v8::StringObject>();
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#ifdef _MSC_VER
#pragma warning(pop)
#endif
}

Expand Down
3 changes: 3 additions & 0 deletions nan_object_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ class ObjectWrap {
inline void MakeWeak() {
persistent().v8::PersistentBase<v8::Object>::SetWeak(
this, WeakCallback, v8::WeakCallbackType::kParameter);
#if NODE_MAJOR_VERSION < 10
// FIXME(bnoordhuis) Probably superfluous in older Node.js versions too.
persistent().MarkIndependent();
#endif
}

#elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION
Expand Down
6 changes: 4 additions & 2 deletions test/cpp/accessors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ NAN_MODULE_INIT(SetterGetter::Init) {
);

v8::Local<v8::Function> createnew =
Nan::New<v8::FunctionTemplate>(CreateNew)->GetFunction();
Nan::GetFunction(
Nan::New<v8::FunctionTemplate>(CreateNew)).ToLocalChecked();
Set(target, Nan::New<v8::String>("create").ToLocalChecked(), createnew);
}

Expand All @@ -70,7 +71,8 @@ v8::Local<v8::Value> SetterGetter::NewInstance () {
v8::Local<v8::FunctionTemplate> constructorHandle =
Nan::New(settergetter_constructor);
v8::Local<v8::Object> instance =
Nan::NewInstance(constructorHandle->GetFunction()).ToLocalChecked();
Nan::NewInstance(
Nan::GetFunction(constructorHandle).ToLocalChecked()).ToLocalChecked();
return scope.Escape(instance);
}

Expand Down
6 changes: 4 additions & 2 deletions test/cpp/accessors2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ NAN_MODULE_INIT(SetterGetter::Init) {
tpl->InstanceTemplate()->SetInternalFieldCount(1);
SetPrototypeMethod(tpl, "log", SetterGetter::Log);
v8::Local<v8::Function> createnew =
Nan::New<v8::FunctionTemplate>(CreateNew)->GetFunction();
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(CreateNew))
.ToLocalChecked();
Set(target, Nan::New<v8::String>("create").ToLocalChecked(), createnew);
}

Expand All @@ -58,7 +59,8 @@ v8::Local<v8::Value> SetterGetter::NewInstance () {
v8::Local<v8::FunctionTemplate> constructorHandle =
Nan::New(settergetter_constructor);
v8::Local<v8::Object> instance =
Nan::NewInstance(constructorHandle->GetFunction()).ToLocalChecked();
Nan::NewInstance(Nan::GetFunction(constructorHandle).ToLocalChecked())
.ToLocalChecked();
SetAccessor(
instance
, Nan::New("prop1").ToLocalChecked()
Expand Down
2 changes: 1 addition & 1 deletion test/cpp/asyncprogressqueueworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ NAN_METHOD(DoProgress) {
NAN_MODULE_INIT(Init) {
Set(target
, New<v8::String>("doProgress").ToLocalChecked()
, New<v8::FunctionTemplate>(DoProgress)->GetFunction());
, GetFunction(New<v8::FunctionTemplate>(DoProgress)).ToLocalChecked());
}

NODE_MODULE(asyncprogressqueueworker, Init)
2 changes: 1 addition & 1 deletion test/cpp/asyncprogressqueueworkerstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ NAN_METHOD(DoProgress) {
NAN_MODULE_INIT(Init) {
Set(target
, New<v8::String>("doProgress").ToLocalChecked()
, New<v8::FunctionTemplate>(DoProgress)->GetFunction());
, GetFunction(New<v8::FunctionTemplate>(DoProgress)).ToLocalChecked());
}

NODE_MODULE(asyncprogressqueueworkerstream, Init)
2 changes: 1 addition & 1 deletion test/cpp/asyncprogressworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ NAN_METHOD(DoProgress) {
NAN_MODULE_INIT(Init) {
Set(target
, New<v8::String>("a").ToLocalChecked()
, New<v8::FunctionTemplate>(DoProgress)->GetFunction());
, GetFunction(New<v8::FunctionTemplate>(DoProgress)).ToLocalChecked());
}

NODE_MODULE(asyncprogressworker, Init)
2 changes: 1 addition & 1 deletion test/cpp/asyncprogressworkersignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ NAN_METHOD(DoProgress) {
NAN_MODULE_INIT(Init) {
Set(target
, New<v8::String>("a").ToLocalChecked()
, New<v8::FunctionTemplate>(DoProgress)->GetFunction());
, GetFunction(New<v8::FunctionTemplate>(DoProgress)).ToLocalChecked());
}

NODE_MODULE(asyncprogressworkersignal, Init)
2 changes: 1 addition & 1 deletion test/cpp/asyncprogressworkerstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ NAN_METHOD(DoProgress) {
NAN_MODULE_INIT(Init) {
Set(target
, New<v8::String>("a").ToLocalChecked()
, New<v8::FunctionTemplate>(DoProgress)->GetFunction());
, GetFunction(New<v8::FunctionTemplate>(DoProgress)).ToLocalChecked());
}

NODE_MODULE(asyncprogressworkerstream, Init)
2 changes: 1 addition & 1 deletion test/cpp/asyncworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ NAN_METHOD(DoSleep) {
NAN_MODULE_INIT(Init) {
Set(target
, New<v8::String>("a").ToLocalChecked()
, New<v8::FunctionTemplate>(DoSleep)->GetFunction());
, GetFunction(New<v8::FunctionTemplate>(DoSleep)).ToLocalChecked());
}

NODE_MODULE(asyncworker, Init)
2 changes: 1 addition & 1 deletion test/cpp/asyncworkererror.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ NAN_METHOD(Work) {
NAN_MODULE_INIT(Init) {
Set(target
, New("a").ToLocalChecked()
, New<v8::FunctionTemplate>(Work)->GetFunction());
, GetFunction(New<v8::FunctionTemplate>(Work)).ToLocalChecked());
}

NODE_MODULE(asyncworkererror, Init)
8 changes: 4 additions & 4 deletions test/cpp/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ NAN_MODULE_INIT(Init) {
}
Set(target
, New<v8::String>("new1").ToLocalChecked()
, New<v8::FunctionTemplate>(New1)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(New1)).ToLocalChecked()
);
Set(target
, New<v8::String>("new2").ToLocalChecked()
, New<v8::FunctionTemplate>(New2)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(New2)).ToLocalChecked()
);
Set(target
, New<v8::String>("new3").ToLocalChecked()
, New<v8::FunctionTemplate>(New3)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(New3)).ToLocalChecked()
);
Set(target
, New<v8::String>("copy").ToLocalChecked()
, New<v8::FunctionTemplate>(Copy)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(Copy)).ToLocalChecked()
);
}

Expand Down
2 changes: 1 addition & 1 deletion test/cpp/bufferworkerpersistent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ NAN_METHOD(DoSleep) {
NAN_MODULE_INIT(Init) {
Set(target
, New<v8::String>("a").ToLocalChecked()
, New<v8::FunctionTemplate>(DoSleep)->GetFunction());
, GetFunction(New<v8::FunctionTemplate>(DoSleep)).ToLocalChecked());
}

NODE_MODULE(bufferworkerpersistent, Init)
30 changes: 15 additions & 15 deletions test/cpp/converters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,63 +75,63 @@ NAN_METHOD(Int32Value) {
NAN_MODULE_INIT(Init) {
Set(target
, New<v8::String>("toBoolean").ToLocalChecked()
, New<v8::FunctionTemplate>(ToBoolean)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(ToBoolean)).ToLocalChecked()
);
Set(target
, New<v8::String>("toNumber").ToLocalChecked()
, New<v8::FunctionTemplate>(ToNumber)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(ToNumber)).ToLocalChecked()
);
Set(target
, New<v8::String>("toString").ToLocalChecked()
, New<v8::FunctionTemplate>(ToString)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(ToString)).ToLocalChecked()
);
Set(target
, New<v8::String>("toDetailString").ToLocalChecked()
, New<v8::FunctionTemplate>(ToDetailString)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(ToDetailString)).ToLocalChecked()
);
Set(target
, New<v8::String>("toFunction").ToLocalChecked()
, New<v8::FunctionTemplate>(ToFunction)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(ToFunction)).ToLocalChecked()
);
Set(target
, New<v8::String>("toObject").ToLocalChecked()
, New<v8::FunctionTemplate>(ToObject)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(ToObject)).ToLocalChecked()
);
Set(target
, New<v8::String>("toInteger").ToLocalChecked()
, New<v8::FunctionTemplate>(ToInteger)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(ToInteger)).ToLocalChecked()
);
Set(target
, New<v8::String>("toUint32").ToLocalChecked()
, New<v8::FunctionTemplate>(ToUint32)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(ToUint32)).ToLocalChecked()
);
Set(target
, New<v8::String>("toInt32").ToLocalChecked()
, New<v8::FunctionTemplate>(ToInt32)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(ToInt32)).ToLocalChecked()
);
Set(target
, New<v8::String>("toArrayIndex").ToLocalChecked()
, New<v8::FunctionTemplate>(ToArrayIndex)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(ToArrayIndex)).ToLocalChecked()
);
Set(target
, New<v8::String>("booleanValue").ToLocalChecked()
, New<v8::FunctionTemplate>(BooleanValue)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(BooleanValue)).ToLocalChecked()
);
Set(target
, New<v8::String>("numberValue").ToLocalChecked()
, New<v8::FunctionTemplate>(NumberValue)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(NumberValue)).ToLocalChecked()
);
Set(target
, New<v8::String>("integerValue").ToLocalChecked()
, New<v8::FunctionTemplate>(IntegerValue)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(IntegerValue)).ToLocalChecked()
);
Set(target
, New<v8::String>("uint32Value").ToLocalChecked()
, New<v8::FunctionTemplate>(Uint32Value)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(Uint32Value)).ToLocalChecked()
);
Set(target
, New<v8::String>("int32Value").ToLocalChecked()
, New<v8::FunctionTemplate>(Int32Value)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(Int32Value)).ToLocalChecked()
);
}

Expand Down
2 changes: 1 addition & 1 deletion test/cpp/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ X(TypeError)
Nan::Set( \
target \
, Nan::New(#NAME).ToLocalChecked() \
, Nan::New<v8::FunctionTemplate>(NAME)->GetFunction());
, Nan::GetFunction(New<v8::FunctionTemplate>(NAME)).ToLocalChecked());


NAN_MODULE_INIT(Init) {
Expand Down
4 changes: 2 additions & 2 deletions test/cpp/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ NAN_METHOD(Check) {
NAN_MODULE_INIT(Init) {
Set(target
, New<v8::String>("hook").ToLocalChecked()
, New<v8::FunctionTemplate>(Hook)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(Hook)).ToLocalChecked()
);
Set(target
, New<v8::String>("check").ToLocalChecked()
, New<v8::FunctionTemplate>(Check)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(Check)).ToLocalChecked()
);
}

Expand Down
6 changes: 4 additions & 2 deletions test/cpp/indexedinterceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ NAN_MODULE_INIT(IndexedInterceptor::Init) {
, IndexedInterceptor::PropertyEnumerator);

v8::Local<v8::Function> createnew =
Nan::New<v8::FunctionTemplate>(CreateNew)->GetFunction();
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(CreateNew))
.ToLocalChecked();
Set(target, Nan::New("create").ToLocalChecked(), createnew);
}

Expand All @@ -59,7 +60,8 @@ v8::Local<v8::Value> IndexedInterceptor::NewInstance () {
v8::Local<v8::FunctionTemplate> constructorHandle =
Nan::New(indexedinterceptors_constructor);
v8::Local<v8::Object> instance =
Nan::NewInstance(constructorHandle->GetFunction()).ToLocalChecked();
Nan::NewInstance(Nan::GetFunction(constructorHandle).ToLocalChecked())
.ToLocalChecked();
return scope.Escape(instance);
}

Expand Down
Loading