Skip to content

Commit 5a4f767

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

File tree

2 files changed

+57
-17
lines changed

2 files changed

+57
-17
lines changed

lib/internal/debugger/inspect_repl.js

+50-10
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,52 @@ 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 'set': {
230+
if (!this.entries) {
231+
return `${this.description} ${this.overflow ? '{ ... }' : '{}'}`;
232+
}
233+
const values = ArrayPrototypeMap(this.entries, (entry) =>
234+
utilInspect(new ObjectPreview(entry.value), opts));
235+
return `${this.description} { ${ArrayPrototypeJoin(values, ', ')} }`;
236+
}
237+
case 'map': {
238+
if (!this.entries) {
239+
return `${this.description} ${this.overflow ? '{ ... }' : '{}'}`;
240+
}
241+
const mappings = ArrayPrototypeMap(this.entries, (entry) => {
242+
const key = utilInspect(new ObjectPreview(entry.key), opts);
243+
const value = utilInspect(new ObjectPreview(entry.value), opts);
244+
return `${key} => ${value}`;
245+
});
246+
return `${this.description} { ${ArrayPrototypeJoin(mappings, ', ')} }`;
247+
}
248+
case 'array':
249+
case undefined: {
250+
if (this.properties.length === 0) {
251+
return this.subtype === 'array' ? '[]' : '{}';
252+
}
253+
const props = ArrayPrototypeMap(this.properties, (prop, idx) => {
254+
const value = utilInspect(new PropertyPreview(prop));
255+
if (prop.name === `${idx}`) return value;
256+
return `${prop.name}: ${value}`;
257+
});
258+
if (this.overflow) {
259+
ArrayPrototypePush(props, '...');
260+
}
261+
const singleLine = ArrayPrototypeJoin(props, ', ');
262+
const propString = singleLine.length > 60 ? ArrayPrototypeJoin(props, ',\n ') : singleLine;
263+
return this.subtype === 'array' ? `[ ${propString} ]` : `{ ${propString} }`;
264+
}
265+
default:
266+
return this.description;
229267
}
230-
const singleLine = ArrayPrototypeJoin(props, ', ');
231-
const propString = singleLine.length > 60 ? ArrayPrototypeJoin(props, ',\n ') : singleLine;
232-
return this.subtype === 'array' ? `[ ${propString} ]` : `{ ${propString} }`;
233268
}
234269
default:
235270
return this.description;
@@ -268,6 +303,11 @@ class RemoteObject {
268303
return utilInspect(null, opts);
269304
case 'regexp':
270305
return opts.stylize(this.description, 'regexp');
306+
case 'map':
307+
case 'set': {
308+
const preview = utilInspect(new ObjectPreview(this.preview), opts);
309+
return `${this.description} ${preview}`;
310+
}
271311
default:
272312
break;
273313
}

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)