Repository navigation
[js-api] Treat an explicit undefined as a missing value in table.set/grow tests - #2307
Merged
Ms2ger merged 1 commit intoOct 28, 2026
Conversation
Collaborator
Author
|
For reference: There already exists a test suite that treats an explicit
|
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.
Related to #1660.
The test "Setting non-function" in
test/js-api/table/get-set.any.jsexpectstable.set(0, undefined)to throw aTypeErroron ananyfunctable.As far as I can tell, the specification says that this call is identical with
table.set(0), and should instead succeed and store a null reference.What the specification says
As discussed in #2259, Web IDL's overload resolution turns an explicit
undefinedpassed for an optional argument without a default into the special value "missing", exactly as if the argument had been omitted.Table.set's second parameter is such an argument:undefined set(AddressValue index, optional any value);and its algorithm checks for it:
So
table.set(0, undefined)is the same call astable.set(0): it takes the first branch, andDefaultValue(funcref)isref.null func, so the table entry becomesnullwithout any exception.The
TypeErrorwould only come fromToWebAssemblyValue(undefined, funcref)in the second branch, which this call never reaches.Change
undefinedfrom the list of invalid values in "Setting non-function".table.set(0, undefined)indeed sets the the entry tonullwithout throwing error.Table.grow: it has the same signature:AddressValue grow(AddressValue delta, optional any value), and the sameIf |value| is missingstep, butgrow.any.jsnever passes an explicitundefinedas the value. (The omitted case is already covered by "Basic i32")Why the test may have been written this way
My guess is that "missing" was read in its ordinary English sense, as "not given".
Under that reading an explicit
undefinedis a "given" value, goes throughToWebAssemblyValue, and is rejected because it is not a function or null.A concern
I am not sure this is the right direction though, because current engines already follow the test rather than the specification.
The latest versions of V8, SpiderMonkey, and JavaScriptCore all throw a
TypeErrorfor bothtable.set(0, undefined)andtable.grow(2, undefined).If want the current engines' behavior as the intended one, the alternative is to somehow change the specification instead, for example by bypassing the
overload resolution algorithmand checking forundefinedexplicitly.