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.
This PR fixes a test for the ImageData(data, width[, height]) constructor that incorrectly expected a TypeError to be thrown when passing a TypedArray that is not a Uint8ClampedArray, such as Int8Array. This behavior is not correct per the WebIDL specification, and the test was passing in Servo due to a previous mismatch in the WebIDL bindings, not because the behavior was actually correct.
Thanks to @jdm explanation , we noticed that Servo was passing a Web Platform Test that every other browser fails. The test was written like this:
this looks like it should call the constructor that takes a Uint8ClampedArray and throw a TypeError because the input is not of the right type. However, this is not what actually happens per spec.
According to WebIDL overload resolution, the selection of the correct constructor works as follows:
Constructors in the IDL:
Given call:
Overload resolution steps:
The first argument (Int8Array) does not match Uint8ClampedArray.
The algorithm continues to look for another overload that accepts a number as its first argument.
As a result, the second constructor is chosen, and no type error is thrown. The object is created incorrectly, but validly.
Why Servo Passed the Test Incorrectly:
Because the overload used object, any typed array — including Int8Array — would match that overload, hitting Step 12.11 in the spec, and calling the constructor that then did manual type checking.
Proposed Fix:
To make the test correctly target the desired constructor (the one expecting a Uint8ClampedArray), we bypass the default overload resolution logic. This is done by directly calling the constructor function with .call():
This PR fixes #44929.