Skip to content

fix(node): Record local variables with falsy values, null and undefined #10821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ function one(name) {
name,
num: 5,
};
const bool = false;
const num = 0;
const str = '';
const something = undefined;
const somethingElse = null;

const ty = new Some();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ function one(name) {
functionsShouldNotBeIncluded: () => {},
functionsShouldNotBeIncluded2() {},
};
const bool = false;
const num = 0;
const str = '';
const something = undefined;
const somethingElse = null;

const ty = new Some();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ function one(name) {
name,
num: 5,
};
const bool = false;
const num = 0;
const str = '';
const something = undefined;
const somethingElse = null;

const ty = new Some();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ function one(name) {
name,
num: 5,
};
const bool = false;
const num = 0;
const str = '';
const something = undefined;
const somethingElse = null;

const ty = new Some();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ function one(name) {
name,
num: 5,
};
const bool = false;
const num = 0;
const str = '';
const something = undefined;
const somethingElse = null;

const ty = new Some();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const EXPECTED_LOCAL_VARIABLES_EVENT = {
arr: [1, '2', null],
obj: { name: 'some name', num: 5 },
ty: '<Some>',
bool: false,
num: 0,
Copy link
Member Author

@Lms24 Lms24 Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of a number, we would previously report '<0>' instead of 0. I think changing this should be okay but wanted to double check if there are implications to this change. Anyone have an idea?

str: '',
something: '<undefined>',
somethingElse: '<null>',
},
}),
expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,20 @@ async function unrollObject(session: Session, objectId: string, name: string, va
}

function unrollOther(prop: Runtime.PropertyDescriptor, vars: Variables): void {
if (prop?.value?.value) {
vars[prop.name] = prop.value.value;
} else if (prop?.value?.description && prop?.value?.type !== 'function') {
if (!prop.value) {
return;
}

if ('value' in prop.value) {
if (prop.value.value === undefined || prop.value.value === null) {
vars[prop.name] = `<${prop.value.value}>`;
} else {
vars[prop.name] = prop.value.value;
}
} else if ('description' in prop.value && prop.value.type !== 'function') {
vars[prop.name] = `<${prop.value.description}>`;
} else if (prop.value.type === 'undefined') {
vars[prop.name] = '<undefined>';
}
}

Expand All @@ -63,7 +73,7 @@ async function getLocalVariables(session: Session, objectId: string): Promise<Va
} else if (prop?.value?.objectId && prop?.value?.className === 'Object') {
const id = prop.value.objectId;
await unrollObject(session, id, prop.name, variables);
} else if (prop?.value?.value || prop?.value?.description) {
} else if (prop?.value) {
unrollOther(prop, variables);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class AsyncSession implements DebugSession {
} else if (prop?.value?.objectId && prop?.value?.className === 'Object') {
const id = prop.value.objectId;
add(vars => this._unrollObject(id, prop.name, vars, next));
} else if (prop?.value?.value || prop?.value?.description) {
} else if (prop?.value) {
add(vars => this._unrollOther(prop, vars, next));
}
}
Expand Down Expand Up @@ -191,10 +191,18 @@ class AsyncSession implements DebugSession {
* Unrolls other properties
*/
private _unrollOther(prop: Runtime.PropertyDescriptor, vars: Variables, next: (vars: Variables) => void): void {
if (prop?.value?.value) {
vars[prop.name] = prop.value.value;
} else if (prop?.value?.description && prop?.value?.type !== 'function') {
vars[prop.name] = `<${prop.value.description}>`;
if (prop.value) {
if ('value' in prop.value) {
if (prop.value.value === undefined || prop.value.value === null) {
vars[prop.name] = `<${prop.value.value}>`;
} else {
vars[prop.name] = prop.value.value;
}
} else if ('description' in prop.value && prop.value.type !== 'function') {
vars[prop.name] = `<${prop.value.description}>`;
} else if (prop.value.type === 'undefined') {
vars[prop.name] = '<undefined>';
}
}

next(vars);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,20 @@ async function unrollObject(session: Session, objectId: string, name: string, va
}

function unrollOther(prop: Runtime.PropertyDescriptor, vars: Variables): void {
if (prop?.value?.value) {
vars[prop.name] = prop.value.value;
} else if (prop?.value?.description && prop?.value?.type !== 'function') {
if (!prop.value) {
return;
}

if ('value' in prop.value) {
if (prop.value.value === undefined || prop.value.value === null) {
vars[prop.name] = `<${prop.value.value}>`;
} else {
vars[prop.name] = prop.value.value;
}
} else if ('description' in prop.value && prop.value.type !== 'function') {
vars[prop.name] = `<${prop.value.description}>`;
} else if (prop.value.type === 'undefined') {
vars[prop.name] = '<undefined>';
}
}

Expand All @@ -63,7 +73,7 @@ async function getLocalVariables(session: Session, objectId: string): Promise<Va
} else if (prop?.value?.objectId && prop?.value?.className === 'Object') {
const id = prop.value.objectId;
await unrollObject(session, id, prop.name, variables);
} else if (prop?.value?.value || prop?.value?.description) {
} else if (prop?.value) {
unrollOther(prop, variables);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class AsyncSession implements DebugSession {
} else if (prop?.value?.objectId && prop?.value?.className === 'Object') {
const id = prop.value.objectId;
add(vars => this._unrollObject(id, prop.name, vars, next));
} else if (prop?.value?.value || prop?.value?.description) {
} else if (prop?.value) {
add(vars => this._unrollOther(prop, vars, next));
}
}
Expand Down Expand Up @@ -192,10 +192,18 @@ class AsyncSession implements DebugSession {
* Unrolls other properties
*/
private _unrollOther(prop: Runtime.PropertyDescriptor, vars: Variables, next: (vars: Variables) => void): void {
if (prop?.value?.value) {
vars[prop.name] = prop.value.value;
} else if (prop?.value?.description && prop?.value?.type !== 'function') {
vars[prop.name] = `<${prop.value.description}>`;
if (prop.value) {
if ('value' in prop.value) {
if (prop.value.value === undefined || prop.value.value === null) {
vars[prop.name] = `<${prop.value.value}>`;
} else {
vars[prop.name] = prop.value.value;
}
} else if ('description' in prop.value && prop.value.type !== 'function') {
vars[prop.name] = `<${prop.value.description}>`;
} else if (prop.value.type === 'undefined') {
vars[prop.name] = '<undefined>';
}
}

next(vars);
Expand Down