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 `mkdtempSync` · nodejs/node@12cda31

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
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,11 +2964,7 @@ function mkdtempSync(prefix, options) {
29642964
path = Buffer.concat([prefix, Buffer.from('XXXXXX')]);
29652965
}
29662966

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);
29722968
}
29732969

29742970
/**
Collapse file

‎src/node_file.cc‎

Copy file name to clipboardExpand all lines: src/node_file.cc
+11-12Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,27 +2795,26 @@ static void Mkdtemp(const FunctionCallbackInfo<Value>& args) {
27952795

27962796
const enum encoding encoding = ParseEncoding(isolate, args[1], UTF8);
27972797

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);
28002800
FS_ASYNC_TRACE_BEGIN1(
28012801
UV_FS_MKDTEMP, req_wrap_async, "path", TRACE_STR_COPY(*tmpl))
28022802
AsyncCall(env, req_wrap_async, args, "mkdtemp", encoding, AfterStringPath,
28032803
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);
28072806
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);
28102809
FS_SYNC_TRACE_END(mkdtemp);
2811-
const char* path = req_wrap_sync.req.path;
2812-
2810+
if (is_uv_error(result)) {
2811+
return;
2812+
}
28132813
Local<Value> error;
28142814
MaybeLocal<Value> rc =
2815-
StringBytes::Encode(isolate, path, encoding, &error);
2815+
StringBytes::Encode(isolate, req_wrap_sync.req.path, encoding, &error);
28162816
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);
28192818
return;
28202819
}
28212820
args.GetReturnValue().Set(rc.ToLocalChecked());
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
@@ -140,6 +140,7 @@ declare namespace InternalFSBinding {
140140
function mkdtemp(prefix: string, encoding: unknown, req: FSReqCallback<string>): void;
141141
function mkdtemp(prefix: string, encoding: unknown, req: undefined, ctx: FSSyncContext): string;
142142
function mkdtemp(prefix: string, encoding: unknown, usePromises: typeof kUsePromises): Promise<string>;
143+
function mkdtemp(prefix: string, encoding: unknown): string;
143144

144145
function mkdir(path: string, mode: number, recursive: boolean, req: FSReqCallback<void | string>): void;
145146
function mkdir(path: string, mode: number, recursive: true, req: FSReqCallback<string>): 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.