Skip to content

Commit 9e79f08

Browse files
committed
No need to escape env.Undefined() (ref #961)
1 parent 485b8b6 commit 9e79f08

12 files changed

+112
-112
lines changed

src/mapnik_image_copy.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ Napi::Value Image::copySync(Napi::CallbackInfo const& info)
197197
if (type >= mapnik::image_dtype::IMAGE_DTYPE_MAX)
198198
{
199199
Napi::TypeError::New(env, "Image 'type' must be a valid image type").ThrowAsJavaScriptException();
200-
return scope.Escape(env.Undefined());
200+
return env.Undefined();
201201
}
202202
}
203203
else if (info[0].IsObject())
@@ -207,7 +207,7 @@ Napi::Value Image::copySync(Napi::CallbackInfo const& info)
207207
else
208208
{
209209
Napi::TypeError::New(env, "Unknown parameters passed").ThrowAsJavaScriptException();
210-
return scope.Escape(env.Undefined());
210+
return env.Undefined();
211211
}
212212
}
213213
if (info.Length() >= 2)
@@ -219,7 +219,7 @@ Napi::Value Image::copySync(Napi::CallbackInfo const& info)
219219
else
220220
{
221221
Napi::TypeError::New(env, "Expected options object as second argument").ThrowAsJavaScriptException();
222-
return scope.Escape(env.Undefined());
222+
return env.Undefined();
223223
}
224224
}
225225

@@ -234,7 +234,7 @@ Napi::Value Image::copySync(Napi::CallbackInfo const& info)
234234
else
235235
{
236236
Napi::TypeError::New(env, "scaling argument must be a number").ThrowAsJavaScriptException();
237-
return scope.Escape(env.Undefined());
237+
return env.Undefined();
238238
}
239239
}
240240

@@ -249,7 +249,7 @@ Napi::Value Image::copySync(Napi::CallbackInfo const& info)
249249
else
250250
{
251251
Napi::TypeError::New(env, "offset argument must be a number").ThrowAsJavaScriptException();
252-
return scope.Escape(env.Undefined());
252+
return env.Undefined();
253253
}
254254
}
255255

@@ -271,6 +271,6 @@ Napi::Value Image::copySync(Napi::CallbackInfo const& info)
271271
catch (std::exception const& ex)
272272
{
273273
Napi::Error::New(env, ex.what()).ThrowAsJavaScriptException();
274-
return scope.Escape(env.Undefined());
274+
return env.Undefined();
275275
}
276276
}

src/mapnik_image_from_bytes.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ Napi::Value Image::fromBytesSync(Napi::CallbackInfo const& info)
8989
if (info.Length() < 1 || !info[0].IsObject())
9090
{
9191
Napi::TypeError::New(env, "must provide a buffer argument").ThrowAsJavaScriptException();
92-
return scope.Escape(env.Undefined());
92+
return env.Undefined();
9393
}
9494

9595
Napi::Object obj = info[0].As<Napi::Object>();
9696
if (!obj.IsBuffer())
9797
{
9898
Napi::TypeError::New(env, "first argument is invalid, must be a Buffer").ThrowAsJavaScriptException();
99-
return scope.Escape(env.Undefined());
99+
return env.Undefined();
100100
}
101101

102102
try
@@ -118,12 +118,12 @@ Napi::Value Image::fromBytesSync(Napi::CallbackInfo const& info)
118118
// mapnik was not providing an image type it should. This should never
119119
// be occuring so marking this out from coverage
120120
Napi::TypeError::New(env, "Failed to load from buffer").ThrowAsJavaScriptException();
121-
return scope.Escape(env.Undefined());
121+
return env.Undefined();
122122
}
123123
catch (std::exception const& ex)
124124
{
125125
Napi::Error::New(env, ex.what()).ThrowAsJavaScriptException();
126-
return scope.Escape(env.Undefined());
126+
return env.Undefined();
127127
}
128128
}
129129

@@ -257,7 +257,7 @@ Napi::Value Image::fromBufferSync(Napi::CallbackInfo const& info)
257257
if (info.Length() < 3 || !info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsObject())
258258
{
259259
Napi::TypeError::New(env, "must provide a width, height, and buffer argument").ThrowAsJavaScriptException();
260-
return scope.Escape(env.Undefined());
260+
return env.Undefined();
261261
}
262262

263263
std::int32_t width = info[0].As<Napi::Number>().Int32Value();
@@ -266,22 +266,22 @@ Napi::Value Image::fromBufferSync(Napi::CallbackInfo const& info)
266266
if (width <= 0 || height <= 0)
267267
{
268268
Napi::TypeError::New(env, "width and height must be greater then zero").ThrowAsJavaScriptException();
269-
return scope.Escape(env.Undefined());
269+
return env.Undefined();
270270
}
271271

272272
Napi::Object obj = info[2].As<Napi::Object>();
273273
if (!obj.IsBuffer())
274274
{
275275
Napi::TypeError::New(env, "third argument is invalid, must be a Buffer").ThrowAsJavaScriptException();
276-
return scope.Escape(env.Undefined());
276+
return env.Undefined();
277277
}
278278

279279
// TODO - support other image types?
280280
auto im_size = mapnik::image_rgba8::pixel_size * width * height;
281281
if (im_size != obj.As<Napi::Buffer<char>>().Length())
282282
{
283283
Napi::TypeError::New(env, "invalid image size").ThrowAsJavaScriptException();
284-
return scope.Escape(env.Undefined());
284+
return env.Undefined();
285285
}
286286

287287
bool premultiplied = false;
@@ -295,7 +295,7 @@ Napi::Value Image::fromBufferSync(Napi::CallbackInfo const& info)
295295
if (options.Has("type"))
296296
{
297297
Napi::TypeError::New(env, "'type' option not supported (only rgba images currently viable)").ThrowAsJavaScriptException();
298-
return scope.Escape(env.Undefined());
298+
return env.Undefined();
299299
}
300300
if (options.Has("premultiplied"))
301301
{
@@ -307,7 +307,7 @@ Napi::Value Image::fromBufferSync(Napi::CallbackInfo const& info)
307307
else
308308
{
309309
Napi::TypeError::New(env, "premultiplied option must be a boolean").ThrowAsJavaScriptException();
310-
return scope.Escape(env.Undefined());
310+
return env.Undefined();
311311
}
312312
}
313313

@@ -321,14 +321,14 @@ Napi::Value Image::fromBufferSync(Napi::CallbackInfo const& info)
321321
else
322322
{
323323
Napi::TypeError::New(env, "painted option must be a boolean").ThrowAsJavaScriptException();
324-
return scope.Escape(env.Undefined());
324+
return env.Undefined();
325325
}
326326
}
327327
}
328328
else
329329
{
330330
Napi::TypeError::New(env, "Options parameter must be an object").ThrowAsJavaScriptException();
331-
return scope.Escape(env.Undefined());
331+
return env.Undefined();
332332
}
333333
}
334334

@@ -346,7 +346,7 @@ Napi::Value Image::fromBufferSync(Napi::CallbackInfo const& info)
346346
// There is no known way for this exception to be reached currently.
347347
// LCOV_EXCL_START
348348
Napi::Error::New(env, ex.what()).ThrowAsJavaScriptException();
349-
return scope.Escape(env.Undefined());
349+
return env.Undefined();
350350
// LCOV_EXCL_STOP
351351
}
352352
}

src/mapnik_image_from_svg.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,13 @@ Napi::Value Image::from_svg_sync_impl(Napi::CallbackInfo const& info, bool from_
271271
if (!from_file && (info.Length() < 1 || !info[0].IsObject()))
272272
{
273273
Napi::TypeError::New(env, "must provide a buffer argument").ThrowAsJavaScriptException();
274-
return scope.Escape(env.Undefined());
274+
return env.Undefined();
275275
}
276276

277277
if (from_file && (info.Length() < 1 || !info[0].IsString()))
278278
{
279279
Napi::TypeError::New(env, "must provide a filename argument").ThrowAsJavaScriptException();
280-
return scope.Escape(env.Undefined());
280+
return env.Undefined();
281281
}
282282
double scale = 1.0;
283283
std::size_t max_size = 2048;
@@ -288,7 +288,7 @@ Napi::Value Image::from_svg_sync_impl(Napi::CallbackInfo const& info, bool from_
288288
{
289289
Napi::TypeError::New(env, "optional second arg must be an options object").ThrowAsJavaScriptException();
290290

291-
return scope.Escape(env.Undefined());
291+
return env.Undefined();
292292
}
293293
Napi::Object options = info[1].As<Napi::Object>();
294294
if (options.Has("scale"))
@@ -297,13 +297,13 @@ Napi::Value Image::from_svg_sync_impl(Napi::CallbackInfo const& info, bool from_
297297
if (!scale_opt.IsNumber())
298298
{
299299
Napi::TypeError::New(env, "'scale' must be a number").ThrowAsJavaScriptException();
300-
return scope.Escape(env.Undefined());
300+
return env.Undefined();
301301
}
302302
scale = scale_opt.As<Napi::Number>().DoubleValue();
303303
if (scale <= 0)
304304
{
305305
Napi::TypeError::New(env, "'scale' must be a positive non zero number").ThrowAsJavaScriptException();
306-
return scope.Escape(env.Undefined());
306+
return env.Undefined();
307307
}
308308
}
309309
if (options.Has("max_size"))
@@ -312,13 +312,13 @@ Napi::Value Image::from_svg_sync_impl(Napi::CallbackInfo const& info, bool from_
312312
if (!opt.IsNumber())
313313
{
314314
Napi::TypeError::New(env, "'max_size' must be a positive integer").ThrowAsJavaScriptException();
315-
return scope.Escape(env.Undefined());
315+
return env.Undefined();
316316
}
317317
auto max_size_val = opt.As<Napi::Number>().Int32Value();
318318
if (max_size_val < 0 || max_size_val > 65535)
319319
{
320320
Napi::TypeError::New(env, "'max_size' must be a positive integer between 0 and 65535").ThrowAsJavaScriptException();
321-
return scope.Escape(env.Undefined());
321+
return env.Undefined();
322322
}
323323
max_size = static_cast<std::size_t>(max_size_val);
324324
}
@@ -328,7 +328,7 @@ Napi::Value Image::from_svg_sync_impl(Napi::CallbackInfo const& info, bool from_
328328
if (!opt.IsBoolean())
329329
{
330330
Napi::TypeError::New(env, "'strict' must be a boolean value").ThrowAsJavaScriptException();
331-
return scope.Escape(env.Undefined());
331+
return env.Undefined();
332332
}
333333
strict = opt.As<Napi::Boolean>();
334334
}
@@ -352,7 +352,7 @@ Napi::Value Image::from_svg_sync_impl(Napi::CallbackInfo const& info, bool from_
352352
errorMessage << error << std::endl;
353353
}
354354
Napi::TypeError::New(env, errorMessage.str().c_str()).ThrowAsJavaScriptException();
355-
return scope.Escape(env.Undefined());
355+
return env.Undefined();
356356
}
357357
}
358358
else
@@ -361,7 +361,7 @@ Napi::Value Image::from_svg_sync_impl(Napi::CallbackInfo const& info, bool from_
361361
if (!obj.IsBuffer())
362362
{
363363
Napi::TypeError::New(env, "first argument is invalid, must be a Buffer").ThrowAsJavaScriptException();
364-
return scope.Escape(env.Undefined());
364+
return env.Undefined();
365365
}
366366
std::string svg_buffer(obj.As<Napi::Buffer<char>>().Data(), obj.As<Napi::Buffer<char>>().Length());
367367
p.parse_from_string(svg_buffer);
@@ -373,7 +373,7 @@ Napi::Value Image::from_svg_sync_impl(Napi::CallbackInfo const& info, bool from_
373373
errorMessage << error << std::endl;
374374
}
375375
Napi::TypeError::New(env, errorMessage.str().c_str()).ThrowAsJavaScriptException();
376-
return scope.Escape(env.Undefined());
376+
return env.Undefined();
377377
}
378378
}
379379

@@ -395,15 +395,15 @@ Napi::Value Image::from_svg_sync_impl(Napi::CallbackInfo const& info, bool from_
395395
if (svg_width <= 0 || svg_height <= 0)
396396
{
397397
Napi::TypeError::New(env, "image created from svg must have a width and height greater then zero").ThrowAsJavaScriptException();
398-
return scope.Escape(env.Undefined());
398+
return env.Undefined();
399399
}
400400

401401
if (svg_width > static_cast<double>(max_size) || svg_height > static_cast<double>(max_size))
402402
{
403403
std::stringstream s;
404404
s << "image created from svg must be " << max_size << " pixels or fewer on each side";
405405
Napi::TypeError::New(env, s.str().c_str()).ThrowAsJavaScriptException();
406-
return scope.Escape(env.Undefined());
406+
return env.Undefined();
407407
}
408408

409409
mapnik::image_rgba8 im(static_cast<int>(std::round(svg_width)),
@@ -442,7 +442,7 @@ Napi::Value Image::from_svg_sync_impl(Napi::CallbackInfo const& info, bool from_
442442
// it is a good idea to keep this. Therefore, any exceptions thrown will fail gracefully.
443443
// LCOV_EXCL_START
444444
Napi::Error::New(env, ex.what()).ThrowAsJavaScriptException();
445-
return scope.Escape(env.Undefined());
445+
return env.Undefined();
446446
// LCOV_EXCL_STOP
447447
}
448448
}

src/mapnik_image_open.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ Napi::Value Image::openSync(Napi::CallbackInfo const& info)
7777
if (info.Length() < 1)
7878
{
7979
Napi::Error::New(env, "must provide a string argument").ThrowAsJavaScriptException();
80-
return scope.Escape(env.Undefined());
80+
return env.Undefined();
8181
}
8282
if (!info[0].IsString())
8383
{
8484
Napi::TypeError::New(env, "Argument must be a string").ThrowAsJavaScriptException();
85-
return scope.Escape(env.Undefined());
85+
return env.Undefined();
8686
}
8787
try
8888
{
@@ -105,12 +105,12 @@ Napi::Value Image::openSync(Napi::CallbackInfo const& info)
105105
}
106106
Napi::TypeError::New(env, ("Unsupported image format:" + filename)).ThrowAsJavaScriptException();
107107

108-
return scope.Escape(env.Undefined());
108+
return env.Undefined();
109109
}
110110
catch (std::exception const& ex)
111111
{
112112
Napi::Error::New(env, ex.what()).ThrowAsJavaScriptException();
113-
return scope.Escape(env.Undefined());
113+
return env.Undefined();
114114
}
115115
}
116116

src/mapnik_image_resize.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -430,36 +430,36 @@ Napi::Value Image::resizeSync(Napi::CallbackInfo const& info)
430430
if (width_tmp <= 0)
431431
{
432432
Napi::TypeError::New(env, "Width parameter must be an integer greater then zero").ThrowAsJavaScriptException();
433-
return scope.Escape(env.Undefined());
433+
return env.Undefined();
434434
}
435435
width = static_cast<std::size_t>(width_tmp);
436436
}
437437
else
438438
{
439439
Napi::TypeError::New(env, "Width must be a number").ThrowAsJavaScriptException();
440440

441-
return scope.Escape(env.Undefined());
441+
return env.Undefined();
442442
}
443443
if (info[1].IsNumber())
444444
{
445445
int height_tmp = info[1].As<Napi::Number>().Int32Value();
446446
if (height_tmp <= 0)
447447
{
448448
Napi::TypeError::New(env, "Height parameter must be an integer greater then zero").ThrowAsJavaScriptException();
449-
return scope.Escape(env.Undefined());
449+
return env.Undefined();
450450
}
451451
height = static_cast<std::size_t>(height_tmp);
452452
}
453453
else
454454
{
455455
Napi::TypeError::New(env, "Height must be a number").ThrowAsJavaScriptException();
456-
return scope.Escape(env.Undefined());
456+
return env.Undefined();
457457
}
458458
}
459459
else
460460
{
461461
Napi::TypeError::New(env, "Resize requires at least a width and height parameter").ThrowAsJavaScriptException();
462-
return scope.Escape(env.Undefined());
462+
return env.Undefined();
463463
}
464464

465465
if (info.Length() >= 3)
@@ -540,7 +540,7 @@ Napi::Value Image::resizeSync(Napi::CallbackInfo const& info)
540540
else
541541
{
542542
Napi::TypeError::New(env, "scaling_method argument must be a number").ThrowAsJavaScriptException();
543-
return scope.Escape(env.Undefined());
543+
return env.Undefined();
544544
}
545545
}
546546

@@ -554,19 +554,19 @@ Napi::Value Image::resizeSync(Napi::CallbackInfo const& info)
554554
else
555555
{
556556
Napi::TypeError::New(env, "filter_factor argument must be a number").ThrowAsJavaScriptException();
557-
return scope.Escape(env.Undefined());
557+
return env.Undefined();
558558
}
559559
}
560560

561561
if (image_->is<mapnik::image_null>())
562562
{
563563
Napi::TypeError::New(env, "Can not resize a null image").ThrowAsJavaScriptException();
564-
return scope.Escape(env.Undefined());
564+
return env.Undefined();
565565
}
566566
if (offset_width <= 0 || offset_height <= 0)
567567
{
568568
Napi::TypeError::New(env, "Image width or height is zero or less then zero.").ThrowAsJavaScriptException();
569-
return scope.Escape(env.Undefined());
569+
return env.Undefined();
570570
}
571571
try
572572
{

src/mapnik_image_solid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,5 @@ Napi::Value Image::isSolidSync(Napi::CallbackInfo const& info)
9898
return scope.Escape(Napi::Boolean::New(env, mapnik::is_solid(*image_)));
9999
}
100100
Napi::Error::New(env, "image does not have valid dimensions").ThrowAsJavaScriptException();
101-
return scope.Escape(env.Undefined());
101+
return env.Undefined();
102102
}

0 commit comments

Comments
 (0)