Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 4 lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ function handleDirents({ result, currentPath, context }) {
const dirent = getDirent(currentPath, names[i], types[i]);
ArrayPrototypePush(context.readdirResults, dirent);

if (dirent.isDirectory() || binding.internalModuleStat(binding, fullPath) === 1) {
if (dirent.isDirectory() || binding.internalModuleStat(fullPath) === 1) {
ArrayPrototypePush(context.pathsQueue, fullPath);
}
}
Expand All @@ -1434,7 +1434,7 @@ function handleFilePaths({ result, currentPath, context }) {
for (let i = 0; i < result.length; i++) {
const resultPath = pathModule.join(currentPath, result[i]);
const relativeResultPath = pathModule.relative(context.basePath, resultPath);
const stat = binding.internalModuleStat(binding, resultPath);
const stat = binding.internalModuleStat(resultPath);
ArrayPrototypePush(context.readdirResults, relativeResultPath);

if (stat === 1) {
Expand Down
2 changes: 1 addition & 1 deletion 2 lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ async function readdirRecursive(originalPath, options) {
const { 0: path, 1: readdir } = ArrayPrototypePop(queue);
for (const ent of readdir) {
const direntPath = pathModule.join(path, ent);
const stat = binding.internalModuleStat(binding, direntPath);
const stat = binding.internalModuleStat(direntPath);
ArrayPrototypePush(
result,
pathModule.relative(originalPath, direntPath),
Expand Down
4 changes: 2 additions & 2 deletions 4 lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ function stat(filename) {
const result = statCache.get(filename);
if (result !== undefined) { return result; }
}
const result = internalFsBinding.internalModuleStat(internalFsBinding, filename);
const result = internalFsBinding.internalModuleStat(filename);
if (statCache !== null && result >= 0) {
// Only set cache when `internalModuleStat(internalFsBinding, filename)` succeeds.
// Only set cache when `internalModuleStat(filename)` succeeds.
statCache.set(filename, result);
}
return result;
Expand Down
1 change: 0 additions & 1 deletion 1 lib/internal/modules/esm/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
}

const stats = internalFsBinding.internalModuleStat(
internalFsBinding,
StringPrototypeEndsWith(internalFsBinding, path, '/') ? StringPrototypeSlice(path, -1) : path,
);

Expand Down
1 change: 0 additions & 1 deletion 1 lib/internal/modules/package_json_reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ function getPackageJSONURL(specifier, base) {
let lastPath;
do {
const stat = internalFsBinding.internalModuleStat(
internalFsBinding,
StringPrototypeSlice(packageJSONPath, 0, packageJSONPath.length - 13),
);
// Check for !stat.isDirectory()
Expand Down
5 changes: 2 additions & 3 deletions 5 src/node_external_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ using CFunctionCallback = void (*)(v8::Local<v8::Value> unused,
using CFunctionCallbackReturnDouble =
double (*)(v8::Local<v8::Object> unused, v8::Local<v8::Object> receiver);
using CFunctionCallbackReturnInt32 =
int32_t (*)(v8::Local<v8::Object> unused,
v8::Local<v8::Object> receiver,
const v8::FastOneByteString& input,
int32_t (*)(v8::Local<v8::Value> receiver,
v8::Local<v8::Value> input,
// NOLINTNEXTLINE(runtime/references) This is V8 api.
v8::FastApiCallbackOptions& options);
using CFunctionCallbackValueReturnDouble =
Expand Down
23 changes: 12 additions & 11 deletions 23 src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "aliased_buffer-inl.h"
#include "memory_tracker-inl.h"
#include "node_buffer.h"
#include "node_debug.h"
#include "node_errors.h"
#include "node_external_reference.h"
#include "node_file-inl.h"
Expand Down Expand Up @@ -63,8 +64,6 @@ using v8::BigInt;
using v8::Context;
using v8::EscapableHandleScope;
using v8::FastApiCallbackOptions;
using v8::FastOneByteString;
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::HandleScope;
Expand Down Expand Up @@ -1056,9 +1055,9 @@ static void ExistsSync(const FunctionCallbackInfo<Value>& args) {
static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

CHECK_GE(args.Length(), 2);
CHECK(args[1]->IsString());
BufferValue path(env->isolate(), args[1]);
CHECK_EQ(args.Length(), 1);
CHECK(args[0]->IsString());
BufferValue path(env->isolate(), args[0]);
CHECK_NOT_NULL(*path);
ToNamespacedPath(env, &path);

Expand All @@ -1074,15 +1073,17 @@ static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) {
}

static int32_t FastInternalModuleStat(
Local<Object> unused,
Local<Object> recv,
const FastOneByteString& input,
Local<Value> recv,
Local<Value> input_,
// NOLINTNEXTLINE(runtime/references) This is V8 api.
FastApiCallbackOptions& options) {
Environment* env = Environment::GetCurrent(options.isolate);
HandleScope scope(env->isolate());
TRACK_V8_FAST_API_CALL("fs.internalModuleStat");
HandleScope scope(options.isolate);

CHECK(input_->IsString());
Utf8Value input(options.isolate, input_.As<String>());

auto path = std::filesystem::path(input.data, input.data + input.length);
auto path = std::filesystem::path(input.ToStringView());

switch (std::filesystem::status(path).type()) {
case std::filesystem::file_type::directory:
Expand Down
24 changes: 18 additions & 6 deletions 24 test/parallel/test-permission-fs-internal-module-stat.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Flags: --expose-internals --permission --allow-fs-read=test/common* --allow-fs-read=tools* --allow-fs-read=test/parallel* --allow-child-process
// Flags: --expose-internals --permission --allow-fs-read=test/common* --allow-fs-read=tools* --allow-fs-read=test/parallel* --allow-child-process --allow-natives-syntax
'use strict';

const common = require('../common');
const { isMainThread } = require('worker_threads');
const { strictEqual } = require('assert');

if (!isMainThread) {
common.skip('This test only works on a main thread');
Expand All @@ -18,9 +19,20 @@ const fixtures = require('../common/fixtures');
const blockedFile = fixtures.path('permission', 'deny', 'protected-file.md');
const internalFsBinding = internalBinding('fs');

// Run this inside a for loop to trigger the fast API
RafaelGSS marked this conversation as resolved.
Show resolved Hide resolved
for (let i = 0; i < 10_000; i++) {
// internalModuleStat does not use permission model.
// doesNotThrow
internalFsBinding.internalModuleStat(internalFsBinding, blockedFile);
strictEqual(internalFsBinding.internalModuleStat(blockedFile), 0);

// Only javascript methods can be optimized through %OptimizeFunctionOnNextCall
// This is why we surround the C++ method we want to optimize with a JS function.
function testFastPaths(file) {
return internalFsBinding.internalModuleStat(file);
}

eval('%PrepareFunctionForOptimization(testFastPaths)');
testFastPaths(blockedFile);
eval('%OptimizeFunctionOnNextCall(testFastPaths)');
strictEqual(testFastPaths(blockedFile), 0);

if (common.isDebug) {
const { getV8FastApiCallCount } = internalBinding('debug');
strictEqual(getV8FastApiCallCount('fs.internalModuleStat'), 1);
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.