Skip to content

Commit 5e1ddd5

Browse files
jasnelladuh95
authored andcommitted
src: fixup more ToLocalChecked uses in node_file
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>
1 parent aa3fd2f commit 5e1ddd5

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

src/node_file.cc

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,16 +1406,15 @@ static void ReadLink(const FunctionCallbackInfo<Value>& args) {
14061406
const char* link_path = static_cast<const char*>(req_wrap_sync.req.ptr);
14071407

14081408
Local<Value> error;
1409-
MaybeLocal<Value> rc = StringBytes::Encode(isolate,
1410-
link_path,
1411-
encoding,
1412-
&error);
1413-
if (rc.IsEmpty()) {
1409+
Local<Value> ret;
1410+
if (!StringBytes::Encode(isolate, link_path, encoding, &error)
1411+
.ToLocal(&ret)) {
1412+
DCHECK(!error.IsEmpty());
14141413
env->isolate()->ThrowException(error);
14151414
return;
14161415
}
14171416

1418-
args.GetReturnValue().Set(rc.ToLocalChecked());
1417+
args.GetReturnValue().Set(ret);
14191418
}
14201419
}
14211420

@@ -1916,15 +1915,16 @@ static void MKDir(const FunctionCallbackInfo<Value>& args) {
19161915
}
19171916
if (!req_wrap_sync.continuation_data()->first_path().empty()) {
19181917
Local<Value> error;
1918+
Local<Value> ret;
19191919
std::string first_path(req_wrap_sync.continuation_data()->first_path());
1920-
MaybeLocal<Value> path = StringBytes::Encode(env->isolate(),
1921-
first_path.c_str(),
1922-
UTF8, &error);
1923-
if (path.IsEmpty()) {
1920+
if (!StringBytes::Encode(
1921+
env->isolate(), first_path.c_str(), UTF8, &error)
1922+
.ToLocal(&ret)) {
1923+
DCHECK(!error.IsEmpty());
19241924
env->isolate()->ThrowException(error);
19251925
return;
19261926
}
1927-
args.GetReturnValue().Set(path.ToLocalChecked());
1927+
args.GetReturnValue().Set(ret);
19281928
}
19291929
} else {
19301930
SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_mkdir, *path, mode);
@@ -1965,16 +1965,15 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) {
19651965
const char* link_path = static_cast<const char*>(req_wrap_sync.req.ptr);
19661966

19671967
Local<Value> error;
1968-
MaybeLocal<Value> rc = StringBytes::Encode(isolate,
1969-
link_path,
1970-
encoding,
1971-
&error);
1972-
if (rc.IsEmpty()) {
1968+
Local<Value> ret;
1969+
if (!StringBytes::Encode(isolate, link_path, encoding, &error)
1970+
.ToLocal(&ret)) {
1971+
DCHECK(!error.IsEmpty());
19731972
env->isolate()->ThrowException(error);
19741973
return;
19751974
}
19761975

1977-
args.GetReturnValue().Set(rc.ToLocalChecked());
1976+
args.GetReturnValue().Set(ret);
19781977
}
19791978
}
19801979

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

20632062
Local<Value> error;
2064-
MaybeLocal<Value> filename = StringBytes::Encode(isolate,
2065-
ent.name,
2066-
encoding,
2067-
&error);
2068-
2069-
if (filename.IsEmpty()) {
2063+
Local<Value> fn;
2064+
if (!StringBytes::Encode(isolate, ent.name, encoding, &error)
2065+
.ToLocal(&fn)) {
2066+
DCHECK(!error.IsEmpty());
20702067
isolate->ThrowException(error);
20712068
return;
20722069
}
20732070

2074-
name_v.push_back(filename.ToLocalChecked());
2071+
name_v.push_back(fn);
20752072

20762073
if (with_types) {
20772074
type_v.emplace_back(Integer::New(isolate, ent.type));
@@ -3092,13 +3089,14 @@ static void Mkdtemp(const FunctionCallbackInfo<Value>& args) {
30923089
return;
30933090
}
30943091
Local<Value> error;
3095-
MaybeLocal<Value> rc =
3096-
StringBytes::Encode(isolate, req_wrap_sync.req.path, encoding, &error);
3097-
if (rc.IsEmpty()) {
3092+
Local<Value> ret;
3093+
if (!StringBytes::Encode(isolate, req_wrap_sync.req.path, encoding, &error)
3094+
.ToLocal(&ret)) {
3095+
DCHECK(!error.IsEmpty());
30983096
env->isolate()->ThrowException(error);
30993097
return;
31003098
}
3101-
args.GetReturnValue().Set(rc.ToLocalChecked());
3099+
args.GetReturnValue().Set(ret);
31023100
}
31033101
}
31043102

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

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy