Closed chjj closed 5 years ago
It looks like nan has upgraded for this, but only for strings: https://github.com/nodejs/nan/commit/24a22c3b25eeeec2016c6ec239bdd6169e985447
Corresponding PR: https://github.com/nodejs/nan/pull/808
Nevermind, looks like it's still in the works: https://github.com/nodejs/nan/pull/811
Finally fixed with 3a3bb28f6d59d6c74108af89d4a9ef50e2e1429b
This issue seems to be getting a lot of attention from people in the community. Please note that Nan::To
can be used in place of the nasty v8 syntax.
For example:
Nan::To<int32_t>(info[0]).FromJust()
Instead of:
info[0]->Int32Value(Nan::GetCurrentContext()).FromJust();
Hi all,
In Node 8, I had:
v8::String::Utf8Value textV8(args[4]->ToString());
std::string text(*textV8);
But in Node 12, with:
v8::Local<v8::String> textV8(args[4]->ToString(context).FromMaybe(v8::Local<v8::String>()));
I don't figure out how concert in std::string
Edit: For the moment, I found this solution but too complicated for me:
v8::Local<v8::String> textV8(args[4]->ToString(context).FromMaybe(v8::Local<v8::String>()));
Nan::Utf8String textNan(textV8);
std::string text(*textNan);
marked
Putting this here to document for my own sanity.
V8 removed a bunch of calls and the node.js devs have decided to maintain them for the time being, but have marked them as deprecated. We need to switch away from them.
Deprecated APIs:
Uint32Value()
Int32Value()
IntegerValue()
NumberValue()
BooleanValue()
ToString()
Example migration:
Originally:
Now must be:
Or:
Or:
Int32Value
returnsMaybe<uint32_t>
.ToInt32
returnsMaybeLocal<Int32>
.Note that
ToChecked()
is an alias forFromJust()
.ToString()
was also deprecated, but nan.h should be handling this. Not us, but for completeness, heres the migration.From:
To:
Note that anything that returns
MaybeLocal
instead ofMaybe
should have anIsEmpty()
check.Example (from the style guide below):
References:
Timeline:
Style Guide (mentioning the changes):
I'm not sure how this will impact node versions prior to node v10. This maybe needs to be added as a part of nan? Not sure. Going to do more research.
Update:
Just discovered the magic of
Nan::To
(1, 2, 3).We can do
Nan::To<int32_t>(info[0]).FromJust()
.Nan::To
seems undocumented, but it seems to be the inverse ofNan::New
.