mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-21 12:40:52 +00:00
* Tweak the implementation of heap closures This commit updates the implementation of the `Closure` type to internally store an `Rc` and be suitable for dropping a `Closure` during the execution of the closure. This is currently needed for promises but may be generally useful as well! * Support asynchronous tests This commit adds support for executing tests asynchronously. This is modeled by tests returning a `Future` instead of simply executing inline, and is signified with `#[wasm_bindgen_test(async)]`. Support for this is added through a new `wasm-bindgen-futures` crate which is a binding between the `futures` crate and JS `Promise` objects. Lots more details can be found in the details of the commit, but one of the end results is that the `web-sys` tests are now entirely contained in the same test suite and don't need `npm install` to be run to execute them! * Review tweaks * Add some bindings for `Function.call` to `js_sys` Name them `call0`, `call1`, `call2`, ... for the number of arguments being passed. * Use oneshots channels with `JsFuture` It did indeed clean up the implementation!
56 lines
1.6 KiB
Rust
56 lines
1.6 KiB
Rust
//! Runtime support for the `#[wasm_bindgen_test]` attribute
|
|
//!
|
|
//! More documentation can be found in the README for this crate!
|
|
|
|
#![feature(use_extern_macros)]
|
|
#![deny(missing_docs)]
|
|
|
|
extern crate console_error_panic_hook;
|
|
extern crate futures;
|
|
extern crate js_sys;
|
|
#[macro_use]
|
|
extern crate scoped_tls;
|
|
extern crate wasm_bindgen;
|
|
extern crate wasm_bindgen_futures;
|
|
extern crate wasm_bindgen_test_macro;
|
|
|
|
pub use wasm_bindgen_test_macro::wasm_bindgen_test;
|
|
|
|
/// Helper macro which acts like `println!` only routes to `console.log`
|
|
/// instead.
|
|
#[macro_export]
|
|
macro_rules! console_log {
|
|
($($arg:tt)*) => (
|
|
$crate::__rt::log(&format_args!($($arg)*))
|
|
)
|
|
}
|
|
|
|
/// A macro used to configured how this test is executed by the
|
|
/// `wasm-bindgen-test-runner` harness.
|
|
///
|
|
/// This macro is invoked as:
|
|
///
|
|
/// wasm_bindgen_test_configure!(foo bar baz);
|
|
///
|
|
/// where all of `foo`, `bar`, and `baz`, would be recognized options to this
|
|
/// macro. The currently known options to this macro are:
|
|
///
|
|
/// * `run_in_browser` - requires that this test is run in a browser rather than
|
|
/// node.js, which is the default for executing tests.
|
|
///
|
|
/// This macro may be invoked at most one time per test suite (an entire binary
|
|
/// like `tests/foo.rs`, not per module)
|
|
#[macro_export]
|
|
macro_rules! wasm_bindgen_test_configure {
|
|
(run_in_browser $($others:tt)*) => (
|
|
#[link_section = "__wasm_bindgen_test_unstable"]
|
|
#[cfg(target_arch = "wasm32")]
|
|
pub static __WBG_TEST_RUN_IN_BROWSER: [u8; 1] = [0x01];
|
|
$crate::wasm_bindgen_test_configure!($($others)*);
|
|
);
|
|
() => ()
|
|
}
|
|
|
|
#[path = "rt/mod.rs"]
|
|
pub mod __rt;
|