Skip to content

Pass host import arguments with their WebAssembly types - #18

Merged
FlorianRappl merged 3 commits into
AngleSharp:develfrom
michaelthyregod:fix/import-argument-types
Nov 9, 2026
Merged

FlorianRappl merged 3 commits into
AngleSharp:develfrom
michaelthyregod:fix/import-argument-types

Conversation

@michaelthyregod

Copy link
Copy Markdown
Contributor

Host import callbacks received every argument as a boxed double. The switch expression in ConvertArguments has int, long, float and double arms, so C# gives it the common type double. An i64 above 2^53 therefore lost precision, and (int)arguments[0] threw InvalidCastException.

  • Change: box each arm as object, so i32, i64, f32 and f64 arrive as int, long, float and double.
  • Behaviour: callbacks that cast an argument to double for a non-f64 parameter need to cast to the real type; Convert.ToXxx keeps working.

Added a test that passes all four types through an import (including 2^53 + 1); it fails before the change and passes after.

🤖 Generated with Claude Code

The switch expression in ConvertArguments had int, long, float and double
arms, so C# gave it the common type double: every argument reached the
import callback as a boxed double, and i64 values above 2^53 lost
precision. Box each arm as object instead, so i32, i64, f32 and f64
arrive as int, long, float and double.
@CLAassistant

CLAassistant commented Nov 9, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@FlorianRappl FlorianRappl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@FlorianRappl FlorianRappl added this to the v1.1.1 milestone Nov 9, 2026
@FlorianRappl
FlorianRappl merged commit a7e0718 into AngleSharp:devel Nov 9, 2026
5 checks passed
@michaelthyregod
michaelthyregod deleted the fix/import-argument-types branch November 9, 2026 07:24
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.

3 participants