Skip to content

Commit a381b4d

Browse files
joyeecheungaduh95
authored andcommitted
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. PR-URL: #58489 Backport-PR-URL: #59065 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 390654e commit a381b4d

File tree

2 files changed

+1
-57
lines changed

2 files changed

+1
-57
lines changed

src/node_file.cc

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ using v8::Array;
6060
using v8::BigInt;
6161
using v8::Context;
6262
using v8::EscapableHandleScope;
63-
using v8::FastApiCallbackOptions;
6463
using v8::FunctionCallbackInfo;
6564
using v8::FunctionTemplate;
6665
using v8::HandleScope;
@@ -1067,39 +1066,6 @@ static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) {
10671066
args.GetReturnValue().Set(rc);
10681067
}
10691068

1070-
static int32_t FastInternalModuleStat(
1071-
Local<Value> recv,
1072-
Local<Value> input_,
1073-
// NOLINTNEXTLINE(runtime/references) This is V8 api.
1074-
FastApiCallbackOptions& options) {
1075-
// This needs a HandleScope which needs an isolate.
1076-
Isolate* isolate = Isolate::TryGetCurrent();
1077-
if (!isolate) {
1078-
options.fallback = true;
1079-
return -1;
1080-
}
1081-
1082-
TRACK_V8_FAST_API_CALL("fs.internalModuleStat");
1083-
HandleScope scope(isolate);
1084-
1085-
CHECK(input_->IsString());
1086-
Utf8Value input(isolate, input_.As<String>());
1087-
1088-
auto path = std::filesystem::path(input.ToStringView());
1089-
1090-
switch (std::filesystem::status(path).type()) {
1091-
case std::filesystem::file_type::directory:
1092-
return 1;
1093-
case std::filesystem::file_type::regular:
1094-
return 0;
1095-
default:
1096-
return -1;
1097-
}
1098-
}
1099-
1100-
v8::CFunction fast_internal_module_stat_(
1101-
v8::CFunction::Make(FastInternalModuleStat));
1102-
11031069
constexpr bool is_uv_error_except_no_entry(int result) {
11041070
return result < 0 && result != UV_ENOENT;
11051071
}
@@ -3819,11 +3785,7 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
38193785
SetMethod(isolate, target, "rmdir", RMDir);
38203786
SetMethod(isolate, target, "mkdir", MKDir);
38213787
SetMethod(isolate, target, "readdir", ReadDir);
3822-
SetFastMethod(isolate,
3823-
target,
3824-
"internalModuleStat",
3825-
InternalModuleStat,
3826-
&fast_internal_module_stat_);
3788+
SetMethod(isolate, target, "internalModuleStat", InternalModuleStat);
38273789
SetMethod(isolate, target, "stat", Stat);
38283790
SetMethod(isolate, target, "lstat", LStat);
38293791
SetMethod(isolate, target, "fstat", FStat);
@@ -3948,8 +3910,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
39483910
registry->Register(MKDir);
39493911
registry->Register(ReadDir);
39503912
registry->Register(InternalModuleStat);
3951-
registry->Register(FastInternalModuleStat);
3952-
registry->Register(fast_internal_module_stat_.GetTypeInfo());
39533913
registry->Register(Stat);
39543914
registry->Register(LStat);
39553915
registry->Register(FStat);

test/parallel/test-permission-fs-internal-module-stat.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,3 @@ const blockedFile = fixtures.path('permission', 'deny', 'protected-file.md');
2020
const internalFsBinding = internalBinding('fs');
2121

2222
strictEqual(internalFsBinding.internalModuleStat(blockedFile), 0);
23-
24-
// Only javascript methods can be optimized through %OptimizeFunctionOnNextCall
25-
// This is why we surround the C++ method we want to optimize with a JS function.
26-
function testFastPaths(file) {
27-
return internalFsBinding.internalModuleStat(file);
28-
}
29-
30-
eval('%PrepareFunctionForOptimization(testFastPaths)');
31-
testFastPaths(blockedFile);
32-
eval('%OptimizeFunctionOnNextCall(testFastPaths)');
33-
strictEqual(testFastPaths(blockedFile), 0);
34-
35-
if (common.isDebug) {
36-
const { getV8FastApiCallCount } = internalBinding('debug');
37-
strictEqual(getV8FastApiCallCount('fs.internalModuleStat'), 1);
38-
}

0 commit comments

Comments
 (0)