src: improve error handling in string_bytes/decoder

PR-URL: https://github.com/nodejs/node/pull/56978
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
James M Snell authored and GitHub committed 2025-02-11 16:40:02 +00:00
1 parent 888e5eb4fd
commit cbedcd1696
2 files changed
+25 -25

No files matched your search

+9 -7
View File
@@ -272,19 +272,21 @@ void DecodeData(const FunctionCallbackInfo<Value>& args) {
ArrayBufferViewContents<char> content(args[1].As<ArrayBufferView>());
size_t length = content.length();
MaybeLocal<String> ret =
decoder->DecodeData(args.GetIsolate(), content.data(), &length);
if (!ret.IsEmpty())
args.GetReturnValue().Set(ret.ToLocalChecked());
Local<String> ret;
if (decoder->DecodeData(args.GetIsolate(), content.data(), &length)
.ToLocal(&ret)) {
args.GetReturnValue().Set(ret);
}
}
void FlushData(const FunctionCallbackInfo<Value>& args) {
StringDecoder* decoder =
reinterpret_cast<StringDecoder*>(Buffer::Data(args[0]));
CHECK_NOT_NULL(decoder);
MaybeLocal<String> ret = decoder->FlushData(args.GetIsolate());
if (!ret.IsEmpty())
args.GetReturnValue().Set(ret.ToLocalChecked());
Local<String> ret;
if (decoder->FlushData(args.GetIsolate()).ToLocal(&ret)) {
args.GetReturnValue().Set(ret);
}
}
void InitializeStringDecoder(Local<Object> target,