mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-06 20:58:28 +00:00
Remove redundant checks form api::Global::set
This commit is contained in:
16
lib/api/src/externals/global.rs
vendored
16
lib/api/src/externals/global.rs
vendored
@@ -43,7 +43,7 @@ impl Global {
|
|||||||
});
|
});
|
||||||
unsafe {
|
unsafe {
|
||||||
global
|
global
|
||||||
.set(val.clone())
|
.set_unchecked(val.clone())
|
||||||
.map_err(|e| RuntimeError::new(format!("create global for {:?}: {}", val, e)))?;
|
.map_err(|e| RuntimeError::new(format!("create global for {:?}: {}", val, e)))?;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -76,25 +76,13 @@ impl Global {
|
|||||||
/// * The global is not mutable
|
/// * The global is not mutable
|
||||||
/// * The type of the `Val` doesn't matches the Global type.
|
/// * The type of the `Val` doesn't matches the Global type.
|
||||||
pub fn set(&self, val: Val) -> Result<(), RuntimeError> {
|
pub fn set(&self, val: Val) -> Result<(), RuntimeError> {
|
||||||
if self.ty().mutability != Mutability::Var {
|
|
||||||
return Err(RuntimeError::new(
|
|
||||||
"immutable global cannot be set".to_string(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if val.ty() != self.ty().ty {
|
|
||||||
return Err(RuntimeError::new(format!(
|
|
||||||
"global of type {:?} cannot be set to {:?}",
|
|
||||||
self.ty().ty,
|
|
||||||
val.ty()
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
if !val.comes_from_same_store(&self.store) {
|
if !val.comes_from_same_store(&self.store) {
|
||||||
return Err(RuntimeError::new("cross-`Store` values are not supported"));
|
return Err(RuntimeError::new("cross-`Store` values are not supported"));
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
self.global
|
self.global
|
||||||
.set(val)
|
.set(val)
|
||||||
.map_err(|e| RuntimeError::new(format!("Failed to set global: {}", e)))?;
|
.map_err(|e| RuntimeError::new(format!("{}", e)))?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user