mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
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:
parent
ab694d5661
commit
bf2384f224
3 changed files with 23 additions and 16 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
6
test/fixtures/permission/fs-write.js
vendored
6
test/fixtures/permission/fs-write.js
vendored
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue