Skip to content

Commit 4c7229c

Browse files
authored
Merge branch 'main' into fix-49848
2 parents 7f12e59 + cc725a6 commit 4c7229c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+731
-339
lines changed
File renamed without changes.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
6+
const bench = common.createBenchmark(main, {
7+
n: [1e6],
8+
code: [
9+
'built-in',
10+
'ERR_HTTP2_STREAM_SELF_DEPENDENCY',
11+
'ERR_INVALID_STATE',
12+
'ERR_INVALID_URL',
13+
],
14+
stackTraceLimit: [0, 10],
15+
}, {
16+
flags: ['--expose-internals'],
17+
});
18+
19+
function getErrorFactory(code) {
20+
const {
21+
ERR_HTTP2_STREAM_SELF_DEPENDENCY,
22+
ERR_INVALID_STATE,
23+
ERR_INVALID_URL,
24+
} = require('internal/errors').codes;
25+
26+
switch (code) {
27+
case 'built-in':
28+
return (n) => new Error();
29+
case 'ERR_HTTP2_STREAM_SELF_DEPENDENCY':
30+
return (n) => new ERR_HTTP2_STREAM_SELF_DEPENDENCY();
31+
case 'ERR_INVALID_STATE':
32+
return (n) => new ERR_INVALID_STATE(n + '');
33+
case 'ERR_INVALID_URL':
34+
return (n) => new ERR_INVALID_URL({ input: n + '' });
35+
default:
36+
throw new Error(`${code} not supported`);
37+
}
38+
}
39+
40+
function main({ n, code, stackTraceLimit }) {
41+
const getError = getErrorFactory(code);
42+
43+
Error.stackTraceLimit = stackTraceLimit;
44+
45+
// Warm up.
46+
const length = 1024;
47+
const array = [];
48+
for (let i = 0; i < length; ++i) {
49+
array.push(getError(i));
50+
}
51+
52+
bench.start();
53+
54+
for (let i = 0; i < n; ++i) {
55+
const index = i % length;
56+
array[index] = getError(index);
57+
}
58+
59+
bench.end(n);
60+
61+
// Verify the entries to prevent dead code elimination from making
62+
// the benchmark invalid.
63+
for (let i = 0; i < length; ++i) {
64+
assert.strictEqual(typeof array[i], 'object');
65+
}
66+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
6+
const bench = common.createBenchmark(main, {
7+
n: [1e6],
8+
code: [
9+
'built-in',
10+
'ERR_HTTP2_STREAM_SELF_DEPENDENCY',
11+
'ERR_INVALID_STATE',
12+
],
13+
stackTraceLimit: [0, 10],
14+
}, {
15+
flags: ['--expose-internals'],
16+
});
17+
18+
function getErrorStackFactory(code) {
19+
const {
20+
ERR_INVALID_STATE,
21+
ERR_HTTP2_STREAM_SELF_DEPENDENCY,
22+
} = require('internal/errors').codes;
23+
24+
switch (code) {
25+
case 'built-in':
26+
return (n) => new Error().stack;
27+
case 'ERR_HTTP2_STREAM_SELF_DEPENDENCY':
28+
return (n) => new ERR_HTTP2_STREAM_SELF_DEPENDENCY().stack;
29+
case 'ERR_INVALID_STATE':
30+
return (n) => new ERR_INVALID_STATE(n + '').stack;
31+
default:
32+
throw new Error(`${code} not supported`);
33+
}
34+
}
35+
36+
function main({ n, code, stackTraceLimit }) {
37+
const getStack = getErrorStackFactory(code);
38+
39+
Error.stackTraceLimit = stackTraceLimit;
40+
41+
// Warm up.
42+
const length = 1024;
43+
const array = [];
44+
for (let i = 0; i < length; ++i) {
45+
array.push(getStack(i));
46+
}
47+
48+
bench.start();
49+
50+
for (let i = 0; i < n; ++i) {
51+
const index = i % length;
52+
array[index] = getStack(index);
53+
}
54+
55+
bench.end(n);
56+
57+
// Verify the entries to prevent dead code elimination from making
58+
// the benchmark invalid.
59+
for (let i = 0; i < length; ++i) {
60+
assert.strictEqual(typeof array[i], 'string');
61+
}
62+
}

benchmark/error/node-error.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

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+
}

benchmark/perf_hooks/timerfied.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const common = require('../common.js');
5+
6+
const {
7+
PerformanceObserver,
8+
performance,
9+
} = require('perf_hooks');
10+
11+
function randomFn() {
12+
return Math.random();
13+
}
14+
15+
const bench = common.createBenchmark(main, {
16+
n: [1e5],
17+
observe: ['function'],
18+
});
19+
20+
let _result;
21+
22+
function main({ n, observe }) {
23+
const obs = new PerformanceObserver(() => {
24+
bench.end(n);
25+
});
26+
obs.observe({ entryTypes: [observe], buffered: true });
27+
28+
const timerfied = performance.timerify(randomFn);
29+
30+
bench.start();
31+
for (let i = 0; i < n; i++)
32+
_result = timerfied();
33+
34+
// Avoid V8 deadcode (elimination)
35+
assert.ok(_result);
36+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const url = require('url');
4+
const URL = url.URL;
5+
6+
const bench = common.createBenchmark(main, {
7+
type: ['valid', 'invalid'],
8+
e: [1e5],
9+
});
10+
11+
// This benchmark is used to compare the `Invalid URL` path of the URL parser
12+
function main({ type, e }) {
13+
const url = type === 'valid' ? 'https://www.nodejs.org' : 'www.nodejs.org';
14+
bench.start();
15+
for (let i = 0; i < e; i++) {
16+
try {
17+
new URL(url);
18+
} catch {
19+
// do nothing
20+
}
21+
}
22+
bench.end(e);
23+
}

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
/**

0 commit comments

Comments
 (0)