You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To get cross-browser functionality working, JS code often does things like
if(typeoffetch==="function"){// assume `fetch` API exists}else{// fall back to XMLHTTPRequest}
We should support this kind of feature detection somehow.
Strawman: add a #[wasm_bindgen(feature_detect = function_name)]-style attribute:
function_name would be the name of a function with signature fn() -> bool that returns true if the thing was found in JS and false otherwise
If the imported thing was not found in JS, we bind to a stub that throws + logs a JS error.
enables usage like this:
#[wasm_bindgen]extern{#[wasm_bindgen(feature_detect = is_fetch_available)]fnfetch(...) -> ...;}ifis_fetch_available(){fetch(...);}else{// do some fall back...}
Perhaps this requires an RFC.
The text was updated successfully, but these errors were encountered:
This got me thinking! I managed to get rust-random/rand#541 working with what we've got today on crates.io!
I'm not entirely sure how much we want to bake in, from what I've seen everyone does feature detection slightly differently so we may want to just be sure to enable various patterns rather than trying to bless one?
To get cross-browser functionality working, JS code often does things like
We should support this kind of feature detection somehow.
Strawman: add a
#[wasm_bindgen(feature_detect = function_name)]
-style attribute:function_name
would be the name of a function with signaturefn() -> bool
that returnstrue
if the thing was found in JS and false otherwiseIf the imported thing was not found in JS, we bind to a stub that throws + logs a JS error.
enables usage like this:
Perhaps this requires an RFC.
The text was updated successfully, but these errors were encountered: