From dc4de1c69baa6ddcfe9b5df5d3c8ae255914bd3e Mon Sep 17 00:00:00 2001 From: pluris Date: Fri, 1 Sep 2023 16:35:51 +0900 Subject: [PATCH] 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 Reviewed-By: Ben Noordhuis Reviewed-By: Darshan Sen Reviewed-By: Luigi Pinca Reviewed-By: Debadree Chatterjee --- src/node_url.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/node_url.cc b/src/node_url.cc index a9f9dd0f71a5ea..666492ca47cee3 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -78,7 +78,7 @@ void BindingData::DomainToASCII(const FunctionCallbackInfo& 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& args) { auto out = ada::parse("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& 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& args) { auto out = ada::parse("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());