From 148c89dd316309ff52312bc2403c9258b725d929 Mon Sep 17 00:00:00 2001 From: Kosolpattanadurong Thitiwat Date: Thu, 12 Jun 2025 02:45:34 +0800 Subject: [PATCH 1/2] fix stepper issues --- src/tracer/builtins/index.ts | 2 +- src/tracer/nodes/Expression/BinaryExpression.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tracer/builtins/index.ts b/src/tracer/builtins/index.ts index e82a28a0e..d4c1c7f77 100644 --- a/src/tracer/builtins/index.ts +++ b/src/tracer/builtins/index.ts @@ -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') } }) diff --git a/src/tracer/nodes/Expression/BinaryExpression.ts b/src/tracer/nodes/Expression/BinaryExpression.ts index 4a3c63d64..535e5b2e7 100644 --- a/src/tracer/nodes/Expression/BinaryExpression.ts +++ b/src/tracer/nodes/Expression/BinaryExpression.ts @@ -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, From 7bb818a588f641357b5f7149af01640c5fe349a5 Mon Sep 17 00:00:00 2001 From: Kosolpattanadurong Thitiwat Date: Thu, 12 Jun 2025 03:19:25 +0800 Subject: [PATCH 2/2] fix: snapshot update --- .../__snapshots__/tracer_full.ts.snap | 28 +++++++++++++------ src/tracer/__tests__/tracer_debug.ts | 8 +----- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/tracer/__tests__/__snapshots__/tracer_full.ts.snap b/src/tracer/__tests__/__snapshots__/tracer_full.ts.snap index 3c704354f..c9f65cdce 100644 --- a/src/tracer/__tests__/__snapshots__/tracer_full.ts.snap +++ b/src/tracer/__tests__/__snapshots__/tracer_full.ts.snap @@ -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 " `; @@ -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 " `; @@ -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 " `; diff --git a/src/tracer/__tests__/tracer_debug.ts b/src/tracer/__tests__/tracer_debug.ts index 8182e792f..1d1e7227f 100644 --- a/src/tracer/__tests__/tracer_debug.ts +++ b/src/tracer/__tests__/tracer_debug.ts @@ -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 })