Skip to content
This repository was archived by the owner on Sep 9, 2019. It is now read-only.

Commit 4d25ae9

Browse files
author
Oleg Klimenko
authored
Merge pull request #5 from d00rman/return-from-error
Return after throwing an error
2 parents 5b503c3 + a1d7f90 commit 4d25ae9

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/Rsvg.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ NAN_METHOD(Rsvg::New) {
8181
if (error) {
8282
Nan::ThrowError(error->message);
8383
g_error_free(error);
84-
ARGVAR.GetReturnValue().Set(Nan::Undefined());
84+
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
8585
}
8686
} else {
8787
handle = rsvg_handle_new();
8888
}
8989
// Error handling.
9090
if (!handle) {
9191
Nan::ThrowError("Unable to create RsvgHandle instance.");
92-
ARGVAR.GetReturnValue().Set(Nan::Undefined());
92+
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
9393
}
9494
// Create object.
9595
Rsvg* obj = new Rsvg(handle);
@@ -235,7 +235,7 @@ NAN_METHOD(Rsvg::Dimensions) {
235235
id = *idArg;
236236
if (!id) {
237237
Nan::ThrowError("Invalid argument: id");
238-
ARGVAR.GetReturnValue().Set(Nan::Undefined());
238+
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
239239
}
240240
}
241241

@@ -271,7 +271,7 @@ NAN_METHOD(Rsvg::HasElement) {
271271
id = *idArg;
272272
if (!id) {
273273
Nan::ThrowError("Invalid argument: id");
274-
ARGVAR.GetReturnValue().Set(Nan::Undefined());
274+
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
275275
}
276276
}
277277

@@ -288,11 +288,11 @@ NAN_METHOD(Rsvg::Render) {
288288

289289
if (width <= 0) {
290290
Nan::ThrowError("Expected width > 0.");
291-
ARGVAR.GetReturnValue().Set(Nan::Undefined());
291+
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
292292
}
293293
if (height <= 0) {
294294
Nan::ThrowError("Expected height > 0.");
295-
ARGVAR.GetReturnValue().Set(Nan::Undefined());
295+
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
296296
}
297297

298298
String::Utf8Value formatArg(ARGVAR[2]);
@@ -304,20 +304,20 @@ NAN_METHOD(Rsvg::Render) {
304304
pixelFormat = CAIRO_FORMAT_ARGB32;
305305
} else if (renderFormat == RENDER_FORMAT_JPEG) {
306306
Nan::ThrowError("Format not supported: JPEG");
307-
ARGVAR.GetReturnValue().Set(Nan::Undefined());
307+
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
308308
} else if (
309309
renderFormat == RENDER_FORMAT_SVG ||
310310
renderFormat == RENDER_FORMAT_PDF) {
311311
pixelFormat = CAIRO_FORMAT_INVALID;
312312
} else if (renderFormat == RENDER_FORMAT_VIPS) {
313313
Nan::ThrowError("Format not supported: VIPS");
314-
ARGVAR.GetReturnValue().Set(Nan::Undefined());
314+
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
315315
} else {
316316
renderFormat = RENDER_FORMAT_RAW;
317317
pixelFormat = CairoFormatFromString(formatString);
318318
if (pixelFormat == CAIRO_FORMAT_INVALID) {
319319
Nan::ThrowError("Invalid argument: format");
320-
ARGVAR.GetReturnValue().Set(Nan::Undefined());
320+
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
321321
}
322322
}
323323

@@ -327,11 +327,11 @@ NAN_METHOD(Rsvg::Render) {
327327
id = *idArg;
328328
if (!id) {
329329
Nan::ThrowError("Invalid argument: id");
330-
ARGVAR.GetReturnValue().Set(Nan::Undefined());
330+
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
331331
}
332332
if (!rsvg_handle_has_sub(obj->_handle, id)) {
333333
Nan::ThrowError("SVG element with given id does not exists.");
334-
ARGVAR.GetReturnValue().Set(Nan::Undefined());
334+
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
335335
}
336336
}
337337

@@ -340,16 +340,16 @@ NAN_METHOD(Rsvg::Render) {
340340

341341
if (!rsvg_handle_get_position_sub(obj->_handle, &position, id)) {
342342
Nan::ThrowError("Could not get position of SVG element with given id.");
343-
ARGVAR.GetReturnValue().Set(Nan::Undefined());
343+
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
344344
}
345345

346346
if (!rsvg_handle_get_dimensions_sub(obj->_handle, &dimensions, id)) {
347347
Nan::ThrowError("Could not get dimensions of SVG element or whole image.");
348-
ARGVAR.GetReturnValue().Set(Nan::Undefined());
348+
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
349349
}
350350
if (dimensions.width <= 0 || dimensions.height <= 0) {
351351
Nan::ThrowError("Got invalid dimensions of SVG element or whole image.");
352-
ARGVAR.GetReturnValue().Set(Nan::Undefined());
352+
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
353353
}
354354

355355
std::string data;
@@ -407,7 +407,7 @@ NAN_METHOD(Rsvg::Render) {
407407
Nan::ThrowError(
408408
status ? cairo_status_to_string(status) : "Failed to render image."
409409
);
410-
ARGVAR.GetReturnValue().Set(Nan::Undefined());
410+
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
411411
}
412412

413413
int stride = -1;
@@ -430,7 +430,7 @@ NAN_METHOD(Rsvg::Render) {
430430
Nan::ThrowError(
431431
"Rendered with invalid stride (byte size of row) for ARGB32 format."
432432
);
433-
ARGVAR.GetReturnValue().Set(Nan::Undefined());
433+
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
434434
}
435435

436436
Handle<ObjectTemplate> image = ObjectTemplate::New();

0 commit comments

Comments
 (0)