Skip to content

Commit 519aacc

Browse files
Lms24Luca Forstner
andauthored
fix(node): Record local variables with falsy values, null and undefined (#10821)
We previously didn't record local local variables with falsy values because we checked for truthiness instead of definedness when unrolling and serializing the variable values. This PR changes how we check for and extract variable properties to record - falsy values (`0`, `''`, `false`) - `null` - `undefined` --------- Co-authored-by: Luca Forstner <[email protected]>
1 parent baa6ba4 commit 519aacc

File tree

10 files changed

+84
-18
lines changed

10 files changed

+84
-18
lines changed

dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables-caught.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ function one(name) {
2020
name,
2121
num: 5,
2222
};
23+
const bool = false;
24+
const num = 0;
25+
const str = '';
26+
const something = undefined;
27+
const somethingElse = null;
2328

2429
const ty = new Some();
2530

dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables-caught.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ function one(name) {
2222
functionsShouldNotBeIncluded: () => {},
2323
functionsShouldNotBeIncluded2() {},
2424
};
25+
const bool = false;
26+
const num = 0;
27+
const str = '';
28+
const something = undefined;
29+
const somethingElse = null;
2530

2631
const ty = new Some();
2732

dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables-memory-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ function one(name) {
2222
name,
2323
num: 5,
2424
};
25+
const bool = false;
26+
const num = 0;
27+
const str = '';
28+
const something = undefined;
29+
const somethingElse = null;
2530

2631
const ty = new Some();
2732

dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ function one(name) {
2424
name,
2525
num: 5,
2626
};
27+
const bool = false;
28+
const num = 0;
29+
const str = '';
30+
const something = undefined;
31+
const somethingElse = null;
2732

2833
const ty = new Some();
2934

dev-packages/node-integration-tests/suites/public-api/LocalVariables/no-local-variables.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ function one(name) {
2323
name,
2424
num: 5,
2525
};
26+
const bool = false;
27+
const num = 0;
28+
const str = '';
29+
const something = undefined;
30+
const somethingElse = null;
2631

2732
const ty = new Some();
2833

dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ const EXPECTED_LOCAL_VARIABLES_EVENT = {
1616
arr: [1, '2', null],
1717
obj: { name: 'some name', num: 5 },
1818
ty: '<Some>',
19+
bool: false,
20+
num: 0,
21+
str: '',
22+
something: '<undefined>',
23+
somethingElse: '<null>',
1924
},
2025
}),
2126
expect.objectContaining({

packages/node-experimental/src/integrations/local-variables/local-variables-async.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,20 @@ async function unrollObject(session: Session, objectId: string, name: string, va
4242
}
4343

4444
function unrollOther(prop: Runtime.PropertyDescriptor, vars: Variables): void {
45-
if (prop?.value?.value) {
46-
vars[prop.name] = prop.value.value;
47-
} else if (prop?.value?.description && prop?.value?.type !== 'function') {
45+
if (!prop.value) {
46+
return;
47+
}
48+
49+
if ('value' in prop.value) {
50+
if (prop.value.value === undefined || prop.value.value === null) {
51+
vars[prop.name] = `<${prop.value.value}>`;
52+
} else {
53+
vars[prop.name] = prop.value.value;
54+
}
55+
} else if ('description' in prop.value && prop.value.type !== 'function') {
4856
vars[prop.name] = `<${prop.value.description}>`;
57+
} else if (prop.value.type === 'undefined') {
58+
vars[prop.name] = '<undefined>';
4959
}
5060
}
5161

@@ -63,7 +73,7 @@ async function getLocalVariables(session: Session, objectId: string): Promise<Va
6373
} else if (prop?.value?.objectId && prop?.value?.className === 'Object') {
6474
const id = prop.value.objectId;
6575
await unrollObject(session, id, prop.name, variables);
66-
} else if (prop?.value?.value || prop?.value?.description) {
76+
} else if (prop?.value) {
6777
unrollOther(prop, variables);
6878
}
6979
}

packages/node-experimental/src/integrations/local-variables/local-variables-sync.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class AsyncSession implements DebugSession {
128128
} else if (prop?.value?.objectId && prop?.value?.className === 'Object') {
129129
const id = prop.value.objectId;
130130
add(vars => this._unrollObject(id, prop.name, vars, next));
131-
} else if (prop?.value?.value || prop?.value?.description) {
131+
} else if (prop?.value) {
132132
add(vars => this._unrollOther(prop, vars, next));
133133
}
134134
}
@@ -191,10 +191,18 @@ class AsyncSession implements DebugSession {
191191
* Unrolls other properties
192192
*/
193193
private _unrollOther(prop: Runtime.PropertyDescriptor, vars: Variables, next: (vars: Variables) => void): void {
194-
if (prop?.value?.value) {
195-
vars[prop.name] = prop.value.value;
196-
} else if (prop?.value?.description && prop?.value?.type !== 'function') {
197-
vars[prop.name] = `<${prop.value.description}>`;
194+
if (prop.value) {
195+
if ('value' in prop.value) {
196+
if (prop.value.value === undefined || prop.value.value === null) {
197+
vars[prop.name] = `<${prop.value.value}>`;
198+
} else {
199+
vars[prop.name] = prop.value.value;
200+
}
201+
} else if ('description' in prop.value && prop.value.type !== 'function') {
202+
vars[prop.name] = `<${prop.value.description}>`;
203+
} else if (prop.value.type === 'undefined') {
204+
vars[prop.name] = '<undefined>';
205+
}
198206
}
199207

200208
next(vars);

packages/node/src/integrations/local-variables/local-variables-async.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,20 @@ async function unrollObject(session: Session, objectId: string, name: string, va
4242
}
4343

4444
function unrollOther(prop: Runtime.PropertyDescriptor, vars: Variables): void {
45-
if (prop?.value?.value) {
46-
vars[prop.name] = prop.value.value;
47-
} else if (prop?.value?.description && prop?.value?.type !== 'function') {
45+
if (!prop.value) {
46+
return;
47+
}
48+
49+
if ('value' in prop.value) {
50+
if (prop.value.value === undefined || prop.value.value === null) {
51+
vars[prop.name] = `<${prop.value.value}>`;
52+
} else {
53+
vars[prop.name] = prop.value.value;
54+
}
55+
} else if ('description' in prop.value && prop.value.type !== 'function') {
4856
vars[prop.name] = `<${prop.value.description}>`;
57+
} else if (prop.value.type === 'undefined') {
58+
vars[prop.name] = '<undefined>';
4959
}
5060
}
5161

@@ -63,7 +73,7 @@ async function getLocalVariables(session: Session, objectId: string): Promise<Va
6373
} else if (prop?.value?.objectId && prop?.value?.className === 'Object') {
6474
const id = prop.value.objectId;
6575
await unrollObject(session, id, prop.name, variables);
66-
} else if (prop?.value?.value || prop?.value?.description) {
76+
} else if (prop?.value) {
6777
unrollOther(prop, variables);
6878
}
6979
}

packages/node/src/integrations/local-variables/local-variables-sync.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class AsyncSession implements DebugSession {
129129
} else if (prop?.value?.objectId && prop?.value?.className === 'Object') {
130130
const id = prop.value.objectId;
131131
add(vars => this._unrollObject(id, prop.name, vars, next));
132-
} else if (prop?.value?.value || prop?.value?.description) {
132+
} else if (prop?.value) {
133133
add(vars => this._unrollOther(prop, vars, next));
134134
}
135135
}
@@ -192,10 +192,18 @@ class AsyncSession implements DebugSession {
192192
* Unrolls other properties
193193
*/
194194
private _unrollOther(prop: Runtime.PropertyDescriptor, vars: Variables, next: (vars: Variables) => void): void {
195-
if (prop?.value?.value) {
196-
vars[prop.name] = prop.value.value;
197-
} else if (prop?.value?.description && prop?.value?.type !== 'function') {
198-
vars[prop.name] = `<${prop.value.description}>`;
195+
if (prop.value) {
196+
if ('value' in prop.value) {
197+
if (prop.value.value === undefined || prop.value.value === null) {
198+
vars[prop.name] = `<${prop.value.value}>`;
199+
} else {
200+
vars[prop.name] = prop.value.value;
201+
}
202+
} else if ('description' in prop.value && prop.value.type !== 'function') {
203+
vars[prop.name] = `<${prop.value.description}>`;
204+
} else if (prop.value.type === 'undefined') {
205+
vars[prop.name] = '<undefined>';
206+
}
199207
}
200208

201209
next(vars);

0 commit comments

Comments
 (0)