Skip to content

Commit a69bc81

Browse files
committed
debugger: add serializers for Map and Set of RemoteObject
1 parent 7820dd4 commit a69bc81

File tree

2 files changed

+52
-17
lines changed

2 files changed

+52
-17
lines changed

lib/internal/debugger/inspect_repl.js

+45-10
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,33 @@ class ObjectPreview {
219219
[customInspectSymbol](depth, opts) {
220220
switch (this.type) {
221221
case 'object': {
222-
const props = ArrayPrototypeMap(this.properties, (prop, idx) => {
223-
const value = utilInspect(new PropertyPreview(prop));
224-
if (prop.name === `${idx}`) return value;
225-
return `${prop.name}: ${value}`;
226-
});
227-
if (this.overflow) {
228-
ArrayPrototypePush(props, '...');
222+
switch (this.subtype) {
223+
case 'date':
224+
return utilInspect(new Date(this.description), opts);
225+
case 'null':
226+
return utilInspect(null, opts);
227+
case 'regexp':
228+
return opts.stylize(this.description, 'regexp');
229+
case 'array':
230+
case undefined: {
231+
if (this.properties.length === 0) {
232+
return this.subtype === 'array' ? '[]' : '{}';
233+
}
234+
const props = ArrayPrototypeMap(this.properties, (prop, idx) => {
235+
const value = utilInspect(new PropertyPreview(prop));
236+
if (prop.name === `${idx}`) return value;
237+
return `${prop.name}: ${value}`;
238+
});
239+
if (this.overflow) {
240+
ArrayPrototypePush(props, '...');
241+
}
242+
const singleLine = ArrayPrototypeJoin(props, ', ');
243+
const propString = singleLine.length > 60 ? ArrayPrototypeJoin(props, ',\n ') : singleLine;
244+
return this.subtype === 'array' ? `[ ${propString} ]` : `{ ${propString} }`;
245+
}
246+
default:
247+
return this.description;
229248
}
230-
const singleLine = ArrayPrototypeJoin(props, ', ');
231-
const propString = singleLine.length > 60 ? ArrayPrototypeJoin(props, ',\n ') : singleLine;
232-
return this.subtype === 'array' ? `[ ${propString} ]` : `{ ${propString} }`;
233249
}
234250
default:
235251
return this.description;
@@ -268,6 +284,25 @@ class RemoteObject {
268284
return utilInspect(null, opts);
269285
case 'regexp':
270286
return opts.stylize(this.description, 'regexp');
287+
case 'set': {
288+
if (!this.preview.entries) {
289+
return `${this.description} {}`;
290+
}
291+
const values = ArrayPrototypeMap(this.preview.entries, (entry) =>
292+
utilInspect(new ObjectPreview(entry.value), opts));
293+
return `${this.description} { ${ArrayPrototypeJoin(values, ', ')} }`;
294+
}
295+
case 'map': {
296+
if (!this.preview.entries) {
297+
return `${this.description} {}`;
298+
}
299+
const mappings = ArrayPrototypeMap(this.preview.entries, (entry) => {
300+
const key = utilInspect(new ObjectPreview(entry.key), opts);
301+
const value = utilInspect(new ObjectPreview(entry.value), opts);
302+
return `${key} => ${value}`;
303+
});
304+
return `${this.description} { ${ArrayPrototypeJoin(mappings, ', ')} }`;
305+
}
271306
default:
272307
break;
273308
}

test/parallel/test-debugger-object-type-remote-object.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ cli.waitForInitialBreak()
2424
.then(() => cli.command('exec /regex/g'))
2525
.then(() => assert.match(cli.output, /\/regex\/g/))
2626
.then(() => cli.command('exec new Map()'))
27-
.then(() => assert.match(cli.output, /{ size: 0 }/))
27+
.then(() => assert.match(cli.output, /Map\(0\) {}/))
2828
.then(() => cli.command('exec new Map([["a",1],["b",2]])'))
29-
.then(() => assert.match(cli.output, /{ size: 2 }/))
29+
.then(() => assert.match(cli.output, /Map\(2\) { a => 1, b => 2 }/))
3030
.then(() => cli.command('exec new Set()'))
31-
.then(() => assert.match(cli.output, /{ size: 0 }/))
31+
.then(() => assert.match(cli.output, /Set\(0\) {}/))
3232
.then(() => cli.command('exec new Set([1,2])'))
33-
.then(() => assert.match(cli.output, /{ size: 2 }/))
33+
.then(() => assert.match(cli.output, /Set\(2\) { 1, 2 }/))
3434
.then(() => cli.command('exec new Set([{a:1},new Set([1])])'))
35-
.then(() => assert.match(cli.output, /{ size: 2 }/))
35+
.then(() => assert.match(cli.output, /Set\(2\) { { a: 1 }, Set\(1\) }/))
3636
.then(() => cli.command('exec a={}; a'))
37-
.then(() => assert.match(cli.output, /{ {2}}/))
37+
.then(() => assert.match(cli.output, /{}/))
3838
.then(() => cli.command('exec a={a:1,b:{c:1}}; a'))
3939
.then(() => assert.match(cli.output, /{ a: 1, b: Object }/))
4040
.then(() => cli.command('exec a=[]; a'))
41-
.then(() => assert.match(cli.output, /\[ {2}\]/))
41+
.then(() => assert.match(cli.output, /\[\]/))
4242
.then(() => cli.command('exec a=[1,2]; a'))
4343
.then(() => assert.match(cli.output, /\[ 1, 2 \]/))
4444
.then(() => cli.quit())

0 commit comments

Comments
 (0)