Skip to content
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

fix: Remove try_array_to_vec and downcast #82

Merged
merged 14 commits into from
Jan 19, 2024
Merged

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Jan 8, 2024

This patch updates wasm-bindgen to 0.2.89. It allows to remove try_array_to_vec (which was fine, but no more necessary), and to remove downcast (which was a problem, see #51).

This patch should ideally be reviewed commit by commit.


@Hywan Hywan requested a review from a team as a code owner January 8, 2024 14:17
@Hywan Hywan requested a review from bnjbvr January 8, 2024 14:17
src/machine.rs Outdated Show resolved Hide resolved
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

lgtm generally, though please could the doc be updated as previously noted.

I don't suppose that wasm-bindgen supports Vec<&identifiers::UserId>, thus avoiding the drop problem?

Particularly given this is a not-very-obvious breaking change, could you add a note to the the CHANGELOG warning applications about this?

src/identifiers.rs Outdated Show resolved Hide resolved
src/machine.rs Outdated Show resolved Hide resolved
@bnjbvr bnjbvr removed their request for review January 8, 2024 16:06
@Hywan
Copy link
Member Author

Hywan commented Jan 8, 2024

I don't suppose that wasm-bindgen supports Vec<&identifiers::UserId>, thus avoiding the drop problem?

It's not supported, indeed.

I've updated the docs.

@richvdh richvdh self-requested a review January 10, 2024 11:57
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

I'm sorry to be so picky about this, but this is such alien behaviour in javascript that I think it's really important to accurately document the hell out of it.

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
src/libolm_migration.rs Outdated Show resolved Hide resolved
src/libolm_migration.rs Outdated Show resolved Hide resolved
src/identities.rs Show resolved Hide resolved
src/machine.rs Outdated Show resolved Hide resolved
src/sync_events.rs Show resolved Hide resolved
src/verification.rs Show resolved Hide resolved
src/verification.rs Outdated Show resolved Hide resolved
Now that `wasm-bindgen` supports `Vec<T>` and `Option<Vec<T>>`, we no
longer need `try_array_to_vec`. This patch removes this helper function.
The `downcast` function is removed in this patch because it was
incompatible with JS code minifier.

Instead, we now rely on the new `wasm_bindgen::convert::TryFromJsValue`
API.

This patch also replaces `&Array` by `Vec<T>`. It's fine, except that JS
arrays that are sent to Rust are going to be dropped after the functions
return. It's quite unsual for JS, but documentations have been updated
accordingly.
This can be helpful when the `user_id` is dropped on the Rust side.
This patch moves the `OlmMachine::import_exported_room_keys_helper` to
a `impl` that is not annotated by `#[wasm_bindgen]` because it doesn't
have to live in the JS binding.
This patch replaces a few `js_sys::Array` by `std::vec::Vec` when
possible. It makes the code simpler, and `wasm_bindgen` now handles
`Vec` well for us.
@Hywan
Copy link
Member Author

Hywan commented Jan 18, 2024

I've rebased the patch. I've updated the documentation. I've also replaced a couple more Array by Vec<T> (in a return position). I've fixed the CHANGELOG. I believe we are good this time 🙂.

@Hywan Hywan requested a review from richvdh January 18, 2024 09:34
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

Thank you, looks great apart from a few more documentation nits!

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
src/machine.rs Outdated Show resolved Hide resolved
src/machine.rs Outdated Show resolved Hide resolved
src/machine.rs Outdated Show resolved Hide resolved
src/machine.rs Outdated Show resolved Hide resolved
src/machine.rs Outdated Show resolved Hide resolved
src/sync_events.rs Outdated Show resolved Hide resolved
src/verification.rs Outdated Show resolved Hide resolved
@richvdh richvdh merged commit 7ad732f into matrix-org:main Jan 19, 2024
3 checks passed
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.

Downcast doesn't play nicely with minification
2 participants