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>
This commit is contained in:
Anna Henningsen 2018-09-22 15:15:05 +02:00 committed by Daniel Bevenius
parent b01e617dcc
commit f004936a13

View File

@ -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 {