From 2a2d44d12788a784949e7dcacdd6682832431316 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Wed, 15 Dec 2021 12:58:49 +0100 Subject: [PATCH 1/2] Added `externs_vec` method to the ImportObject --- lib/api/src/sys/import_object.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/api/src/sys/import_object.rs b/lib/api/src/sys/import_object.rs index d98f220809d..7a184eb5139 100644 --- a/lib/api/src/sys/import_object.rs +++ b/lib/api/src/sys/import_object.rs @@ -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}; @@ -117,6 +118,24 @@ impl ImportObject { map.get(name).and_then(|ns| ns.as_exports()) } + /// Returns the externs + 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(); From d110bd370026567ba09957205f47b69eb55e08f7 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Fri, 17 Dec 2021 18:18:49 +0100 Subject: [PATCH 2/2] Improve comment --- lib/api/src/sys/import_object.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/api/src/sys/import_object.rs b/lib/api/src/sys/import_object.rs index 7a184eb5139..e047c4cbe6b 100644 --- a/lib/api/src/sys/import_object.rs +++ b/lib/api/src/sys/import_object.rs @@ -118,7 +118,7 @@ impl ImportObject { map.get(name).and_then(|ns| ns.as_exports()) } - /// Returns the externs + /// 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();