| 1313 | } |
| 1314 | |
| 1315 | inline table_parameters_ptr argumentsToTableParameter(const Napi::CallbackInfo &args, |
| 1316 | bool requires_multiple_coordinates) |
| 1317 | { |
| 1318 | table_parameters_ptr params = std::make_unique<osrm::TableParameters>(); |
| 1319 | bool has_base_params = argumentsToParameter(args, params, requires_multiple_coordinates); |
| 1320 | if (!has_base_params) |
| 1321 | return table_parameters_ptr(); |
| 1322 | |
| 1323 | Napi::Object obj = args[0].As<Napi::Object>(); |
| 1324 | if (obj.IsEmpty()) |
| 1325 | return table_parameters_ptr(); |
| 1326 | |
| 1327 | if (obj.Has("sources")) |
| 1328 | { |
| 1329 | Napi::Value sources = obj.Get("sources"); |
| 1330 | if (sources.IsEmpty()) |
| 1331 | return table_parameters_ptr(); |
| 1332 | |
| 1333 | if (!sources.IsArray()) |
| 1334 | { |
| 1335 | ThrowError(args.Env(), "Sources must be an array of indices (or undefined)"); |
| 1336 | return table_parameters_ptr(); |
| 1337 | } |
| 1338 | |
| 1339 | Napi::Array sources_array = sources.As<Napi::Array>(); |
| 1340 | for (uint32_t i = 0; i < sources_array.Length(); ++i) |
| 1341 | { |
| 1342 | Napi::Value source = sources_array.Get(i); |
| 1343 | if (source.IsEmpty()) |
| 1344 | return table_parameters_ptr(); |
| 1345 | |
| 1346 | if (IsUnsignedInteger(source)) |
| 1347 | { |
| 1348 | size_t source_value = source.ToNumber().Uint32Value(); |
| 1349 | if (source_value >= params->coordinates.size()) |
| 1350 | { |
| 1351 | ThrowError(args.Env(), |
| 1352 | "Source indices must be less than the number of coordinates"); |
| 1353 | return table_parameters_ptr(); |
| 1354 | } |
| 1355 | |
| 1356 | params->sources.push_back(source.ToNumber().Uint32Value()); |
| 1357 | } |
| 1358 | else |
| 1359 | { |
| 1360 | ThrowError(args.Env(), "Source must be an integer"); |
| 1361 | return table_parameters_ptr(); |
| 1362 | } |
| 1363 | } |
| 1364 | } |
| 1365 | |
| 1366 | if (obj.Has("destinations")) |
| 1367 | { |
| 1368 | Napi::Value destinations = obj.Get("destinations"); |
| 1369 | if (destinations.IsEmpty()) |
| 1370 | return table_parameters_ptr(); |
| 1371 | |
| 1372 | if (!destinations.IsArray()) |
nothing calls this directly
no test coverage detected