Skip to content

Commit e5a38cd

Browse files
refactor: 'features' -> 'feature' in WIT & Rust component (#270)
1 parent e769db2 commit e5a38cd

File tree

7 files changed

+33
-33
lines changed

7 files changed

+33
-33
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::str::FromStr;
55
use anyhow::{Context, Result};
66
use clap::{Parser, Subcommand};
77

8-
use spidermonkey_embedding_splicer::wit::exports::local::spidermonkey_embedding_splicer::splicer::Features;
8+
use spidermonkey_embedding_splicer::wit::exports::local::spidermonkey_embedding_splicer::splicer::Feature;
99
use spidermonkey_embedding_splicer::{splice, stub_wasi};
1010

1111
#[derive(Parser, Debug)]
@@ -85,7 +85,7 @@ fn main() -> Result<()> {
8585
let wit_path_str = wit_path.as_ref().map(|p| p.to_string_lossy().to_string());
8686
let features = features
8787
.iter()
88-
.map(|v| Features::from_str(v))
88+
.map(|v| Feature::from_str(v))
8989
.collect::<Result<Vec<_>>>()?;
9090

9191
let result = stub_wasi::stub_wasi(wasm, features, None, wit_path_str, world_name)
@@ -120,7 +120,7 @@ fn main() -> Result<()> {
120120

121121
let features = features
122122
.iter()
123-
.map(|v| Features::from_str(v))
123+
.map(|v| Feature::from_str(v))
124124
.collect::<Result<Vec<_>>>()?;
125125

126126
let result =

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use wit_component::StringEncoding;
1919
use wit_parser::abi::WasmType;
2020
use wit_parser::abi::{AbiVariant, WasmSignature};
2121

22-
use crate::wit::exports::local::spidermonkey_embedding_splicer::splicer::Features;
22+
use crate::wit::exports::local::spidermonkey_embedding_splicer::splicer::Feature;
2323

2424
use crate::{uwrite, uwriteln};
2525

@@ -108,7 +108,7 @@ struct JsBindgen<'a> {
108108
imported_resources: BTreeSet<TypeId>,
109109

110110
/// Features that were enabled at the time of generation
111-
features: &'a Vec<Features>,
111+
features: &'a Vec<Feature>,
112112
}
113113

114114
#[derive(Debug)]
@@ -139,7 +139,7 @@ pub struct Componentization {
139139
pub fn componentize_bindgen(
140140
resolve: &Resolve,
141141
wid: WorldId,
142-
features: &Vec<Features>,
142+
features: &Vec<Feature>,
143143
) -> Result<Componentization> {
144144
let mut bindgen = JsBindgen {
145145
src: Source::default(),
@@ -407,7 +407,7 @@ impl JsBindgen<'_> {
407407
// Skip bindings generation for wasi:http/incoming-handler if the fetch-event
408408
// feature was enabled. We expect that the built-in engine implementation will be used
409409
if name.starts_with("wasi:http/incoming-handler@0.2.")
410-
&& self.features.contains(&Features::FetchEvent)
410+
&& self.features.contains(&Feature::FetchEvent)
411411
{
412412
continue;
413413
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use wit_parser::Resolve;
1818

1919
use crate::bindgen::BindingItem;
2020
use crate::wit::exports::local::spidermonkey_embedding_splicer::splicer::{
21-
CoreFn, CoreTy, Features, SpliceResult,
21+
CoreFn, CoreTy, Feature, SpliceResult,
2222
};
2323
use crate::{bindgen, map_core_fn, parse_wit, splice};
2424

@@ -32,7 +32,7 @@ use crate::{bindgen, map_core_fn, parse_wit, splice};
3232
// }
3333
pub fn splice_bindings(
3434
engine: Vec<u8>,
35-
features: Vec<Features>,
35+
features: Vec<Feature>,
3636
wit_source: Option<String>,
3737
wit_path: Option<String>,
3838
world_name: Option<String>,
@@ -340,7 +340,7 @@ pub fn splice(
340340
engine: Vec<u8>,
341341
imports: Vec<(String, String, CoreFn, Option<i32>)>,
342342
exports: Vec<(String, CoreFn)>,
343-
features: Vec<Features>,
343+
features: Vec<Feature>,
344344
debug: bool,
345345
) -> Result<Vec<u8>> {
346346
let mut module = Module::parse(&engine, false).unwrap();
@@ -351,7 +351,7 @@ pub fn splice(
351351

352352
// if 'fetch-event' feature is disabled (default being default-enabled),
353353
// remove the built-in incoming-handler which is built around it's use.
354-
if !features.contains(&Features::FetchEvent) {
354+
if !features.contains(&Feature::FetchEvent) {
355355
remove_if_exported_by_js(
356356
&mut module,
357357
&exports,

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use wasmparser::{MemArg, TypeRef};
1313
use wit_parser::Resolve;
1414

1515
use crate::parse_wit;
16-
use crate::wit::exports::local::spidermonkey_embedding_splicer::splicer::Features;
16+
use crate::wit::exports::local::spidermonkey_embedding_splicer::splicer::Feature;
1717

1818
const WASI_VERSIONS: [&str; 4] = ["0.2.0", "0.2.1", "0.2.2", "0.2.3"];
1919

@@ -96,7 +96,7 @@ fn unreachable_stub(body: &mut FunctionBuilder) -> Result<Vec<LocalID>> {
9696

9797
pub fn stub_wasi(
9898
wasm: Vec<u8>,
99-
features: Vec<Features>,
99+
features: Vec<Feature>,
100100
wit_source: Option<String>,
101101
wit_path: Option<String>,
102102
world_name: Option<String>,
@@ -127,25 +127,25 @@ pub fn stub_wasi(
127127
stub_filesystem(&mut module, &target_world_imports)?;
128128
stub_cli(&mut module, &target_world_imports)?;
129129

130-
if !features.contains(&Features::Random) {
130+
if !features.contains(&Feature::Random) {
131131
stub_random(&mut module)?;
132132
}
133133

134-
if !features.contains(&Features::Clocks) {
134+
if !features.contains(&Feature::Clocks) {
135135
stub_clocks(&mut module)?;
136136
}
137137

138-
if !features.contains(&Features::Stdio) {
138+
if !features.contains(&Feature::Stdio) {
139139
stub_stdio(&mut module)?;
140140
}
141141

142-
if !features.contains(&Features::Http) && !features.contains(&Features::FetchEvent) {
142+
if !features.contains(&Feature::Http) && !features.contains(&Feature::FetchEvent) {
143143
stub_http(&mut module)?;
144144
}
145145

146-
let has_io = features.contains(&Features::Clocks)
147-
|| features.contains(&Features::Stdio)
148-
|| features.contains(&Features::Http)
146+
let has_io = features.contains(&Feature::Clocks)
147+
|| features.contains(&Feature::Stdio)
148+
|| features.contains(&Feature::Http)
149149
|| target_world_requires_io(&target_world_imports);
150150
if !has_io {
151151
stub_io(&mut module)?;

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ wit_bindgen::generate!({
55
pub_export_macro: true
66
});
77

8-
use crate::wit::exports::local::spidermonkey_embedding_splicer::splicer::Features;
8+
use crate::wit::exports::local::spidermonkey_embedding_splicer::splicer::Feature;
99

10-
impl std::str::FromStr for Features {
10+
impl std::str::FromStr for Feature {
1111
type Err = anyhow::Error;
1212

1313
fn from_str(s: &str) -> Result<Self> {
1414
match s {
15-
"stdio" => Ok(Features::Stdio),
16-
"clocks" => Ok(Features::Clocks),
17-
"random" => Ok(Features::Random),
18-
"http" => Ok(Features::Http),
19-
"fetch-event" => Ok(Features::FetchEvent),
15+
"stdio" => Ok(Feature::Stdio),
16+
"clocks" => Ok(Feature::Clocks),
17+
"random" => Ok(Feature::Random),
18+
"http" => Ok(Feature::Http),
19+
"fetch-event" => Ok(Feature::FetchEvent),
2020
_ => bail!("unrecognized feature string [{s}]"),
2121
}
2222
}

crates/spidermonkey-embedding-splicer/wit/spidermonkey-embedding-splicer.wit

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface splicer {
88
%f64
99
}
1010

11-
enum features {
11+
enum feature {
1212
stdio,
1313
clocks,
1414
random,
@@ -37,7 +37,7 @@ interface splicer {
3737
/// imports may be stubbed (for example to be made unreachable).
3838
stub-wasi: func(
3939
engine: list<u8>,
40-
features: list<features>,
40+
features: list<feature>,
4141
wit-world: option<string>,
4242
wit-path: option<string>,
4343
world-name: option<string>
@@ -47,7 +47,7 @@ interface splicer {
4747
/// this function produces a new WebAssembly component
4848
splice-bindings: func(
4949
spidermonkey-engine: list<u8>,
50-
features: list<features>,
50+
features: list<feature>,
5151
wit-world: option<string>,
5252
wit-path: option<string>,
5353
world-name: option<string>,

crates/splicer-component/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use spidermonkey_embedding_splicer::stub_wasi::stub_wasi;
22
use spidermonkey_embedding_splicer::wit::{self, export};
3-
use spidermonkey_embedding_splicer::wit::exports::local::spidermonkey_embedding_splicer::splicer::{Features, Guest, SpliceResult};
3+
use spidermonkey_embedding_splicer::wit::exports::local::spidermonkey_embedding_splicer::splicer::{Feature, Guest, SpliceResult};
44
use spidermonkey_embedding_splicer::splice;
55

66
struct SpidermonkeyEmbeddingSplicerComponent;
77

88
impl Guest for SpidermonkeyEmbeddingSplicerComponent {
99
fn stub_wasi(
1010
wasm: Vec<u8>,
11-
features: Vec<Features>,
11+
features: Vec<Feature>,
1212
wit_source: Option<String>,
1313
wit_path: Option<String>,
1414
world_name: Option<String>,
@@ -18,7 +18,7 @@ impl Guest for SpidermonkeyEmbeddingSplicerComponent {
1818

1919
fn splice_bindings(
2020
engine: Vec<u8>,
21-
features: Vec<Features>,
21+
features: Vec<Feature>,
2222
wit_source: Option<String>,
2323
wit_path: Option<String>,
2424
world_name: Option<String>,

0 commit comments

Comments
 (0)