| 1 |
#![cfg(target_arch = "wasm32")] |
| 2 |
|
| 3 |
extern crate wasm_bindgen; |
| 4 |
extern crate wasm_bindgen_test; |
| 5 |
|
| 6 |
use wasm_bindgen::prelude::*; |
| 7 |
use wasm_bindgen_test::*; |
| 8 |
|
| 9 |
wasm_bindgen_test_configure!(run_in_browser); |
| 10 |
|
| 11 |
#[wasm_bindgen] |
| 12 |
pub struct ConsumeRetString; |
| 13 |
|
| 14 |
#[wasm_bindgen] |
| 15 |
impl ConsumeRetString { |
| 16 |
// https://github.com/rustwasm/wasm-bindgen/issues/329#issuecomment-411082013 |
| 17 |
// |
| 18 |
// This used to cause two `const ptr = ...` declarations, which is invalid |
| 19 |
// JS. |
| 20 |
pub fn consume(self) -> String { |
| 21 |
String::new() |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
#[wasm_bindgen_test] |
| 26 |
fn works() { |
| 27 |
ConsumeRetString.consume(); |
| 28 |
} |
| 29 |
|
| 30 |
#[wasm_bindgen] |
| 31 |
extern "C" { |
| 32 |
#[wasm_bindgen(js_namespace = console)] |
| 33 |
pub fn log(s: &str); |
| 34 |
} |
| 35 |
|
| 36 |
#[wasm_bindgen_test] |
| 37 |
fn can_log_html_strings() { |
| 38 |
log("<script>alert('lol')</script>"); |
| 39 |
} |
| 40 |
|
| 41 |
#[wasm_bindgen] |
| 42 |
pub fn import_export_same_name() { |
| 43 |
#[wasm_bindgen(module = "/tests/headless/main.js")] |
| 44 |
extern "C" { |
| 45 |
fn import_export_same_name(); |
| 46 |
} |
| 47 |
import_export_same_name(); |
| 48 |
} |
| 49 |
|
| 50 |
pub mod externref_heap_live_count; |
| 51 |
pub mod modules; |
| 52 |
pub mod snippets; |
| 53 |
pub mod strings; |
| 54 |
|
| 55 |
#[wasm_bindgen_test] |
| 56 |
fn closures_work() { |
| 57 |
let x = Closure::wrap(Box::new(|| {}) as Box<dyn FnMut()>); |
| 58 |
drop(x); |
| 59 |
let x = Closure::wrap(Box::new(|| {}) as Box<dyn FnMut()>); |
| 60 |
x.forget(); |
| 61 |
} |