diff --git a/doc/api/process.md b/doc/api/process.md index 5b08ce8a4b8367..548f0fdcf44378 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -3517,6 +3517,19 @@ throw an error. Using this function is mutually exclusive with using the deprecated [`domain`][] built-in module. +## `process.sourceMapsEnabled` + + + +> Stability: 1 - Experimental + +* {boolean} + +The `process.sourceMapsEnabled` property returns whether the +[Source Map v3][Source Map] support for stack traces is enabled. + ## `process.stderr` * {Stream} diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 36ff5bcd8c526a..7a773d5208e250 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -326,6 +326,7 @@ process.emitWarning = emitWarning; { const { + getSourceMapsEnabled, setSourceMapsEnabled, maybeCacheGeneratedSourceMap, } = require('internal/source_map/source_map_cache'); @@ -333,6 +334,14 @@ process.emitWarning = emitWarning; setMaybeCacheGeneratedSourceMap, } = internalBinding('errors'); + ObjectDefineProperty(process, 'sourceMapsEnabled', { + __proto__: null, + enumerable: true, + configurable: true, + get() { + return getSourceMapsEnabled(); + }, + }); process.setSourceMapsEnabled = setSourceMapsEnabled; // The C++ land calls back to maybeCacheGeneratedSourceMap() // when code is generated by user with eval() or new Function() diff --git a/test/fixtures/source-map/output/source_map_disabled_by_api.js b/test/fixtures/source-map/output/source_map_disabled_by_api.js index b1a28d0eae1c2e..d94a6310cff7ae 100644 --- a/test/fixtures/source-map/output/source_map_disabled_by_api.js +++ b/test/fixtures/source-map/output/source_map_disabled_by_api.js @@ -2,9 +2,12 @@ 'use strict'; require('../../../common'); +const assert = require('assert'); Error.stackTraceLimit = 5; +assert.strictEqual(process.sourceMapsEnabled, true); process.setSourceMapsEnabled(false); +assert.strictEqual(process.sourceMapsEnabled, false); try { require('../enclosing-call-site-min.js'); @@ -17,6 +20,7 @@ delete require.cache[require // Re-enable. process.setSourceMapsEnabled(true); +assert.strictEqual(process.sourceMapsEnabled, true); try { require('../enclosing-call-site-min.js'); diff --git a/test/fixtures/source-map/output/source_map_enabled_by_api.js b/test/fixtures/source-map/output/source_map_enabled_by_api.js index 4c70fa1cb2a240..1dd4f9530c68db 100644 --- a/test/fixtures/source-map/output/source_map_enabled_by_api.js +++ b/test/fixtures/source-map/output/source_map_enabled_by_api.js @@ -1,8 +1,11 @@ 'use strict'; require('../../../common'); +const assert = require('assert'); Error.stackTraceLimit = 5; +assert.strictEqual(process.sourceMapsEnabled, false); process.setSourceMapsEnabled(true); +assert.strictEqual(process.sourceMapsEnabled, true); try { require('../enclosing-call-site-min.js'); @@ -14,6 +17,7 @@ delete require.cache[require .resolve('../enclosing-call-site-min.js')]; process.setSourceMapsEnabled(false); +assert.strictEqual(process.sourceMapsEnabled, false); try { require('../enclosing-call-site-min.js');