Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Oct 30, 2024
1 parent 97fe6aa commit fad120f
Show file tree
Hide file tree
Showing 3 changed files with 568 additions and 556 deletions.
10 changes: 8 additions & 2 deletions crates/spidermonkey-embedding-splicer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ impl Guest for SpidermonkeyEmbeddingSplicerComponent {
let maybe_run = engine_resolve.worlds[engine_world]
.exports
.iter()
.find(|(key, _)| engine_resolve.name_world_key(key) == "wasi:cli/[email protected]")
.find(|(key, _)| {
engine_resolve
.name_world_key(key)
.starts_with("wasi:cli/[email protected]")
})
.map(|(key, _)| key.clone());
if let Some(run) = maybe_run {
engine_resolve.worlds[engine_world]
Expand All @@ -169,7 +173,9 @@ impl Guest for SpidermonkeyEmbeddingSplicerComponent {
.exports
.iter()
.find(|(key, _)| {
engine_resolve.name_world_key(key) == "wasi:http/[email protected]"
engine_resolve
.name_world_key(key)
.starts_with("wasi:http/[email protected]")
})
.map(|(key, _)| key.clone());

Expand Down
40 changes: 18 additions & 22 deletions crates/spidermonkey-embedding-splicer/src/splice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use wasmparser::Operator;

use crate::*;

const WASI_VERSIONS: [&str; 3] = ["0.2.0", "0.2.1", "0.2.2"];

//
// Parses the Spidermonkey binary into section data for reserialization
// into an output binary, and in the process:
Expand Down Expand Up @@ -44,31 +46,25 @@ pub fn splice(

// since StarlingMonkey implements CLI Run and incoming handler,
// we override them only if the guest content exports those functions
if exports
.iter()
.any(|(name, _)| name == "wasi:cli/[email protected]#run")
{
if let Some(run) = module
.exports
.get_func_by_name("wasi:cli/[email protected]#run".to_string())
{
let expt = module.exports.get_func_by_id(run).unwrap();
module.exports.delete(expt);
module.delete_func(run); // TODO: Look at the intended behaviour here. Need to pass function ID to delete from functions. Was Previously passing Exports ID
for wasi_version in WASI_VERSIONS {
let import = format!("wasi:cli/run@{wasi_version}#run");
if exports.iter().any(|(name, _)| *name == import) {
if let Some(run) = module.exports.get_func_by_name(import) {
let expt = module.exports.get_func_by_id(run).unwrap();
module.exports.delete(expt);
module.delete_func(run); // TODO: Look at the intended behaviour here. Need to pass function ID to delete from functions. Was Previously passing Exports ID
}
}
}

if exports
.iter()
.any(|(name, _)| name == "wasi:http/[email protected]#handle")
{
if let Some(serve) = module
.exports
.get_func_by_name("wasi:http/[email protected]#handle".to_string())
{
let expt = module.exports.get_func_by_id(serve).unwrap();
module.exports.delete(expt);
module.delete_func(serve); // TODO: Look at the intended behaviour here. Same as above comment
for wasi_version in WASI_VERSIONS {
let import = format!("wasi:http/incoming-handler@{wasi_version}#handle");
if exports.iter().any(|(name, _)| *name == import) {
if let Some(serve) = module.exports.get_func_by_name(import) {
let expt = module.exports.get_func_by_id(serve).unwrap();
module.exports.delete(expt);
module.delete_func(serve); // TODO: Look at the intended behaviour here. Same as above comment
}
}
}

Expand Down
Loading

0 comments on commit fad120f

Please sign in to comment.