如何使用可能的v8 :: String :: NewFromUtf8版本?

时间:2019-04-24 23:53:28

标签: node.js v8 node-nan

我正在尝试针对Node 12构建本机节点模块,并遇到如下错误:

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

关于代码,例如:

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

我理解该错误,但是基于v8 :: String文档,我不知道如何指定Maybe版本...原型看起来相同。如何使用此功能的Maybe版本?

1 个答案:

答案 0 :(得分:0)

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