Skip to content

Commit

Permalink
src: fixup more ToLocalChecked uses in node_file
Browse files Browse the repository at this point in the history
PR-URL: #56484
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
  • Loading branch information
jasnell committed Jan 7, 2025
1 parent 3b5f235 commit 8d9dac4
Showing 1 changed file with 36 additions and 34 deletions.
70 changes: 36 additions & 34 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1406,16 +1406,15 @@ static void ReadLink(const FunctionCallbackInfo<Value>& args) {
const char* link_path = static_cast<const char*>(req_wrap_sync.req.ptr);

Local<Value> error;
MaybeLocal<Value> rc = StringBytes::Encode(isolate,
link_path,
encoding,
&error);
if (rc.IsEmpty()) {
Local<Value> ret;
if (!StringBytes::Encode(isolate, link_path, encoding, &error)
.ToLocal(&ret)) {
DCHECK(!error.IsEmpty());
env->isolate()->ThrowException(error);
return;
}

args.GetReturnValue().Set(rc.ToLocalChecked());
args.GetReturnValue().Set(ret);
}
}

Expand Down Expand Up @@ -1916,15 +1915,16 @@ static void MKDir(const FunctionCallbackInfo<Value>& args) {
}
if (!req_wrap_sync.continuation_data()->first_path().empty()) {
Local<Value> error;
Local<Value> ret;
std::string first_path(req_wrap_sync.continuation_data()->first_path());
MaybeLocal<Value> path = StringBytes::Encode(env->isolate(),
first_path.c_str(),
UTF8, &error);
if (path.IsEmpty()) {
if (!StringBytes::Encode(
env->isolate(), first_path.c_str(), UTF8, &error)
.ToLocal(&ret)) {
DCHECK(!error.IsEmpty());
env->isolate()->ThrowException(error);
return;
}
args.GetReturnValue().Set(path.ToLocalChecked());
args.GetReturnValue().Set(ret);
}
} else {
SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_mkdir, *path, mode);
Expand Down Expand Up @@ -1965,16 +1965,15 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) {
const char* link_path = static_cast<const char*>(req_wrap_sync.req.ptr);

Local<Value> error;
MaybeLocal<Value> rc = StringBytes::Encode(isolate,
link_path,
encoding,
&error);
if (rc.IsEmpty()) {
Local<Value> ret;
if (!StringBytes::Encode(isolate, link_path, encoding, &error)
.ToLocal(&ret)) {
DCHECK(!error.IsEmpty());
env->isolate()->ThrowException(error);
return;
}

args.GetReturnValue().Set(rc.ToLocalChecked());
args.GetReturnValue().Set(ret);
}
}

Expand Down Expand Up @@ -2061,17 +2060,15 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
}

Local<Value> error;
MaybeLocal<Value> filename = StringBytes::Encode(isolate,
ent.name,
encoding,
&error);

if (filename.IsEmpty()) {
Local<Value> fn;
if (!StringBytes::Encode(isolate, ent.name, encoding, &error)
.ToLocal(&fn)) {
DCHECK(!error.IsEmpty());
isolate->ThrowException(error);
return;
}

name_v.push_back(filename.ToLocalChecked());
name_v.push_back(fn);

if (with_types) {
type_v.emplace_back(Integer::New(isolate, ent.type));
Expand Down Expand Up @@ -3092,13 +3089,14 @@ static void Mkdtemp(const FunctionCallbackInfo<Value>& args) {
return;
}
Local<Value> error;
MaybeLocal<Value> rc =
StringBytes::Encode(isolate, req_wrap_sync.req.path, encoding, &error);
if (rc.IsEmpty()) {
Local<Value> ret;
if (!StringBytes::Encode(isolate, req_wrap_sync.req.path, encoding, &error)
.ToLocal(&ret)) {
DCHECK(!error.IsEmpty());
env->isolate()->ThrowException(error);
return;
}
args.GetReturnValue().Set(rc.ToLocalChecked());
args.GetReturnValue().Set(ret);
}
}

Expand Down Expand Up @@ -3410,9 +3408,11 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
for (int i = 0; i < legacy_main_extensions_with_main_end; i++) {
file_path = *initial_file_path + std::string(legacy_main_extensions[i]);
// TODO(anonrig): Remove this when ToNamespacedPath supports std::string
Local<Value> local_file_path =
Buffer::Copy(env->isolate(), file_path.c_str(), file_path.size())
.ToLocalChecked();
Local<Value> local_file_path;
if (!Buffer::Copy(env->isolate(), file_path.c_str(), file_path.size())
.ToLocal(&local_file_path)) {
return;
}
BufferValue buff_file_path(isolate, local_file_path);
ToNamespacedPath(env, &buff_file_path);

Expand Down Expand Up @@ -3445,9 +3445,11 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
i++) {
file_path = *initial_file_path + std::string(legacy_main_extensions[i]);
// TODO(anonrig): Remove this when ToNamespacedPath supports std::string
Local<Value> local_file_path =
Buffer::Copy(env->isolate(), file_path.c_str(), file_path.size())
.ToLocalChecked();
Local<Value> local_file_path;
if (!Buffer::Copy(env->isolate(), file_path.c_str(), file_path.size())
.ToLocal(&local_file_path)) {
return;
}
BufferValue buff_file_path(isolate, local_file_path);
ToNamespacedPath(env, &buff_file_path);

Expand Down

0 comments on commit 8d9dac4

Please sign in to comment.