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

Error when executing stdweb::web:window function #1713

Closed
wikiwong opened this issue Aug 8, 2019 · 5 comments
Closed

Error when executing stdweb::web:window function #1713

wikiwong opened this issue Aug 8, 2019 · 5 comments
Labels

Comments

@wikiwong
Copy link

wikiwong commented Aug 8, 2019

Describe the Bug

After scaffolding a project using https://github.com/rustwasm/wasm-pack-template , I am encountering the follow error when attempting to invoke the stdweb::web::window function (stdweb version 0.4.18), using the npm start command of wasm-pack-template, which uses the webpack WasmPackPlugin:

Screen Shot 2019-08-07 at 11 18 39 PM

lib.rs:

use wasm_bindgen::prelude::*;
use web_sys::console;
use stdweb::{web::window};

#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

#[wasm_bindgen(start)]
pub fn main_js() -> Result<(), JsValue> {
    #[cfg(debug_assertions)]
    console_error_panic_hook::set_once();

    let w = window();
    Ok(())
}

Steps to Reproduce

  1. npm init rust-webpack bug && cd bug (ensure you have at least NPM 6)
  2. Include stdweb = "0.4.18" as a dependency in your Cargo.toml
  3. Edit ./src/lib.rs to be what's in the description.
  4. npm start
  5. A webpage should open up with the error in the console.

If applicable, add a link to a test case (as a zip file or link to a repository we can clone).

Expected Behavior

let win = window();

executes without error

Actual Behavior

Attached error is thrown. Exact line below

const __wbg_cargowebsnippet1c30acb32a1994a07c75e804ae9855b43f191d63_74dac66dda56bf23 = function(arg0) {
    try {
        const ret = Object(_snippets_stdweb_fdcd3965c5b71088_inline370_js__WEBPACK_IMPORTED_MODULE_5__["__cargo_web_snippet_1c30acb32a1994a07c75e804ae9855b43f191d63"])(takeObject(arg0));
        _assertNum(ret);  // <-----!!! ERROR HERE!!!!!!
        return ret;
    } catch (e) {
        logError(e)
    }
};

Additional Context

Thank you to everyone who contributed to this project as well as stdweb. It is a beautiful thing to see collaboration such as koute/stdweb#318 taking place in the open source community. It's truly amazing what can be done when brilliant people from all over the world put their minds together.

@wikiwong wikiwong added the bug label Aug 8, 2019
@alexcrichton
Copy link
Contributor

Thanks for the report! I think though this may be a bug in stdweb? It may be that a function is typed to return a number but it doesn't locally. I was able to reproduce this, but the return value was undefined instead of a number. Mind reopening on stdweb since I think it may not be a bug in wasm-bindgen itself?

@Pauan
Copy link
Contributor

Pauan commented Aug 8, 2019

As a more meta note, stdweb currently doesn't interop very well with wasm-bindgen, so I recommend using one or the other.

For wasm-bindgen, you can use web-sys to access all of the DOM APIs.

@wikiwong
Copy link
Author

wikiwong commented Aug 8, 2019

Sure, thanks for looking!

@wikiwong
Copy link
Author

wikiwong commented Aug 9, 2019

and just to add some color, web-sys is fantastic and I'm grateful for its existence, unfortunately typed_html doesn't allow you to define click handlers as flexibly using the html! macros unless it's stdweb Output: https://github.com/bodil/typed-html/blob/master/examples/stdweb/src/main.rs#L20-L22

I really like aspects of both libraries, I feel as if web-sys is lower level, and stdweb provides some nice abstractions. It'd be great to combine the power of the two, although I understand that allowing such easy syntax to define click handlers might actually be a feature request of typed_html

@Pauan
Copy link
Contributor

Pauan commented Aug 9, 2019

It'd be great to combine the power of the two, although I understand that allowing such easy syntax to define click handlers might actually be a feature request of typed_html

Indeed web-sys is intentionally low level, but that's why we created gloo, which contains high-level abstractions.

And I created a proposal to have high-level event listeners, very similar to what stdweb does.

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

No branches or pull requests

3 participants