Skip to content

Commit

Permalink
fixup! lib: add api to enable source-maps programmatically
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed Jun 20, 2021
1 parent 8043985 commit 49ccdd5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/internal/source_map/source_map_cache.js
Expand Up @@ -29,6 +29,7 @@ const { IterableWeakMap } = require('internal/util/iterable_weak_map');
const {
normalizeReferrerURL,
} = require('internal/modules/cjs/helpers');
const { validateBoolean } = require('internal/validators');
// Since the CJS module cache is mutable, which leads to memory leaks when
// modules are deleted, we use a WeakMap so that the source map cache will
// be purged automatically:
Expand All @@ -47,6 +48,8 @@ function getSourceMapsEnabled() {
}

function setSourceMapsEnabled(val) {
validateBoolean(val, 'val');

const {
setSourceMapsEnabled,
setPrepareStackTraceCallback
Expand All @@ -58,7 +61,7 @@ function setSourceMapsEnabled(val) {
} = require('internal/source_map/prepare_stack_trace');
setPrepareStackTraceCallback(prepareStackTrace);
} else if (sourceMapsEnabled !== undefined) {
// Set prepare stack trace callback only when disabling source maps.
// Reset prepare stack trace callback only when disabling source maps.
const {
prepareStackTrace,
} = require('internal/errors');
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-process-setsourcemapsenabled.js
@@ -0,0 +1,16 @@
'use strict';
require('../common');
const assert = require('assert');

const unexpectedValues = [
undefined,
null,
1,
{},
() => {},
];
for (const it of unexpectedValues) {
assert.throws(() => {
process.setSourceMapsEnabled(it);
}, /ERR_INVALID_ARG_TYPE/);
}

0 comments on commit 49ccdd5

Please sign in to comment.