@@ -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) {
255265template <typename AliasedBufferT>
256266void 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}
0 commit comments