Skip to content

Commit 57b5224

Browse files
authored
Merge branch 'nodejs:main' into main
2 parents f42fbb5 + 9c025a9 commit 57b5224

29 files changed

+827
-191
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const assert = require('assert');
5+
const fixtures = require('../../test/common/fixtures');
6+
7+
const bench = common.createBenchmark(
8+
main,
9+
{
10+
operation: [
11+
'findSourceMap-valid',
12+
'findSourceMap-generated-source',
13+
],
14+
n: [1e5],
15+
},
16+
);
17+
18+
function main({ operation, n }) {
19+
const Module = require('node:module');
20+
21+
Module.setSourceMapsSupport(true, {
22+
generatedCode: true,
23+
});
24+
const validFileName = fixtures.path('test-runner/source-maps/line-lengths/index.js');
25+
26+
const fileNameKey = '/source-map/disk.js';
27+
const generatedFileName = fixtures.path(fileNameKey);
28+
const generatedFileContent = fixtures.readSync(fileNameKey, 'utf8');
29+
const sourceMapUrl = generatedFileName.replace(/\.js$/, '.map');
30+
const sourceWithGeneratedSourceMap =
31+
`${generatedFileContent}\n//# sourceMappingURL=${sourceMapUrl}\n//# sourceURL=${generatedFileName}`;
32+
const generatedExpectedUrl = `file://${generatedFileName}`;
33+
34+
let sourceMap;
35+
switch (operation) {
36+
case 'findSourceMap-valid':
37+
require(validFileName);
38+
39+
bench.start();
40+
for (let i = 0; i < n; i++) {
41+
sourceMap = Module.findSourceMap(validFileName);
42+
}
43+
bench.end(n);
44+
break;
45+
46+
case 'findSourceMap-generated-source':
47+
eval(sourceWithGeneratedSourceMap);
48+
49+
bench.start();
50+
for (let i = 0; i < n; i++) {
51+
sourceMap = Module.findSourceMap(generatedExpectedUrl);
52+
}
53+
bench.end(n);
54+
break;
55+
56+
default:
57+
throw new Error(`Unknown operation: ${operation}`);
58+
}
59+
assert.ok(sourceMap);
60+
}

benchmark/source_map/source-map.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const assert = require('assert');
5+
const fixtures = require('../../test/common/fixtures');
6+
7+
const bench = common.createBenchmark(
8+
main,
9+
{
10+
operation: [
11+
'parse',
12+
'parse-sectioned',
13+
'findEntry',
14+
'findEntry-sectioned',
15+
'findOrigin',
16+
'findOrigin-sectioned',
17+
],
18+
n: [1e5],
19+
},
20+
);
21+
22+
function main({ operation, n }) {
23+
const { SourceMap } = require('node:module');
24+
25+
const samplePayload = JSON.parse(
26+
fixtures.readSync('source-map/no-source.js.map', 'utf8'),
27+
);
28+
const sectionedPayload = JSON.parse(
29+
fixtures.readSync('source-map/disk-index.map', 'utf8'),
30+
);
31+
32+
let sourceMap;
33+
let sourceMapMethod;
34+
switch (operation) {
35+
case 'parse':
36+
bench.start();
37+
for (let i = 0; i < n; i++) {
38+
sourceMap = new SourceMap(samplePayload);
39+
}
40+
bench.end(n);
41+
break;
42+
43+
case 'parse-sectioned':
44+
bench.start();
45+
for (let i = 0; i < n; i++) {
46+
sourceMap = new SourceMap(sectionedPayload);
47+
}
48+
bench.end(n);
49+
break;
50+
51+
case 'findEntry':
52+
sourceMap = new SourceMap(samplePayload);
53+
bench.start();
54+
for (let i = 0; i < n; i++) {
55+
sourceMapMethod = sourceMap.findEntry(i, i);
56+
}
57+
bench.end(n);
58+
assert.ok(sourceMapMethod);
59+
break;
60+
61+
case 'findEntry-sectioned':
62+
sourceMap = new SourceMap(sectionedPayload);
63+
bench.start();
64+
for (let i = 0; i < n; i++) {
65+
sourceMapMethod = sourceMap.findEntry(i, i);
66+
}
67+
bench.end(n);
68+
assert.ok(sourceMapMethod);
69+
break;
70+
71+
case 'findOrigin':
72+
sourceMap = new SourceMap(samplePayload);
73+
bench.start();
74+
for (let i = 0; i < n; i++) {
75+
sourceMapMethod = sourceMap.findOrigin(i, i);
76+
}
77+
bench.end(n);
78+
assert.ok(sourceMapMethod);
79+
break;
80+
81+
case 'findOrigin-sectioned':
82+
sourceMap = new SourceMap(sectionedPayload);
83+
bench.start();
84+
for (let i = 0; i < n; i++) {
85+
sourceMapMethod = sourceMap.findOrigin(i, i);
86+
}
87+
bench.end(n);
88+
assert.ok(sourceMapMethod);
89+
break;
90+
91+
default:
92+
throw new Error(`Unknown operation: ${operation}`);
93+
}
94+
assert.ok(sourceMap);
95+
}

doc/api/fs.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,37 @@ characters directly to the `prefix` string. For instance, given a directory
13181318
`prefix` must end with a trailing platform-specific path separator
13191319
(`require('node:path').sep`).
13201320
1321+
### `fsPromises.mkdtempDisposable(prefix[, options])`
1322+
1323+
<!-- YAML
1324+
added: REPLACEME
1325+
-->
1326+
1327+
* `prefix` {string|Buffer|URL}
1328+
* `options` {string|Object}
1329+
* `encoding` {string} **Default:** `'utf8'`
1330+
* Returns: {Promise} Fulfills with a Promise for an async-disposable Object:
1331+
* `path` {string} The path of the created directory.
1332+
* `remove` {AsyncFunction} A function which removes the created directory.
1333+
* `[Symbol.asyncDispose]` {AsyncFunction} The same as `remove`.
1334+
1335+
The resulting Promise holds an async-disposable object whose `path` property
1336+
holds the created directory path. When the object is disposed, the directory
1337+
and its contents will be removed asynchronously if it still exists. If the
1338+
directory cannot be deleted, disposal will throw an error. The object has an
1339+
async `remove()` method which will perform the same task.
1340+
1341+
Both this function and the disposal function on the resulting object are
1342+
async, so it should be used with `await` + `await using` as in
1343+
`await using dir = await fsPromises.mkdtempDisposable('prefix')`.
1344+
1345+
<!-- TODO: link MDN docs for disposables once https://github.com/mdn/content/pull/38027 lands -->
1346+
1347+
For detailed information, see the documentation of [`fsPromises.mkdtemp()`][].
1348+
1349+
The optional `options` argument can be a string specifying an encoding, or an
1350+
object with an `encoding` property specifying the character encoding to use.
1351+
13211352
### `fsPromises.open(path, flags[, mode])`
13221353
13231354
<!-- YAML
@@ -5917,6 +5948,36 @@ this API: [`fs.mkdtemp()`][].
59175948
The optional `options` argument can be a string specifying an encoding, or an
59185949
object with an `encoding` property specifying the character encoding to use.
59195950
5951+
### `fs.mkdtempDisposableSync(prefix[, options])`
5952+
5953+
<!-- YAML
5954+
added: REPLACEME
5955+
-->
5956+
5957+
* `prefix` {string|Buffer|URL}
5958+
* `options` {string|Object}
5959+
* `encoding` {string} **Default:** `'utf8'`
5960+
* Returns: {Object} A disposable object:
5961+
* `path` {string} The path of the created directory.
5962+
* `remove` {Function} A function which removes the created directory.
5963+
* `[Symbol.dispose]` {Function} The same as `remove`.
5964+
5965+
Returns a disposable object whose `path` property holds the created directory
5966+
path. When the object is disposed, the directory and its contents will be
5967+
removed if it still exists. If the directory cannot be deleted, disposal will
5968+
throw an error. The object has a `remove()` method which will perform the same
5969+
task.
5970+
5971+
<!-- TODO: link MDN docs for disposables once https://github.com/mdn/content/pull/38027 lands -->
5972+
5973+
For detailed information, see the documentation of [`fs.mkdtemp()`][].
5974+
5975+
There is no callback-based version of this API because it is designed for use
5976+
with the `using` syntax.
5977+
5978+
The optional `options` argument can be a string specifying an encoding, or an
5979+
object with an `encoding` property specifying the character encoding to use.
5980+
59205981
### `fs.opendirSync(path[, options])`
59215982
59225983
<!-- YAML
@@ -8511,6 +8572,7 @@ the file contents.
85118572
[`fs.writev()`]: #fswritevfd-buffers-position-callback
85128573
[`fsPromises.access()`]: #fspromisesaccesspath-mode
85138574
[`fsPromises.copyFile()`]: #fspromisescopyfilesrc-dest-mode
8575+
[`fsPromises.mkdtemp()`]: #fspromisesmkdtempprefix-options
85148576
[`fsPromises.open()`]: #fspromisesopenpath-flags-mode
85158577
[`fsPromises.opendir()`]: #fspromisesopendirpath-options
85168578
[`fsPromises.rm()`]: #fspromisesrmpath-options

0 commit comments

Comments
 (0)