Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Commit

Permalink
update deprecated callback->Call call
Browse files Browse the repository at this point in the history
  • Loading branch information
karenzshea committed Mar 9, 2018
1 parent 472ce4f commit 840df60
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"@mapbox/cloudfriend": "^1.9.0",
"aws-sdk": "^2.3.5",
"nan": "^2.2.1",
"nan": "^2.9.0",
"node-cmake": "^1.2.0",
"node-pre-gyp": "^0.6.26",
"tape": "^4.6.3"
Expand Down
11 changes: 9 additions & 2 deletions src/extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ Extractor::Extractor(const std::vector<std::string> &osm_files, Database &db) :
SetupDatabase();
}

Extractor::Extractor(const std::vector<std::string> &osm_files, Database &db, const std::string &tagfilename) : db(db)
Extractor::Extractor(const std::vector<std::string> &osm_files,
Database &db,
const std::string &tagfilename)
: db(db)
{
// add tags to tag filter object for use in way parsing
if (!tagfilename.empty())
Expand All @@ -103,7 +106,11 @@ Extractor::Extractor(const std::vector<std::string> &osm_files, Database &db, co
SetupDatabase();
}

Extractor::Extractor(const char *buffer, std::size_t buffersize, const std::string &format, Database &db) : db(db)
Extractor::Extractor(const char *buffer,
std::size_t buffersize,
const std::string &format,
Database &db)
: db(db)
{
std::cerr << "Parsing OSM buffer in format " << format << " ... " << std::flush;
osmium::io::File osmfile{buffer, buffersize, format};
Expand Down
4 changes: 3 additions & 1 deletion src/extractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ struct Extractor final : osmium::handler::Handler
* @param d the Database object where everything will end up
*/
Extractor(const std::vector<std::string> &osm_files, Database &d);
Extractor(const std::vector<std::string> &osm_files, Database &d, const std::string &tagfilename);
Extractor(const std::vector<std::string> &osm_files,
Database &d,
const std::string &tagfilename);

/**
* Constructs an extractor from in-memory OSM XML data.
Expand Down
35 changes: 21 additions & 14 deletions src/nodejs_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ NAN_METHOD(Annotator::loadOSMExtract)
{
if (!info[1]->IsString() || !info[2]->IsFunction())
{
return Nan::ThrowTypeError("Expecting a string (or array of strings), a string, and a callback");
return Nan::ThrowTypeError(
"Expecting a string (or array of strings), a string, and a callback");
}
// convert tag file path into string
const v8::String::Utf8Value tag_utf8String(info[1]);
Expand All @@ -127,13 +128,15 @@ NAN_METHOD(Annotator::loadOSMExtract)
return Nan::ThrowTypeError("Input OSM files array can't be empty");
for (std::uint32_t idx = 0; idx < file_array->Length(); ++idx)
{
//std::cout << std::string(file_array->Get(idx)->ToString() << std::endl;
if (!file_array->Get(idx)->IsString())
return Nan::ThrowError("Unable to convert file path to Utf8String at place " + idx);
{
// TODO include the idx number in this error message
return Nan::ThrowError("Unable to convert file path to Utf8String");
}

const v8::String::Utf8Value file{file_array->Get(idx)};
if (!(*file))
return Nan::ThrowError("Unable to convert file path to Utf8String at place " + idx);
return Nan::ThrowError("Unable to convert file path to Utf8String");
osm_paths.emplace_back(*file, file.length());
}
}
Expand All @@ -147,8 +150,8 @@ NAN_METHOD(Annotator::loadOSMExtract)
Nan::Callback *callback,
std::vector<std::string> osm_paths_,
std::string tag_path_)
: Nan::AsyncWorker(callback), self{self_}, osm_paths{std::move(osm_paths_)},
tag_path{tag_path_}
: Nan::AsyncWorker(callback, "annotator:osm.load"), self{self_},
osm_paths{std::move(osm_paths_)}, tag_path{tag_path_}
{
}

Expand Down Expand Up @@ -176,7 +179,7 @@ NAN_METHOD(Annotator::loadOSMExtract)
Nan::HandleScope scope;
const constexpr auto argc = 1u;
v8::Local<v8::Value> argv[argc] = {Nan::Null()};
callback->Call(argc, argv);
callback->Call(argc, argv, async_resource);
}

Annotator &self;
Expand All @@ -186,7 +189,8 @@ NAN_METHOD(Annotator::loadOSMExtract)

auto *callback = info.Length() == 3 ? new Nan::Callback{info[2].As<v8::Function>()}
: new Nan::Callback{info[1].As<v8::Function>()};
Nan::AsyncQueueWorker(new OSMLoader{*self, callback, std::move(osm_paths), std::move(tag_path)});
Nan::AsyncQueueWorker(
new OSMLoader{*self, callback, std::move(osm_paths), std::move(tag_path)});
}

NAN_METHOD(Annotator::annotateRouteFromNodeIds)
Expand Down Expand Up @@ -234,7 +238,8 @@ NAN_METHOD(Annotator::annotateRouteFromNodeIds)
explicit WayIdsFromNodeIdsLoader(Annotator &self_,
Nan::Callback *callback,
std::vector<external_nodeid_t> externalIds_)
: Nan::AsyncWorker(callback), self{self_}, externalIds{std::move(externalIds_)}
: Nan::AsyncWorker(callback, "annotator:osm.annotatefromnodeids"), self{self_},
externalIds{std::move(externalIds_)}
{
}

Expand Down Expand Up @@ -263,7 +268,7 @@ NAN_METHOD(Annotator::annotateRouteFromNodeIds)
const constexpr auto argc = 2u;
v8::Local<v8::Value> argv[argc] = {Nan::Null(), annotated};

callback->Call(argc, argv);
callback->Call(argc, argv, async_resource);
}

Annotator &self;
Expand Down Expand Up @@ -322,7 +327,8 @@ NAN_METHOD(Annotator::annotateRouteFromLonLats)
explicit WayIdsFromLonLatsLoader(Annotator &self_,
Nan::Callback *callback,
std::vector<point_t> coordinates_)
: Nan::AsyncWorker(callback), self{self_}, coordinates{std::move(coordinates_)}
: Nan::AsyncWorker(callback, "annotator:osm.annotatefromlonlats"), self{self_},
coordinates{std::move(coordinates_)}
{
}

Expand Down Expand Up @@ -362,7 +368,7 @@ NAN_METHOD(Annotator::annotateRouteFromLonLats)
const constexpr auto argc = 2u;
v8::Local<v8::Value> argv[argc] = {Nan::Null(), annotated};

callback->Call(argc, argv);
callback->Call(argc, argv, async_resource);
}

Annotator &self;
Expand All @@ -389,7 +395,8 @@ NAN_METHOD(Annotator::getAllTagsForWayId)
struct TagsForWayIdLoader final : Nan::AsyncWorker
{
explicit TagsForWayIdLoader(Annotator &self_, Nan::Callback *callback, wayid_t wayId_)
: Nan::AsyncWorker(callback), self{self_}, wayId{std::move(wayId_)}
: Nan::AsyncWorker(callback, "annotator:osm.gettagsforids"), self{self_},
wayId{std::move(wayId_)}
{
}

Expand All @@ -413,7 +420,7 @@ NAN_METHOD(Annotator::getAllTagsForWayId)
const constexpr auto argc = 2u;
v8::Local<v8::Value> argv[argc] = {Nan::Null(), tags};

callback->Call(argc, argv);
callback->Call(argc, argv, async_resource);
}

Annotator &self;
Expand Down
9 changes: 5 additions & 4 deletions src/speed_lookup_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ NAN_METHOD(SpeedLookup::loadCSV)
explicit CSVLoader(v8::Local<v8::Object> self_,
Nan::Callback *callback,
std::vector<std::string> paths_)
: Nan::AsyncWorker(callback), paths{std::move(paths_)}
: Nan::AsyncWorker(callback, "annotator:speed.load"), paths{std::move(paths_)}
{
SaveToPersistent("self", self_);
}
Expand Down Expand Up @@ -118,7 +118,7 @@ NAN_METHOD(SpeedLookup::loadCSV)
swap(unwrapped->datamap, map);
const constexpr auto argc = 1u;
v8::Local<v8::Value> argv[argc] = {Nan::Null()};
callback->Call(argc, argv);
callback->Call(argc, argv, async_resource);
}

std::vector<std::string> paths;
Expand Down Expand Up @@ -176,7 +176,8 @@ NAN_METHOD(SpeedLookup::getRouteSpeeds)
Worker(std::shared_ptr<SegmentSpeedMap> datamap_,
Nan::Callback *callback,
std::vector<external_nodeid_t> nodeIds)
: Base(callback), datamap{datamap_}, nodeIds(std::move(nodeIds))
: Base(callback, "annotator:speed.annotatefromnodeids"), datamap{datamap_},
nodeIds(std::move(nodeIds))
{
}

Expand Down Expand Up @@ -208,7 +209,7 @@ NAN_METHOD(SpeedLookup::getRouteSpeeds)
const auto argc = 2u;
v8::Local<v8::Value> argv[argc] = {Nan::Null(), jsAnnotations};

callback->Call(argc, argv);
callback->Call(argc, argv, async_resource);
}

std::shared_ptr<SegmentSpeedMap> datamap;
Expand Down

0 comments on commit 840df60

Please sign in to comment.