Skip to content

fix: should throw TypeError if drawImage param mismatched#1190

Merged
Brooooooklyn merged 2 commits intomainfrom
12-27-fix_should_throw_typeerror_if_drawimage_param_mismatched
Dec 27, 2025
Merged

fix: should throw TypeError if drawImage param mismatched#1190
Brooooooklyn merged 2 commits intomainfrom
12-27-fix_should_throw_typeerror_if_drawimage_param_mismatched

Conversation

@Brooooooklyn
Copy link
Copy Markdown
Owner

@Brooooooklyn Brooooooklyn commented Dec 27, 2025

Note

Strengthens drawImage argument validation and covers it with tests.

  • In src/ctx.rs, change draw_image to accept Unknown and coerce to Either3<CanvasElement, SVGCanvas, Image>; if coercion fails, throw TypeError with message Value is not one of these types: \CanvasElement`, `SVGCanvas`, `Image``
  • Add drawImage-throws-TypeError-for-invalid-image-type test in __test__/draw.spec.ts to assert errors for object, number, string, null, and undefined inputs

Written by Cursor Bugbot for commit 53134e2. This will update automatically on new commits. Configure here.

Copilot AI review requested due to automatic review settings December 27, 2025 15:01
Copy link
Copy Markdown
Owner Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 drawImage parameter type from strict Either3<&mut CanvasElement, &mut SVGCanvas, &mut Image> to Unknown with runtime type validation
  • Added explicit type checking that throws TypeError for 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.

Comment thread src/ctx.rs Outdated
Comment thread src/ctx.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Brooooooklyn Brooooooklyn merged commit 386ac90 into main Dec 27, 2025
39 of 40 checks passed
@Brooooooklyn Brooooooklyn deleted the 12-27-fix_should_throw_typeerror_if_drawimage_param_mismatched branch December 27, 2025 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants