Skip to content

Commit ee06d0c

Browse files
fix stepper issues (#1761)
* fix stepper issues * fix: snapshot update --------- Co-authored-by: Martin Henz <[email protected]>
1 parent a32e05e commit ee06d0c

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

src/tracer/__tests__/__snapshots__/tracer_full.ts.snap

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4604,10 +4604,13 @@ exports[`Builtin math negative numbers as arguments 1`] = `
46044604
[noMarker] Start of evaluation
46054605

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

4609-
math_sin(-1);
4610-
[noMarker] Evaluation stuck
4609+
-0.8414709848078965;
4610+
[afterMarker] math_sin runs
4611+
4612+
-0.8414709848078965;
4613+
[noMarker] Evaluation complete
46114614
"
46124615
`;
46134616

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

1760217605
math_pow(2, 20) || NaN;
17603-
[beforeMarker] Math functions must be called with number arguments
17606+
[beforeMarker] math_pow runs
1760417607

17605-
math_pow(2, 20) || NaN;
17608+
1048576 || NaN;
17609+
[afterMarker] math_pow runs
17610+
17611+
1048576 || NaN;
17612+
[beforeMarker] Line 2: Expected boolean on left hand side of operation, got number.
17613+
17614+
1048576 || NaN;
1760617615
[noMarker] Evaluation stuck
1760717616
"
1760817617
`;
@@ -17612,10 +17621,13 @@ exports[`SOURCE 0 (Tests from previous stepper) plus undefined 1`] = `
1761217621
[noMarker] Start of evaluation
1761317622

1761417623
math_sin(1) + undefined;
17615-
[beforeMarker] Math functions must be called with number arguments
17624+
[beforeMarker] math_sin runs
1761617625

17617-
math_sin(1) + undefined;
17618-
[noMarker] Evaluation stuck
17626+
0.8414709848078965 + undefined;
17627+
[afterMarker] math_sin runs
17628+
17629+
0.8414709848078965 + undefined;
17630+
[noMarker] Evaluation complete
1761917631
"
1762017632
`;
1762117633

src/tracer/__tests__/tracer_debug.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,7 @@ test('function calling', () => {
9595

9696
test('general', () => {
9797
const code = `
98-
if (1 !== 1) {
99-
2;
100-
} else if (2 === 2) {
101-
3;
102-
} else {
103-
1;
104-
}
98+
math_sqrt("TEST");
10599
`
106100
const program = parse(code, { ecmaVersion: 10, locations: true })!
107101
const steps = getSteps(convert(program), createContext(2), { stepLimit: 200 })

src/tracer/builtins/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function getBuiltinFunction(name: string, args: StepperExpression[]): Ste
5959
const fn = (Math as any)[mathFnName]
6060
const argVal = args.map(arg => (arg as StepperLiteral).value)
6161
argVal.forEach(arg => {
62-
if (typeof arg !== 'number' || typeof arg !== 'bigint') {
62+
if (typeof arg !== 'number' && typeof arg !== 'bigint') {
6363
throw new Error('Math functions must be called with number arguments')
6464
}
6565
})

src/tracer/nodes/Expression/BinaryExpression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class StepperBinaryExpression implements BinaryExpression, StepperBaseNod
155155

156156
let ret = new StepperLiteral(
157157
value,
158-
value !== null ? value.toString() : 'null',
158+
typeof value === 'string' ? '"' + value + '"' : value !== null ? value.toString() : 'null',
159159
undefined,
160160
undefined,
161161
this.loc,

0 commit comments

Comments
 (0)