Avoid implicit casts and make code more portable (#716)

This commit is contained in:
tdcosta100
2023-01-23 07:32:53 -03:00
committed by GitHub
parent e47efe3761
commit d5acff3c74
18 changed files with 63 additions and 61 deletions

View File

@@ -39,7 +39,7 @@ public:
Nan::EscapableHandleScope scope;
// const_cast because v8::Local<T>::As is not marked const until node v8.0
v8::Local<v8::Array> array = const_cast<v8::Local<v8::Value>&>(value).As<v8::Array>();
return scope.Escape(Nan::Get(array, i).ToLocalChecked());
return scope.Escape(Nan::Get(array, static_cast<uint32_t>(i)).ToLocalChecked());
}
static bool isObject(const v8::Local<v8::Value>& value) {

View File

@@ -79,9 +79,7 @@ void NodeExpression::Parse(const Nan::FunctionCallbackInfo<v8::Value>& info) {
auto success = [&cons, &info](std::unique_ptr<Expression> result) {
auto nodeExpr = new NodeExpression(std::move(result));
const int argc = 0;
v8::Local<v8::Value> argv[0] = {};
auto wrapped = Nan::NewInstance(cons, argc, argv).ToLocalChecked();
auto wrapped = Nan::NewInstance(cons).ToLocalChecked();
nodeExpr->Wrap(wrapped);
info.GetReturnValue().Set(wrapped);
};
@@ -243,7 +241,7 @@ void NodeExpression::Evaluate(const Nan::FunctionCallbackInfo<v8::Value>& info)
mbgl::optional<float> zoom;
v8::Local<v8::Value> v8zoom = Nan::Get(info[0]->ToObject(context).ToLocalChecked(), Nan::New("zoom").ToLocalChecked()).ToLocalChecked();
if (v8zoom->IsNumber()) zoom = Nan::To<double>(v8zoom).FromJust();
if (v8zoom->IsNumber()) zoom = static_cast<float>(Nan::To<double>(v8zoom).FromJust());
mbgl::optional<double> heatmapDensity;
v8::Local<v8::Value> v8heatmapDensity = Nan::Get(info[0]->ToObject(context).ToLocalChecked(), Nan::New("heatmapDensity").ToLocalChecked()).ToLocalChecked();

View File

@@ -62,7 +62,7 @@ public:
Nan::EscapableHandleScope scope;
v8::Local<v8::Array> result = Nan::New<v8::Array>(vector.size());
for (std::size_t i = 0; i < vector.size(); ++i) {
Nan::Set(result, i, operator()(vector[i]));
Nan::Set(result, static_cast<uint32_t>(i), operator()(vector[i]));
}
return scope.Escape(result);
}
@@ -113,7 +113,7 @@ struct ToValue {
Nan::EscapableHandleScope scope;
v8::Local<v8::Array> result = Nan::New<v8::Array>();
for (std::size_t i = 0; i < array.size(); i++) {
Nan::Set(result, i, toJS(array[i]));
Nan::Set(result, static_cast<uint32_t>(i), toJS(array[i]));
}
return scope.Escape(result);
}

View File

@@ -32,8 +32,6 @@
#include <mbgl/util/logging.hpp>
#include <mbgl/util/premultiply.hpp>
#include <unistd.h>
namespace node_mbgl {
struct NodeMap::RenderOptions {
@@ -344,11 +342,11 @@ NodeMap::RenderOptions NodeMap::ParseOptions(v8::Local<v8::Object> obj) {
}
if (Nan::Has(obj, Nan::New("width").ToLocalChecked()).FromJust()) {
options.size.width = Nan::To<int64_t>(Nan::Get(obj, Nan::New("width").ToLocalChecked()).ToLocalChecked()).ToChecked();
options.size.width = static_cast<uint32_t>(Nan::To<int64_t>(Nan::Get(obj, Nan::New("width").ToLocalChecked()).ToLocalChecked()).ToChecked());
}
if (Nan::Has(obj, Nan::New("height").ToLocalChecked()).FromJust()) {
options.size.height = Nan::To<int64_t>(Nan::Get(obj, Nan::New("height").ToLocalChecked()).ToLocalChecked()).ToChecked();
options.size.height = static_cast<uint32_t>(Nan::To<int64_t>(Nan::Get(obj, Nan::New("height").ToLocalChecked()).ToLocalChecked()).ToChecked());
}
if (Nan::Has(obj, Nan::New("classes").ToLocalChecked()).FromJust()) {
@@ -852,8 +850,8 @@ void NodeMap::SetLayerZoomRange(const Nan::FunctionCallbackInfo<v8::Value>& info
return Nan::ThrowTypeError("layer not found");
}
layer->setMinZoom(Nan::To<double>(info[1]).ToChecked());
layer->setMaxZoom(Nan::To<double>(info[2]).ToChecked());
layer->setMinZoom(static_cast<float>(Nan::To<double>(info[1]).ToChecked()));
layer->setMaxZoom(static_cast<float>(Nan::To<double>(info[2]).ToChecked()));
}
void NodeMap::SetLayerProperty(const Nan::FunctionCallbackInfo<v8::Value>& info) {
@@ -1385,7 +1383,7 @@ void NodeMap::QueryRenderedFeatures(const Nan::FunctionCallbackInfo<v8::Value>&
auto array = Nan::New<v8::Array>();
for (std::size_t i = 0; i < optional.size(); i++) {
Nan::Set(array, i, toJS(optional[i]));
Nan::Set(array, static_cast<uint32_t>(i), toJS(optional[i]));
}
info.GetReturnValue().Set(array);
} catch (const std::exception &ex) {
@@ -1397,9 +1395,9 @@ NodeMap::NodeMap(v8::Local<v8::Object> options)
: pixelRatio([&] {
Nan::HandleScope scope;
return Nan::Has(options, Nan::New("ratio").ToLocalChecked()).FromJust()
? Nan::To<double>(Nan::Get(options, Nan::New("ratio").ToLocalChecked())
.ToLocalChecked()).ToChecked()
: 1.0;
? static_cast<float>(Nan::To<double>(Nan::Get(options, Nan::New("ratio").ToLocalChecked())
.ToLocalChecked()).ToChecked())
: 1.0f;
}())
, mode([&] {
Nan::HandleScope scope;