v8中获取被调用者的方法名
Get the method name of the callee in v8
因为 nodejs >= 10 FunctionCallbackInfo::Callee 已被弃用 (https://github.com/nodejs/nan/blob/master/CHANGELOG.md)。我需要更新使用 v8 的 c++ 代码,其中使用了被调用的方法名称。现在如何获取?
建议使用info.Data()
代替。但我不遵循如何从中获取方法名称。我猜它是这样的:
void GetData(IN const Nan::FunctionCallbackInfo<v8::Value>& info)
{
v8::Local<v8::Function> data = v8::Local<v8::Function>::Cast(info.Data());
....
}
如何从 data
获取方法名称?从文档来看,它似乎无法再完成 (https://github.com/nodejs/nan/blob/master/doc/methods.md):
Note: FunctionCallbackInfo::Callee is removed in Node.js after 10.0.0 because it is was deprecated in V8. Consider using info.Data() to pass any information you need.
所以,如果不提供额外的信息,就没有办法得到被调用者的名字吗?
这成功了:
v8::Local<v8::Function> out;
out = v8::Local<v8::Function>::Cast(info.Data());
v8::String::Utf8Value callee(out->GetName()->ToString());
因为 nodejs >= 10 FunctionCallbackInfo::Callee 已被弃用 (https://github.com/nodejs/nan/blob/master/CHANGELOG.md)。我需要更新使用 v8 的 c++ 代码,其中使用了被调用的方法名称。现在如何获取?
建议使用info.Data()
代替。但我不遵循如何从中获取方法名称。我猜它是这样的:
void GetData(IN const Nan::FunctionCallbackInfo<v8::Value>& info)
{
v8::Local<v8::Function> data = v8::Local<v8::Function>::Cast(info.Data());
....
}
如何从 data
获取方法名称?从文档来看,它似乎无法再完成 (https://github.com/nodejs/nan/blob/master/doc/methods.md):
Note: FunctionCallbackInfo::Callee is removed in Node.js after 10.0.0 because it is was deprecated in V8. Consider using info.Data() to pass any information you need.
所以,如果不提供额外的信息,就没有办法得到被调用者的名字吗?
这成功了:
v8::Local<v8::Function> out;
out = v8::Local<v8::Function>::Cast(info.Data());
v8::String::Utf8Value callee(out->GetName()->ToString());