Skip to content

Commit a94c3ae

Browse files
jasnelltargos
authored andcommitted
src: replace ToLocalChecked uses with ToLocal in node-file
PR-URL: #53869 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 55461be commit a94c3ae

File tree

2 files changed

+45
-20
lines changed

2 files changed

+45
-20
lines changed

src/node_file-inl.h

+23-9
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,15 @@ void FSReqPromise<AliasedBufferT>::Reject(v8::Local<v8::Value> reject) {
221221
finished_ = true;
222222
v8::HandleScope scope(env()->isolate());
223223
InternalCallbackScope callback_scope(this);
224-
v8::Local<v8::Value> value =
225-
object()->Get(env()->context(),
226-
env()->promise_string()).ToLocalChecked();
224+
v8::Local<v8::Value> value;
225+
if (!object()
226+
->Get(env()->context(), env()->promise_string())
227+
.ToLocal(&value)) {
228+
// If we hit this, getting the value from the object failed and
229+
// an error was likely scheduled. We could try to reject the promise
230+
// but let's just allow the error to propagate.
231+
return;
232+
}
227233
v8::Local<v8::Promise::Resolver> resolver = value.As<v8::Promise::Resolver>();
228234
USE(resolver->Reject(env()->context(), reject).FromJust());
229235
}
@@ -233,9 +239,13 @@ void FSReqPromise<AliasedBufferT>::Resolve(v8::Local<v8::Value> value) {
233239
finished_ = true;
234240
v8::HandleScope scope(env()->isolate());
235241
InternalCallbackScope callback_scope(this);
236-
v8::Local<v8::Value> val =
237-
object()->Get(env()->context(),
238-
env()->promise_string()).ToLocalChecked();
242+
v8::Local<v8::Value> val;
243+
if (!object()->Get(env()->context(), env()->promise_string()).ToLocal(&val)) {
244+
// If we hit this, getting the value from the object failed and
245+
// an error was likely scheduled. We could try to reject the promise
246+
// but let's just allow the error to propagate.
247+
return;
248+
}
239249
v8::Local<v8::Promise::Resolver> resolver = val.As<v8::Promise::Resolver>();
240250
USE(resolver->Resolve(env()->context(), value).FromJust());
241251
}
@@ -255,9 +265,13 @@ void FSReqPromise<AliasedBufferT>::ResolveStatFs(const uv_statfs_t* stat) {
255265
template <typename AliasedBufferT>
256266
void FSReqPromise<AliasedBufferT>::SetReturnValue(
257267
const v8::FunctionCallbackInfo<v8::Value>& args) {
258-
v8::Local<v8::Value> val =
259-
object()->Get(env()->context(),
260-
env()->promise_string()).ToLocalChecked();
268+
v8::Local<v8::Value> val;
269+
if (!object()->Get(env()->context(), env()->promise_string()).ToLocal(&val)) {
270+
// If we hit this, getting the value from the object failed and
271+
// an error was likely scheduled. We could try to reject the promise
272+
// but let's just allow the error to propagate.
273+
return;
274+
}
261275
v8::Local<v8::Promise::Resolver> resolver = val.As<v8::Promise::Resolver>();
262276
args.GetReturnValue().Set(resolver->GetPromise());
263277
}

src/node_file.cc

+22-11
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ MaybeLocal<Promise> FileHandle::ClosePromise() {
437437

438438
auto maybe_resolver = Promise::Resolver::New(context);
439439
CHECK(!maybe_resolver.IsEmpty());
440-
Local<Promise::Resolver> resolver = maybe_resolver.ToLocalChecked();
440+
Local<Promise::Resolver> resolver;
441+
if (!maybe_resolver.ToLocal(&resolver)) return {};
441442
Local<Promise> promise = resolver.As<Promise>();
442443

443444
Local<Object> close_req_obj;
@@ -844,10 +845,12 @@ void AfterStringPath(uv_fs_t* req) {
844845
req->path,
845846
req_wrap->encoding(),
846847
&error);
847-
if (link.IsEmpty())
848+
if (link.IsEmpty()) {
848849
req_wrap->Reject(error);
849-
else
850-
req_wrap->Resolve(link.ToLocalChecked());
850+
} else {
851+
Local<Value> val;
852+
if (link.ToLocal(&val)) req_wrap->Resolve(val);
853+
}
851854
}
852855
}
853856

@@ -864,10 +867,12 @@ void AfterStringPtr(uv_fs_t* req) {
864867
static_cast<const char*>(req->ptr),
865868
req_wrap->encoding(),
866869
&error);
867-
if (link.IsEmpty())
870+
if (link.IsEmpty()) {
868871
req_wrap->Reject(error);
869-
else
870-
req_wrap->Resolve(link.ToLocalChecked());
872+
} else {
873+
Local<Value> val;
874+
if (link.ToLocal(&val)) req_wrap->Resolve(val);
875+
}
871876
}
872877
}
873878

@@ -2237,7 +2242,8 @@ static void WriteBuffers(const FunctionCallbackInfo<Value>& args) {
22372242
MaybeStackBuffer<uv_buf_t> iovs(chunks->Length());
22382243

22392244
for (uint32_t i = 0; i < iovs.length(); i++) {
2240-
Local<Value> chunk = chunks->Get(env->context(), i).ToLocalChecked();
2245+
Local<Value> chunk;
2246+
if (!chunks->Get(env->context(), i).ToLocal(&chunk)) return;
22412247
CHECK(Buffer::HasInstance(chunk));
22422248
iovs[i] = uv_buf_init(Buffer::Data(chunk), Buffer::Length(chunk));
22432249
}
@@ -2577,8 +2583,12 @@ static void ReadFileUtf8(const FunctionCallbackInfo<Value>& args) {
25772583
}
25782584
FS_SYNC_TRACE_END(read);
25792585

2580-
args.GetReturnValue().Set(
2581-
ToV8Value(env->context(), result, isolate).ToLocalChecked());
2586+
Local<Value> val;
2587+
if (!ToV8Value(env->context(), result, isolate).ToLocal(&val)) {
2588+
return;
2589+
}
2590+
2591+
args.GetReturnValue().Set(val);
25822592
}
25832593

25842594
// Wrapper for readv(2).
@@ -2606,7 +2616,8 @@ static void ReadBuffers(const FunctionCallbackInfo<Value>& args) {
26062616

26072617
// Init uv buffers from ArrayBufferViews
26082618
for (uint32_t i = 0; i < iovs.length(); i++) {
2609-
Local<Value> buffer = buffers->Get(env->context(), i).ToLocalChecked();
2619+
Local<Value> buffer;
2620+
if (!buffers->Get(env->context(), i).ToLocal(&buffer)) return;
26102621
CHECK(Buffer::HasInstance(buffer));
26112622
iovs[i] = uv_buf_init(Buffer::Data(buffer), Buffer::Length(buffer));
26122623
}

0 commit comments

Comments
 (0)