From a3830ebacbc9430345ef3723574feee32b622a26 Mon Sep 17 00:00:00 2001 From: ishabi Date: Sun, 28 Dec 2025 11:34:09 +0100 Subject: [PATCH 1/3] v8: add GCProfiler support for erm --- lib/v8.js | 4 +++ .../test-v8-collect-gc-profile-using.js | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 test/parallel/test-v8-collect-gc-profile-using.js diff --git a/lib/v8.js b/lib/v8.js index 54395945aa1787..c0d4074aac21d5 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -488,6 +488,10 @@ class GCProfiler { return JSONParse(data); } } + + [SymbolDispose]() { + this.stop(); + } } module.exports = { diff --git a/test/parallel/test-v8-collect-gc-profile-using.js b/test/parallel/test-v8-collect-gc-profile-using.js new file mode 100644 index 00000000000000..4e048548f29868 --- /dev/null +++ b/test/parallel/test-v8-collect-gc-profile-using.js @@ -0,0 +1,26 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); +const { GCProfiler } = require('v8'); + +{ + const profiler = new GCProfiler(); + profiler.start(); + + const result = profiler[Symbol.dispose](); + + assert.strictEqual(result, undefined); + assert.strictEqual(profiler.stop(), undefined); +} + +{ + const profiler = new GCProfiler(); + profiler.start(); + + profiler[Symbol.dispose](); + // Repeat invocations should not throw + profiler[Symbol.dispose](); + + assert.strictEqual(profiler.stop(), undefined); +} From 6f5bb398eabfa232839f91dcc838418a9f33f814 Mon Sep 17 00:00:00 2001 From: ishabi Date: Thu, 8 Jan 2026 22:01:53 +0100 Subject: [PATCH 2/3] add documentation --- doc/api/v8.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/api/v8.md b/doc/api/v8.md index db92ad062b7e63..9e2b7709dc7061 100644 --- a/doc/api/v8.md +++ b/doc/api/v8.md @@ -1320,6 +1320,7 @@ added: --> Start collecting GC data. +This API supports `using` syntax. ### `profiler.stop()` @@ -1329,7 +1330,7 @@ added: - v18.15.0 --> -Stop collecting GC data and return an object.The content of object +Stop collecting GC data and return an object. The content of object is as follows. ```json @@ -1405,6 +1406,15 @@ setTimeout(() => { }, 1000); ``` +### `profiler[Symbol.dispose]()` + + + +Stop collecting GC data and return an object. The content of object +is as follows. + ## Class: `SyncCPUProfileHandle` Create a new instance of the `v8.GCProfiler` class. +This API supports `using` syntax. ### `profiler.start()` @@ -1320,7 +1321,6 @@ added: --> Start collecting GC data. -This API supports `using` syntax. ### `profiler.stop()` @@ -1412,8 +1412,7 @@ setTimeout(() => { added: REPLACEME --> -Stop collecting GC data and return an object. The content of object -is as follows. +Stop collecting GC data, and discard the profile. ## Class: `SyncCPUProfileHandle`