diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-09-22 16:15:05 +0300 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2018-09-25 08:17:44 +0300 |
commit | f004936a13ca9b5c68faf65d91187b7c063d8a07 (patch) | |
tree | 78459bccd9e8dc630986ae43a3ad83223e877a2d /src/node_i18n.cc | |
parent | b01e617dcc4cf3f38f2b4516545aaf14d352f6e4 (diff) |
src: use RAII cleanup in node_i18n.cc
PR-URL: https://github.com/nodejs/node/pull/23021
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'src/node_i18n.cc')
-rw-r--r-- | src/node_i18n.cc | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/node_i18n.cc b/src/node_i18n.cc index abe8addfadc..e87f8f59550 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -215,6 +215,13 @@ class ConverterObject : public BaseObject, Converter { result.AllocateSufficientStorage(limit); UBool flush = (flags & CONVERTER_FLAGS_FLUSH) == CONVERTER_FLAGS_FLUSH; + OnScopeLeave cleanup([&]() { + if (flush) { + // Reset the converter state. + converter->bomSeen_ = false; + ucnv_reset(converter->conv); + } + }); const char* source = input_obj_data; size_t source_length = input_obj_length; @@ -238,17 +245,10 @@ class ConverterObject : public BaseObject, Converter { result.SetLength(target - &result[0]); ret = ToBufferEndian(env, &result); args.GetReturnValue().Set(ret.ToLocalChecked()); - goto reset; + return; } args.GetReturnValue().Set(status); - - reset: - if (flush) { - // Reset the converter state - converter->bomSeen_ = false; - ucnv_reset(converter->conv); - } } void MemoryInfo(MemoryTracker* tracker) const override { |