Skip to content

test262: String conformance fixes (wave 15) - #81

Merged
hiett merged 1 commit into
experiment/js-frontendfrom
js262/wave15-String
Jul 15, 2026
Merged

test262: String conformance fixes (wave 15)#81
hiett merged 1 commit into
experiment/js-frontendfrom
js262/wave15-String

Conversation

@hiett

@hiett hiett commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Applies RequireObjectCoercible + ToString to the receiver of String.prototype.startsWith, endsWith, and substring, which previously dereferenced this directly and crashed (Erlang badarg) on a null/undefined/Symbol receiver reached via .call.

Per ECMAScript 22.1.3, each String.prototype method does RequireObjectCoercible(this) (null/undefined -> TypeError) then ToString(this) (a Symbol -> TypeError). The methods now route through the existing str_this/1 helper, which also gains the missing Symbol clause.

Spec-driven tests appended at EOF of js_compiler_test.gleam.

test262 String/prototype (concat/slice/substring/indexOf/includes/startsWith/endsWith/repeat): pass 57 -> 65, runtime_error 10 -> 2.

String.prototype.startsWith/endsWith/substring dereferenced their receiver
directly via cps/1, so a null, undefined, or Symbol `this` (reachable through
.call) crashed with an Erlang badarg instead of the TypeError the spec mandates.

Per 22.1.3, every String.prototype method first performs RequireObjectCoercible
(null/undefined throw TypeError) then ToString (a Symbol throws TypeError, since
ToString of a Symbol is abrupt). Route these three methods through the existing
str_this/1 receiver coercion, and extend str_this/1 with the missing Symbol
clause so a Symbol receiver throws rather than stringifying to "[object Object]".

Fixes the startsWith/endsWith this-is-null / this-is-undefined /
return-abrupt-from-this-as-symbol and substring this-value-tostring-throws-symbol
test262 cases (String prototype pass 57 -> 65).
@hiett
hiett merged commit cab05ef into experiment/js-frontend Jul 15, 2026
1 check passed
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.

1 participant