mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-25 19:11:45 +03:00
Generate normal Rust functions for imported bindings (#410)
* Generate normal Rust functions for imported bindings No need to use the C ABI, it just mixes up the documentation! * Update expected webidl output
This commit is contained in:
parent
2d50d5209b
commit
791e69a5c0
@ -701,7 +701,7 @@ impl ToTokens for ast::ImportFunction {
|
||||
#(#attrs)*
|
||||
#[allow(bad_style)]
|
||||
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
|
||||
#vis extern fn #rust_name(#me #(#arguments),*) #ret {
|
||||
#vis fn #rust_name(#me #(#arguments),*) #ret {
|
||||
::wasm_bindgen::__rt::link_this_library();
|
||||
#[wasm_import_module = "__wbindgen_placeholder__"]
|
||||
extern {
|
||||
|
@ -1,8 +1,11 @@
|
||||
use diff;
|
||||
use env_logger;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::{self, Write};
|
||||
use std::process;
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
|
||||
use diff;
|
||||
use env_logger;
|
||||
use wb_webidl;
|
||||
|
||||
fn rustfmt<S: Into<String>>(source: S) -> (String, String) {
|
||||
@ -82,7 +85,7 @@ The latest `rustfmt` is required to run the `wasm-bindgen` test suite. Install
|
||||
(formatted, stderr)
|
||||
}
|
||||
|
||||
fn strip_wasm_bindgen_generated(source: String) -> String {
|
||||
fn strip_wasm_bindgen_generated(source: &str) -> String {
|
||||
let lines: Vec<_> = source
|
||||
.lines()
|
||||
.filter(|l| !l.contains("__WASM_BINDGEN_GENERATED"))
|
||||
@ -90,7 +93,7 @@ fn strip_wasm_bindgen_generated(source: String) -> String {
|
||||
lines.join("\n")
|
||||
}
|
||||
|
||||
pub fn assert_compile(webidl: &str, expected: &str) {
|
||||
pub fn assert_compile(webidl: &str, expected: &str, expected_file: &str) {
|
||||
static INIT_ENV_LOGGER: Once = ONCE_INIT;
|
||||
INIT_ENV_LOGGER.call_once(|| {
|
||||
env_logger::init();
|
||||
@ -98,16 +101,24 @@ pub fn assert_compile(webidl: &str, expected: &str) {
|
||||
|
||||
let actual = wb_webidl::compile(webidl).expect("should compile the webidl source OK");
|
||||
|
||||
let (actual, actual_stderr) = rustfmt(actual);
|
||||
let (actual_orig, actual_stderr) = rustfmt(actual);
|
||||
let (expected, expected_stderr) = rustfmt(expected);
|
||||
|
||||
let actual = strip_wasm_bindgen_generated(actual);
|
||||
let expected = strip_wasm_bindgen_generated(expected);
|
||||
let actual = strip_wasm_bindgen_generated(&actual_orig);
|
||||
let expected = strip_wasm_bindgen_generated(&expected);
|
||||
|
||||
if expected == actual {
|
||||
return;
|
||||
}
|
||||
|
||||
if env::var("UPDATE_EXPECTED").is_ok() {
|
||||
File::create(expected_file)
|
||||
.unwrap()
|
||||
.write_all(actual_orig.as_bytes())
|
||||
.unwrap();
|
||||
return
|
||||
}
|
||||
|
||||
eprintln!("rustfmt(expected) stderr:");
|
||||
eprintln!("{}", expected_stderr);
|
||||
eprintln!();
|
||||
@ -149,7 +160,13 @@ macro_rules! assert_compile {
|
||||
stringify!($test_name),
|
||||
".rs"
|
||||
));
|
||||
$crate::assert_compile(webidl_source, expected_output);
|
||||
let expected_file = concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/tests/expected/",
|
||||
stringify!($test_name),
|
||||
".rs"
|
||||
);
|
||||
$crate::assert_compile(webidl_source, expected_output, expected_file);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -418,7 +418,8 @@ fn rename_setter_getter() {
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn run() {
|
||||
let a = Foo::new();
|
||||
let x: fn() -> Foo = Foo::new;
|
||||
let a = x();
|
||||
assert_eq!(a.test(), 1);
|
||||
a.another(2);
|
||||
assert_eq!(a.test(), 2);
|
||||
|
Loading…
Reference in New Issue
Block a user