Skip to content

Commit b7f91b9

Browse files
authored
Merge branch 'main' into PR/PureFinalizers
2 parents 9053793 + 3838b57 commit b7f91b9

File tree

7 files changed

+86
-10
lines changed

7 files changed

+86
-10
lines changed

benchmark/fs/bench-unlinkSync.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const fs = require('fs');
5+
const tmpdir = require('../../test/common/tmpdir');
6+
tmpdir.refresh();
7+
8+
const bench = common.createBenchmark(main, {
9+
type: ['existing', 'non-existing'],
10+
n: [1e3],
11+
});
12+
13+
function main({ n, type }) {
14+
let files;
15+
16+
switch (type) {
17+
case 'existing':
18+
files = [];
19+
20+
// Populate tmpdir with mock files
21+
for (let i = 0; i < n; i++) {
22+
const path = tmpdir.resolve(`unlinksync-bench-file-${i}`);
23+
fs.writeFileSync(path, 'bench');
24+
files.push(path);
25+
}
26+
break;
27+
case 'non-existing':
28+
files = new Array(n).fill(tmpdir.resolve(`.non-existing-file-${Date.now()}`));
29+
break;
30+
default:
31+
new Error('Invalid type');
32+
}
33+
34+
bench.start();
35+
for (let i = 0; i < n; i++) {
36+
try {
37+
fs.unlinkSync(files[i]);
38+
} catch {
39+
// do nothing
40+
}
41+
}
42+
bench.end(n);
43+
}

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Reset this number to 0 on major V8 upgrades.
3838
# Increment by one for each non-official patch applied to deps/v8.
39-
'v8_embedder_string': '-node.18',
39+
'v8_embedder_string': '-node.19',
4040

4141
##### V8 defaults for Node.js #####
4242

deps/v8/src/snapshot/embedded/platform-embedded-file-writer-base.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ EmbeddedTargetOs ToEmbeddedTargetOs(const char* s) {
130130
}
131131

132132
std::string string(s);
133-
if (string == "aix") {
133+
// Python 3.9+ on IBM i returns os400 as sys.platform instead of aix
134+
if (string == "aix" || string == "os400") {
134135
return EmbeddedTargetOs::kAIX;
135136
} else if (string == "chromeos") {
136137
return EmbeddedTargetOs::kChromeOS;

lib/fs.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,10 +1850,7 @@ function unlink(path, callback) {
18501850
* @returns {void}
18511851
*/
18521852
function unlinkSync(path) {
1853-
path = getValidatedPath(path);
1854-
const ctx = { path };
1855-
binding.unlink(pathModule.toNamespacedPath(path), undefined, ctx);
1856-
handleErrorFromBinding(ctx);
1853+
return syncFs.unlink(path);
18571854
}
18581855

18591856
/**

lib/internal/fs/sync.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ function close(fd) {
8888
return binding.closeSync(fd);
8989
}
9090

91+
function unlink(path) {
92+
path = pathModule.toNamespacedPath(getValidatedPath(path));
93+
return binding.unlinkSync(path);
94+
}
95+
9196
module.exports = {
9297
readFileUtf8,
9398
exists,
@@ -97,4 +102,5 @@ module.exports = {
97102
statfs,
98103
open,
99104
close,
105+
unlink,
100106
};

src/node_file.cc

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,27 @@ static void Unlink(const FunctionCallbackInfo<Value>& args) {
16671667
}
16681668
}
16691669

1670+
static void UnlinkSync(const FunctionCallbackInfo<Value>& args) {
1671+
Environment* env = Environment::GetCurrent(args);
1672+
1673+
const int argc = args.Length();
1674+
CHECK_GE(argc, 1);
1675+
1676+
BufferValue path(env->isolate(), args[0]);
1677+
CHECK_NOT_NULL(*path);
1678+
THROW_IF_INSUFFICIENT_PERMISSIONS(
1679+
env, permission::PermissionScope::kFileSystemWrite, path.ToStringView());
1680+
1681+
uv_fs_t req;
1682+
auto make = OnScopeLeave([&req]() { uv_fs_req_cleanup(&req); });
1683+
FS_SYNC_TRACE_BEGIN(unlink);
1684+
int err = uv_fs_unlink(nullptr, &req, *path, nullptr);
1685+
FS_SYNC_TRACE_END(unlink);
1686+
if (err < 0) {
1687+
return env->ThrowUVException(err, "unlink", nullptr, *path);
1688+
}
1689+
}
1690+
16701691
static void RMDir(const FunctionCallbackInfo<Value>& args) {
16711692
Environment* env = Environment::GetCurrent(args);
16721693

@@ -3361,15 +3382,15 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
33613382
Isolate* isolate = isolate_data->isolate();
33623383

33633384
SetMethod(isolate, target, "access", Access);
3364-
SetMethodNoSideEffect(isolate, target, "accessSync", AccessSync);
3385+
SetMethod(isolate, target, "accessSync", AccessSync);
33653386
SetMethod(isolate, target, "close", Close);
33663387
SetMethod(isolate, target, "closeSync", CloseSync);
3367-
SetMethodNoSideEffect(isolate, target, "existsSync", ExistsSync);
3388+
SetMethod(isolate, target, "existsSync", ExistsSync);
33683389
SetMethod(isolate, target, "open", Open);
33693390
SetMethod(isolate, target, "openSync", OpenSync);
33703391
SetMethod(isolate, target, "openFileHandle", OpenFileHandle);
33713392
SetMethod(isolate, target, "read", Read);
3372-
SetMethodNoSideEffect(isolate, target, "readFileUtf8", ReadFileUtf8);
3393+
SetMethod(isolate, target, "readFileUtf8", ReadFileUtf8);
33733394
SetMethod(isolate, target, "readBuffers", ReadBuffers);
33743395
SetMethod(isolate, target, "fdatasync", Fdatasync);
33753396
SetMethod(isolate, target, "fsync", Fsync);
@@ -3390,12 +3411,13 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
33903411
SetMethod(isolate, target, "symlink", Symlink);
33913412
SetMethod(isolate, target, "readlink", ReadLink);
33923413
SetMethod(isolate, target, "unlink", Unlink);
3414+
SetMethod(isolate, target, "unlinkSync", UnlinkSync);
33933415
SetMethod(isolate, target, "writeBuffer", WriteBuffer);
33943416
SetMethod(isolate, target, "writeBuffers", WriteBuffers);
33953417
SetMethod(isolate, target, "writeString", WriteString);
33963418
SetMethod(isolate, target, "realpath", RealPath);
33973419
SetMethod(isolate, target, "copyFile", CopyFile);
3398-
SetMethodNoSideEffect(isolate, target, "copyFileSync", CopyFileSync);
3420+
SetMethod(isolate, target, "copyFileSync", CopyFileSync);
33993421

34003422
SetMethod(isolate, target, "chmod", Chmod);
34013423
SetMethod(isolate, target, "fchmod", FChmod);
@@ -3515,6 +3537,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
35153537
registry->Register(Symlink);
35163538
registry->Register(ReadLink);
35173539
registry->Register(Unlink);
3540+
registry->Register(UnlinkSync);
35183541
registry->Register(WriteBuffer);
35193542
registry->Register(WriteBuffers);
35203543
registry->Register(WriteString);

test/parallel/test-os.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ const hostname = os.hostname();
8181
is.string(hostname);
8282
assert.ok(hostname.length > 0);
8383

84+
const DUMMY_PRIORITY = 10;
85+
os.setPriority(DUMMY_PRIORITY);
86+
const priority = os.getPriority();
87+
is.number(priority);
88+
assert.strictEqual(priority, DUMMY_PRIORITY);
89+
8490
// On IBMi, os.uptime() returns 'undefined'
8591
if (!common.isIBMi) {
8692
const uptime = os.uptime();

0 commit comments

Comments
 (0)