Make globals non leaking

This commit is contained in:
Syrus
2020-05-04 13:10:22 -07:00
parent 0885cb5c95
commit c24c5c6946
6 changed files with 26 additions and 35 deletions

View File

@@ -10,8 +10,8 @@ use wasm_common::entity::PrimaryMap;
use wasm_common::FuncType;
use wasm_common::{
DataIndex, DataInitializer, DataInitializerLocation, ElemIndex, ExportIndex, FuncIndex,
GlobalIndex, GlobalType, ImportIndex, LocalFuncIndex, MemoryIndex, MemoryType, SignatureIndex,
TableIndex, TableType,
GlobalIndex, GlobalInit, GlobalType, ImportIndex, LocalFuncIndex, MemoryIndex, MemoryType,
SignatureIndex, TableIndex, TableType,
};
use wasmer_runtime::{Module, TableElements};
@@ -263,8 +263,13 @@ impl<'data> ModuleEnvironment<'data> {
Ok(())
}
pub(crate) fn declare_global(&mut self, global: GlobalType) -> WasmResult<()> {
pub(crate) fn declare_global(
&mut self,
global: GlobalType,
initializer: GlobalInit,
) -> WasmResult<()> {
self.result.module.globals.push(global);
self.result.module.global_initializers.push(initializer);
Ok(())
}

View File

@@ -130,7 +130,6 @@ pub fn parse_import_section<'data>(
GlobalType {
ty: wptype_to_type(ty.content_type).unwrap(),
mutability: ty.mutable.into(),
initializer: GlobalInit::Import,
},
module_name,
field_name,
@@ -254,9 +253,8 @@ pub fn parse_global_section(
let global = GlobalType {
ty: wptype_to_type(content_type).unwrap(),
mutability: mutable.into(),
initializer,
};
environ.declare_global(global)?;
environ.declare_global(global, initializer)?;
}
Ok(())