From aacc963fc60358696dfbcc6ab095095e87111289 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Mon, 18 Nov 2024 11:53:41 -0500 Subject: [PATCH 1/6] bootstrap: expose process._rawDebug as a global function The `process._rawDebug` function is very helpful when triaging bugs that cross asynchronous boundaries. It is also quite cumbersome to write out `process._rawDebug` everywhere such a line is needed. So this change exposes it as a global function to facilitate an improved developer experience. --- lib/internal/bootstrap/node.js | 16 ++++++++++++++++ test/parallel/test-bootstrap-rawdebug.js | 6 ++++++ 2 files changed, 22 insertions(+) create mode 100644 test/parallel/test-bootstrap-rawdebug.js diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index b8c47ee0f54b..d25bf53ca7e4 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -86,6 +86,7 @@ setupProcessObject(); setupGlobalProxy(); setupBuffer(); +setupGlobalDebug(); process.domain = null; @@ -461,3 +462,18 @@ function setupBuffer() { configurable: true, }); } + +function setupGlobalDebug() { + let _process = process; + ObjectDefineProperty(globalThis, 'rawDebug', { + __proto__: null, + get() { + return _process._rawDebug; + }, + set(value) { + _process._rawDebug = value; + }, + enumerable: false, + configurable: true, + }); +} diff --git a/test/parallel/test-bootstrap-rawdebug.js b/test/parallel/test-bootstrap-rawdebug.js new file mode 100644 index 000000000000..828cb7a51077 --- /dev/null +++ b/test/parallel/test-bootstrap-rawdebug.js @@ -0,0 +1,6 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); + +assert.equal(typeof rawDebug === 'function', true); \ No newline at end of file From 4ed8284e272818a4a7f2ab7bd6f7ad2fd37ad8e6 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Mon, 18 Nov 2024 14:58:34 -0500 Subject: [PATCH 2/6] satisfy linter --- lib/internal/bootstrap/node.js | 2 +- test/parallel/test-bootstrap-rawdebug.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index d25bf53ca7e4..d7de5a269ea5 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -464,7 +464,7 @@ function setupBuffer() { } function setupGlobalDebug() { - let _process = process; + const _process = process; ObjectDefineProperty(globalThis, 'rawDebug', { __proto__: null, get() { diff --git a/test/parallel/test-bootstrap-rawdebug.js b/test/parallel/test-bootstrap-rawdebug.js index 828cb7a51077..c7b075e3cb42 100644 --- a/test/parallel/test-bootstrap-rawdebug.js +++ b/test/parallel/test-bootstrap-rawdebug.js @@ -3,4 +3,5 @@ const common = require('../common'); const assert = require('assert'); -assert.equal(typeof rawDebug === 'function', true); \ No newline at end of file +common.allowGlobals('rawDebug'); +assert.strictEqual(typeof global.rawDebug === 'function', true); From 3c333b8c1d563a1f2d265dc7a9d66d00960a0e76 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Tue, 19 Nov 2024 08:44:59 -0500 Subject: [PATCH 3/6] fix test --- test/common/globals.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/common/globals.js b/test/common/globals.js index 42caece2b8d1..670a23e7f114 100644 --- a/test/common/globals.js +++ b/test/common/globals.js @@ -136,6 +136,7 @@ const nodeGlobals = new Set([ 'Buffer', 'clearImmediate', 'setImmediate', + 'rawDebug' ]); module.exports = { From 1886bf7b2cef0378b60097dd6d13772f9f66f7b3 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Tue, 19 Nov 2024 09:36:52 -0500 Subject: [PATCH 4/6] satisfy linter --- test/common/globals.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common/globals.js b/test/common/globals.js index 670a23e7f114..794c69d23a3f 100644 --- a/test/common/globals.js +++ b/test/common/globals.js @@ -136,7 +136,7 @@ const nodeGlobals = new Set([ 'Buffer', 'clearImmediate', 'setImmediate', - 'rawDebug' + 'rawDebug', ]); module.exports = { From d02f7a9aa0f2e7d71b11a71a900b198a51c44dfe Mon Sep 17 00:00:00 2001 From: James Sumners Date: Tue, 19 Nov 2024 14:13:28 -0500 Subject: [PATCH 5/6] satisfy codecov --- lib/internal/bootstrap/node.js | 6 +++--- test/parallel/test-bootstrap-rawdebug.js | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index d7de5a269ea5..7e6fd24a049f 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -464,14 +464,14 @@ function setupBuffer() { } function setupGlobalDebug() { - const _process = process; + let _rawDebug = process._rawDebug; ObjectDefineProperty(globalThis, 'rawDebug', { __proto__: null, get() { - return _process._rawDebug; + return _rawDebug; }, set(value) { - _process._rawDebug = value; + _rawDebug = value; }, enumerable: false, configurable: true, diff --git a/test/parallel/test-bootstrap-rawdebug.js b/test/parallel/test-bootstrap-rawdebug.js index c7b075e3cb42..187665c2786b 100644 --- a/test/parallel/test-bootstrap-rawdebug.js +++ b/test/parallel/test-bootstrap-rawdebug.js @@ -5,3 +5,7 @@ const assert = require('assert'); common.allowGlobals('rawDebug'); assert.strictEqual(typeof global.rawDebug === 'function', true); +assert.strictEqual(global.rawDebug === process._rawDebug, true); + +global.rawDebug = 42; +assert.strictEqual(global.rawDebug === 42, true); From 12839f9f687f46fce60b6ff2b0a4cb5b92171891 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Fri, 22 Nov 2024 06:18:28 -0500 Subject: [PATCH 6/6] remove impossible test --- test/parallel/test-bootstrap-rawdebug.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/parallel/test-bootstrap-rawdebug.js b/test/parallel/test-bootstrap-rawdebug.js index 187665c2786b..9a8a6cf6b53a 100644 --- a/test/parallel/test-bootstrap-rawdebug.js +++ b/test/parallel/test-bootstrap-rawdebug.js @@ -5,7 +5,6 @@ const assert = require('assert'); common.allowGlobals('rawDebug'); assert.strictEqual(typeof global.rawDebug === 'function', true); -assert.strictEqual(global.rawDebug === process._rawDebug, true); global.rawDebug = 42; assert.strictEqual(global.rawDebug === 42, true);