Commit Graph

7938 Commits

Author SHA1 Message Date
Luigi Pinca
db8ff56629
doc: move history entry to class description
Move the history entry for the `TextDecoder` class into the class
description itself instead of its constructor.

Refs: https://github.com/nodejs/node/issues/55938
PR-URL: https://github.com/nodejs/node/pull/55991
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
2024-11-27 14:24:53 +00:00
Luigi Pinca
090aa8bd8e
doc: add history entry for textEncoder.encodeInto()
Fixes: https://github.com/nodejs/node/issues/55938
PR-URL: https://github.com/nodejs/node/pull/55990
Refs: https://github.com/nodejs/node/pull/29524
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
2024-11-27 14:11:49 +00:00
Filip Skokan
5bdf1c4ee8
doc: fix deprecation codes
PR-URL: https://github.com/nodejs/node/pull/56018
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2024-11-27 13:16:21 +00:00
Luigi Pinca
17f39bcf3c
doc: remove confusing and outdated sentence
Remove confusing and outdated sentence in `doc/api/stream.md`.

Fixes: https://github.com/nodejs/node/issues/55987
PR-URL: https://github.com/nodejs/node/pull/55988
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jason Zhang <xzha4350@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
2024-11-27 10:26:27 +00:00
Joyee Cheung
9029aec834
cli: implement --trace-env and --trace-env-[js|native]-stack
This implements --trace-env, --trace-env-js-stack and
--trace-env-native-stack CLI options which can be used to find
out what environment variables are accessed and where they are
accessed.

PR-URL: https://github.com/nodejs/node/pull/55604
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-11-27 09:44:16 +00:00
René
ae8280c95d
process: deprecate features.{ipv6,uv} and features.tls_*
PR-URL: https://github.com/nodejs/node/pull/55545
Fixes: https://github.com/nodejs/node/issues/55537
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
2024-11-27 04:19:16 +00:00
Carlos Espa
a01319a55f
doc: deprecate passing invalid types in fs.existsSync
PR-URL: https://github.com/nodejs/node/pull/55892
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jason Zhang <xzha4350@gmail.com>
2024-11-25 23:48:24 +01:00
skyclouds2001
b17a1fb1ce
doc: add doc for PerformanceObserver.takeRecords()
PR-URL: https://github.com/nodejs/node/pull/55786
Fixes: https://github.com/nodejs/node/issues/55779
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jason Zhang <xzha4350@gmail.com>
2024-11-25 10:02:32 +00:00
Giovanni Bucci
d0d52092cf
assert: add partialDeepStrictEqual
Fixes: https://github.com/nodejs/node/issues/50399

Co-Authored-By: Cristian Barlutiu <cristian.barlutiu@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/54630
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Jithil P Ponnan <jithil@outlook.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2024-11-23 17:45:49 +00:00
Julian Gassner
a2a0c22fbf
doc: order node:crypto APIs alphabetically
PR-URL: https://github.com/nodejs/node/pull/55831
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2024-11-23 18:10:44 +01:00
Filip Skokan
0116e80827 crypto: allow non-multiple of 8 in SubtleCrypto.deriveBits
PR-URL: https://github.com/nodejs/node/pull/55296
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-11-23 08:22:12 -08:00
Leonardo Peixoto
6190bbc12c
doc: add esm example for zlib
PR-URL: https://github.com/nodejs/node/pull/55946
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-11-23 14:04:16 +00:00
tpoisseau
bc701e90f3
sqlite: add StatementSync.prototype.iterate method
PR-URL: https://github.com/nodejs/node/pull/54213
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2024-11-22 10:21:48 +01:00
Alfredo González
d894772157
doc: add esm examples to node:timers
PR-URL: https://github.com/nodejs/node/pull/55857
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jason Zhang <xzha4350@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2024-11-20 23:26:30 +00:00
RafaelGSS
cb7d855f88 2024-11-20, Version 23.3.0 (Current)
Notable changes:

doc:
  * enforce strict policy to semver-major releases (Rafael Gonzaga) https://github.com/nodejs/node/pull/55732
src:
  * (SEMVER-MINOR) add cli option to preserve env vars on dr (Rafael Gonzaga) https://github.com/nodejs/node/pull/55697
util:
  * (SEMVER-MINOR) add sourcemap support to getCallSites (Marco Ippolito) https://github.com/nodejs/node/pull/55589
  * (SEMVER-MINOR) fix util.getCallSites plurality (Chengzhong Wu) https://github.com/nodejs/node/pull/55626

PR-URL: https://github.com/nodejs/node/pull/55921
2024-11-20 19:54:14 -03:00
Hüseyin Açacak
eb1cb369fe
src: fix kill signal on Windows
Fixes: https://github.com/nodejs/node/issues/42923
PR-URL: https://github.com/nodejs/node/pull/55514
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
2024-11-20 12:14:20 +00:00
Livia Medeiros
2c11d6e61c
tools: lint js in doc/**/*.md
PR-URL: https://github.com/nodejs/node/pull/55904
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2024-11-20 10:10:38 +00:00
Rafael Gonzaga
f4cd4d9749
doc: fix relative path mention in --allow-fs
PR-URL: https://github.com/nodejs/node/pull/55791
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2024-11-19 18:31:29 +00:00
Colin Ihrig
c921676512
test_runner: mark snapshot testing as stable
This commit marks the test runner's snapshot testing API as
stable.

PR-URL: https://github.com/nodejs/node/pull/55897
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2024-11-19 17:37:35 +00:00
Colin Ihrig
01b9a54a58
test_runner: mark context.plan() as stable
This function does not require a CLI flag, does not emit a warning,
and is a fairly simple API that is already being used heavily in
the ecosystem. This commit marks context.plan() as stable.

PR-URL: https://github.com/nodejs/node/pull/55895
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2024-11-19 15:01:30 +00:00
Colin Ihrig
1d01ad6773
doc,lib,src,test: unflag sqlite module
This commit allows the node:sqlite module to be used without
starting Node with a CLI flag. The module is still experimental.

Fixes: https://github.com/nodejs/node/issues/55854
PR-URL: https://github.com/nodejs/node/pull/55890
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2024-11-19 03:23:18 +00:00
Antoine du Hamel
a8daa45070
doc: add history entry for import assertion removal
PR-URL: https://github.com/nodejs/node/pull/55883
Refs: https://github.com/nodejs/node/pull/52104
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
2024-11-18 16:58:59 +00:00
Bart Louwers
746b17e1a5
sqlite: add support for SQLite Session Extension
PR-URL: https://github.com/nodejs/node/pull/54181
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2024-11-18 00:57:04 +00:00
Jordan Harband
e577618227 util: inspect: enumerable Symbols no longer have square brackets
Implements https://github.com/orgs/nodejs/discussions/41283#discussioncomment-11188239

PR-URL: https://github.com/nodejs/node/pull/55778
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2024-11-17 06:57:37 +00:00
Antoine du Hamel
669b6927e4
doc: remove non-working example
PR-URL: https://github.com/nodejs/node/pull/55856
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Raz Luvaton <rluvaton@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2024-11-16 16:43:57 +00:00
Antoine du Hamel
a6d853c63b
doc: add history entries for JSON modules stabilization
PR-URL: https://github.com/nodejs/node/pull/55855
Refs: https://github.com/nodejs/node/pull/55333
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
2024-11-16 16:36:27 +00:00
翠 / green
b67986f57a
doc: add node:sqlite to mandatory node: prefix list
PR-URL: https://github.com/nodejs/node/pull/55846
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-11-16 04:05:45 +00:00
Preveen P
0c8ef483ee
doc: clarify UV_THREADPOOL_SIZE env var usage
Setting of UV_THREADPOOL_SIZE from inside process using
process.env.UV_THREADPOOL_SIZE is not guaranteed to work as
the thread pool would have been created as part of the runtime
initialisation much before user code is run.

update doc/api/cli.md

PR-URL: https://github.com/nodejs/node/pull/55832
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-11-15 08:37:52 +00:00
Livia Medeiros
b02cd411c2
fs: runtime deprecate fs.F_OK, fs.R_OK, fs.W_OK, fs.X_OK
PR-URL: https://github.com/nodejs/node/pull/49686
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-11-14 23:34:02 +00:00
Antoine du Hamel
d9540b51eb
fs: remove dirent.path
PR-URL: https://github.com/nodejs/node/pull/55548
Fixes: https://github.com/nodejs/node/issues/55538
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2024-11-15 00:18:05 +01:00
Antoine du Hamel
be5a500ae3
doc: fix history info for URL.prototype.toJSON
PR-URL: https://github.com/nodejs/node/pull/55818
Fixes: https://github.com/nodejs/node/issues/55806
Refs: https://github.com/nodejs/node/pull/11236
Refs: https://github.com/nodejs/node/pull/17365
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2024-11-13 16:47:28 +00:00
Joe Bowbeer
598bbf4833
doc: correct max-semi-space-size statement
Signed-off-by: Joe Bowbeer <joe.bowbeer@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/55812
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
2024-11-12 23:55:32 +00:00
Antoine du Hamel
f17b9a4c78
2024-11-12, Version 18.20.5 'Hydrogen' (LTS)
Notable changes:

esm:
  * mark import attributes and JSON module as stable (Nicolò Ribaudo) https://github.com/nodejs/node/pull/55333

PR-URL: https://github.com/nodejs/node/pull/55768
2024-11-12 22:35:04 +01:00
skyclouds2001
0d29315972
doc: update unflag info of import.meta.resolve
PR-URL: https://github.com/nodejs/node/pull/55810
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-11-12 21:01:17 +00:00
Adrien Foulon
2310409a89
report: fix network queries in getReport libuv with exclude-network
PR-URL: https://github.com/nodejs/node/pull/55602
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
2024-11-12 15:57:59 +00:00
Antoine du Hamel
c52c670ad4
2024-11-11, Version 23.2.0 (Current)
Notable changes:

crypto:
  * update root certificates to NSS 3.104 (Richard Lau) https://github.com/nodejs/node/pull/55681
doc:
  * move typescript support to active development (Marco Ippolito) https://github.com/nodejs/node/pull/55536
  * add jazelly to collaborators (Jason Zhang) https://github.com/nodejs/node/pull/55531
fs:
  * (SEMVER-MINOR) make `dirent.path` writable (Antoine du Hamel) https://github.com/nodejs/node/pull/55547
http:
  * (SEMVER-MINOR) add diagnostic channel `http.client.request.created` (Marco Ippolito) https://github.com/nodejs/node/pull/55586
module:
  * (SEMVER-MINOR) add `findPackageJSON` util (Jacob Smith) https://github.com/nodejs/node/pull/55412
  * (SEMVER-MINOR) add `module.stripTypeScriptTypes` (Marco Ippolito) https://github.com/nodejs/node/pull/55282

PR-URL: https://github.com/nodejs/node/pull/55741
2024-11-11 21:23:33 +01:00
Rafael Gonzaga
3a0968db43
permission: ignore internalModuleStat on module loading
This improves Permission Model usage when allowing read access to
specifi modules. To achieve that, the permission model check on
internalModuleStat has been removed meaning that on module loading,
uv_fs_stat is performed on files and folders even when the permission
model is enabled. Although a uv_fs_stat is performed, reading/executing
the module will still pass by the permission model check.

Without this PR when an app tries to --allow-fs-read=./a.js
--allow-fs-read=./b.js where `a` attempt to load b, it will fails as
it reads $pwd and no permission has been given to this path.

PR-URL: https://github.com/nodejs/node/pull/55797
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
2024-11-11 17:31:44 +00:00
Rafael Gonzaga
0a00217a5f
doc: sort --report-exclude alphabetically
PR-URL: https://github.com/nodejs/node/pull/55788
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
2024-11-09 12:13:31 +00:00
Edigleysson Silva (Edy)
069ec1b983
doc: consolidate history table of CustomEvent
PR-URL: https://github.com/nodejs/node/pull/55758
Fixes: https://github.com/nodejs/node/issues/55733
Refs: https://github.com/nodejs/node/issues/55733
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
2024-11-09 02:47:32 +00:00
Rafael Gonzaga
a243225aa2
src: add cli option to preserve env vars on dr
PR-URL: https://github.com/nodejs/node/pull/55697
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
2024-11-08 17:49:43 +00:00
Antoine du Hamel
94be10ac32
util: do not mark experimental feature as deprecated
PR-URL: https://github.com/nodejs/node/pull/55740
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2024-11-08 16:16:15 +00:00
Antoine du Hamel
37c941be05
doc: clarify removal of experimental API does not require a deprecation
PR-URL: https://github.com/nodejs/node/pull/55746
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-11-08 13:02:49 +00:00
Carlos Espa
765f16c442
doc: add path aliases typescript doc
PR-URL: https://github.com/nodejs/node/pull/55766
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2024-11-08 10:28:40 +00:00
Aviv Keller
daf5346742
doc: add esm example in path.md
PR-URL: https://github.com/nodejs/node/pull/55745
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
2024-11-08 11:27:17 +01:00
Aviv Keller
0368f2f662
repl: runtime deprecate instantiating without new
PR-URL: https://github.com/nodejs/node/pull/54869
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
2024-11-07 08:03:05 +00:00
Gireesh Punathil
6f12f1e500
doc: consistent use of word child process
reword "child" to "child process" wherever possible.
this helps in maintaining clarity and precision,
consistency while avoiding misinterpretation.

PR-URL: https://github.com/nodejs/node/pull/55654
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2024-11-06 10:28:28 +00:00
Preveen P
98e5693cd4
doc: clarity to available addon options
bullet pointed addon optons; wording clarity; fixes typo

PR-URL: https://github.com/nodejs/node/pull/55715
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2024-11-06 07:55:49 +00:00
Joe Bowbeer
25f8474730
doc: update --max-semi-space-size description
PR-URL: https://github.com/nodejs/node/pull/55495
Fixes: https://github.com/nodejs/node/issues/55487
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2024-11-06 00:14:15 +01:00
Marco Ippolito
d35cde624f
util: add sourcemap support to getCallSites
PR-URL: https://github.com/nodejs/node/pull/55589
Fixes: https://github.com/nodejs/node/issues/55109
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2024-11-04 16:06:47 +00:00
Dom Harrington
e124b0ff7d
doc: broken PerformanceObserver code sample
The code sample at the top of the "Performance measurements API"
section of the docs does not run.

The code in question:

```js
const { PerformanceObserver, performance } = require('node:perf_hooks');

const obs = new PerformanceObserver((items) => {
  console.log(items.getEntries()[0].duration);
  performance.clearMarks();
});
obs.observe({ type: 'measure' });
performance.measure('Start to Now');

performance.mark('A');
doSomeLongRunningProcess(() => {
  performance.measure('A to Now', 'A');

  performance.mark('B');
  performance.measure('A to B', 'A', 'B');
});
```

If you replace `doSomeLongRunningProcess` with an IIFE with a sleep()
at the top of it, you get this:

```js
const { PerformanceObserver, performance } = require('node:perf_hooks');

const obs = new PerformanceObserver((items) => {
  console.log(items.getEntries()[0].duration);
  performance.clearMarks();
});
obs.observe({ type: 'measure' });
performance.measure('Start to Now');

performance.mark('A');

(async function doSomeLongRunningProcess() {
  await new Promise(r => setTimeout(r, 5000));
  performance.measure('A to Now', 'A');

  performance.mark('B');
  performance.measure('A to B', 'A', 'B');
})()
```

When you run this, you get the following output:

```sh
$ node performance-test.js
17.873416

node:internal/per_context/domexception:53
    ErrorCaptureStackTrace(this);
    ^
DOMException [SyntaxError]: The "A" performance mark has not been set
    at new DOMException (node:internal/per_context/domexception:53:5)
    at __node_internal_ (node:internal/util:695:10)
    at getMark (node:internal/perf/usertiming:65:11)
    at calculateStartDuration (node:internal/perf/usertiming:202:13)
    at measure (node:internal/perf/usertiming:220:7)
    at Performance.measure (node:internal/perf/performance:135:12)
    at /private/tmp/performance-test.js:14:15

Node.js v20.11.1
```

I believe it's due to the call to `performance.clearMarks();` in the
PerformanceObserver callback. If you remove that, it works as expected:

```js
const { PerformanceObserver, performance } = require('node:perf_hooks');

const obs = new PerformanceObserver((items) => {
  console.log(items.getEntries()[0].duration);
});
obs.observe({ type: 'measure' });
performance.measure('Start to Now');

performance.mark('A');

(async function doSomeLongRunningProcess() {
  await new Promise(r => setTimeout(r, 5000));
  performance.measure('A to Now', 'A');

  performance.mark('B');
  performance.measure('A to B', 'A', 'B');
})()
```

```sh
$ node performance-test.js
17.761083
5002.468417
```

PR-URL: https://github.com/nodejs/node/pull/54227
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2024-11-02 17:05:24 +00:00