Sha256: 687ef5e4a3961fddcb94d24f69abec0ea64f6df306f4593974b69589215980b1

Contents?: true

Size: 1.2 KB

Versions: 30

Compression:

Stored size: 1.2 KB

Contents

# Type Translations in `web-sys`

Most of the types specified in [WebIDL (the interface definition language for
all Web APIs)][webidl] have relatively straightforward translations into
`web-sys`, but it's worth calling out a few in particular:

* `BufferSource` and `ArrayBufferView` - these two types show up in a number of
  APIs that generally deal with a buffer of bytes. We bind them in `web-sys`
  with two different types, `js_sys::Object` and `&mut [u8]`. Using
  `js_sys::Object` allows passing in arbitrary JS values which represent a view
  of bytes (like any typed array object), and `&mut [u8]` allows using a raw
  slice in Rust. Unfortunately we must pessimistically assume that JS will
  modify all slices as we don't currently have information of whether they're
  modified or not.

* Callbacks are all represented as `js_sys::Function`. This means that all
  callbacks going through `web-sys` are a raw JS value. You can work with this
  by either juggling actual `js_sys::Function` instances or you can create a
  `Closure<dyn FnMut(...)>`, extract the underlying `JsValue` with `as_ref`, and
  then use `JsCast::unchecked_ref` to convert it to a `js_sys::Function`.

[webidl]: https://heycam.github.io/webidl/

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
wasmtime-23.0.2 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/web-sys/type-translations.md
wasmtime-22.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/web-sys/type-translations.md
wasmtime-21.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/web-sys/type-translations.md
wasmtime-20.0.2 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/web-sys/type-translations.md
wasmtime-20.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/web-sys/type-translations.md
wasmtime-18.0.3 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/web-sys/type-translations.md
wasmtime-17.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/web-sys/type-translations.md
wasmtime-17.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/web-sys/type-translations.md
wasmtime-16.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/web-sys/type-translations.md
wasmtime-15.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/web-sys/type-translations.md
wasmtime-15.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.89/guide/src/web-sys/type-translations.md
wasmtime-14.0.4 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/web-sys/type-translations.md
wasmtime-14.0.3 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/web-sys/type-translations.md
wasmtime-14.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/web-sys/type-translations.md
wasmtime-14.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/web-sys/type-translations.md
wasmtime-13.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/web-sys/type-translations.md
wasmtime-12.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/web-sys/type-translations.md
wasmtime-12.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/web-sys/type-translations.md
wasmtime-11.0.0 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/web-sys/type-translations.md
wasmtime-10.0.1 ./ext/cargo-vendor/wasm-bindgen-0.2.87/guide/src/web-sys/type-translations.md