summaryrefslogtreecommitdiff
path: root/platform/node
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-03-07 17:00:53 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-03-23 13:31:13 -0700
commitd7227e13a7a87cf50a4c8c1f0615fc565f5a2679 (patch)
treeeda76a2da3220f3cfeec901400369cf9c8361f58 /platform/node
parent1c757cce34344dfecc9a724034680225143f92b7 (diff)
downloadqtlocation-mapboxgl-d7227e13a7a87cf50a4c8c1f0615fc565f5a2679.tar.gz
[all] Replace Result<T> with optional<T> plus out Error parameter
Diffstat (limited to 'platform/node')
-rw-r--r--platform/node/src/node_geojson.hpp5
-rw-r--r--platform/node/src/node_map.cpp30
2 files changed, 20 insertions, 15 deletions
diff --git a/platform/node/src/node_geojson.hpp b/platform/node/src/node_geojson.hpp
index ace4c91426..e4b2ca47e7 100644
--- a/platform/node/src/node_geojson.hpp
+++ b/platform/node/src/node_geojson.hpp
@@ -5,8 +5,9 @@ namespace style {
namespace conversion {
template <>
-Result<GeoJSON> convertGeoJSON(const v8::Local<v8::Value>&) {
- return Error { "not implemented" };
+optional<GeoJSON> convertGeoJSON(const v8::Local<v8::Value>&, Error& error) {
+ error = { "not implemented" };
+ return {};
}
} // namespace conversion
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index a3a11a1907..881c1b2fb7 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -538,9 +538,10 @@ void NodeMap::AddSource(const Nan::FunctionCallbackInfo<v8::Value>& info) {
return Nan::ThrowTypeError("First argument must be a string");
}
- Result<std::unique_ptr<Source>> source = convert<std::unique_ptr<Source>>(info[1], *Nan::Utf8String(info[0]));
+ Error error;
+ mbgl::optional<std::unique_ptr<Source>> source = convert<std::unique_ptr<Source>>(info[1], error, *Nan::Utf8String(info[0]));
if (!source) {
- Nan::ThrowTypeError(source.error().message.c_str());
+ Nan::ThrowTypeError(error.message.c_str());
return;
}
@@ -558,9 +559,10 @@ void NodeMap::AddLayer(const Nan::FunctionCallbackInfo<v8::Value>& info) {
return Nan::ThrowTypeError("One argument required");
}
- Result<std::unique_ptr<Layer>> layer = convert<std::unique_ptr<Layer>>(info[0]);
+ Error error;
+ mbgl::optional<std::unique_ptr<Layer>> layer = convert<std::unique_ptr<Layer>>(info[0], error);
if (!layer) {
- Nan::ThrowTypeError(layer.error().message.c_str());
+ Nan::ThrowTypeError(error.message.c_str());
return;
}
@@ -774,9 +776,10 @@ void NodeMap::SetFilter(const Nan::FunctionCallbackInfo<v8::Value>& info) {
Filter filter;
if (!info[1]->IsNull() && !info[1]->IsUndefined()) {
- Result<Filter> converted = convert<Filter>(info[1]);
+ Error error;
+ mbgl::optional<Filter> converted = convert<Filter>(info[1], error);
if (!converted) {
- Nan::ThrowTypeError(converted.error().message.c_str());
+ Nan::ThrowTypeError(error.message.c_str());
return;
}
filter = std::move(*converted);
@@ -908,23 +911,24 @@ void NodeMap::QueryRenderedFeatures(const Nan::FunctionCallbackInfo<v8::Value>&
//Check if filter is provided. If set it must be a valid Filter object
if (Nan::Has(options, Nan::New("filter").ToLocalChecked()).FromJust()) {
auto filterOption = Nan::Get(options, Nan::New("filter").ToLocalChecked()).ToLocalChecked();
- Result<Filter> converted = convert<Filter>(filterOption);
+ Error error;
+ mbgl::optional<Filter> converted = convert<Filter>(filterOption, error);
if (!converted) {
- return Nan::ThrowTypeError(converted.error().message.c_str());
+ return Nan::ThrowTypeError(error.message.c_str());
}
queryOptions.filter = std::move(*converted);
}
}
try {
- std::vector<mbgl::Feature> result;
+ std::vector<mbgl::Feature> optional;
if (Nan::Get(posOrBox, 0).ToLocalChecked()->IsArray()) {
auto pos0 = Nan::Get(posOrBox, 0).ToLocalChecked().As<v8::Array>();
auto pos1 = Nan::Get(posOrBox, 1).ToLocalChecked().As<v8::Array>();
- result = nodeMap->map->queryRenderedFeatures(mbgl::ScreenBox {
+ optional = nodeMap->map->queryRenderedFeatures(mbgl::ScreenBox {
{
Nan::Get(pos0, 0).ToLocalChecked()->NumberValue(),
Nan::Get(pos0, 1).ToLocalChecked()->NumberValue()
@@ -935,15 +939,15 @@ void NodeMap::QueryRenderedFeatures(const Nan::FunctionCallbackInfo<v8::Value>&
}, queryOptions);
} else {
- result = nodeMap->map->queryRenderedFeatures(mbgl::ScreenCoordinate {
+ optional = nodeMap->map->queryRenderedFeatures(mbgl::ScreenCoordinate {
Nan::Get(posOrBox, 0).ToLocalChecked()->NumberValue(),
Nan::Get(posOrBox, 1).ToLocalChecked()->NumberValue()
}, queryOptions);
}
auto array = Nan::New<v8::Array>();
- for (unsigned int i = 0; i < result.size(); i++) {
- array->Set(i, toJS(result[i]));
+ for (unsigned int i = 0; i < optional.size(); i++) {
+ array->Set(i, toJS(optional[i]));
}
info.GetReturnValue().Set(array);
} catch (const std::exception &ex) {