From 1a6bf1c4a3151112fbea79297d2385242a45a9fa Mon Sep 17 00:00:00 2001 From: legendecas Date: Sat, 19 Jun 2021 15:32:31 +0800 Subject: [PATCH] process: add api to enable source-maps programmatically Add `process.setSourceMapsEnabled` to enable source-maps programmatically. PR-URL: https://github.com/nodejs/node/pull/39085 Reviewed-By: Ben Coe Reviewed-By: James M Snell --- doc/api/process.md | 19 +++++++++ lib/internal/bootstrap/pre_execution.js | 8 ++++ lib/internal/main/worker_thread.js | 2 + lib/internal/source_map/source_map_cache.js | 39 +++++++++++++------ src/node_errors.cc | 7 ++-- test/message/source_map_disabled_by_api.js | 20 ++++++++++ test/message/source_map_disabled_by_api.out | 26 +++++++++++++ test/message/source_map_enabled_by_api.js | 17 ++++++++ test/message/source_map_enabled_by_api.out | 30 ++++++++++++++ .../test-process-setsourcemapsenabled.js | 16 ++++++++ 10 files changed, 169 insertions(+), 15 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 create mode 100644 test/parallel/test-process-setsourcemapsenabled.js diff --git a/doc/api/process.md b/doc/api/process.md index 20eea01d6b9a01..f0f72fc07a7587 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -2348,6 +2348,24 @@ 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)` + + +> Stability: 1 - Experimental + +* `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)`