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 ca1bb15
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -2384,6 +2384,8 @@ This feature is not available in [`Worker`][] threads.
added: REPLACEME
-->

> Stability: 1 - Experimental
* `val` {boolean}

This function enables or disables the [Source Map v3][Source Map] support for
Expand Down
5 changes: 4 additions & 1 deletion lib/internal/source_map/source_map_cache.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 ca1bb15

Please sign in to comment.