From 6400009d98b74aa12fab73359652f70a86a41d0a Mon Sep 17 00:00:00 2001 From: legendecas Date: Sat, 19 Jun 2021 15:32:31 +0800 Subject: [PATCH] lib: add api to enable source-maps programmatically Add `process.setSourceMapsEnabled` to enable source-maps programmatically. --- doc/api/process.md | 17 ++++++++++ lib/internal/bootstrap/pre_execution.js | 6 ++++ lib/internal/source_map/source_map_cache.js | 36 ++++++++++++++------- src/node_errors.cc | 9 +++--- test/message/source_map_disabled_by_api.js | 19 +++++++++++ test/message/source_map_disabled_by_api.out | 30 +++++++++++++++++ test/message/source_map_enabled_by_api.js | 16 +++++++++ test/message/source_map_enabled_by_api.out | 30 +++++++++++++++++ 8 files changed, 147 insertions(+), 16 deletions(-) create mode 100644 test/message/source_map_disabled_by_api.js create mode 100644 test/message/source_map_disabled_by_api.out create mode 100644 test/message/source_map_enabled_by_api.js create mode 100644 test/message/source_map_enabled_by_api.out diff --git a/doc/api/process.md b/doc/api/process.md index 85e3bf5458a901b..2b2b87073b8cc1b 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -2379,6 +2379,22 @@ This function is only available on POSIX platforms (i.e. not Windows or Android). This feature is not available in [`Worker`][] threads. +## `process.setSourceMapsEnabled(val)` + + +* `val` {boolean} + +This function enables or disables the [Source Map v3][Source Map] support for +stack traces. + +It provides same features as launching Node.js process with commandline options +`--enable-source-maps`. + +Only source maps in JavaScript files that are loaded after source maps has been +enabled will be parsed and loaded. + ## `process.setUncaughtExceptionCaptureCallback(fn)`