|
10 | 10 | #include <mapnik/save_map.hpp> // for save_map, etc
|
11 | 11 | // stl
|
12 | 12 | #include <sstream> // for basic_ostringstream, etc
|
| 13 | +#include <cmath> |
| 14 | +#include <limits> |
13 | 15 |
|
14 | 16 | Napi::FunctionReference Map::constructor;
|
15 | 17 |
|
@@ -128,35 +130,46 @@ Map::Map(Napi::CallbackInfo const& info)
|
128 | 130 | return;
|
129 | 131 | }
|
130 | 132 |
|
131 |
| - if (info.Length() == 2) |
| 133 | + if (info.Length() > 1 && info.Length() < 4 ) |
132 | 134 | {
|
133 |
| - if (!info[0].IsNumber() || !info[1].IsNumber()) |
| 135 | + if (info[0].IsNumber() && info[1].IsNumber()) |
134 | 136 | {
|
135 |
| - Napi::TypeError::New(env, "'width' and 'height' must be integers").ThrowAsJavaScriptException(); |
136 |
| - return; |
137 |
| - } |
138 |
| - map_ = std::make_shared<mapnik::Map>(info[0].As<Napi::Number>().Int32Value(), info[1].As<Napi::Number>().Int32Value()); |
139 |
| - return; |
140 |
| - } |
141 |
| - else if (info.Length() == 3) |
142 |
| - { |
143 |
| - if (!info[0].IsNumber() || !info[1].IsNumber()) |
144 |
| - { |
145 |
| - Napi::TypeError::New(env, "'width' and 'height' must be integers").ThrowAsJavaScriptException(); |
146 |
| - return; |
| 137 | + std::int32_t width = info[0].As<Napi::Number>().Int32Value(); |
| 138 | + std::int32_t height = info[1].As<Napi::Number>().Int32Value(); |
| 139 | + if (width > 0 && width <= std::numeric_limits<std::int32_t>::max() |
| 140 | + && height > 0 && height <= std::numeric_limits<std::int32_t>::max()) |
| 141 | + { |
| 142 | + |
| 143 | + if (info.Length() == 3) |
| 144 | + { |
| 145 | + if (!info[2].IsString()) |
| 146 | + { |
| 147 | + Napi::Error::New(env, "'srs' value must be a string").ThrowAsJavaScriptException(); |
| 148 | + return; |
| 149 | + } |
| 150 | + |
| 151 | + map_ = std::make_shared<mapnik::Map>(width, height, info[2].As<Napi::String>()); |
| 152 | + } |
| 153 | + else |
| 154 | + { |
| 155 | + map_ = std::make_shared<mapnik::Map>(width, height); |
| 156 | + } |
| 157 | + } |
| 158 | + else |
| 159 | + { |
| 160 | + Napi::TypeError::New(env, "'width' and 'height' must be positive finite numbers").ThrowAsJavaScriptException(); |
| 161 | + return; |
| 162 | + } |
147 | 163 | }
|
148 |
| - if (!info[2].IsString()) |
| 164 | + else |
149 | 165 | {
|
150 |
| - Napi::Error::New(env, "'srs' value must be a string").ThrowAsJavaScriptException(); |
151 |
| - return; |
| 166 | + Napi::TypeError::New(env, "'width' and 'height' must positive finite numbers").ThrowAsJavaScriptException(); |
| 167 | + return; |
152 | 168 | }
|
153 |
| - map_ = std::make_shared<mapnik::Map>(info[0].As<Napi::Number>().Int32Value(), |
154 |
| - info[1].As<Napi::Number>().Int32Value(), |
155 |
| - info[2].As<Napi::String>()); |
156 | 169 | }
|
157 | 170 | else
|
158 | 171 | {
|
159 |
| - Napi::Error::New(env, "please provide Map width and height and optional srs").ThrowAsJavaScriptException(); |
| 172 | + Napi::Error::New(env, "please provide Map width, height and optional srs").ThrowAsJavaScriptException(); |
160 | 173 | }
|
161 | 174 | }
|
162 | 175 |
|
|
0 commit comments