Skip to content

Fix bugs and performance issues in JSI interpreter#31

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-performance-implementation-bugs
Draft

Fix bugs and performance issues in JSI interpreter#31
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-performance-implementation-bugs

Conversation

Copy link

Copilot AI commented Feb 27, 2026

Several correctness bugs and performance issues identified in the interpreter's runtime evaluation and object model.

Bug Fixes

  • Object literal class type (context.rs): new_object was calling create_object with ClassType::Array instead of ClassType::Object, causing {} literals to be misidentified as arrays (breaking Object.prototype.toString etc.)

  • Double expression evaluation (context.rs): In new_object, computed property names were evaluated twice — once into an unused variable x, then again for the actual name. Side-effecting expressions ran twice.

  • Logical &&/|| return values (context.rs): Both operators were coercing their result to Value::Boolean instead of returning the actual operand. JS short-circuit semantics require returning the operand value:

    null || 'default'  // was: true  → now: 'default'
    obj && obj.prop    // was: false → now: null (when obj is null)
    1 && 2             // was: true  → now: 2
  • String.prototype.charAt encoding (string.rs): u16::to_string() returns the decimal integer representation (e.g. "65" for 'A'), not the character. Fixed with char::from_u32(code as u32).

Performance Fixes

  • close_scope (context.rs): Loop over child scopes continued after finding the match. Added break.

  • Atomic ID counter (object.rs): Object::new and force_copy were doing fetch_add + load to get the new ID. fetch_add returns the previous value, so a single fetch_add(...) + 1 suffices.

Original prompt

This section details on the original issue you should resolve

<issue_title>bug fix</issue_title>
<issue_description>检测当前的实现是否存在性能和实现的bug,帮忙在尽量少改动的情况下修复问题、提升性能</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…t char encoding, and performance fixes

Co-authored-by: echosoar <14832743+echosoar@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix performance and implementation bugs Fix bugs and performance issues in JSI interpreter Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug fix

2 participants