Skip to content

Commit

Permalink
lib: add api to detect whether source-maps are enabled
Browse files Browse the repository at this point in the history
Add `process.sourceMapsEnabled` to detect
whether source-maps are enabled.

Fixes: nodejs/node#46304
PR-URL: nodejs/node#46391
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
  • Loading branch information
sercher committed Apr 25, 2024
1 parent ba47e0e commit 1233288
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions graal-nodejs/doc/api/process.md
Expand Up @@ -3458,6 +3458,19 @@ throw an error.
Using this function is mutually exclusive with using the deprecated
[`domain`][] built-in module.
## `process.sourceMapsEnabled`
<!-- YAML
added: REPLACEME
-->
> 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}
Expand Down
9 changes: 9 additions & 0 deletions graal-nodejs/lib/internal/bootstrap/node.js
Expand Up @@ -365,13 +365,22 @@ process.emitWarning = emitWarning;

{
const {
getSourceMapsEnabled,
setSourceMapsEnabled,
maybeCacheGeneratedSourceMap,
} = require('internal/source_map/source_map_cache');
const {
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()
Expand Down
Expand Up @@ -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');
Expand All @@ -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');
Expand Down
@@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit 1233288

Please sign in to comment.