Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3989493

Browse files
RafaelGSSQard
authored andcommittedFeb 5, 2025
lib: add diagnostics_channel events to module loading
This commit adds a tracing channel for module loading through `import()` and `require()`. Co-Authored-By: Stephen Belanger <[email protected]> PR-URL: nodejs#44340 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]>
1 parent e4dadea commit 3989493

25 files changed

+398
-37
lines changed
 

‎doc/api/diagnostics_channel.md

+52
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,58 @@ Emitted when server receives a request.
11501150

11511151
Emitted when server sends a response.
11521152

1153+
#### Modules
1154+
1155+
`module.require.start`
1156+
1157+
* `event` {Object} containing the following properties
1158+
* `id` - Argument passed to `require()`. Module name.
1159+
* `parentFilename` - Name of the module that attempted to require(id).
1160+
1161+
Emitted when `require()` is executed. See [`start` event][].
1162+
1163+
`module.require.end`
1164+
1165+
* `event` {Object} containing the following properties
1166+
* `id` - Argument passed to `require()`. Module name.
1167+
* `parentFilename` - Name of the module that attempted to require(id).
1168+
1169+
Emitted when a `require()` call returns. See [`end` event][].
1170+
1171+
`module.require.error`
1172+
1173+
* `event` {Object} containing the following properties
1174+
* `id` - Argument passed to `require()`. Module name.
1175+
* `parentFilename` - Name of the module that attempted to require(id).
1176+
* `error` {Error}
1177+
1178+
Emitted when a `require()` throws an error. See [`error` event][].
1179+
1180+
`module.import.asyncStart`
1181+
1182+
* `event` {Object} containing the following properties
1183+
* `id` - Argument passed to `import()`. Module name.
1184+
* `parentURL` - URL object of the module that attempted to import(id).
1185+
1186+
Emitted when `import()` is invoked. See [`asyncStart` event][].
1187+
1188+
`module.import.asyncEnd`
1189+
1190+
* `event` {Object} containing the following properties
1191+
* `id` - Argument passed to `import()`. Module name.
1192+
* `parentURL` - URL object of the module that attempted to import(id).
1193+
1194+
Emitted when `import()` has completed. See [`asyncEnd` event][].
1195+
1196+
`module.import.error`
1197+
1198+
* `event` {Object} containing the following properties
1199+
* `id` - Argument passed to `import()`. Module name.
1200+
* `parentURL` - URL object of the module that attempted to import(id).
1201+
* `error` {Error}
1202+
1203+
Emitted when a `import()` throws an error. See [`error` event][].
1204+
11531205
#### NET
11541206

11551207
`net.client.socket`

‎lib/diagnostics_channel.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ function tracingChannelFrom(nameOrChannels, name) {
276276

277277
class TracingChannel {
278278
constructor(nameOrChannels) {
279-
for (const eventName of traceEvents) {
279+
for (let i = 0; i < traceEvents.length; ++i) {
280+
const eventName = traceEvents[i];
280281
ObjectDefineProperty(this, eventName, {
281282
__proto__: null,
282283
value: tracingChannelFrom(nameOrChannels, eventName),
@@ -285,15 +286,16 @@ class TracingChannel {
285286
}
286287

287288
get hasSubscribers() {
288-
return this.start.hasSubscribers ||
289-
this.end.hasSubscribers ||
290-
this.asyncStart.hasSubscribers ||
291-
this.asyncEnd.hasSubscribers ||
292-
this.error.hasSubscribers;
289+
return this.start?.hasSubscribers ||
290+
this.end?.hasSubscribers ||
291+
this.asyncStart?.hasSubscribers ||
292+
this.asyncEnd?.hasSubscribers ||
293+
this.error?.hasSubscribers;
293294
}
294295

295296
subscribe(handlers) {
296-
for (const name of traceEvents) {
297+
for (let i = 0; i < traceEvents.length; ++i) {
298+
const name = traceEvents[i];
297299
if (!handlers[name]) continue;
298300

299301
this[name]?.subscribe(handlers[name]);
@@ -303,7 +305,8 @@ class TracingChannel {
303305
unsubscribe(handlers) {
304306
let done = true;
305307

306-
for (const name of traceEvents) {
308+
for (let i = 0; i < traceEvents.length; ++i) {
309+
const name = traceEvents[i];
307310
if (!handlers[name]) continue;
308311

309312
if (!this[name]?.unsubscribe(handlers[name])) {

‎lib/internal/modules/cjs/loader.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ let { startTimer, endTimer } = debugWithTimer('module_timer', (start, end) => {
198198
endTimer = end;
199199
});
200200

201+
const { tracingChannel } = require('diagnostics_channel');
202+
const onRequire = getLazy(() => tracingChannel('module.require'));
203+
201204
const isWindows = process.platform === 'win32';
202205

203206
const relativeResolveCache = { __proto__: null };
@@ -237,7 +240,11 @@ function wrapModuleLoad(request, parent, isMain) {
237240
startTimer(logLabel, traceLabel);
238241

239242
try {
240-
return Module._load(request, parent, isMain);
243+
return onRequire().traceSync(Module._load, {
244+
__proto__: null,
245+
parentFilename: parent?.filename,
246+
id: request,
247+
}, Module, request, parent, isMain);
241248
} finally {
242249
endTimer(logLabel, traceLabel);
243250
}

‎lib/internal/modules/esm/loader.js

+23-7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ const {
4141
} = require('internal/modules/helpers');
4242
let defaultResolve, defaultLoad, defaultLoadSync, importMetaInitializer;
4343

44+
const { tracingChannel } = require('diagnostics_channel');
45+
const onImport = tracingChannel('module.import');
46+
4447
/**
4548
* @typedef {import('url').URL} URL
4649
*/
@@ -209,10 +212,17 @@ class ModuleLoader {
209212
return compileSourceTextModule(url, source, this);
210213
};
211214
const { ModuleJob } = require('internal/modules/esm/module_job');
212-
const job = new ModuleJob(
213-
this, url, undefined, evalInstance, false, false);
214-
this.loadCache.set(url, undefined, job);
215-
const { module } = await job.run();
215+
const module = await onImport.tracePromise(async () => {
216+
const job = new ModuleJob(
217+
this, url, undefined, evalInstance, false, false);
218+
this.loadCache.set(url, undefined, job);
219+
const { module } = await job.run();
220+
return module;
221+
}, {
222+
__proto__: null,
223+
parentURL: '<eval>',
224+
url,
225+
});
216226

217227
return {
218228
__proto__: null,
@@ -470,9 +480,15 @@ class ModuleLoader {
470480
* @returns {Promise<ModuleExports>}
471481
*/
472482
async import(specifier, parentURL, importAttributes) {
473-
const moduleJob = await this.getModuleJob(specifier, parentURL, importAttributes);
474-
const { module } = await moduleJob.run();
475-
return module.getNamespace();
483+
return onImport.tracePromise(async () => {
484+
const moduleJob = await this.getModuleJob(specifier, parentURL, importAttributes);
485+
const { module } = await moduleJob.run();
486+
return module.getNamespace();
487+
}, {
488+
__proto__: null,
489+
parentURL,
490+
url: specifier,
491+
});
476492
}
477493

478494
/**

‎test/fixtures/console/console.snapshot

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Trace: foo
77
at *
88
at *
99
at *
10+
at *

‎test/fixtures/errors/force_colors.snapshot

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ Error: Should include grayed stack trace
1111
 at *
1212
 at *
1313
 at *
14+
 at *
1415

1516
Node.js *

‎test/fixtures/errors/promise_unhandled_warn_with_error.snapshot

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
at *
88
at *
99
at *
10+
at *
1011
(Use `node --trace-warnings ...` to show where the warning was created)
1112
(node:*) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https:*nodejs.org*api*cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

‎test/fixtures/errors/unhandled_promise_trace_warnings.snapshot

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
at *
1212
at *
1313
at *
14+
at *
1415
(node:*) Error: This was rejected
1516
at *
1617
at *
@@ -20,6 +21,7 @@
2021
at *
2122
at *
2223
at *
24+
at *
2325
(node:*) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)
2426
at *
2527
at *

‎test/message/assert_throws_stack.out

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
1616
at *
1717
at *
1818
at *
19+
at *
1920
at * {
2021
generatedMessage: true,
2122
code: 'ERR_ASSERTION',

‎test/message/internal_assert.out

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Please open an issue with this stack trace at https://github.com/nodejs/node/iss
1313
at *
1414
at *
1515
at *
16+
at *
1617
at * {
1718
code: 'ERR_INTERNAL_ASSERTION'
1819
}

‎test/message/internal_assert_fail.out

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Please open an issue with this stack trace at https://github.com/nodejs/node/iss
1414
at *
1515
at *
1616
at *
17+
at *
1718
at * {
1819
code: 'ERR_INTERNAL_ASSERTION'
1920
}

‎test/message/util-inspect-error-cause.out

+20-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Error: Number error cause
66
at *
77
at *
88
at *
9+
at *
910
at * {
1011
[cause]: 42
1112
}
@@ -17,6 +18,7 @@ Error: Object cause
1718
at *
1819
at *
1920
at *
21+
at *
2022
at * {
2123
[cause]: {
2224
message: 'Unique',
@@ -33,6 +35,7 @@ Error: undefined cause
3335
at *
3436
at *
3537
at *
38+
at *
3639
at * {
3740
[cause]: undefined
3841
}
@@ -44,6 +47,7 @@ Error: cause that throws
4447
at *
4548
at *
4649
at *
50+
at *
4751
at * {
4852
[cause]: [Getter]
4953
}
@@ -53,7 +57,7 @@ RangeError: New Stack Frames
5357
[cause]: FoobarError: Individual message
5458
at *
5559
*[90m at *[39m
56-
*[90m ... 5 lines matching cause stack trace ...*[39m
60+
*[90m ... 6 lines matching cause stack trace ...*[39m
5761
*[90m at *[39m {
5862
status: *[32m'Feeling good'*[39m,
5963
extraProperties: *[32m'Yes!'*[39m,
@@ -66,17 +70,18 @@ RangeError: New Stack Frames
6670
*[90m at *[39m
6771
*[90m at *[39m
6872
*[90m at *[39m
73+
*[90m at *[39m
6974
}
7075
}
7176
Error: Stack causes
7277
at *
7378
*[90m at *[39m
74-
*[90m ... 5 lines matching cause stack trace ...*[39m
79+
*[90m ... 6 lines matching cause stack trace ...*[39m
7580
*[90m at *[39m {
7681
[cause]: FoobarError: Individual message
7782
at *
7883
*[90m at *[39m
79-
*[90m ... 5 lines matching cause stack trace ...*[39m
84+
*[90m ... 6 lines matching cause stack trace ...*[39m
8085
*[90m at *[39m {
8186
status: *[32m'Feeling good'*[39m,
8287
extraProperties: *[32m'Yes!'*[39m,
@@ -89,6 +94,7 @@ Error: Stack causes
8994
*[90m at *[39m
9095
*[90m at *[39m
9196
*[90m at *[39m
97+
*[90m at *[39m
9298
}
9399
}
94100
RangeError: New Stack Frames
@@ -97,12 +103,12 @@ RangeError: New Stack Frames
97103
[cause]: Error: Stack causes
98104
at *
99105
*[90m at *[39m
100-
*[90m ... 5 lines matching cause stack trace ...*[39m
106+
*[90m ... 6 lines matching cause stack trace ...*[39m
101107
*[90m at *[39m {
102108
[cause]: FoobarError: Individual message
103109
at *
104110
*[90m at *[39m
105-
*[90m ... 5 lines matching cause stack trace ...*[39m
111+
*[90m ... 6 lines matching cause stack trace ...*[39m
106112
*[90m at *[39m {
107113
status: *[32m'Feeling good'*[39m,
108114
extraProperties: *[32m'Yes!'*[39m,
@@ -115,6 +121,7 @@ RangeError: New Stack Frames
115121
*[90m at *[39m
116122
*[90m at *[39m
117123
*[90m at *[39m
124+
*[90m at *[39m
118125
}
119126
}
120127
}
@@ -124,7 +131,7 @@ RangeError: New Stack Frames
124131
[cause]: FoobarError: Individual message
125132
at *
126133
at *
127-
... 5 lines matching cause stack trace ...
134+
... 6 lines matching cause stack trace ...
128135
at * {
129136
status: 'Feeling good',
130137
extraProperties: 'Yes!',
@@ -137,17 +144,18 @@ RangeError: New Stack Frames
137144
at *
138145
at *
139146
at *
147+
at *
140148
}
141149
}
142150
Error: Stack causes
143151
at *
144152
at *
145-
... 5 lines matching cause stack trace ...
153+
... 6 lines matching cause stack trace ...
146154
at * {
147155
[cause]: FoobarError: Individual message
148156
at *
149157
at *
150-
... 5 lines matching cause stack trace ...
158+
... 6 lines matching cause stack trace ...
151159
at *
152160
status: 'Feeling good',
153161
extraProperties: 'Yes!',
@@ -160,6 +168,7 @@ Error: Stack causes
160168
at *
161169
at *
162170
at *
171+
at *
163172
}
164173
}
165174
RangeError: New Stack Frames
@@ -168,12 +177,12 @@ RangeError: New Stack Frames
168177
[cause]: Error: Stack causes
169178
at *
170179
at *
171-
... 5 lines matching cause stack trace ...
180+
... 6 lines matching cause stack trace ...
172181
at * {
173182
[cause]: FoobarError: Individual message
174183
at *
175184
at *
176-
... 5 lines matching cause stack trace ...
185+
... 6 lines matching cause stack trace ...
177186
at * {
178187
status: 'Feeling good',
179188
extraProperties: 'Yes!',
@@ -186,6 +195,7 @@ RangeError: New Stack Frames
186195
at *
187196
at *
188197
at *
198+
at *
189199
}
190200
}
191201
}

‎test/message/util_inspect_error.out

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
at *
1010
at *
1111
at *
12+
at *
1213
nested:
1314
{ err:
1415
Error: foo
@@ -21,6 +22,7 @@
2122
at *
2223
at *
2324
at *
25+
at *
2426
{
2527
err: Error: foo
2628
bar
@@ -32,6 +34,7 @@
3234
at *
3335
at *
3436
at *
37+
at *
3538
nested: {
3639
err: Error: foo
3740
bar
@@ -43,6 +46,7 @@
4346
at *
4447
at *
4548
at *
49+
at *
4650
}
4751
}
4852
{ Error: foo
@@ -55,4 +59,5 @@ bar
5559
at *
5660
at *
5761
at *
62+
at *
5863
foo: 'bar' }

‎test/parallel/test-bootstrap-modules.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ expected.beforePreExec = new Set([
9898
'NativeModule internal/modules/package_json_reader',
9999
'Internal Binding module_wrap',
100100
'NativeModule internal/modules/cjs/loader',
101+
'NativeModule diagnostics_channel',
101102
'Internal Binding wasm_web_api',
102103
'NativeModule internal/events/abort_listener',
103104
]);
@@ -162,11 +163,11 @@ if (process.features.inspector) {
162163
expected.beforePreExec.add('Internal Binding inspector');
163164
expected.beforePreExec.add('NativeModule internal/util/inspector');
164165
expected.atRunTime.add('NativeModule internal/inspector_async_hook');
166+
}
165167

166-
// This is loaded if the test is run with NODE_V8_COVERAGE.
167-
if (process.env.NODE_V8_COVERAGE) {
168-
expected.atRunTime.add('Internal Binding profiler');
169-
}
168+
// This is loaded if the test is run with NODE_V8_COVERAGE.
169+
if (process.env.NODE_V8_COVERAGE) {
170+
expected.atRunTime.add('Internal Binding profiler');
170171
}
171172

172173
const difference = (setA, setB) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const dc = require('diagnostics_channel');
5+
6+
const trace = dc.tracingChannel('module.import');
7+
const events = [];
8+
let lastEvent;
9+
10+
function track(name) {
11+
return (event) => {
12+
// Verify every event after the first is the same object
13+
if (events.length) {
14+
assert.strictEqual(event, lastEvent);
15+
}
16+
lastEvent = event;
17+
18+
events.push({ name, ...event });
19+
};
20+
}
21+
22+
trace.subscribe({
23+
start: common.mustCall(track('start')),
24+
end: common.mustCall(track('end')),
25+
asyncStart: common.mustCall(track('asyncStart')),
26+
asyncEnd: common.mustCall(track('asyncEnd')),
27+
error: common.mustCall(track('error')),
28+
});
29+
30+
import('does-not-exist').then(
31+
common.mustNotCall(),
32+
common.mustCall((error) => {
33+
let expectedParentURL = module.filename.replaceAll('\\', '/');
34+
expectedParentURL = common.isWindows ?
35+
`file:///${expectedParentURL}` :
36+
`file://${expectedParentURL}`;
37+
// Verify order and contents of each event
38+
assert.deepStrictEqual(events, [
39+
{
40+
name: 'start',
41+
parentURL: expectedParentURL,
42+
url: 'does-not-exist',
43+
},
44+
{
45+
name: 'end',
46+
parentURL: expectedParentURL,
47+
url: 'does-not-exist',
48+
},
49+
{
50+
name: 'error',
51+
parentURL: expectedParentURL,
52+
url: 'does-not-exist',
53+
error,
54+
},
55+
{
56+
name: 'asyncStart',
57+
parentURL: expectedParentURL,
58+
url: 'does-not-exist',
59+
error,
60+
},
61+
{
62+
name: 'asyncEnd',
63+
parentURL: expectedParentURL,
64+
url: 'does-not-exist',
65+
error,
66+
},
67+
]);
68+
})
69+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const dc = require('diagnostics_channel');
5+
6+
const trace = dc.tracingChannel('module.import');
7+
const events = [];
8+
let lastEvent;
9+
10+
function track(name) {
11+
return (event) => {
12+
// Verify every event after the first is the same object
13+
if (events.length) {
14+
assert.strictEqual(event, lastEvent);
15+
}
16+
lastEvent = event;
17+
18+
events.push({ name, ...event });
19+
};
20+
}
21+
22+
trace.subscribe({
23+
start: common.mustCall(track('start')),
24+
end: common.mustCall(track('end')),
25+
asyncStart: common.mustCall(track('asyncStart')),
26+
asyncEnd: common.mustCall(track('asyncEnd')),
27+
error: common.mustNotCall(track('error')),
28+
});
29+
30+
import('http').then(
31+
common.mustCall((result) => {
32+
let expectedParentURL = module.filename.replaceAll('\\', '/');
33+
expectedParentURL = common.isWindows ?
34+
`file:///${expectedParentURL}` :
35+
`file://${expectedParentURL}`;
36+
// Verify order and contents of each event
37+
assert.deepStrictEqual(events, [
38+
{
39+
name: 'start',
40+
parentURL: expectedParentURL,
41+
url: 'http',
42+
},
43+
{
44+
name: 'end',
45+
parentURL: expectedParentURL,
46+
url: 'http',
47+
},
48+
{
49+
name: 'asyncStart',
50+
parentURL: expectedParentURL,
51+
url: 'http',
52+
result,
53+
},
54+
{
55+
name: 'asyncEnd',
56+
parentURL: expectedParentURL,
57+
url: 'http',
58+
result,
59+
},
60+
]);
61+
}),
62+
common.mustNotCall(),
63+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const dc = require('diagnostics_channel');
5+
6+
const trace = dc.tracingChannel('module.require');
7+
const events = [];
8+
let lastEvent;
9+
10+
function track(name) {
11+
return (event) => {
12+
// Verify every event after the first is the same object
13+
if (events.length) {
14+
assert.strictEqual(event, lastEvent);
15+
}
16+
lastEvent = event;
17+
18+
events.push({ name, ...event });
19+
};
20+
}
21+
22+
trace.subscribe({
23+
start: common.mustCall(track('start')),
24+
end: common.mustCall(track('end')),
25+
asyncStart: common.mustNotCall(track('asyncStart')),
26+
asyncEnd: common.mustNotCall(track('asyncEnd')),
27+
error: common.mustCall(track('error')),
28+
});
29+
30+
let error;
31+
try {
32+
require('does-not-exist');
33+
} catch (err) {
34+
error = err;
35+
}
36+
37+
// Verify order and contents of each event
38+
assert.deepStrictEqual(events, [
39+
{
40+
name: 'start',
41+
parentFilename: module.filename,
42+
id: 'does-not-exist',
43+
},
44+
{
45+
name: 'error',
46+
parentFilename: module.filename,
47+
id: 'does-not-exist',
48+
error,
49+
},
50+
{
51+
name: 'end',
52+
parentFilename: module.filename,
53+
id: 'does-not-exist',
54+
error,
55+
},
56+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const dc = require('diagnostics_channel');
5+
6+
const trace = dc.tracingChannel('module.require');
7+
const events = [];
8+
let lastEvent;
9+
10+
function track(name) {
11+
return (event) => {
12+
// Verify every event after the first is the same object
13+
if (events.length) {
14+
assert.strictEqual(event, lastEvent);
15+
}
16+
lastEvent = event;
17+
18+
events.push({ name, ...event });
19+
};
20+
}
21+
22+
trace.subscribe({
23+
start: common.mustCall(track('start')),
24+
end: common.mustCall(track('end')),
25+
asyncStart: common.mustNotCall(track('asyncStart')),
26+
asyncEnd: common.mustNotCall(track('asyncEnd')),
27+
error: common.mustNotCall(track('error')),
28+
});
29+
30+
const result = require('http');
31+
32+
// Verify order and contents of each event
33+
assert.deepStrictEqual(events, [
34+
{
35+
name: 'start',
36+
parentFilename: module.filename,
37+
id: 'http',
38+
},
39+
{
40+
name: 'end',
41+
parentFilename: module.filename,
42+
id: 'http',
43+
result,
44+
},
45+
]);

‎test/parallel/test-domain-set-uncaught-exception-capture-after-load.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
const common = require('../common');
33
const assert = require('assert');
44

5+
Error.stackTraceLimit = Infinity;
6+
57
(function foobar() {
68
require('domain');
79
})();

‎test/parallel/test-module-prototype-mutation.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
'use strict';
22
const common = require('../common');
33
const fixtures = require('../common/fixtures');
4+
const { Channel } = require('diagnostics_channel');
45
const assert = require('assert');
56

67
Object.defineProperty(Object.prototype, 'name', {
78
__proto__: null,
89
get: common.mustNotCall('get %Object.prototype%.name'),
9-
set: common.mustNotCall('set %Object.prototype%.name'),
10+
set: function(v) {
11+
// A diagnostic_channel is created to track module loading
12+
// when using `require` or `import`. This class contains a
13+
// `name` property that would cause a false alert for this
14+
// test case. See Channel.prototype.name.
15+
if (!(this instanceof Channel)) {
16+
common.mustNotCall('set %Object.prototype%.name')(v);
17+
}
18+
},
1019
enumerable: false,
1120
});
1221
Object.defineProperty(Object.prototype, 'main', {

‎test/parallel/test-repl.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -592,11 +592,12 @@ const errorTests = [
592592
/^Uncaught Error: Cannot find module 'internal\/repl'/,
593593
/^Require stack:/,
594594
/^- <repl>/,
595-
/^ {4}at .*/,
596-
/^ {4}at .*/,
597-
/^ {4}at .*/,
598-
/^ {4}at .*/,
599-
/^ {4}at .*/,
595+
/^ {4}at .*/, // at Module._resolveFilename
596+
/^ {4}at .*/, // at Module._load
597+
/^ {4}at .*/, // at TracingChannel.traceSync
598+
/^ {4}at .*/, // at wrapModuleLoad
599+
/^ {4}at .*/, // at Module.require
600+
/^ {4}at .*/, // at require
600601
" code: 'MODULE_NOT_FOUND',",
601602
" requireStack: [ '<repl>' ]",
602603
'}',

‎test/pseudo-tty/console_colors.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const vm = require('vm');
44
// Make this test OS-independent by overriding stdio getColorDepth().
55
process.stdout.getColorDepth = () => 8;
66
process.stderr.getColorDepth = () => 8;
7+
Error.stackTraceLimit = Infinity;
78

89
console.log({ foo: 'bar' });
910
console.log('%s q', 'string');

‎test/pseudo-tty/console_colors.out

+11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ foobar
1313
[90m at *[39m
1414
[90m at *[39m
1515
[90m at *[39m
16+
[90m at *[39m
1617

1718
Error: Should not ever get here.
1819
at Object.<anonymous> [90m(*node_modules*[4m*node_modules*[24m*bar.js:*:*[90m)[39m
@@ -22,9 +23,17 @@ Error: Should not ever get here.
2223
[90m at *[39m
2324
[90m at *[39m
2425
[90m at *[39m
26+
[90m at *[39m
2527
[90m at *[39m
2628
at Object.<anonymous> [90m(*console_colors.js:*:*[90m)[39m
2729
[90m at *[39m
30+
[90m at *[39m
31+
[90m at *[39m
32+
[90m at *[39m
33+
[90m at *[39m
34+
[90m at *[39m
35+
[90m at *[39m
36+
[90m at *[39m
2837

2938
Error
3039
at evalmachine.<anonymous>:*:*
@@ -37,3 +46,5 @@ Error
3746
[90m at *[39m
3847
[90m at *[39m
3948
[90m at *[39m
49+
[90m at *[39m
50+
[90m at *[39m

‎test/pseudo-tty/test-fatal-error.out

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ TypeError: foobar
88
[90m at *(node:internal*loader:*:*)[39m
99
[90m at *(node:internal*loader:*:*)[39m
1010
[90m at *(node:internal*loader:*:*)[39m
11-
[90m at *(node:internal*loader:*:*)[39m
11+
[90m at *[39m
12+
[90m at *[39m
1213
[90m at *[39m
1314
[90m at *[39m {
1415
bla: [33mtrue[39m

‎test/pseudo-tty/test-trace-sigint.out

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ KEYBOARD_INTERRUPT: Script execution was interrupted by `SIGINT`
88
at *
99
at *
1010
at *
11+
at *

0 commit comments

Comments
 (0)
Please sign in to comment.