diff --git a/src/node_file-inl.h b/src/node_file-inl.h index ac74ab8f27f53b..29d8a12c429cb6 100644 --- a/src/node_file-inl.h +++ b/src/node_file-inl.h @@ -287,21 +287,27 @@ FSReqBase* GetReqWrap(const v8::FunctionCallbackInfo& args, int index, bool use_bigint) { v8::Local value = args[index]; + FSReqBase* result = nullptr; if (value->IsObject()) { - return BaseObject::Unwrap(value.As()); - } - - Realm* realm = Realm::GetCurrent(args); - BindingData* binding_data = realm->GetBindingData(); - - if (value->StrictEquals(realm->isolate_data()->fs_use_promises_symbol())) { - if (use_bigint) { - return FSReqPromise::New(binding_data, use_bigint); - } else { - return FSReqPromise::New(binding_data, use_bigint); + result = BaseObject::Unwrap(value.As()); + } else { + Realm* realm = Realm::GetCurrent(args); + BindingData* binding_data = realm->GetBindingData(); + + if (value->StrictEquals(realm->isolate_data()->fs_use_promises_symbol())) { + if (use_bigint) { + result = + FSReqPromise::New(binding_data, use_bigint); + } else { + result = + FSReqPromise::New(binding_data, use_bigint); + } } } - return nullptr; + if (result != nullptr) { + result->SetReturnValue(args); + } + return result; } // Returns nullptr if the operation fails from the start. @@ -320,10 +326,7 @@ FSReqBase* AsyncDestCall(Environment* env, FSReqBase* req_wrap, uv_req->path = nullptr; after(uv_req); // after may delete req_wrap if there is an error req_wrap = nullptr; - } else { - req_wrap->SetReturnValue(args); } - return req_wrap; } diff --git a/src/node_file.cc b/src/node_file.cc index 9636e42a9d556d..2a2384c88c63d7 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -2473,8 +2473,6 @@ static void WriteString(const FunctionCallbackInfo& args) { uv_req->path = nullptr; AfterInteger(uv_req); // after may delete req_wrap_async if there is // an error - } else { - req_wrap_async->SetReturnValue(args); } } else { // write(fd, string, pos, enc, undefined, ctx) CHECK_EQ(argc, 6); diff --git a/test/fixtures/permission/fs-write.js b/test/fixtures/permission/fs-write.js index 9ac9a30facc196..cd57591c3b0d28 100644 --- a/test/fixtures/permission/fs-write.js +++ b/test/fixtures/permission/fs-write.js @@ -211,6 +211,12 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER; code: 'ERR_ACCESS_DENIED', permission: 'FileSystemWrite', })); + assert.rejects(async () => { + await fs.promises.mkdtemp(path.join(blockedFolder, 'any-folder')); + }, { + code: 'ERR_ACCESS_DENIED', + permission: 'FileSystemWrite', + }); } // fs.mkdtempDisposableSync