Skip to content

Commit

Permalink
Merge #2726
Browse files Browse the repository at this point in the history
2726: Added `externs_vec` method to the ImportObject r=Amanieu a=syrusakbary

<!-- 
Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test:
https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests

-->

# Description

This PR is needed to be able to consume the ImportObject in a more sane way than using `Exports` using `Extern` instead (since `Export` is Engine related, and `Extern` is API related).



Co-authored-by: Syrus Akbary <[email protected]>
Co-authored-by: Amanieu d'Antras <[email protected]>
  • Loading branch information
3 people authored Dec 17, 2021
2 parents 75e4cab + d110bd3 commit c9eab66
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/api/src/sys/import_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! manipulate and access a wasm module's imports including memories, tables, globals, and
//! functions.
use crate::Exports;
use crate::Extern;
use std::borrow::{Borrow, BorrowMut};
use std::collections::VecDeque;
use std::collections::{hash_map::Entry, HashMap};
Expand Down Expand Up @@ -117,6 +118,24 @@ impl ImportObject {
map.get(name).and_then(|ns| ns.as_exports())
}

/// Returns a list of all externs defined in all namespaces.
pub fn externs_vec(&self) -> Vec<(String, String, Extern)> {
let mut out = Vec::new();
let guard = self.map.lock().unwrap();
let map = guard.borrow();
for (namespace, ns) in map.iter() {
match ns.as_exports() {
Some(exports) => {
for (name, extern_) in exports.iter() {
out.push((namespace.clone(), name.clone(), extern_.clone()));
}
}
None => {}
}
}
out
}

fn get_objects(&self) -> VecDeque<((String, String), Export)> {
let mut out = VecDeque::new();
let guard = self.map.lock().unwrap();
Expand Down

0 comments on commit c9eab66

Please sign in to comment.