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

Issue with JSFuture::from(promise) imported from local source js file #1637

Closed
CallumJHays opened this issue Jul 1, 2019 · 2 comments · Fixed by #1649
Closed

Issue with JSFuture::from(promise) imported from local source js file #1637

CallumJHays opened this issue Jul 1, 2019 · 2 comments · Fixed by #1649
Labels

Comments

@CallumJHays
Copy link

WASM-bindgen-futures aint workin' for me

This repo exemplifies my issue.

Clone & Run it

git clone https://github.com/CallumJHays/wasm-bindgen-futures-test
cd wasm-bindgen-futures-test
yarn # install
rimraf dist pkg && webpack-dev-server --open -d # run

The Code

src/lib.rs:

use wasm_bindgen::prelude::*;
use js_sys::Promise;
use wasm_bindgen_futures::JsFuture;

// This is like the `main` function, except for JavaScript.
#[wasm_bindgen(start)]
pub fn main_js() -> Result<(), JsValue> {
    // This provides better error messages in debug mode.
    // It's disabled in release mode so it doesn't bloat up the file size.
    #[cfg(debug_assertions)]
    console_error_panic_hook::set_once();


    // Your code goes here!
    JsFuture::from(promise_true());

    Ok(())
}

#[wasm_bindgen(module = "/src/promise_true.js")]
extern "C" {
    fn promise_true() -> Promise;
}

src/promise_true.js:

export const promise_true = async () => {
  console.log("promise_true() successfully called from Rust");
  return true;
};

It all compiles fine.

Output

This is the runtime error I experience:

Help? 🐱

@CallumJHays CallumJHays added the bug label Jul 1, 2019
@CallumJHays CallumJHays changed the title Issue with JSFuture::From(promise) imported from local source js file Issue with JSFuture::from(promise) imported from local source js file Jul 1, 2019
alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue Jul 8, 2019
JS engines guarantee that at least one of our `then` callbacks are
invoked, so that means if we destroy them prematurely they're guaranteed
to log an exception to the console! Instead to prevent exceptions from
happening tweak how the completion callbacks for JS futures are managed
and ensure that the closures stay alive until they're invoked later.

Closes rustwasm#1637
@alexcrichton
Copy link
Contributor

Thanks for the report! THe exception here is actually benign, but it's a good one for us to fix and should be fixed in #1649

@CallumJHays
Copy link
Author

Awesome! That's good to hear, thanks

alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue Jul 9, 2019
JS engines guarantee that at least one of our `then` callbacks are
invoked, so that means if we destroy them prematurely they're guaranteed
to log an exception to the console! Instead to prevent exceptions from
happening tweak how the completion callbacks for JS futures are managed
and ensure that the closures stay alive until they're invoked later.

Closes rustwasm#1637
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants