Skip to content

Commit 6201767

Browse files
chore(deps): update upstream wasm deps to *.227.1
Signed-off-by: Victor Adossi <vadossi@cosmonic.com>
1 parent 54ab085 commit 6201767

3 files changed

Lines changed: 88 additions & 36 deletions

File tree

Cargo.toml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,28 @@ edition = "2021"
88
version = "0.1.0"
99

1010
[workspace.dependencies]
11-
anyhow = "1.0.95"
12-
heck = "0.5"
13-
js-component-bindgen = "1.10.0"
14-
wasm-encoder = "0.225.0"
15-
wasmparser = "0.224.0"
16-
wit-bindgen = "0.39.0"
17-
wit-bindgen-core = "0.39.0"
18-
wit-component = { version = "0.225.0", features = ["dummy-module"] }
19-
wit-parser = "0.225.0"
20-
orca-wasm = "0.9.0"
11+
anyhow = { version = "1.0.95", default-features = false }
12+
heck = { version = "0.5", default-features = false }
13+
#js-component-bindgen = { version = "1.10.0", default-features = false }
14+
#orca-wasm = { version = "0.9.0", default-features = false }
15+
rand = { version = "0.8", default-features = false }
16+
#wasm-encoder = { version = "0.225.0", default-features = false }
17+
#wasmparser = { version = "0.224.0", features = ["features"] }
18+
#wit-bindgen = { version = "0.39.0", features = [ "macros" ] }
19+
#wit-bindgen-core = { version = "0.39.0", default-features = false }
20+
#wit-component = { version = "0.225.0", features = ["dummy-module"] }
21+
#wit-parser = { version = "0.225.0", default-features = false }
22+
23+
# TODO: remove once js-component-bindgen with newer upstream versions is released
24+
js-component-bindgen = { path = "../jco/crates/js-component-bindgen", default-features = false }
25+
26+
# TODO: remove once orca PR has merged
27+
# see: https://github.com/thesuhas/orca/pull/241
28+
orca-wasm = { path = "../orca" }
29+
30+
wasm-encoder = { version = "0.227.1", default-features = false }
31+
wasmparser = { version = "0.227.1", features = ["features"] }
32+
wit-bindgen = { version = "0.41.0", features = [ "macros" ] }
33+
wit-bindgen-core = { version = "0.41.0", default-features = false }
34+
wit-component = { version = "0.227.1", features = ["dummy-module"] }
35+
wit-parser = { version = "0.227.1", default-features = false }

crates/spidermonkey-embedding-splicer/Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ edition.workspace = true
1010

1111
[dependencies]
1212
anyhow = { workspace = true }
13+
clap = { version = "4.5.31", features = ["suggestions", "color", "derive"] }
1314
heck = { workspace = true }
1415
js-component-bindgen = { workspace = true }
15-
wasmparser = { workspace = true }
16+
orca-wasm = { workspace = true }
17+
rand = { workspace = true }
1618
wasm-encoder = { workspace = true }
19+
wasmparser = { workspace = true }
20+
wit-bindgen = { workspace = true }
21+
wit-bindgen-core = { workspace = true }
1722
wit-component = { workspace = true }
1823
wit-parser = { workspace = true }
19-
wit-bindgen-core = { workspace = true }
20-
wit-bindgen = { workspace = true }
21-
orca-wasm.workspace = true
22-
clap = { version = "4.5.31", features = ["suggestions", "color", "derive"] }

crates/spidermonkey-embedding-splicer/src/bindgen.rs

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
use crate::{uwrite, uwriteln};
2-
use anyhow::Result;
1+
use std::collections::{BTreeMap, BTreeSet, HashMap};
2+
use std::fmt::Write;
3+
4+
use anyhow::{bail, Result};
35
use heck::*;
46
use js_component_bindgen::function_bindgen::{
57
ErrHandling, FunctionBindgen, ResourceData, ResourceMap, ResourceTable,
68
};
79
use js_component_bindgen::intrinsics::{render_intrinsics, Intrinsic};
810
use js_component_bindgen::names::LocalNames;
911
use js_component_bindgen::source::Source;
10-
use std::collections::{BTreeMap, BTreeSet, HashMap};
11-
use std::fmt::Write;
1212
use wit_bindgen_core::abi::{self, LiftLower};
1313
use wit_bindgen_core::wit_parser::Resolve;
1414
use wit_bindgen_core::wit_parser::{
@@ -19,6 +19,8 @@ use wit_component::StringEncoding;
1919
use wit_parser::abi::WasmType;
2020
use wit_parser::abi::{AbiVariant, WasmSignature};
2121

22+
use crate::{uwrite, uwriteln, Features};
23+
2224
#[derive(Debug)]
2325
pub enum Resource {
2426
None,
@@ -518,6 +520,9 @@ impl JsBindgen<'_> {
518520
resource_name,
519521
);
520522
}
523+
FunctionKind::AsyncFreestanding => todo!(),
524+
FunctionKind::AsyncMethod(_id) => todo!(),
525+
FunctionKind::AsyncStatic(_id) => todo!(),
521526
};
522527
}
523528
}
@@ -607,10 +612,14 @@ impl JsBindgen<'_> {
607612
BTreeMap::<_, Vec<_>>::new(),
608613
|mut map, (name, func)| {
609614
map.entry(match &func.kind {
610-
FunctionKind::Freestanding => None,
615+
FunctionKind::Freestanding | FunctionKind::AsyncFreestanding => {
616+
None
617+
}
611618
FunctionKind::Method(ty)
612619
| FunctionKind::Static(ty)
613-
| FunctionKind::Constructor(ty) => Some(*ty),
620+
| FunctionKind::Constructor(ty)
621+
| FunctionKind::AsyncMethod(ty)
622+
| FunctionKind::AsyncStatic(ty) => Some(*ty),
614623
})
615624
.or_default()
616625
.push((name.as_str(), func));
@@ -728,6 +737,9 @@ impl JsBindgen<'_> {
728737
Resource::Constructor(self.resolve.types[*ty].name.clone().unwrap()),
729738
)
730739
}
740+
FunctionKind::AsyncFreestanding => todo!(),
741+
FunctionKind::AsyncMethod(_id) => todo!(),
742+
FunctionKind::AsyncStatic(_id) => todo!(),
731743
};
732744

733745
// imports are canonicalized as exports because
@@ -783,8 +795,8 @@ impl JsBindgen<'_> {
783795
for (_, ty) in func.params.iter() {
784796
self.iter_resources(ty, &mut resource_map);
785797
}
786-
for ty in func.results.iter_types() {
787-
self.iter_resources(ty, &mut resource_map);
798+
if let Some(ty) = func.result {
799+
self.iter_resources(&ty, &mut resource_map);
788800
}
789801
resource_map
790802
}
@@ -893,23 +905,27 @@ impl JsBindgen<'_> {
893905
}
894906
}
895907

908+
let err = if get_thrown_type(self.resolve, func.result)
909+
.is_some_and(|(_, err_ty)| err_ty.is_some())
910+
{
911+
match abi {
912+
AbiVariant::GuestExport => ErrHandling::ThrowResultErr,
913+
AbiVariant::GuestImport => ErrHandling::ResultCatchHandler,
914+
AbiVariant::GuestImportAsync => todo!(),
915+
AbiVariant::GuestExportAsync => todo!(),
916+
AbiVariant::GuestExportAsyncStackful => todo!(),
917+
}
918+
} else {
919+
ErrHandling::None
920+
};
921+
896922
let mut f = FunctionBindgen {
897923
is_async: false,
898924
tracing_prefix: None,
899925
intrinsics: &mut self.all_intrinsics,
900926
valid_lifting_optimization: true,
901927
sizes: &self.sizes,
902-
err: if func.results.throws(self.resolve).is_some() {
903-
match abi {
904-
AbiVariant::GuestExport => ErrHandling::ThrowResultErr,
905-
AbiVariant::GuestImport => ErrHandling::ResultCatchHandler,
906-
AbiVariant::GuestImportAsync => todo!(),
907-
AbiVariant::GuestExportAsync => todo!(),
908-
AbiVariant::GuestExportAsyncStackful => todo!(),
909-
}
910-
} else {
911-
ErrHandling::None
912-
},
928+
err,
913929
block_storage: Vec::new(),
914930
blocks: Vec::new(),
915931
callee,
@@ -973,6 +989,9 @@ impl JsBindgen<'_> {
973989
Resource::Constructor(self.resolve.types[*ty].name.clone().unwrap()),
974990
format!("new {callee}"),
975991
),
992+
FunctionKind::AsyncFreestanding => todo!(),
993+
FunctionKind::AsyncMethod(_id) => todo!(),
994+
FunctionKind::AsyncStatic(_id) => todo!(),
976995
};
977996

978997
let binding_name = format!(
@@ -1017,8 +1036,8 @@ impl JsBindgen<'_> {
10171036
CoreFn {
10181037
retsize: if sig.retptr {
10191038
let mut retsize: u32 = 0;
1020-
for ret_ty in func.results.iter_types() {
1021-
retsize += self.sizes.size(ret_ty).size_wasm32() as u32;
1039+
if let Some(ret_ty) = func.result {
1040+
retsize += self.sizes.size(&ret_ty).size_wasm32() as u32;
10221041
}
10231042
retsize
10241043
} else {
@@ -1327,3 +1346,20 @@ fn binding_name(func_name: &str, iface_name: &Option<String>) -> String {
13271346
None => format!("{func_name}"),
13281347
}
13291348
}
1349+
1350+
/// Utility function for deducing whether a type can throw
1351+
pub fn get_thrown_type<'a>(
1352+
resolve: &'a Resolve,
1353+
return_type: Option<Type>,
1354+
) -> Option<(Option<&'a Type>, Option<&'a Type>)> {
1355+
match return_type {
1356+
None => None,
1357+
Some(ty) => match ty {
1358+
Type::Id(id) => match &resolve.types[id].kind {
1359+
TypeDefKind::Result(r) => Some((r.ok.as_ref(), r.err.as_ref())),
1360+
_ => None,
1361+
},
1362+
_ => None,
1363+
},
1364+
}
1365+
}

0 commit comments

Comments
 (0)