From 5a45609fc2ce8c0934c553c2213a1a3f186291f4 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 16 Jun 2020 09:13:04 -0700 Subject: [PATCH] Address some review comments --- crates/wasmparser/src/binary_reader.rs | 8 +++++++- crates/wasmparser/src/primitives.rs | 6 +++--- crates/wasmparser/src/validator.rs | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/wasmparser/src/binary_reader.rs b/crates/wasmparser/src/binary_reader.rs index c0cd464dc8..2bcd35891d 100644 --- a/crates/wasmparser/src/binary_reader.rs +++ b/crates/wasmparser/src/binary_reader.rs @@ -293,7 +293,7 @@ impl<'a> BinaryReader<'a> { }) } - fn read_export_types(&mut self) -> Result>> { + fn read_export_types(&mut self) -> Result]>> { let pos = self.original_position(); let exports_len = self.read_var_u32()? as usize; if exports_len > MAX_WASM_EXPORTS { @@ -304,6 +304,11 @@ impl<'a> BinaryReader<'a> { pub(crate) fn read_import(&mut self) -> Result> { let module = self.read_string()?; + + // For the `field`, figure out if we're the experimental encoding of + // single-level imports for the module linking proposal (a single-byte + // string which is 0xc0, which is invalid utf-8) or if we have a second + // level of import. let mut clone = self.clone(); let field = if clone.read_var_u32()? == 1 && clone.read_u8()? == 0xc0 { *self = clone; @@ -311,6 +316,7 @@ impl<'a> BinaryReader<'a> { } else { Some(self.read_string()?) }; + let ty = self.read_import_desc()?; Ok(Import { module, field, ty }) } diff --git a/crates/wasmparser/src/primitives.rs b/crates/wasmparser/src/primitives.rs index cf2270f1ad..08fa1fb7e0 100644 --- a/crates/wasmparser/src/primitives.rs +++ b/crates/wasmparser/src/primitives.rs @@ -159,13 +159,13 @@ pub struct FuncType { #[derive(Debug, Clone)] pub struct InstanceType<'a> { - pub exports: Vec>, + pub exports: Box<[ExportType<'a>]>, } #[derive(Debug, Clone)] pub struct ModuleType<'a> { - pub imports: Vec>, - pub exports: Vec>, + pub imports: Box<[crate::Import<'a>]>, + pub exports: Box<[ExportType<'a>]>, } #[derive(Debug, Clone)] diff --git a/crates/wasmparser/src/validator.rs b/crates/wasmparser/src/validator.rs index c74091d4ff..94a6f6f890 100644 --- a/crates/wasmparser/src/validator.rs +++ b/crates/wasmparser/src/validator.rs @@ -1033,7 +1033,7 @@ impl<'a> ValidatingParser<'a> { if expected.imports.len() != actual.imports.len() { return self.create_error("mismatched number of module imports"); } - for (expected, actual) in expected.imports.iter().zip(&actual.imports) { + for (expected, actual) in expected.imports.iter().zip(actual.imports.iter()) { self.check_imports_match(&expected.ty, &actual.ty)?; } self.check_export_sets_match(&expected.exports, &actual.exports)?;