fix: should throw TypeError if drawImage param mismatched#1190
Merged
Brooooooklyn merged 2 commits intomainfrom Dec 27, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes the drawImage method to properly throw a TypeError when invalid image types are passed as arguments, improving API error handling and alignment with web standards.
Key Changes:
- Modified
drawImageparameter type from strictEither3<&mut CanvasElement, &mut SVGCanvas, &mut Image>toUnknownwith runtime type validation - Added explicit type checking that throws
TypeErrorfor invalid image arguments - Added comprehensive test coverage for various invalid input types (plain object, number, string, null, undefined)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/ctx.rs | Changed draw_image to accept Unknown type parameter and perform runtime validation using FromNapiValue, throwing TypeError for invalid types |
| test/draw.spec.ts | Added comprehensive test case covering 5 different invalid input types to verify proper TypeError throwing behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

Note
Strengthens
drawImageargument validation and covers it with tests.src/ctx.rs, changedraw_imageto acceptUnknownand coerce toEither3<CanvasElement, SVGCanvas, Image>; if coercion fails, throwTypeErrorwith messageValue is not one of these types: \CanvasElement`, `SVGCanvas`, `Image``drawImage-throws-TypeError-for-invalid-image-typetest in__test__/draw.spec.tsto assert errors for object, number, string, null, and undefined inputsWritten by Cursor Bugbot for commit 53134e2. This will update automatically on new commits. Configure here.