GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: improve error performance of `realpathSync` · nodejs/node@c5ff000

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • fs.js
  • src
    • node_file.cc
  • typings/internalBinding
    • fs.d.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/fs.js‎

Copy file name to clipboardExpand all lines: lib/fs.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,10 +2752,10 @@ function realpathSync(p, options) {
27522752
realpathSync.native = (path, options) => {
27532753
options = getOptions(options);
27542754
path = getValidatedPath(path);
2755-
const ctx = { path };
2756-
const result = binding.realpath(pathModule.toNamespacedPath(path), options.encoding, undefined, ctx);
2757-
handleErrorFromBinding(ctx);
2758-
return result;
2755+
return binding.realpath(
2756+
pathModule.toNamespacedPath(path),
2757+
options.encoding,
2758+
);
27592759
};
27602760

27612761
/**
Collapse file

‎src/node_file.cc‎

Copy file name to clipboardExpand all lines: src/node_file.cc
+8-10Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,28 +1828,27 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) {
18281828
Isolate* isolate = env->isolate();
18291829

18301830
const int argc = args.Length();
1831-
CHECK_GE(argc, 3);
1831+
CHECK_GE(argc, 2);
18321832

18331833
BufferValue path(isolate, args[0]);
18341834
CHECK_NOT_NULL(*path);
18351835

18361836
const enum encoding encoding = ParseEncoding(isolate, args[1], UTF8);
18371837

1838-
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
1839-
if (req_wrap_async != nullptr) { // realpath(path, encoding, req)
1838+
if (argc > 2) { // realpath(path, encoding, req)
1839+
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
18401840
FS_ASYNC_TRACE_BEGIN1(
18411841
UV_FS_REALPATH, req_wrap_async, "path", TRACE_STR_COPY(*path))
18421842
AsyncCall(env, req_wrap_async, args, "realpath", encoding, AfterStringPtr,
18431843
uv_fs_realpath, *path);
18441844
} else { // realpath(path, encoding, undefined, ctx)
1845-
CHECK_EQ(argc, 4);
1846-
FSReqWrapSync req_wrap_sync;
1845+
FSReqWrapSync req_wrap_sync("realpath", *path);
18471846
FS_SYNC_TRACE_BEGIN(realpath);
1848-
int err = SyncCall(env, args[3], &req_wrap_sync, "realpath",
1849-
uv_fs_realpath, *path);
1847+
int err =
1848+
SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_realpath, *path);
18501849
FS_SYNC_TRACE_END(realpath);
18511850
if (err < 0) {
1852-
return; // syscall failed, no need to continue, error info is in ctx
1851+
return;
18531852
}
18541853

18551854
const char* link_path = static_cast<const char*>(req_wrap_sync.req.ptr);
@@ -1860,8 +1859,7 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) {
18601859
encoding,
18611860
&error);
18621861
if (rc.IsEmpty()) {
1863-
Local<Object> ctx = args[3].As<Object>();
1864-
ctx->Set(env->context(), env->error_string(), error).Check();
1862+
env->isolate()->ThrowException(error);
18651863
return;
18661864
}
18671865

Collapse file

‎typings/internalBinding/fs.d.ts‎

Copy file name to clipboardExpand all lines: typings/internalBinding/fs.d.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ declare namespace InternalFSBinding {
184184
function realpath(path: StringOrBuffer, encoding: unknown, req: FSReqCallback<string | Buffer>): void;
185185
function realpath(path: StringOrBuffer, encoding: unknown, req: undefined, ctx: FSSyncContext): string | Buffer;
186186
function realpath(path: StringOrBuffer, encoding: unknown, usePromises: typeof kUsePromises): Promise<string | Buffer>;
187+
function realpath(path: StringOrBuffer, encoding: unknown): StringOrBuffer;
187188

188189
function rename(oldPath: string, newPath: string, req: FSReqCallback): void;
189190
function rename(oldPath: string, newPath: string, req: undefined, ctx: FSSyncContext): void;

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.