mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-15 07:05:41 +00:00
35 lines
1.2 KiB
Rust
35 lines
1.2 KiB
Rust
|
use crate::webassembly::module::Module;
|
||
|
|
||
|
/// We check if a provided module is an Emscripten generated one
|
||
|
pub fn is_emscripten_module(module: &Module) -> bool {
|
||
|
for (module, field) in &module.info.imported_funcs {
|
||
|
if module == "env" {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
|
#[cfg(test)]
|
||
|
mod tests {
|
||
|
use crate::webassembly::instantiate;
|
||
|
use super::is_emscripten_module;
|
||
|
use super::super::generate_emscripten_env;
|
||
|
|
||
|
#[test]
|
||
|
fn should_detect_emscripten_files() {
|
||
|
let wasm_bytes = include_wast2wasm_bytes!("tests/is_emscripten_true.wast");
|
||
|
let import_object = generate_emscripten_env();
|
||
|
let result_object = instantiate(wasm_bytes, import_object).expect("Not compiled properly");
|
||
|
assert!(is_emscripten_module(&result_object.module));
|
||
|
}
|
||
|
|
||
|
#[test]
|
||
|
fn should_detect_non_emscripten_files() {
|
||
|
let wasm_bytes = include_wast2wasm_bytes!("tests/is_emscripten_false.wast");
|
||
|
let import_object = generate_emscripten_env();
|
||
|
let result_object = instantiate(wasm_bytes, import_object).expect("Not compiled properly");
|
||
|
assert!(!is_emscripten_module(&result_object.module));
|
||
|
}
|
||
|
}
|