GeezerVison is showing github.com — fs: improve error performance of `mkdtempSync` · nodejs/node@12cda31
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 +1-5Lines changed: 1 addition & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2964,11 +2964,7 @@ function mkdtempSync(prefix, options) { | 2964 | 2964 | path = Buffer.concat([prefix, Buffer.from('XXXXXX')]); | 2965 | 2965 | } | 2966 | 2966 |
| 2967 | | - const ctx = { path }; | 2968 | | - const result = binding.mkdtemp(path, options.encoding, | 2969 | | - undefined, ctx); | 2970 | | - handleErrorFromBinding(ctx); | 2971 | | - return result; | | 2967 | + return binding.mkdtemp(path, options.encoding); | 2972 | 2968 | } | 2973 | 2969 |
| 2974 | 2970 | /** | |
Collapse file Copy file name to clipboardExpand all lines: src/node_file.cc +11-12Lines changed: 11 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2795,27 +2795,26 @@ static void Mkdtemp(const FunctionCallbackInfo<Value>& args) { | 2795 | 2795 |
| 2796 | 2796 | const enum encoding encoding = ParseEncoding(isolate, args[1], UTF8); | 2797 | 2797 |
| 2798 | | - FSReqBase* req_wrap_async = GetReqWrap(args, 2); | 2799 | | - if (req_wrap_async != nullptr) { // mkdtemp(tmpl, encoding, req) | | 2798 | + if (argc > 2) { // mkdtemp(tmpl, encoding, req) | | 2799 | + FSReqBase* req_wrap_async = GetReqWrap(args, 2); | 2800 | 2800 | FS_ASYNC_TRACE_BEGIN1( | 2801 | 2801 | UV_FS_MKDTEMP, req_wrap_async, "path", TRACE_STR_COPY(*tmpl)) | 2802 | 2802 | AsyncCall(env, req_wrap_async, args, "mkdtemp", encoding, AfterStringPath, | 2803 | 2803 | uv_fs_mkdtemp, *tmpl); | 2804 | | - } else { // mkdtemp(tmpl, encoding, undefined, ctx) | 2805 | | - CHECK_EQ(argc, 4); | 2806 | | - FSReqWrapSync req_wrap_sync; | | 2804 | + } else { // mkdtemp(tmpl, encoding) | | 2805 | + FSReqWrapSync req_wrap_sync("mkdtemp", *tmpl); | 2807 | 2806 | FS_SYNC_TRACE_BEGIN(mkdtemp); | 2808 | | - SyncCall(env, args[3], &req_wrap_sync, "mkdtemp", | 2809 | | - uv_fs_mkdtemp, *tmpl); | | 2807 | + int result = | | 2808 | + SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_mkdtemp, *tmpl); | 2810 | 2809 | FS_SYNC_TRACE_END(mkdtemp); | 2811 | | - const char* path = req_wrap_sync.req.path; | 2812 | | - | | 2810 | + if (is_uv_error(result)) { | | 2811 | + return; | | 2812 | + } | 2813 | 2813 | Local<Value> error; | 2814 | 2814 | MaybeLocal<Value> rc = | 2815 | | - StringBytes::Encode(isolate, path, encoding, &error); | | 2815 | + StringBytes::Encode(isolate, req_wrap_sync.req.path, encoding, &error); | 2816 | 2816 | if (rc.IsEmpty()) { | 2817 | | - Local<Object> ctx = args[3].As<Object>(); | 2818 | | - ctx->Set(env->context(), env->error_string(), error).Check(); | | 2817 | + env->isolate()->ThrowException(error); | 2819 | 2818 | return; | 2820 | 2819 | } | 2821 | 2820 | args.GetReturnValue().Set(rc.ToLocalChecked()); | |
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 |
|---|
@@ -140,6 +140,7 @@ declare namespace InternalFSBinding { | 140 | 140 | function mkdtemp(prefix: string, encoding: unknown, req: FSReqCallback<string>): void; | 141 | 141 | function mkdtemp(prefix: string, encoding: unknown, req: undefined, ctx: FSSyncContext): string; | 142 | 142 | function mkdtemp(prefix: string, encoding: unknown, usePromises: typeof kUsePromises): Promise<string>; | | 143 | + function mkdtemp(prefix: string, encoding: unknown): string; | 143 | 144 |
| 144 | 145 | function mkdir(path: string, mode: number, recursive: boolean, req: FSReqCallback<void | string>): void; | 145 | 146 | function mkdir(path: string, mode: number, recursive: true, req: FSReqCallback<string>): void; | |
|