How to use Maybe version of v8::String::NewFromUtf8?

2.3k views Asked by At

I'm trying to build a native node module against Node 12 and am getting errors such as:

warning: ‘static v8::Local<v8::String> v8::String::NewFromUtf8(v8::Isolate*, const char*, v8::String::NewStringType, int)’ is deprecated: Use maybe version [-Wdeprecated-declarations]

On code such as:

v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), "some string")

I understand the error, but based on the v8::String docs, I can't figure out how to specify the Maybe version... The prototypes look the same. How can I use the Maybe version of this function?

1

There are 1 answers

1
Satyan On BEST ANSWER
size_t size = 100;
char *CharBuff = new char[size + 1];

v8::MaybeLocal<v8::String> result = v8::String::NewFromUtf8(
    isolate, CharBuff, v8::NewStringType::kNormal, static_cast<int>(size));