Skip to content

Commit

Permalink
Allow mutable exported global (bytecodealliance#228)
Browse files Browse the repository at this point in the history
* Allow mutable exported global.

* Update test for mutable global which is now legal.
  • Loading branch information
taegyunkim authored and pepyakin committed Jan 22, 2020
1 parent d35bb3c commit e8d5fb6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tests/spec/testsuite
11 changes: 2 additions & 9 deletions validation/src/lib.rs
Expand Up @@ -262,7 +262,7 @@ pub fn validate_module<V: Validator>(module: &Module) -> Result<V::Output, Error
context.require_function(function_index)?;
}
Internal::Global(global_index) => {
context.require_global(global_index, Some(false))?;
context.require_global(global_index, None)?;
}
Internal::Memory(memory_index) => {
context.require_memory(memory_index)?;
Expand All @@ -281,14 +281,7 @@ pub fn validate_module<V: Validator>(module: &Module) -> Result<V::Output, Error
External::Function(function_type_index) => {
context.require_function_type(function_type_index)?;
}
External::Global(ref global_type) => {
if global_type.is_mutable() {
return Err(Error(format!(
"trying to import mutable global {}",
import.field()
)));
}
}
External::Global(_) => {}
External::Memory(ref memory_type) => {
validate_memory_type(memory_type)?;
}
Expand Down
4 changes: 2 additions & 2 deletions validation/src/tests.rs
Expand Up @@ -239,15 +239,15 @@ fn globals() {
.build();
assert!(validate_module(&m).is_ok());

// import mutable global is invalid.
// import mutable global is legal.
let m = module()
.with_import(ImportEntry::new(
"env".into(),
"ext_global".into(),
External::Global(GlobalType::new(ValueType::I32, true)),
))
.build();
assert!(validate_module(&m).is_err());
assert!(validate_module(&m).is_ok());
}

#[test]
Expand Down

0 comments on commit e8d5fb6

Please sign in to comment.