Skip to content

Commit 2f659a3

Browse files
addaleaxtargos
authored andcommittedSep 25, 2018
src: use RAII cleanup in node_i18n.cc
PR-URL: #23021 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent 87565c7 commit 2f659a3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed
 

‎src/node_i18n.cc

+8-8
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ class ConverterObject : public BaseObject, Converter {
215215
result.AllocateSufficientStorage(limit);
216216

217217
UBool flush = (flags & CONVERTER_FLAGS_FLUSH) == CONVERTER_FLAGS_FLUSH;
218+
OnScopeLeave cleanup([&]() {
219+
if (flush) {
220+
// Reset the converter state.
221+
converter->bomSeen_ = false;
222+
ucnv_reset(converter->conv);
223+
}
224+
});
218225

219226
const char* source = input_obj_data;
220227
size_t source_length = input_obj_length;
@@ -238,17 +245,10 @@ class ConverterObject : public BaseObject, Converter {
238245
result.SetLength(target - &result[0]);
239246
ret = ToBufferEndian(env, &result);
240247
args.GetReturnValue().Set(ret.ToLocalChecked());
241-
goto reset;
248+
return;
242249
}
243250

244251
args.GetReturnValue().Set(status);
245-
246-
reset:
247-
if (flush) {
248-
// Reset the converter state
249-
converter->bomSeen_ = false;
250-
ucnv_reset(converter->conv);
251-
}
252252
}
253253

254254
void MemoryInfo(MemoryTracker* tracker) const override {

0 commit comments

Comments
 (0)
Please sign in to comment.