Skip to content

feat(m4-12): P2.5 generic this coercion — String.prototype methods#65

Merged
send merged 1 commit intomainfrom
feat/m4-12-p2.5-generic-this
Apr 11, 2026
Merged

feat(m4-12): P2.5 generic this coercion — String.prototype methods#65
send merged 1 commit intomainfrom
feat/m4-12-p2.5-generic-this

Conversation

@send
Copy link
Copy Markdown
Owner

@send send commented Apr 11, 2026

Summary

Replace this_string_id (accepted only JsValue::String) with coerce_this_string (RequireObjectCoercible + ToString) for all 23 String.prototype methods. Non-string this values now work correctly:

  • null/undefined → TypeError
  • StringWrapper → unwrap
  • Other primitives (number, boolean, etc.) → ToString coercion

Example: String.prototype.indexOf.call(42, '2')1

Tests: 1460 → 1464 (+4)

Test plan

  • mise run ci — full pass
  • cargo clippy -- -D warnings — clean

🤖 Generated with Claude Code

Replace this_string_id (String-only) with coerce_this_string:
RequireObjectCoercible(this) + ToString(this). All 23 String.prototype
methods now correctly handle non-string this values:
- null/undefined → TypeError
- StringWrapper → unwrap to StringId
- other primitives → ToString coercion

String.prototype.indexOf.call(42, '2') now returns 1 (was error).
1460→1464 tests (+4: generic this coercion cases).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 11, 2026 06:35
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the VM’s String.prototype native implementations to use spec-aligned “generic this” coercion (RequireObjectCoercible + ToString) so non-string this values behave correctly (throw on null/undefined; coerce other primitives; unwrap string wrappers).

Changes:

  • Replaced the old this_string_id helper with coerce_this_string(ctx, this) -> Result<StringId, VmError>.
  • Updated multiple String.prototype native methods (core + complement set) to use the new coercion helper.
  • Added regression tests covering non-string this behavior (number/boolean coercion; null/undefined throw).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
crates/script/elidex-js/src/vm/natives_string.rs Introduces coerce_this_string and switches multiple String.prototype natives to use it.
crates/script/elidex-js/src/vm/natives_string_ext.rs Switches String.prototype “complement” natives to use coerce_this_string.
crates/script/elidex-js/src/vm/tests/tests_string_complement.rs Adds tests for generic this coercion behavior on String.prototype methods.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@send send merged commit 96f6fe5 into main Apr 11, 2026
13 checks passed
@send send deleted the feat/m4-12-p2.5-generic-this branch April 11, 2026 06:45
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.

2 participants