Why does wasm-bindgen allows invalid arguments to rust function from js

If I create a rust wasm_bindgen function that accepts an HtmlCanvasElement, why does it NOT fail when I pass a string instead?


(async () => {
    const demo = await import('./pkg/demo').catch(console.error);
    demo.setCanvas('Hello Element!');  


use wasm_bindgen::prelude::*;
use web_sys::{console, HtmlCanvasElement};

pub fn setCanvas(canvas: &HtmlCanvasElement) {
  //  Why does this even get here? I didn't pass in an HtmlCanvasElement
1 Like

Not an official answer but likely along the line of being slow.
Bit of digging and you could at the start of the function call is_instance_of.
This my give insight; only glanced but contains "right enough" and bits on unsafe.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.