Skip to content

Add JavaScript S-expression execution engine#52

Open
rogeralsing wants to merge 12 commits intomainfrom
codex/create-js-execution-engine-in-c#-4704ws
Open

Add JavaScript S-expression execution engine#52
rogeralsing wants to merge 12 commits intomainfrom
codex/create-js-execution-engine-in-c#-4704ws

Conversation

@rogeralsing
Copy link
Copy Markdown
Contributor

@rogeralsing rogeralsing commented Nov 6, 2025

Summary

  • add the Asynkron.JsEngine library that lexes JavaScript into S-expressions and evaluates them with Lisp-like semantics
  • expose a JsEngine facade, cons cell primitives, and environments with documentation updates
  • create Asynkron.JsEngine.Tests to validate parsing, evaluation, closures, and host interop

Testing

  • dotnet build Asynkron.OTelMCP.sln
  • dotnet test Asynkron.OTelMCP.sln

https://chatgpt.com/codex/tasks/task_e_690d1332a964832893299aeb69ca57f3


Note

Introduces Asynkron.JsEngine to parse JavaScript into S-expressions and evaluate with JS-like semantics, plus comprehensive tests and solution/docs wiring.

  • New library src/Asynkron.JsEngine:
    • Core runtime: Lexer, Parser -> S-expressions (Cons, Symbol, JsSymbols); Evaluator with lexical Environment and control signals.
    • Language features: variables (let/var/const), functions/closures, object/array literals (JsObject/JsArray), property/index ops, new, classes with extends/super, control flow (if/for/while/do-while/switch/try-catch-finally), logical/equality operators; host interop via HostFunction; public JsEngine façade.
  • Tests tests/Asynkron.JsEngine.Tests: xUnit coverage for parsing, evaluation, closures, interop, arrays/objects, classes/inheritance, control flow, operators.
  • Solution/Docs: add projects to Asynkron.OTelMCP.sln; update src/context.md; add Asynkron.JsEngine/context.md and tests context.

Written by Cursor Bugbot for commit 323088b. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Comment thread src/Asynkron.JsEngine/Lexer.cs
"+" => Add(left, right),
"-" => ToNumber(left) - ToNumber(right),
"*" => ToNumber(left) * ToNumber(right),
"/" => ToNumber(right) == 0 ? throw new DivideByZeroException() : ToNumber(left) / ToNumber(right),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Floating-Point Zero-Check Fails Near-Zero Values

Division by zero check compares floating-point ToNumber(right) using exact equality with 0, which can fail due to floating-point precision issues. Values very close to zero but not exactly zero may incorrectly pass the check, while the division itself could still produce infinity or unexpected results.

Fix in Cursor Fix in Web

@asynkron asynkron deleted a comment from cursor bot Nov 7, 2025
Comment thread src/Asynkron.JsEngine/Lexer.cs
"+" => Add(left, right),
"-" => ToNumber(left) - ToNumber(right),
"*" => ToNumber(left) * ToNumber(right),
"/" => ToNumber(right) == 0 ? throw new DivideByZeroException() : ToNumber(left) / ToNumber(right),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Arithmetic division by zero throws exception instead of Infinity

Division by zero throws DivideByZeroException instead of returning Infinity like JavaScript. In JavaScript, dividing by zero produces Infinity or -Infinity, not an exception. This breaks JavaScript semantics and will cause runtime errors for valid JavaScript code like 1/0.

Fix in Cursor Fix in Web

SetPrototype(value);
}

this[name] = value;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Redundant Dictionary Update After SetPrototype Call

SetProperty always sets the dictionary entry on line 49 even after calling SetPrototype for __proto__. Since SetPrototype already updates the dictionary, this redundantly overwrites the same value. The method needs a return after line 46 or an else clause to avoid the redundant assignment.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant