src: modify code for empty string

PR-URL: https://github.com/nodejs/node/pull/49336
Refs: https://github.com/nodejs/node/pull/49097
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
This commit is contained in:
pluris authored and Ulises Gascón committed 2023-09-10 18:09:41 +00:00
1 parent 84195d9584
commit dc4de1c69b
1 file changed
+4 -6
+4 -6
View File
@@ -78,7 +78,7 @@ void BindingData::DomainToASCII(const FunctionCallbackInfo<Value>& args) {
std::string input = Utf8Value(env->isolate(), args[0]).ToString();
if (input.empty()) {
return args.GetReturnValue().Set(FIXED_ONE_BYTE_STRING(env->isolate(), ""));
return args.GetReturnValue().Set(String::Empty(env->isolate()));
}
// It is important to have an initial value that contains a special scheme.
@@ -87,7 +87,7 @@ void BindingData::DomainToASCII(const FunctionCallbackInfo<Value>& args) {
auto out = ada::parse<ada::url>("ws://x");
DCHECK(out);
if (!out->set_hostname(input)) {
return args.GetReturnValue().Set(FIXED_ONE_BYTE_STRING(env->isolate(), ""));
return args.GetReturnValue().Set(String::Empty(env->isolate()));
}
std::string host = out->get_hostname();
args.GetReturnValue().Set(
@@ -101,8 +101,7 @@ void BindingData::DomainToUnicode(const FunctionCallbackInfo<Value>& args) {
std::string input = Utf8Value(env->isolate(), args[0]).ToString();
if (input.empty()) {
return args.GetReturnValue().Set(
String::NewFromUtf8(env->isolate(), "").ToLocalChecked());
return args.GetReturnValue().Set(String::Empty(env->isolate()));
}
// It is important to have an initial value that contains a special scheme.
@@ -111,8 +110,7 @@ void BindingData::DomainToUnicode(const FunctionCallbackInfo<Value>& args) {
auto out = ada::parse<ada::url>("ws://x");
DCHECK(out);
if (!out->set_hostname(input)) {
return args.GetReturnValue().Set(
String::NewFromUtf8(env->isolate(), "").ToLocalChecked());
return args.GetReturnValue().Set(String::Empty(env->isolate()));
}
std::string result = ada::unicode::to_unicode(out->get_hostname());