Skip to content

Commit 49ccdd5

Browse files
committed
fixup! lib: add api to enable source-maps programmatically
1 parent 8043985 commit 49ccdd5

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/internal/source_map/source_map_cache.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const { IterableWeakMap } = require('internal/util/iterable_weak_map');
2929
const {
3030
normalizeReferrerURL,
3131
} = require('internal/modules/cjs/helpers');
32+
const { validateBoolean } = require('internal/validators');
3233
// Since the CJS module cache is mutable, which leads to memory leaks when
3334
// modules are deleted, we use a WeakMap so that the source map cache will
3435
// be purged automatically:
@@ -47,6 +48,8 @@ function getSourceMapsEnabled() {
4748
}
4849

4950
function setSourceMapsEnabled(val) {
51+
validateBoolean(val, 'val');
52+
5053
const {
5154
setSourceMapsEnabled,
5255
setPrepareStackTraceCallback
@@ -58,7 +61,7 @@ function setSourceMapsEnabled(val) {
5861
} = require('internal/source_map/prepare_stack_trace');
5962
setPrepareStackTraceCallback(prepareStackTrace);
6063
} else if (sourceMapsEnabled !== undefined) {
61-
// Set prepare stack trace callback only when disabling source maps.
64+
// Reset prepare stack trace callback only when disabling source maps.
6265
const {
6366
prepareStackTrace,
6467
} = require('internal/errors');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
5+
const unexpectedValues = [
6+
undefined,
7+
null,
8+
1,
9+
{},
10+
() => {},
11+
];
12+
for (const it of unexpectedValues) {
13+
assert.throws(() => {
14+
process.setSourceMapsEnabled(it);
15+
}, /ERR_INVALID_ARG_TYPE/);
16+
}

0 commit comments

Comments
 (0)