From 82b1b551223f89dd2023d46344fa4a882babebad 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 | 9 +++-- 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, 170 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 create mode 100644 test/parallel/test-process-setsourcemapsenabled.js diff --git a/doc/api/process.md b/doc/api/process.md index b8c9d7b4b7ce03..2a4d6e839760be 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -3249,6 +3249,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)`