Skip to content

Commit 8d869e6

Browse files
theanarkhaduh95
authored andcommitted
fs: fix return value of fs APIs
PR-URL: #58996 Fixes: #58747 Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Jason Zhang <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]>
1 parent ef89c2f commit 8d869e6

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

src/node_file-inl.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -287,21 +287,27 @@ FSReqBase* GetReqWrap(const v8::FunctionCallbackInfo<v8::Value>& args,
287287
int index,
288288
bool use_bigint) {
289289
v8::Local<v8::Value> value = args[index];
290+
FSReqBase* result = nullptr;
290291
if (value->IsObject()) {
291-
return BaseObject::Unwrap<FSReqBase>(value.As<v8::Object>());
292-
}
293-
294-
Realm* realm = Realm::GetCurrent(args);
295-
BindingData* binding_data = realm->GetBindingData<BindingData>();
296-
297-
if (value->StrictEquals(realm->isolate_data()->fs_use_promises_symbol())) {
298-
if (use_bigint) {
299-
return FSReqPromise<AliasedBigInt64Array>::New(binding_data, use_bigint);
300-
} else {
301-
return FSReqPromise<AliasedFloat64Array>::New(binding_data, use_bigint);
292+
result = BaseObject::Unwrap<FSReqBase>(value.As<v8::Object>());
293+
} else {
294+
Realm* realm = Realm::GetCurrent(args);
295+
BindingData* binding_data = realm->GetBindingData<BindingData>();
296+
297+
if (value->StrictEquals(realm->isolate_data()->fs_use_promises_symbol())) {
298+
if (use_bigint) {
299+
result =
300+
FSReqPromise<AliasedBigInt64Array>::New(binding_data, use_bigint);
301+
} else {
302+
result =
303+
FSReqPromise<AliasedFloat64Array>::New(binding_data, use_bigint);
304+
}
302305
}
303306
}
304-
return nullptr;
307+
if (result != nullptr) {
308+
result->SetReturnValue(args);
309+
}
310+
return result;
305311
}
306312

307313
// Returns nullptr if the operation fails from the start.
@@ -320,10 +326,7 @@ FSReqBase* AsyncDestCall(Environment* env, FSReqBase* req_wrap,
320326
uv_req->path = nullptr;
321327
after(uv_req); // after may delete req_wrap if there is an error
322328
req_wrap = nullptr;
323-
} else {
324-
req_wrap->SetReturnValue(args);
325329
}
326-
327330
return req_wrap;
328331
}
329332

src/node_file.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,8 +2479,6 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
24792479
uv_req->path = nullptr;
24802480
AfterInteger(uv_req); // after may delete req_wrap_async if there is
24812481
// an error
2482-
} else {
2483-
req_wrap_async->SetReturnValue(args);
24842482
}
24852483
} else { // write(fd, string, pos, enc, undefined, ctx)
24862484
CHECK_EQ(argc, 6);

test/fixtures/permission/fs-write.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
211211
code: 'ERR_ACCESS_DENIED',
212212
permission: 'FileSystemWrite',
213213
}));
214+
assert.rejects(async () => {
215+
await fs.promises.mkdtemp(path.join(blockedFolder, 'any-folder'));
216+
}, {
217+
code: 'ERR_ACCESS_DENIED',
218+
permission: 'FileSystemWrite',
219+
});
214220
}
215221

216222
// fs.mkdtempDisposableSync

0 commit comments

Comments
 (0)