summaryrefslogtreecommitdiffstats
path: root/vendor/wasm-bindgen/tests/headless
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/wasm-bindgen/tests/headless')
-rw-r--r--vendor/wasm-bindgen/tests/headless/externref_heap_live_count.rs20
-rw-r--r--vendor/wasm-bindgen/tests/headless/main.js2
-rw-r--r--vendor/wasm-bindgen/tests/headless/main.rs61
-rw-r--r--vendor/wasm-bindgen/tests/headless/modules.js3
-rw-r--r--vendor/wasm-bindgen/tests/headless/modules.rs12
-rw-r--r--vendor/wasm-bindgen/tests/headless/snippets.rs58
-rw-r--r--vendor/wasm-bindgen/tests/headless/snippets1.js9
-rw-r--r--vendor/wasm-bindgen/tests/headless/strings.js21
-rw-r--r--vendor/wasm-bindgen/tests/headless/strings.rs16
9 files changed, 202 insertions, 0 deletions
diff --git a/vendor/wasm-bindgen/tests/headless/externref_heap_live_count.rs b/vendor/wasm-bindgen/tests/headless/externref_heap_live_count.rs
new file mode 100644
index 000000000..c344febbf
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/headless/externref_heap_live_count.rs
@@ -0,0 +1,20 @@
+use wasm_bindgen::prelude::*;
+use wasm_bindgen_test::*;
+
+// This test is in the headless suite so that we can test the `externref` table
+// implementation of `externref_heap_live_count` (as opposed to the JS `heap`
+// implementation) in Firefox.
+#[wasm_bindgen_test]
+fn test_externref_heap_live_count() {
+ let initial = wasm_bindgen::externref_heap_live_count();
+
+ let after_alloc = {
+ let _vals: Vec<_> = (0..10).map(JsValue::from).collect();
+ wasm_bindgen::externref_heap_live_count()
+ };
+
+ let after_dealloc = wasm_bindgen::externref_heap_live_count();
+
+ assert_eq!(initial, after_dealloc);
+ assert_eq!(initial + 10, after_alloc);
+}
diff --git a/vendor/wasm-bindgen/tests/headless/main.js b/vendor/wasm-bindgen/tests/headless/main.js
new file mode 100644
index 000000000..cfedddf93
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/headless/main.js
@@ -0,0 +1,2 @@
+export function import_export_same_name() {
+}
diff --git a/vendor/wasm-bindgen/tests/headless/main.rs b/vendor/wasm-bindgen/tests/headless/main.rs
new file mode 100644
index 000000000..b5f6f12a0
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/headless/main.rs
@@ -0,0 +1,61 @@
+#![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>");
+}
+
+#[wasm_bindgen]
+pub fn import_export_same_name() {
+ #[wasm_bindgen(module = "/tests/headless/main.js")]
+ extern "C" {
+ fn import_export_same_name();
+ }
+ import_export_same_name();
+}
+
+pub mod externref_heap_live_count;
+pub mod modules;
+pub mod snippets;
+pub mod strings;
+
+#[wasm_bindgen_test]
+fn closures_work() {
+ let x = Closure::wrap(Box::new(|| {}) as Box<dyn FnMut()>);
+ drop(x);
+ let x = Closure::wrap(Box::new(|| {}) as Box<dyn FnMut()>);
+ x.forget();
+}
diff --git a/vendor/wasm-bindgen/tests/headless/modules.js b/vendor/wasm-bindgen/tests/headless/modules.js
new file mode 100644
index 000000000..c6ce3f0eb
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/headless/modules.js
@@ -0,0 +1,3 @@
+export function get_five() {
+ return 5;
+}
diff --git a/vendor/wasm-bindgen/tests/headless/modules.rs b/vendor/wasm-bindgen/tests/headless/modules.rs
new file mode 100644
index 000000000..9e894f340
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/headless/modules.rs
@@ -0,0 +1,12 @@
+use wasm_bindgen::prelude::*;
+use wasm_bindgen_test::*;
+
+#[wasm_bindgen(raw_module = "./tests/headless/modules.js")]
+extern "C" {
+ fn get_five() -> u32;
+}
+
+#[wasm_bindgen_test]
+fn test_get_five() {
+ assert_eq!(get_five(), 5);
+}
diff --git a/vendor/wasm-bindgen/tests/headless/snippets.rs b/vendor/wasm-bindgen/tests/headless/snippets.rs
new file mode 100644
index 000000000..6e637fe7e
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/headless/snippets.rs
@@ -0,0 +1,58 @@
+use wasm_bindgen::prelude::*;
+use wasm_bindgen_test::*;
+
+#[wasm_bindgen(module = "/tests/headless/snippets1.js")]
+extern "C" {
+ fn get_two() -> u32;
+ #[wasm_bindgen(js_name = get_stateful)]
+ fn get_stateful1() -> u32;
+}
+
+#[wasm_bindgen(module = "/tests/headless/snippets1.js")]
+extern "C" {
+ #[wasm_bindgen(js_name = get_stateful)]
+ fn get_stateful2() -> u32;
+}
+
+#[wasm_bindgen_test]
+fn test_get_two() {
+ assert_eq!(get_two(), 2);
+}
+
+#[wasm_bindgen_test]
+fn stateful_deduplicated() {
+ assert_eq!(get_stateful1(), 1);
+ assert_eq!(get_stateful2(), 2);
+ assert_eq!(get_stateful1(), 3);
+ assert_eq!(get_stateful2(), 4);
+}
+
+#[wasm_bindgen(inline_js = "export function get_three() { return 3; }")]
+extern "C" {
+ fn get_three() -> u32;
+}
+
+#[wasm_bindgen_test]
+fn test_get_three() {
+ assert_eq!(get_three(), 3);
+}
+
+#[wasm_bindgen(inline_js = "let a = 0; export function get() { a += 1; return a; }")]
+extern "C" {
+ #[wasm_bindgen(js_name = get)]
+ fn duplicate1() -> u32;
+}
+
+#[wasm_bindgen(inline_js = "let a = 0; export function get() { a += 1; return a; }")]
+extern "C" {
+ #[wasm_bindgen(js_name = get)]
+ fn duplicate2() -> u32;
+}
+
+#[wasm_bindgen_test]
+fn duplicate_inline_not_unified() {
+ assert_eq!(duplicate1(), 1);
+ assert_eq!(duplicate2(), 1);
+ assert_eq!(duplicate1(), 2);
+ assert_eq!(duplicate2(), 2);
+}
diff --git a/vendor/wasm-bindgen/tests/headless/snippets1.js b/vendor/wasm-bindgen/tests/headless/snippets1.js
new file mode 100644
index 000000000..12e5a6bff
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/headless/snippets1.js
@@ -0,0 +1,9 @@
+export function get_two() {
+ return 2;
+}
+
+let a = 0;
+export function get_stateful() {
+ a += 1;
+ return a;
+}
diff --git a/vendor/wasm-bindgen/tests/headless/strings.js b/vendor/wasm-bindgen/tests/headless/strings.js
new file mode 100644
index 000000000..866bad653
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/headless/strings.js
@@ -0,0 +1,21 @@
+export function test_string_roundtrip(f) {
+ const test = expected => {
+ const actual = f(expected);
+ if (actual === expected)
+ return;
+ throw new Error(`string roundtrip "${actual}" != "${expected}"`);
+ };
+
+ test('');
+ test('a');
+ test('💖');
+
+ test('a longer string');
+ test('a longer 💖 string');
+
+ test('\uFEFFbar');
+}
+
+export function identity(s) {
+ return s;
+}
diff --git a/vendor/wasm-bindgen/tests/headless/strings.rs b/vendor/wasm-bindgen/tests/headless/strings.rs
new file mode 100644
index 000000000..300187b2c
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/headless/strings.rs
@@ -0,0 +1,16 @@
+use wasm_bindgen::prelude::*;
+use wasm_bindgen_test::*;
+
+#[wasm_bindgen(module = "/tests/headless/strings.js")]
+extern "C" {
+ fn test_string_roundtrip(c: &Closure<dyn Fn(String) -> String>);
+
+ fn identity(s: &str) -> String;
+}
+
+#[wasm_bindgen_test]
+fn string_roundtrip() {
+ test_string_roundtrip(&Closure::wrap(Box::new(|s| s)));
+
+ assert_eq!("\u{feff}bar", &identity("\u{feff}bar"));
+}