我正在尝试修复node-osmium以便它与 Node 12 一起使用,因为我有一些我想运行的旧代码。
v8 现在已经完全弃用了许多不能正确发出故障信号的 API。这些以前只是即将弃用的警告,现在它们是错误,因此将不再构建。我(想我已经)通过遵循这个 CPP STYLE GUIDE.md 的使用可能版本的 v8 API部分来修复其中的大部分。
但是,我对 GetFunction 遇到了这个错误:
../src/utils.hpp:39:67: error: no matching function for call to ‘v8::FunctionTemplate::GetFunction()’
Nan::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(T::constructor)->GetFunction(), 1, &ext);
我认为这是与其他函数类似的修复,但是我从哪里获取此构造函数中的上下文?
从node-osmium/src/utils.hpp 中提取:
namespace node_osmium {
template<class T>
auto unwrap(const v8::Local<v8::Object>& object) -> decltype(Nan::ObjectWrap::Unwrap<T>(object)->get()) {
return Nan::ObjectWrap::Unwrap<T>(object)->get();
}
template<class T, class... Args>
v8::Local<v8::Object> new_external(Args&&... args) {
Nan::EscapableHandleScope scope;
v8::Local<v8::Value> ext = Nan::New<v8::External>(new T(std::forward<Args>(args)...));
Nan::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(T::constructor)->GetFunction(context), 1, &ext);
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Buffer instance");
return scope.Escape(maybe_local.ToLocalChecked());
}
v8::Local<v8::Value> create_js_box(const osmium::Box& box);
osmium::osm_entity_bits::type object_to_entity_bits(v8::Local<v8::Object> options);
} // namespace node_osmium