Skip to content

Commit 828640a

Browse files
committed
src: remove fast API for InternalModuleStat
There are several motivation for removing this: 1. The implementation does not align with InternalModuleStat, most noticably it does not namespace the path or convert it to UTF-16 before using it with std::filesystem::path on Windows which could crash on non-English locale. 2. It needs the Environment - if not for decoding the string, at least for env->exec_path() to resolve the path for namespacing - and therefore needs a handle to the Context which requires a handle scope which actually makes the fast API version slower than the normal binding. For simplicity this just removes the fast API to fix the bug and improve the performance.
1 parent 5a23443 commit 828640a

File tree

1 file changed

+1
-33
lines changed

1 file changed

+1
-33
lines changed

src/node_file.cc

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,32 +1073,6 @@ static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) {
10731073
args.GetReturnValue().Set(rc);
10741074
}
10751075

1076-
static int32_t FastInternalModuleStat(
1077-
Local<Value> recv,
1078-
Local<Value> input_,
1079-
// NOLINTNEXTLINE(runtime/references) This is V8 api.
1080-
FastApiCallbackOptions& options) {
1081-
TRACK_V8_FAST_API_CALL("fs.internalModuleStat");
1082-
HandleScope scope(options.isolate);
1083-
1084-
CHECK(input_->IsString());
1085-
Utf8Value input(options.isolate, input_.As<String>());
1086-
1087-
auto path = std::filesystem::path(input.ToStringView());
1088-
1089-
switch (std::filesystem::status(path).type()) {
1090-
case std::filesystem::file_type::directory:
1091-
return 1;
1092-
case std::filesystem::file_type::regular:
1093-
return 0;
1094-
default:
1095-
return -1;
1096-
}
1097-
}
1098-
1099-
v8::CFunction fast_internal_module_stat_(
1100-
v8::CFunction::Make(FastInternalModuleStat));
1101-
11021076
constexpr bool is_uv_error_except_no_entry(int result) {
11031077
return result < 0 && result != UV_ENOENT;
11041078
}
@@ -3722,11 +3696,7 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
37223696
SetMethod(isolate, target, "rmSync", RmSync);
37233697
SetMethod(isolate, target, "mkdir", MKDir);
37243698
SetMethod(isolate, target, "readdir", ReadDir);
3725-
SetFastMethod(isolate,
3726-
target,
3727-
"internalModuleStat",
3728-
InternalModuleStat,
3729-
&fast_internal_module_stat_);
3699+
SetMethod(isolate, target, "internalModuleStat", InternalModuleStat);
37303700
SetMethod(isolate, target, "stat", Stat);
37313701
SetMethod(isolate, target, "lstat", LStat);
37323702
SetMethod(isolate, target, "fstat", FStat);
@@ -3851,8 +3821,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
38513821
registry->Register(MKDir);
38523822
registry->Register(ReadDir);
38533823
registry->Register(InternalModuleStat);
3854-
registry->Register(FastInternalModuleStat);
3855-
registry->Register(fast_internal_module_stat_.GetTypeInfo());
38563824
registry->Register(Stat);
38573825
registry->Register(LStat);
38583826
registry->Register(FStat);

0 commit comments

Comments
 (0)