Align input sanitization with WebIDL #57
Merged
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.
In #52, I updated the polyfill just enough to get all tests passing again. However, there were still a lot of differences between how the polyfill does its input sanitization and how the reference implementation does it.
The reference implementation uses webidl2js to generate wrapper classes which around the actual implementation class, which handle all input sanitization based on the WebIDL. For the polyfill, I decided to write these checks manually, utilizing TypeScript's type system (with custom type guards) where possible.
By writing the type checks and conversions manually, we can also avoid some weirdness from the reference implementation. For example, the spec needs to pass both the original
underlyingSource
as well as the convertedunderlyingSourceDict
toSetUpReadableStreamDefaultControllerFromUnderlyingSource
, so that it can call the source's methods with the correctthis
context. For the polyfill, I make sure that the converted underlying source already has its methods bound to the original object, so I don't need to worry about this in the rest of the implementation. 🙂I've also restructured the code to better match the new structure of the reference implementation. It's not a perfect match, for example the reference implementation puts all of the abstract operations for readable streams in a single file, whereas the polyfill puts them in the files that use them.