Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added externs_vec method to the ImportObject #2726

Merged
merged 2 commits into from
Dec 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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