Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb71250a

Browse files
jasnellmarco-ippolito
authored andcommitted
src: replace ToLocalChecked uses with ToLocal in node-file
PR-URL:#53869Reviewed-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 parent51ba566 commitb71250a

File tree

2 files changed

+45
-20
lines changed

2 files changed

+45
-20
lines changed

‎src/node_file-inl.h

Lines changed: 23 additions & 9 deletions
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::HandleScopescope(env()->isolate());
223223
InternalCallbackScopecallback_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::HandleScopescope(env()->isolate());
235241
InternalCallbackScopecallback_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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ MaybeLocal<Promise> FileHandle::ClosePromise() {
460460

461461
auto maybe_resolver =Promise::Resolver::New(context);
462462
CHECK(!maybe_resolver.IsEmpty());
463-
Local<Promise::Resolver> resolver = maybe_resolver.ToLocalChecked();
463+
Local<Promise::Resolver> resolver;
464+
if (!maybe_resolver.ToLocal(&resolver))return {};
464465
Local<Promise> promise = resolver.As<Promise>();
465466

466467
Local<Object> close_req_obj;
@@ -868,10 +869,12 @@ void AfterStringPath(uv_fs_t* req) {
868869
req->path,
869870
req_wrap->encoding(),
870871
&error);
871-
if (link.IsEmpty())
872+
if (link.IsEmpty()) {
872873
req_wrap->Reject(error);
873-
else
874-
req_wrap->Resolve(link.ToLocalChecked());
874+
}else {
875+
Local<Value> val;
876+
if (link.ToLocal(&val)) req_wrap->Resolve(val);
877+
}
875878
}
876879
}
877880

@@ -888,10 +891,12 @@ void AfterStringPtr(uv_fs_t* req) {
888891
static_cast<constchar*>(req->ptr),
889892
req_wrap->encoding(),
890893
&error);
891-
if (link.IsEmpty())
894+
if (link.IsEmpty()) {
892895
req_wrap->Reject(error);
893-
else
894-
req_wrap->Resolve(link.ToLocalChecked());
896+
}else {
897+
Local<Value> val;
898+
if (link.ToLocal(&val)) req_wrap->Resolve(val);
899+
}
895900
}
896901
}
897902

@@ -2308,7 +2313,8 @@ static void WriteBuffers(const FunctionCallbackInfo<Value>& args) {
23082313
MaybeStackBuffer<uv_buf_t>iovs(chunks->Length());
23092314

23102315
for (uint32_t i =0; i < iovs.length(); i++) {
2311-
Local<Value> chunk = chunks->Get(env->context(), i).ToLocalChecked();
2316+
Local<Value> chunk;
2317+
if (!chunks->Get(env->context(), i).ToLocal(&chunk))return;
23122318
CHECK(Buffer::HasInstance(chunk));
23132319
iovs[i] =uv_buf_init(Buffer::Data(chunk),Buffer::Length(chunk));
23142320
}
@@ -2642,8 +2648,12 @@ static void ReadFileUtf8(const FunctionCallbackInfo<Value>& args) {
26422648
}
26432649
FS_SYNC_TRACE_END(read);
26442650

2645-
args.GetReturnValue().Set(
2646-
ToV8Value(env->context(), result, isolate).ToLocalChecked());
2651+
Local<Value> val;
2652+
if (!ToV8Value(env->context(), result, isolate).ToLocal(&val)) {
2653+
return;
2654+
}
2655+
2656+
args.GetReturnValue().Set(val);
26472657
}
26482658

26492659
// Wrapper for readv(2).
@@ -2671,7 +2681,8 @@ static void ReadBuffers(const FunctionCallbackInfo<Value>& args) {
26712681

26722682
// Init uv buffers from ArrayBufferViews
26732683
for (uint32_t i =0; i < iovs.length(); i++) {
2674-
Local<Value> buffer = buffers->Get(env->context(), i).ToLocalChecked();
2684+
Local<Value> buffer;
2685+
if (!buffers->Get(env->context(), i).ToLocal(&buffer))return;
26752686
CHECK(Buffer::HasInstance(buffer));
26762687
iovs[i] =uv_buf_init(Buffer::Data(buffer),Buffer::Length(buffer));
26772688
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp