mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-25 14:12:13 +00:00
Currently the import object constructed for the `--target web` output only ever includes the current module as an one of the modules included. With `wasm-bindgen`'s optimization to import directly from modules, however, it's possible to have more modules imported from in the generated wasm file. This commit ensures that the imports are hooked up in the `--target web` es6 emulation mode, ensuring there aren't extraneous errors about import objects.
43 lines
829 B
Rust
43 lines
829 B
Rust
#![cfg(target_arch = "wasm32")]
|
|
|
|
extern crate wasm_bindgen;
|
|
extern crate wasm_bindgen_test;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
use wasm_bindgen_test::*;
|
|
|
|
wasm_bindgen_test_configure!(run_in_browser);
|
|
|
|
#[wasm_bindgen]
|
|
pub struct ConsumeRetString;
|
|
|
|
#[wasm_bindgen]
|
|
impl ConsumeRetString {
|
|
// https://github.com/rustwasm/wasm-bindgen/issues/329#issuecomment-411082013
|
|
//
|
|
// This used to cause two `const ptr = ...` declarations, which is invalid
|
|
// JS.
|
|
pub fn consume(self) -> String {
|
|
String::new()
|
|
}
|
|
}
|
|
|
|
#[wasm_bindgen_test]
|
|
fn works() {
|
|
ConsumeRetString.consume();
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
extern "C" {
|
|
#[wasm_bindgen(js_namespace = console)]
|
|
pub fn log(s: &str);
|
|
}
|
|
|
|
#[wasm_bindgen_test]
|
|
fn can_log_html_strings() {
|
|
log("<script>alert('lol')</script>");
|
|
}
|
|
|
|
pub mod snippets;
|
|
pub mod modules;
|