Skip to content

Commit

Permalink
Further tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
matburnham committed Jul 28, 2020
1 parent d8bc92a commit ff44f08
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/buffer_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace node_osmium {
// Store the node::Buffer in the new osmium::Buffer object
// so the node::Buffer doesn't go away if it goes out of scope
// outside this function.
Nan::Set(info.This(), Nan::New("_data").ToLocalChecked(), obj);
Nan::Set(info.This(), Nan::New("_data").ToLocalChecked(), obj);
info.GetReturnValue().Set(info.This());
return;
} catch (std::exception const& ex) {
Expand All @@ -76,7 +76,7 @@ namespace node_osmium {

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

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

osmium::Timestamp point_in_time;
if (info[0]->IsInt32()) {
point_in_time = info[0]->Int32Value(Nan::GetCurrentContext()).ToChecked();
point_in_time = Nan::To<int32_t>(info[0]).ToChecked();
} else if (info[0]->IsString()) {
Nan::Utf8String time_string { info[0] };
point_in_time = osmium::Timestamp(*time_string);
Expand Down Expand Up @@ -173,7 +173,7 @@ namespace node_osmium {
v8::Local<v8::Object> global = Nan::GetCurrentContext()->Global();

v8::Local<v8::Function> buffer_constructor =
v8::Local<v8::Function>::Cast(global->Get(Nan::GetCurrentContext(), Nan::New("Buffer").ToLocalChecked()).ToLocalChecked());
v8::Local<v8::Function>::Cast(Nan::Get(global, Nan::New("Buffer").ToLocalChecked()).ToLocalChecked());

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

Expand All @@ -43,13 +42,11 @@ 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(context).ToLocalChecked())) {
auto source = info[0]->ToObject(context).ToLocalChecked();
} else if (info[0]->IsObject() && node::Buffer::HasInstance(info[0]->ToObject(Nan::GetCurrentContext()).ToLocalChecked())) {
auto source = info[0]->ToObject(Nan::GetCurrentContext()).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: 1 addition & 2 deletions src/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ namespace node_osmium {

NAN_METHOD(Filter::register_filter) {
if (info.Length() == 1 && info[0]->IsObject()) {
v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
auto object = info[0]->ToObject(context).ToLocalChecked();
auto object = info[0]->ToObject(Nan::GetCurrentContext()).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
1 change: 0 additions & 1 deletion src/flex_reader_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ namespace node_osmium {
Nan::Set(bounds_array, i++, create_js_box(box));
}

//obj->Set(Nan::GetCurrentContext(), Nan::New(symbol_bounds), bounds_array);
Nan::Set(obj, Nan::New(symbol_bounds), bounds_array);
info.GetReturnValue().Set(obj);
return;
Expand Down
1 change: 0 additions & 1 deletion src/osm_area_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ namespace node_osmium {
NAN_METHOD(OSMAreaWrap::coordinates) {
INSTANCE_CHECK(OSMAreaWrap, "Area", "coordinates");

//v8::Local<v8::Value> cf = Nan::New(module)->Get(Nan::GetCurrentContext(), Nan::New(symbol_Coordinates));
v8::Local<v8::Value> cf = Nan::Get(Nan::New(module), Nan::New(symbol_Coordinates)).ToLocalChecked();
assert(cf->IsFunction());

Expand Down
2 changes: 1 addition & 1 deletion src/osm_node_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace node_osmium {
}

NAN_GETTER(OSMNodeWrap::get_coordinates) {
auto cf = Nan::New(module)->Get(Nan::GetCurrentContext(), Nan::New(symbol_Coordinates)).ToLocalChecked();
auto cf = Nan::Get(Nan::New(module), Nan::New(symbol_Coordinates)).ToLocalChecked();
assert(cf->IsFunction());

const osmium::Location& location = wrapped(info.This()).location();
Expand Down
2 changes: 1 addition & 1 deletion src/osm_relation_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace node_osmium {
Nan::ThrowTypeError(Nan::New("call members() without parameters or the index of the member you want").ToLocalChecked());
return;
}
uint32_t n = info[0]->Uint32Value(Nan::GetCurrentContext()).ToChecked();
uint32_t n = Nan::To<uint32_t>(info[0]).ToChecked();
if (n < relation.members().size()) {
auto it = relation.members().begin();
std::advance(it, n);
Expand Down
4 changes: 2 additions & 2 deletions src/osm_way_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace node_osmium {
Nan::ThrowTypeError(Nan::New("call node_refs() without parameters or the index of the node you want").ToLocalChecked());
return;
}
uint32_t n = info[0]->Uint32Value(Nan::GetCurrentContext()).ToChecked();
uint32_t n = Nan::To<uint32_t>(info[0]).ToChecked();
if (n < way.nodes().size()) {
info.GetReturnValue().Set(Nan::New<v8::Number>(way.nodes()[n].ref()));
return;
Expand Down Expand Up @@ -151,7 +151,7 @@ namespace node_osmium {
Nan::ThrowTypeError(Nan::New("call node_coordinates() without parameters or the index of the node you want").ToLocalChecked());
return;
}
uint32_t n = info[0]->Uint32Value(Nan::GetCurrentContext()).ToChecked();
uint32_t n = Nan::To<uint32_t>(info[0]).ToChecked();
if (n < way.nodes().size()) {
const osmium::Location location = way.nodes()[n].location();
if (location.valid()) {
Expand Down
14 changes: 7 additions & 7 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace node_osmium {
return scope.Escape(Nan::Undefined());
}

auto cf = Nan::New(module)->Get(Nan::GetCurrentContext(), Nan::New(symbol_Coordinates)).ToLocalChecked();
auto cf = Nan::Get(Nan::New(module), Nan::New(symbol_Coordinates)).ToLocalChecked();
assert(cf->IsFunction());
auto bf = Nan::New(module)->Get(Nan::GetCurrentContext(), Nan::New(symbol_Box)).ToLocalChecked();
auto bf = Nan::Get(Nan::New(module), Nan::New(symbol_Box)).ToLocalChecked();
assert(bf->IsFunction());

v8::Local<v8::Value> argv_bl[2] = { Nan::New(box.bottom_left().lon()), Nan::New<v8::Number>(box.bottom_left().lat()) };
Expand All @@ -43,27 +43,27 @@ namespace node_osmium {
osmium::osm_entity_bits::type object_to_entity_bits(v8::Local<v8::Object> options) {
osmium::osm_entity_bits::type entities = osmium::osm_entity_bits::nothing;

v8::Local<v8::Value> want_nodes = options->Get(Nan::GetCurrentContext(), Nan::New(symbol_node)).ToLocalChecked();
v8::Local<v8::Value> want_nodes = Nan::Get(options, Nan::New(symbol_node)).ToLocalChecked();
if (want_nodes->IsBoolean() && Nan::To<bool>(want_nodes).ToChecked()) {
entities |= osmium::osm_entity_bits::node;
}

v8::Local<v8::Value> want_ways = options->Get(Nan::GetCurrentContext(), Nan::New(symbol_way)).ToLocalChecked();
v8::Local<v8::Value> want_ways = Nan::Get(options, Nan::New(symbol_way)).ToLocalChecked();
if (want_ways->IsBoolean() && Nan::To<bool>(want_ways).ToChecked()) {
entities |= osmium::osm_entity_bits::way;
}

v8::Local<v8::Value> want_relations = options->Get(Nan::GetCurrentContext(), Nan::New(symbol_relation)).ToLocalChecked();
v8::Local<v8::Value> want_relations = Nan::Get(options, Nan::New(symbol_relation)).ToLocalChecked();
if (want_relations->IsBoolean() && Nan::To<bool>(want_relations).ToChecked()) {
entities |= osmium::osm_entity_bits::relation;
}

v8::Local<v8::Value> want_areas = options->Get(Nan::GetCurrentContext(), Nan::New(symbol_area)).ToLocalChecked();
v8::Local<v8::Value> want_areas = Nan::Get(options, Nan::New(symbol_area)).ToLocalChecked();
if (want_areas->IsBoolean() && Nan::To<bool>(want_areas).ToChecked()) {
entities |= osmium::osm_entity_bits::area;
}

v8::Local<v8::Value> want_changesets = options->Get(Nan::GetCurrentContext(), Nan::New(symbol_changeset)).ToLocalChecked();
v8::Local<v8::Value> want_changesets = Nan::Get(options, Nan::New(symbol_changeset)).ToLocalChecked();
if (want_changesets->IsBoolean() && Nan::To<bool>(want_changesets).ToChecked()) {
entities |= osmium::osm_entity_bits::changeset;
}
Expand Down

0 comments on commit ff44f08

Please sign in to comment.