GeezerVison is showing github.com — fs: improve error performance of `realpathSync` · nodejs/node@c5ff000
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/fs.js +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2752,10 +2752,10 @@ function realpathSync(p, options) { | 2752 | 2752 | realpathSync.native = (path, options) => { | 2753 | 2753 | options = getOptions(options); | 2754 | 2754 | 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 | + ); | 2759 | 2759 | }; | 2760 | 2760 |
| 2761 | 2761 | /** | |
Collapse file Copy file name to clipboardExpand all lines: src/node_file.cc +8-10Lines changed: 8 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1828,28 +1828,27 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) { | 1828 | 1828 | Isolate* isolate = env->isolate(); | 1829 | 1829 |
| 1830 | 1830 | const int argc = args.Length(); | 1831 | | - CHECK_GE(argc, 3); | | 1831 | + CHECK_GE(argc, 2); | 1832 | 1832 |
| 1833 | 1833 | BufferValue path(isolate, args[0]); | 1834 | 1834 | CHECK_NOT_NULL(*path); | 1835 | 1835 |
| 1836 | 1836 | const enum encoding encoding = ParseEncoding(isolate, args[1], UTF8); | 1837 | 1837 |
| 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); | 1840 | 1840 | FS_ASYNC_TRACE_BEGIN1( | 1841 | 1841 | UV_FS_REALPATH, req_wrap_async, "path", TRACE_STR_COPY(*path)) | 1842 | 1842 | AsyncCall(env, req_wrap_async, args, "realpath", encoding, AfterStringPtr, | 1843 | 1843 | uv_fs_realpath, *path); | 1844 | 1844 | } else { // realpath(path, encoding, undefined, ctx) | 1845 | | - CHECK_EQ(argc, 4); | 1846 | | - FSReqWrapSync req_wrap_sync; | | 1845 | + FSReqWrapSync req_wrap_sync("realpath", *path); | 1847 | 1846 | 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); | 1850 | 1849 | FS_SYNC_TRACE_END(realpath); | 1851 | 1850 | if (err < 0) { | 1852 | | - return; // syscall failed, no need to continue, error info is in ctx | | 1851 | + return; | 1853 | 1852 | } | 1854 | 1853 |
| 1855 | 1854 | const char* link_path = static_cast<const char*>(req_wrap_sync.req.ptr); | @@ -1860,8 +1859,7 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) { | 1860 | 1859 | encoding, | 1861 | 1860 | &error); | 1862 | 1861 | 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); | 1865 | 1863 | return; | 1866 | 1864 | } | 1867 | 1865 |
| |
Collapse file Copy file name to clipboardExpand all lines: typings/internalBinding/fs.d.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -184,6 +184,7 @@ declare namespace InternalFSBinding { | 184 | 184 | function realpath(path: StringOrBuffer, encoding: unknown, req: FSReqCallback<string | Buffer>): void; | 185 | 185 | function realpath(path: StringOrBuffer, encoding: unknown, req: undefined, ctx: FSSyncContext): string | Buffer; | 186 | 186 | function realpath(path: StringOrBuffer, encoding: unknown, usePromises: typeof kUsePromises): Promise<string | Buffer>; | | 187 | + function realpath(path: StringOrBuffer, encoding: unknown): StringOrBuffer; | 187 | 188 |
| 188 | 189 | function rename(oldPath: string, newPath: string, req: FSReqCallback): void; | 189 | 190 | function rename(oldPath: string, newPath: string, req: undefined, ctx: FSSyncContext): void; | |
|