Skip to content

Added tests for ToString throwing in String.prototype methods#4887

Merged
ptomato merged 1 commit intotc39:mainfrom
G-Lee1031:tostring-throws0126
Feb 3, 2026
Merged

Added tests for ToString throwing in String.prototype methods#4887
ptomato merged 1 commit intotc39:mainfrom
G-Lee1031:tostring-throws0126

Conversation

@G-Lee1031
Copy link
Copy Markdown
Contributor

Hello.
This PR adds tests covering two cases where ToString returns an abrupt completion.
The changes are applied to String.prototype.replace, String.prototype.slice, String.prototype.substring, String.prototype.toLowerCase.

In all sections, the following two abrupt completion cases are tested:

  • When the argument is a Symbol (throws TypeError).
  • When ToPrimitive returns an abrupt completion (specifically, by passing { valueOf: undefined, toString: undefined } to trigger a throw in OrdinaryToPrimitive step 4)

String.prototype.replace

  • tostring-this-throws-symbol.js: tests Symbol case
  • tostring-this-throws-toprimitive.js: tests the case where ToPrimitive returns an abrupt completion

String.prototype.slice

  • this-value-tostring-throws-symbol.js: tests Symbol case
  • this-value-tostring-throws-toprimitive.js: tests the case where ToPrimitive returns an abrupt completion

String.prototype.substring

  • this-value-tostring-throws-symbol.js: tests Symbol case
  • this-value-tostring-throws-toprimitive.js: tests the case where ToPrimitive returns an abrupt completion

String.prototype.toLowerCase

  • this-value-tostring-throws-symbol.js: tests Symbol case
  • this-value-tostring-throws-toprimitive.js: tests the case where ToPrimitive returns an abrupt completion

I'm sorry if the duplicate filenames cause any confusion. My intention was to keep the structure consistent.

@G-Lee1031 G-Lee1031 requested a review from a team as a code owner January 26, 2026 06:53
@ptomato ptomato force-pushed the tostring-throws0126 branch from c89a876 to d6a3c19 Compare February 3, 2026 20:28
Copy link
Copy Markdown
Contributor

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

Thanks!

@ptomato ptomato merged commit cf992db into tc39:main Feb 3, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants