Skip to content

runtime/object-model: pass correct this binding to callback invocations such as String.replace #3578

Closed

Description

@andrewtdiz

Summary

Built-ins that invoke user callbacks pass the correct callback this value and arguments, including String.prototype.replace replacement callbacks.

Affected Test262 rows

Perry actual behavior from report

  • 1 x runtime-fail: Uncaught exception: "ab".replace("b", f) Expected SameValue(«"a\u0000"», «"aa"») to be true
  • 1 x runtime-fail: Uncaught exception: Expected SameValue(«"a\u0000"», «"aa"») to be true

Node / ECMAScript expected behavior

Built-ins that invoke user callbacks pass the correct callback this value and arguments, including String.prototype.replace replacement callbacks.

Likely subsystem

built-in callback dispatch / implicit this handling

Acceptance criteria

  • The String.replace callback rows produce "aa" rather than NUL/undefined-derived output.
  • Strict and sloppy callback forms agree with Node.
  • Existing replacement-string behavior does not regress.

Validation

Run the Test262 differential against the affected area and confirm these rows leave the gap report:

scripts/test262_subset.py --root vendor/test262 --dir language/function-code --sample-cap 99999 --report /tmp/FUNC_CALLBACK_THIS.json

This is Perry language/runtime semantics triage, not a Node core API compatibility issue.

Activity

  1. proggeramlug commented on Jun 3, 2026

    @proggeramlug
    Contributor

    Verified resolved against current main (built fresh from origin/main, 207 commits ahead of an older checkout) and compared byte-for-byte to node --experimental-strip-types. Callback this-binding for String.replace matches node: ab.replace(b, fn) and the regex-pattern callback form both produce node-identical output with no NUL/undefined-derived results. Closing as resolved.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions