Skip to content

Commit b85c0e5

Browse files
committed
src: replace ToLocalChecked uses with ToLocal in node-file
1 parent cff7da7 commit b85c0e5

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
@@ -438,7 +438,8 @@ MaybeLocal<Promise> FileHandle::ClosePromise() {
438438

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

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

@@ -865,10 +868,12 @@ void AfterStringPtr(uv_fs_t* req) {
865868
static_cast<const char*>(req->ptr),
866869
req_wrap->encoding(),
867870
&error);
868-
if (link.IsEmpty())
871+
if (link.IsEmpty()) {
869872
req_wrap->Reject(error);
870-
else
871-
req_wrap->Resolve(link.ToLocalChecked());
873+
} else {
874+
Local<Value> val;
875+
if (link.ToLocal(&val)) req_wrap->Resolve(val);
876+
}
872877
}
873878
}
874879

@@ -2262,7 +2267,8 @@ static void WriteBuffers(const FunctionCallbackInfo<Value>& args) {
22622267
MaybeStackBuffer<uv_buf_t> iovs(chunks->Length());
22632268

22642269
for (uint32_t i = 0; i < iovs.length(); i++) {
2265-
Local<Value> chunk = chunks->Get(env->context(), i).ToLocalChecked();
2270+
Local<Value> chunk;
2271+
if (!chunks->Get(env->context(), i).ToLocal(&chunk)) return;
22662272
CHECK(Buffer::HasInstance(chunk));
22672273
iovs[i] = uv_buf_init(Buffer::Data(chunk), Buffer::Length(chunk));
22682274
}
@@ -2602,8 +2608,12 @@ static void ReadFileUtf8(const FunctionCallbackInfo<Value>& args) {
26022608
}
26032609
FS_SYNC_TRACE_END(read);
26042610

2605-
args.GetReturnValue().Set(
2606-
ToV8Value(env->context(), result, isolate).ToLocalChecked());
2611+
Local<Value> val;
2612+
if (!ToV8Value(env->context(), result, isolate).ToLocal(&val)) {
2613+
return;
2614+
}
2615+
2616+
args.GetReturnValue().Set(val);
26072617
}
26082618

26092619
// Wrapper for readv(2).
@@ -2631,7 +2641,8 @@ static void ReadBuffers(const FunctionCallbackInfo<Value>& args) {
26312641

26322642
// Init uv buffers from ArrayBufferViews
26332643
for (uint32_t i = 0; i < iovs.length(); i++) {
2634-
Local<Value> buffer = buffers->Get(env->context(), i).ToLocalChecked();
2644+
Local<Value> buffer;
2645+
if (!buffers->Get(env->context(), i).ToLocal(&buffer)) return;
26352646
CHECK(Buffer::HasInstance(buffer));
26362647
iovs[i] = uv_buf_init(Buffer::Data(buffer), Buffer::Length(buffer));
26372648
}

0 commit comments

Comments
 (0)