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

Implement Debug for JsFuture #1477

Merged
merged 1 commit into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
#![deny(missing_docs)]

use std::cell::{Cell, RefCell};
use std::fmt;
use std::rc::Rc;
use std::sync::Arc;

Expand All @@ -128,6 +129,12 @@ pub struct JsFuture {
callbacks: Option<(Closure<FnMut(JsValue)>, Closure<FnMut(JsValue)>)>,
}

impl fmt::Debug for JsFuture {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "JsFuture {{ ... }}")
}
}

impl From<Promise> for JsFuture {
fn from(js: Promise) -> JsFuture {
// Use the `then` method to schedule two callbacks, one for the
Expand Down
7 changes: 7 additions & 0 deletions crates/futures/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ fn error_future_is_rejected_promise() -> impl Future<Item = (), Error = JsValue>
})
}

#[wasm_bindgen_test]
fn debug_jsfuture() {
let p = js_sys::Promise::resolve(&JsValue::from(42));
let f = JsFuture::from(p);
assert_eq!(&format!("{:?}", f), "JsFuture { ... }");
}

#[wasm_bindgen]
extern "C" {
fn setTimeout(c: &Closure<FnMut()>);
Expand Down