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