diff --git a/src/node_file-inl.h b/src/node_file-inl.h index 6c059add3bfc02..36c2f8067c6e49 100644 --- a/src/node_file-inl.h +++ b/src/node_file-inl.h @@ -221,9 +221,15 @@ void FSReqPromise::Reject(v8::Local reject) { finished_ = true; v8::HandleScope scope(env()->isolate()); InternalCallbackScope callback_scope(this); - v8::Local value = - object()->Get(env()->context(), - env()->promise_string()).ToLocalChecked(); + v8::Local value; + if (!object() + ->Get(env()->context(), env()->promise_string()) + .ToLocal(&value)) { + // If we hit this, getting the value from the object failed and + // an error was likely scheduled. We could try to reject the promise + // but let's just allow the error to propagate. + return; + } v8::Local resolver = value.As(); USE(resolver->Reject(env()->context(), reject).FromJust()); } @@ -233,9 +239,13 @@ void FSReqPromise::Resolve(v8::Local value) { finished_ = true; v8::HandleScope scope(env()->isolate()); InternalCallbackScope callback_scope(this); - v8::Local val = - object()->Get(env()->context(), - env()->promise_string()).ToLocalChecked(); + v8::Local val; + if (!object()->Get(env()->context(), env()->promise_string()).ToLocal(&val)) { + // If we hit this, getting the value from the object failed and + // an error was likely scheduled. We could try to reject the promise + // but let's just allow the error to propagate. + return; + } v8::Local resolver = val.As(); USE(resolver->Resolve(env()->context(), value).FromJust()); } @@ -255,9 +265,13 @@ void FSReqPromise::ResolveStatFs(const uv_statfs_t* stat) { template void FSReqPromise::SetReturnValue( const v8::FunctionCallbackInfo& args) { - v8::Local val = - object()->Get(env()->context(), - env()->promise_string()).ToLocalChecked(); + v8::Local val; + if (!object()->Get(env()->context(), env()->promise_string()).ToLocal(&val)) { + // If we hit this, getting the value from the object failed and + // an error was likely scheduled. We could try to reject the promise + // but let's just allow the error to propagate. + return; + } v8::Local resolver = val.As(); args.GetReturnValue().Set(resolver->GetPromise()); } diff --git a/src/node_file.cc b/src/node_file.cc index c59235b51cca9f..150935e05a0276 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -437,7 +437,8 @@ MaybeLocal FileHandle::ClosePromise() { auto maybe_resolver = Promise::Resolver::New(context); CHECK(!maybe_resolver.IsEmpty()); - Local resolver = maybe_resolver.ToLocalChecked(); + Local resolver; + if (!maybe_resolver.ToLocal(&resolver)) return {}; Local promise = resolver.As(); Local close_req_obj; @@ -844,10 +845,12 @@ void AfterStringPath(uv_fs_t* req) { req->path, req_wrap->encoding(), &error); - if (link.IsEmpty()) + if (link.IsEmpty()) { req_wrap->Reject(error); - else - req_wrap->Resolve(link.ToLocalChecked()); + } else { + Local val; + if (link.ToLocal(&val)) req_wrap->Resolve(val); + } } } @@ -864,10 +867,12 @@ void AfterStringPtr(uv_fs_t* req) { static_cast(req->ptr), req_wrap->encoding(), &error); - if (link.IsEmpty()) + if (link.IsEmpty()) { req_wrap->Reject(error); - else - req_wrap->Resolve(link.ToLocalChecked()); + } else { + Local val; + if (link.ToLocal(&val)) req_wrap->Resolve(val); + } } } @@ -2237,7 +2242,8 @@ static void WriteBuffers(const FunctionCallbackInfo& args) { MaybeStackBuffer iovs(chunks->Length()); for (uint32_t i = 0; i < iovs.length(); i++) { - Local chunk = chunks->Get(env->context(), i).ToLocalChecked(); + Local chunk; + if (!chunks->Get(env->context(), i).ToLocal(&chunk)) return; CHECK(Buffer::HasInstance(chunk)); iovs[i] = uv_buf_init(Buffer::Data(chunk), Buffer::Length(chunk)); } @@ -2577,8 +2583,12 @@ static void ReadFileUtf8(const FunctionCallbackInfo& args) { } FS_SYNC_TRACE_END(read); - args.GetReturnValue().Set( - ToV8Value(env->context(), result, isolate).ToLocalChecked()); + Local val; + if (!ToV8Value(env->context(), result, isolate).ToLocal(&val)) { + return; + } + + args.GetReturnValue().Set(val); } // Wrapper for readv(2). @@ -2606,7 +2616,8 @@ static void ReadBuffers(const FunctionCallbackInfo& args) { // Init uv buffers from ArrayBufferViews for (uint32_t i = 0; i < iovs.length(); i++) { - Local buffer = buffers->Get(env->context(), i).ToLocalChecked(); + Local buffer; + if (!buffers->Get(env->context(), i).ToLocal(&buffer)) return; CHECK(Buffer::HasInstance(buffer)); iovs[i] = uv_buf_init(Buffer::Data(buffer), Buffer::Length(buffer)); }