Repository navigation
[js-api] Convert builtin arguments and results like host functions do - #2348
Merged
eqrion merged 1 commit intoNov 24, 2026
Merged
Conversation
eqrion
approved these changes
Nov 24, 2026
eqrion
left a comment
Collaborator
There was a problem hiding this comment.
Thank you, that's a big improvement.
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.
Resolves #2330.
create a builtin functionnow mirrors the behavior ofcreate a host function:the host function now converts its arguments with
ToJSValueand its result withToWebAssemblyValue. It also turns a throw into a trap, and explicitly takes/returns the store, as in #2326.It also brings several changes and refactorings:
i32parameters are reinterpreted as unsigned withToUint32, as the original proposal does with>>>= 0.Let |startIndex| be ℝ(...|start|...)), and are then used directly in comparisons.AssertandToJSValueare removed.+0𝔽,-1𝔽,𝔽(stringLength), ...).as if a trap was executedphrase is removed, since the host function now explicitly turns a throw into a trap.ArrayLength,ArrayCharCodeAt, andSetArrayCharCodeAt. These behaviors involve accessing the associated store and type conversion from/toI16, and factoring them out into separate abstract algorithms makes the spec cleaner and more concise.While updating the test, I found that it was missing some cases and that its polyfill had a few oversights, so I fixed those along the way:
i32arguments with the top bit set. The existing tests only passed small, non-negative values, where reading ani32as signed or unsigned gives the same result. I added a test, "i32 parameters are unsigned", that passes-1and-0x80000000from JS (i.e.0xffffffffand0x80000000) to everyi32parameter, which should be read as large unsigned values.fromCodePointwas wrong: it did not trap above0x10ffff, unlike the spec.fromCharCodeArraywas wrong: its third argument's role is anendindex, but it was using it as acount.fromCharCodeArraywas only called with astartof 0, and in that case, anendindex and acountmean the same thing. I added a loop that calls it with every start from 0 to the length.substringcondition was wrong: it used the comma operator, so only its last comparison counted, and the rest were ignored. Moreover, the conditionend > lengthwas not supposed to be there, which just happened to be ignored. I replaced it with the correct condition (start > end || start > length).