[node] make ratio optional, default to 1.0

This commit is contained in:
Mike Morris
2015-11-04 18:18:08 -05:00
parent 3528002b58
commit 5e58070dec
4 changed files with 39 additions and 20 deletions

View File

@@ -107,20 +107,21 @@ NAN_METHOD(NodeMap::New) {
auto options = info[0]->ToObject();
// Check that 'request', 'cancel' and 'ratio' are defined.
// Check that 'request' is set. If 'cancel' is set it must be a
// function and if 'ratio' is set it must be a number.
if (!Nan::Has(options, Nan::New("request").ToLocalChecked()).FromJust()
|| !Nan::Get(options, Nan::New("request").ToLocalChecked()).ToLocalChecked()->IsFunction()) {
return Nan::ThrowError("Options object must have a 'request' method");
}
if ( Nan::Has(options, Nan::New("cancel").ToLocalChecked()).FromJust()
if (Nan::Has(options, Nan::New("cancel").ToLocalChecked()).FromJust()
&& !Nan::Get(options, Nan::New("cancel").ToLocalChecked()).ToLocalChecked()->IsFunction()) {
return Nan::ThrowError("Options object 'cancel' property must be a function");
}
if (!Nan::Has(options, Nan::New("ratio").ToLocalChecked()).FromJust()
|| !Nan::Get(options, Nan::New("ratio").ToLocalChecked()).ToLocalChecked()->IsNumber()) {
return Nan::ThrowError("Options object must have a numerical 'ratio' property");
if (Nan::Has(options, Nan::New("ratio").ToLocalChecked()).FromJust()
&& !Nan::Get(options, Nan::New("ratio").ToLocalChecked()).ToLocalChecked()->IsNumber()) {
return Nan::ThrowError("Options object 'ratio' property must be a number");
}
try {
@@ -424,7 +425,7 @@ NAN_METHOD(NodeMap::DumpDebugLogs) {
NodeMap::NodeMap(v8::Local<v8::Object> options) :
view(sharedDisplay(), [&] {
Nan::HandleScope scope;
return Nan::Get(options, Nan::New("ratio").ToLocalChecked()).ToLocalChecked()->NumberValue();
return Nan::Has(options, Nan::New("ratio").ToLocalChecked()).FromJust() ? Nan::Get(options, Nan::New("ratio").ToLocalChecked()).ToLocalChecked()->NumberValue() : 1.0;
}()),
fs(options),
map(std::make_unique<mbgl::Map>(view, fs, mbgl::MapMode::Still)),