Skip to content

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

@wikiwong

Description

@wikiwong

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions