-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DomStringMap::get() throws an unexpected error #1756
Comments
Well, this is interesting. The WebIDL says that the getter returns a document.body.dataset["foo"] So I'm not sure if this is a spec bug (?) or a browser bug. It seems |
@alexcrichton I believe it's a bug in our interpretation of WebIDL. According to the official spec, it says that So web-sys generates a This all seems fine, except the WebIDL is fibbing a bit: it might return a So we need to change web-sys so it generates I think we only need to do this for getters, not for non-getters. We should also check to see whether other getters are affected, or if it's only |
@alexcrichton I think it's the ambiguity of our interpretation due to the official spec being implicit about when to use
Following @Pauan 's suggestion, I did more tests starting with
Interestingly, Thanks for follow-ups. I'm new to Rust and excuse me if I were saying something out of focus. |
CSS styles are a bit weird. They accept either a number or a string: document.body.style["backgroundColor"] = "red";
console.log(document.body.style["backgroundColor"]);
console.log(document.body.style[0]); But according to the CSS spec, the getter is on
Yes, because it's not a getter, it's a method, so it never returns It's also important to note that
I don't think that's a good idea. |
@Pauan Your explanations make sense to me. |
Ok I've tagged this as a breaking change for now to ensure we get back to it, but it'd be good to investigate this in the meantime if someone gets a chance! (in that it'd be great to fix in a non-breaking way now so we can have something to move over when we do release breaking changes) |
Currently, web-sys imports 46 indexing getters that are our concern. I've dumped them all along with their signatures. We can see 24 getters (in pink) are already wrapped as Now I'm leaning toward fixing this issue conservatively by wrapping the 14 getters' return types as After the change applied, we have the following bindings with updated signatures: If this approach sounds ok, I'd like to go ahead to update the examples so they become consistent with the new signatures. |
Closing since this issue has been fixed by #1789. Many thanks! |
Describe the Bug
DomStringMap::get()
throws an unexpected error when non-existent key string is passed as argument.Steps to Reproduce
todomvc
example:Expected Behavior
The remove operation should be successful without errors.
Actual Behavior
The output is errors starting with:
Additional Context
el.dataset().get(key)
whenel.dataset()
(which is aDomStringMap
) doesn't have the correspondingkey
:wasm-bindgen/examples/todomvc/src/element.rs
Lines 292 to 303 in 7fd6702
Per API, I think
.get()
should simply return""
instead in that case. (like wasm-bindgen <= 0.2.32)by modifying https://github.com/rustwasm/wasm-bindgen/blob/master/crates/web-sys/tests/wasm/html_element.rs
In my local experiment with the latest wasm-bindgen version, the first line
assert_eq!(element.dataset().get("id"), "", "Shouldn't have data-id");
is failing asThe text was updated successfully, but these errors were encountered: