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

Index out of bounds on statics with non-JS types #1777

Closed
unneon opened this issue Sep 20, 2019 · 1 comment · Fixed by #1784
Closed

Index out of bounds on statics with non-JS types #1777

unneon opened this issue Sep 20, 2019 · 1 comment · Fixed by #1784
Labels

Comments

@unneon
Copy link

unneon commented Sep 20, 2019

Describe the Bug

Declaring and using a static with a type that is e.g. String or Option<_> compiles, but causes an index out of bounds error when running the wasm-bindgen CLI step in wasm-pack. Types that are handles to JavaScript values(JsValue, js_sys::Array, wasm-bindgen types generated from type declarations in extern "C" blocks) work fine.

Steps to Reproduce

Set up the following project, and run wasm-pack build.

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
    static EXTENSION_ROOT: String;
}

#[wasm_bindgen]
pub fn hello() -> String {
    EXTENSION_ROOT.clone()
}
[package]
name = "oopsie"
version = "0.1.0"
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
wasm-bindgen = "0.2"

Expected Behavior

This should either create a static correctly and use *WasmAbi implicit conversions, or result in a non-panic error at some stage of compilation.

Actual Behavior

A panic in the build process occurs:

[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
    Finished release [optimized] target(s) in 0.01s
:-) [WARN]: origin crate has no README
[INFO]: Installing wasm-bindgen...
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', crates/cli-support/src/webidl/bindings.rs:209:36
stack backtrace:
   0: std::panicking::default_hook::{{closure}}
   1: std::panicking::default_hook
   2: std::panicking::rust_panic_with_hook
   3: std::panicking::continue_panic_fmt
   4: rust_begin_unwind
   5: core::panicking::panic_fmt
   6: core::panicking::panic_bounds_check
   7: wasm_bindgen_cli_support::webidl::bindings::assert_signature_match
   8: wasm_bindgen_cli_support::webidl::bindings::register_import
   9: wasm_bindgen_cli_support::webidl::Context::program
  10: wasm_bindgen_cli_support::webidl::process
  11: wasm_bindgen_cli_support::Bindgen::generate_output
  12: wasm_bindgen_cli_support::Bindgen::generate
  13: wasm_bindgen::main
  14: std::rt::lang_start::{{closure}}
  15: std::panicking::try::do_call
  16: __rust_maybe_catch_panic
  17: std::rt::lang_start_internal
  18: main
Error: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit code: 101
@unneon unneon added the bug label Sep 20, 2019
alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue Sep 23, 2019
This hasn't ever actually worked in `wasm-bindgen` but there's been
enough refactorings since the initial implementation that it's actually
quite trivial to implement now!

Closes rustwasm#1777
@alexcrichton
Copy link
Contributor

Thanks for the report! Funnily enough this hasn't actually ever worked, but we just forgot to get around to fixing it! Nowadays though I think the fix should be pretty easy -- #1784

alexcrichton added a commit that referenced this issue Sep 25, 2019
This hasn't ever actually worked in `wasm-bindgen` but there's been
enough refactorings since the initial implementation that it's actually
quite trivial to implement now!

Closes #1777
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