mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
This PR contains a few major improvements: * Code duplication has been removed. * Everything has been refactored so that the implementation is much easier to understand. * `future_to_promise` is now implemented with `spawn_local` rather than the other way around (this means `spawn_local` is faster since it doesn't need to create an unneeded `Promise`). * Both the single threaded and multi threaded executors have been rewritten from scratch: * They only create 1-2 allocations in Rust per Task, and all of the allocations happen when the Task is created. * The singlethreaded executor creates 1 Promise per tick, rather than 1 Promise per tick per Task. * Both executors do *not* create `Closure`s during polling, instead all needed `Closure`s are created ahead of time. * Both executors now have correct behavior with regard to spurious wakeups and waking up during the call to `poll`. * Both executors cache the `Waker` so it doesn't need to be recreated all the time. I believe both executors are now optimal in terms of both Rust and JS performance.
wasm-bindgen-macro
Implementation of the #[wasm_bindgen]
attribute. See the wasm-bindgen
documentation for more information about what this macro does.
Testing
Testing of this macro is done through "ui tests" in the ui-tests
subdirectory
of this crate. Each Rust file in this folder is compiled with the wasm_bindgen
crate, and the *.stderr
file sitting next to it is the asserted output of the
compiler. If the output matches, the test passes, and if the output doesn't
match the test fails. Note that it is also considered a failure if a test
actually compiles successfully.
To add a test:
- Create
ui-tests/my-awesome-test.rs
- Write an invalid
#[wasm_bindgen]
invocation, testing the error you're generating - Execute
cargo test -p ui-tests
, the test will fail - From within the
ui-tests
folder, execute./update-all-references.sh
. This should create amy-awesome-test.stderr
file. - Inspect
my-awesome-test.stderr
to make sure it looks ok - Rerun
cargo test -p ui-tests
and your tests should pass!
Testing here is a work in progress, see #601 for more information.