Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Beginnings of a fix for node-osmium on node 12 / v8 deprecations.
Browse files Browse the repository at this point in the history
Stash attempts to fix node-osmium so that it compiles on node 12 with
v8 deprecatons before I got bored and decided to use 'n' to downgrade
node for this one bit of code I wanted to run instead. Ever feel you
start with somethihng simple and end up six problems deep?

No idea whether any of this actually works. I was stabbing at fixing
compiler errors before making it logically work before I gave up.

I was having particular trouble with fixing GetFunction
(see https://stackoverflow.com/questions/61946241)

Useful info:
- https://github.com/joyeecheung/node/blob/v8-maybe-doc/CPP_STYLE_GUIDE.md#use-maybe-version-of-v8-apis
- https://nodesource.com/blog/cpp-addons-for-nodejs-v4
- bcoin-org/bcrypto#7

(Vaguely) relevant issues:
- #108
  • Loading branch information
matburnham committed May 22, 2020
1 parent b2abe20 commit d8eb02c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
"package_name": "{node_abi}-{platform}-{arch}.tar.gz"
},
"dependencies": {
"nan": "^2.10.0",
"node-pre-gyp": "^0.10.2"
"nan": "^2.14.1",
"node-pre-gyp": "^0.10.3"
},
"devDependencies": {
"aws-sdk": "^2.266.1",
"aws-sdk": "^2.682.0",
"geojson-coords": "0.0.0",
"mocha": "^2.5.3",
"osm-testdata": "^1.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/apply.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ namespace node_osmium {
Nan::ThrowTypeError(Nan::New("please provide handler objects as second and further parameters to apply()").ToLocalChecked());
return;
}
auto obj = info[i]->ToObject();
auto obj = info[i]->ToObject(info.GetIsolate()->GetCurrentContext()).ToLocalChecked();
if (Nan::New(JSHandler::constructor)->HasInstance(obj)) {
handlers.push_back(unwrap<JSHandler>(obj));
} else if (Nan::New(LocationHandlerWrap::constructor)->HasInstance(obj)) {
Expand All @@ -172,7 +172,7 @@ namespace node_osmium {
}

try {
auto source = info[0]->ToObject();
auto source = info[0]->ToObject(info.GetIsolate()->GetCurrentContext()).ToLocalChecked();
if (Nan::New(BasicReaderWrap::constructor)->HasInstance(source)) {
osmium::io::Reader& reader = unwrap<BasicReaderWrap>(source);

Expand Down
12 changes: 6 additions & 6 deletions src/buffer_wrap.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace node_osmium {
Nan::SetPrototypeMethod(lcons, "next", next);
Nan::SetPrototypeMethod(lcons, "filter_point_in_time", filter_point_in_time);
Nan::SetPrototypeMethod(lcons, "create_node_buffer", create_node_buffer);
target->Set(Nan::New(symbol_Buffer), lcons->GetFunction());
target->Set(Nan::New(symbol_Buffer), lcons->GetFunction(target->CreationContext()).ToLocalChecked());
constructor.Reset(lcons);
}

Expand All @@ -39,7 +39,7 @@ namespace node_osmium {
info.GetReturnValue().Set(info.This());
return;
} else if (info.Length() == 1 && info[0]->IsObject()) {
auto obj = info[0]->ToObject();
auto obj = info[0]->ToObject(info.GetIsolate()->GetCurrentContext()).ToLocalChecked();
if (node::Buffer::HasInstance(obj)) {
try {
osmium::memory::Buffer buffer(reinterpret_cast<unsigned char*>(node::Buffer::Data(obj)), node::Buffer::Length(obj));
Expand Down Expand Up @@ -76,7 +76,7 @@ namespace node_osmium {

int filter_id = 0;
if (info.Length() == 1 && info[0]->IsInt32()) {
filter_id = info[0]->Int32Value();
filter_id = info[0]->Int32Value(Nan::GetCurrentContext()).ToChecked();
}

while (buffer_wrap->m_iterator != buffer_wrap->m_this.end()) {
Expand Down Expand Up @@ -130,12 +130,12 @@ namespace node_osmium {

osmium::Timestamp point_in_time;
if (info[0]->IsInt32()) {
point_in_time = info[0]->Int32Value();
point_in_time = info[0]->Int32Value(Nan::GetCurrentContext()).ToChecked();
} else if (info[0]->IsString()) {
Nan::Utf8String time_string { info[0] };
point_in_time = osmium::Timestamp(*time_string);
} else if (info[0]->IsDate()) {
point_in_time = osmium::Timestamp(static_cast<int32_t>(v8::Date::Cast(*info[0])->NumberValue() / 1000));
point_in_time = osmium::Timestamp(static_cast<int32_t>(v8::Date::Cast(*info[0])->NumberValue(info.GetIsolate()->GetCurrentContext()).ToChecked() / 1000));
}

typedef osmium::DiffIterator<osmium::memory::Buffer::t_iterator<osmium::OSMObject>> diff_iterator;
Expand Down Expand Up @@ -183,7 +183,7 @@ namespace node_osmium {

Nan::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(buffer_constructor, 3, constructor_info);
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Buffer instance");
info.GetReturnValue().Set(maybe_local.ToLocalChecked()->ToObject());
info.GetReturnValue().Set(maybe_local.ToLocalChecked());
return;
}

Expand Down
8 changes: 5 additions & 3 deletions src/file_wrap.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace node_osmium {
v8::Local<v8::FunctionTemplate> lcons = Nan::New<v8::FunctionTemplate>(FileWrap::New);
lcons->InstanceTemplate()->SetInternalFieldCount(1);
lcons->SetClassName(Nan::New(symbol_File));
target->Set(Nan::New(symbol_File), lcons->GetFunction());
v8::Local<v8::Context> context = target->CreationContext();
target->Set(Nan::New(symbol_File), lcons->GetFunction(context).ToLocalChecked());
constructor.Reset(lcons);
}

Expand All @@ -42,12 +43,13 @@ namespace node_osmium {

try {
osmium::io::File file;
v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();

if (info[0]->IsString()) {
Nan::Utf8String filename { info[0] };
file = osmium::io::File(*filename, format);
} else if (info[0]->IsObject() && node::Buffer::HasInstance(info[0]->ToObject())) {
auto source = info[0]->ToObject();
} else if (info[0]->IsObject() && node::Buffer::HasInstance(info[0]->ToObject(context).ToLocalChecked())) {
auto source = info[0]->ToObject(context).ToLocalChecked();
file = osmium::io::File(node::Buffer::Data(source), node::Buffer::Length(source), format);
} else {
Nan::ThrowTypeError(Nan::New("first argument to File constructor must be a string (filename) or node.Buffer").ToLocalChecked());
Expand Down
3 changes: 2 additions & 1 deletion src/filter.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ namespace node_osmium {

NAN_METHOD(Filter::register_filter) {
if (info.Length() == 1 && info[0]->IsObject()) {
auto object = info[0]->ToObject();
v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
auto object = info[0]->ToObject(context).ToLocalChecked();
// XXX check that object is of class Filter
Filter::all_filters.emplace_back(new Filter(object));
assert(Filter::all_filters.size() < std::numeric_limits<int32_t>::max());
Expand Down

0 comments on commit d8eb02c

Please sign in to comment.