fs: fix return value of fs APIs

PR-URL: https://github.com/nodejs/node/pull/58996
Fixes: https://github.com/nodejs/node/issues/58747
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Jason Zhang <xzha4350@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
This commit is contained in:
theanarkh 2025-07-20 14:51:26 +08:00 committed by GitHub
parent ab694d5661
commit bf2384f224
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 16 deletions

View file

@ -287,21 +287,27 @@ FSReqBase* GetReqWrap(const v8::FunctionCallbackInfo<v8::Value>& args,
int index,
bool use_bigint) {
v8::Local<v8::Value> value = args[index];
FSReqBase* result = nullptr;
if (value->IsObject()) {
return BaseObject::Unwrap<FSReqBase>(value.As<v8::Object>());
}
result = BaseObject::Unwrap<FSReqBase>(value.As<v8::Object>());
} else {
Realm* realm = Realm::GetCurrent(args);
BindingData* binding_data = realm->GetBindingData<BindingData>();
Realm* realm = Realm::GetCurrent(args);
BindingData* binding_data = realm->GetBindingData<BindingData>();
if (value->StrictEquals(realm->isolate_data()->fs_use_promises_symbol())) {
if (use_bigint) {
return FSReqPromise<AliasedBigInt64Array>::New(binding_data, use_bigint);
} else {
return FSReqPromise<AliasedFloat64Array>::New(binding_data, use_bigint);
if (value->StrictEquals(realm->isolate_data()->fs_use_promises_symbol())) {
if (use_bigint) {
result =
FSReqPromise<AliasedBigInt64Array>::New(binding_data, use_bigint);
} else {
result =
FSReqPromise<AliasedFloat64Array>::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;
}

View file

@ -2473,8 +2473,6 @@ static void WriteString(const FunctionCallbackInfo<Value>& 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);

View file

@ -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