Search code examples
node.jsv8node-nan

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


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?


Solution

  • 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));