test262: String conformance fixes (wave 15) - #81
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Applies RequireObjectCoercible + ToString to the receiver of
String.prototype.startsWith,endsWith, andsubstring, which previously dereferencedthisdirectly 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/1helper, 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.