Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dafd561

Browse filesBrowse files
theanarkhrichardlau
authored andcommitted
fs: fix return value of fs APIs
PR-URL: #58996 Fixes: #58747 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
1 parent b4a43ed commit dafd561
Copy full SHA for dafd561

File tree

Expand file treeCollapse file tree

3 files changed

+24
-17
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+24
-17
lines changed
Open diff view settings
Collapse file

‎src/node_file-inl.h‎

Copy file name to clipboardExpand all lines: src/node_file-inl.h
+18-15Lines 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 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 = 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

Collapse file

‎src/node_file.cc‎

Copy file name to clipboardExpand all lines: src/node_file.cc
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,8 +2381,6 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
23812381
uv_req->path = nullptr;
23822382
AfterInteger(uv_req); // after may delete req_wrap_async if there is
23832383
// an error
2384-
} else {
2385-
req_wrap_async->SetReturnValue(args);
23862384
}
23872385
} else { // write(fd, string, pos, enc, undefined, ctx)
23882386
CHECK_EQ(argc, 6);
Collapse file

‎test/fixtures/permission/fs-write.js‎

Copy file name to clipboardExpand all lines: test/fixtures/permission/fs-write.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ const relativeProtectedFolder = process.env.RELATIVEBLOCKEDFOLDER;
210210
code: 'ERR_ACCESS_DENIED',
211211
permission: 'FileSystemWrite',
212212
}));
213+
assert.rejects(async () => {
214+
await fs.promises.mkdtemp(path.join(blockedFolder, 'any-folder'));
215+
}, {
216+
code: 'ERR_ACCESS_DENIED',
217+
permission: 'FileSystemWrite',
218+
});
213219
}
214220

215221
// fs.rename

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.