Skip to content

fix stepper issues #1761

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 3 commits into from
Jun 12, 2025
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
28 changes: 20 additions & 8 deletions src/tracer/__tests__/__snapshots__/tracer_full.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4604,10 +4604,13 @@ exports[`Builtin math negative numbers as arguments 1`] = `
[noMarker] Start of evaluation

math_sin(-1);
[beforeMarker] Math functions must be called with number arguments
[beforeMarker] math_sin runs

math_sin(-1);
[noMarker] Evaluation stuck
-0.8414709848078965;
[afterMarker] math_sin runs

-0.8414709848078965;
[noMarker] Evaluation complete
"
`;

Expand Down Expand Up @@ -17600,9 +17603,15 @@ exports[`SOURCE 0 (Tests from previous stepper) math_pow 1`] = `
[noMarker] Start of evaluation

math_pow(2, 20) || NaN;
[beforeMarker] Math functions must be called with number arguments
[beforeMarker] math_pow runs

math_pow(2, 20) || NaN;
1048576 || NaN;
[afterMarker] math_pow runs

1048576 || NaN;
[beforeMarker] Line 2: Expected boolean on left hand side of operation, got number.

1048576 || NaN;
[noMarker] Evaluation stuck
"
`;
Expand All @@ -17612,10 +17621,13 @@ exports[`SOURCE 0 (Tests from previous stepper) plus undefined 1`] = `
[noMarker] Start of evaluation

math_sin(1) + undefined;
[beforeMarker] Math functions must be called with number arguments
[beforeMarker] math_sin runs

math_sin(1) + undefined;
[noMarker] Evaluation stuck
0.8414709848078965 + undefined;
[afterMarker] math_sin runs

0.8414709848078965 + undefined;
[noMarker] Evaluation complete
"
`;

Expand Down
8 changes: 1 addition & 7 deletions src/tracer/__tests__/tracer_debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,7 @@ test('function calling', () => {

test('general', () => {
const code = `
if (1 !== 1) {
2;
} else if (2 === 2) {
3;
} else {
1;
}
math_sqrt("TEST");
`
const program = parse(code, { ecmaVersion: 10, locations: true })!
const steps = getSteps(convert(program), createContext(2), { stepLimit: 200 })
Expand Down
2 changes: 1 addition & 1 deletion src/tracer/builtins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function getBuiltinFunction(name: string, args: StepperExpression[]): Ste
const fn = (Math as any)[mathFnName]
const argVal = args.map(arg => (arg as StepperLiteral).value)
argVal.forEach(arg => {
if (typeof arg !== 'number' || typeof arg !== 'bigint') {
if (typeof arg !== 'number' && typeof arg !== 'bigint') {
throw new Error('Math functions must be called with number arguments')
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/tracer/nodes/Expression/BinaryExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class StepperBinaryExpression implements BinaryExpression, StepperBaseNod

let ret = new StepperLiteral(
value,
value !== null ? value.toString() : 'null',
typeof value === 'string' ? '"' + value + '"' : value !== null ? value.toString() : 'null',
undefined,
undefined,
this.loc,
Expand Down
Loading