From acbface4be3214915148778c0a082ed1fcfa9188 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Thu, 20 Jun 2019 14:51:31 -0700 Subject: [PATCH] Factor out creating wasmparser::ValidatingParserConfig to its own function. --- lib/runtime-core/src/codegen.rs | 16 +++++++++++++++- lib/runtime-core/src/parse.rs | 15 ++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/runtime-core/src/codegen.rs b/lib/runtime-core/src/codegen.rs index 25f42612c..f0fd2c934 100644 --- a/lib/runtime-core/src/codegen.rs +++ b/lib/runtime-core/src/codegen.rs @@ -137,8 +137,22 @@ impl< } } +pub fn default_validating_parser_config() -> wasmparser::ValidatingParserConfig { + wasmparser::ValidatingParserConfig { + operator_config: wasmparser::OperatorValidatorConfig { + enable_threads: false, + enable_reference_types: false, + enable_simd: false, + enable_bulk_memory: false, + enable_multi_value: false, + }, + mutable_global_imports: false, + } +} + fn validate(bytes: &[u8]) -> CompileResult<()> { - let mut parser = wasmparser::ValidatingParser::new(bytes, None); + let mut parser = + wasmparser::ValidatingParser::new(bytes, Some(default_validating_parser_config())); loop { let state = parser.read(); match *state { diff --git a/lib/runtime-core/src/parse.rs b/lib/runtime-core/src/parse.rs index 93f8d24d4..9f911f036 100644 --- a/lib/runtime-core/src/parse.rs +++ b/lib/runtime-core/src/parse.rs @@ -85,19 +85,8 @@ pub fn read_module< custom_sections: HashMap::new(), })); - let mut parser = wasmparser::ValidatingParser::new( - wasm, - Some(wasmparser::ValidatingParserConfig { - operator_config: wasmparser::OperatorValidatorConfig { - enable_threads: false, - enable_reference_types: false, - enable_simd: false, - enable_bulk_memory: false, - enable_multi_value: false, - }, - mutable_global_imports: false, - }), - ); + let mut parser = + wasmparser::ValidatingParser::new(wasm, Some(default_validating_parser_config())); let mut namespace_builder = Some(StringTableBuilder::new()); let mut name_builder = Some(StringTableBuilder::new());