@@ -23,7 +23,6 @@ WebAssemblyModule::WebAssemblyModule(Js::ScriptContext* scriptContext, const byt
2323 m_memoryMaxSize (0 ),
2424 m_tableInitSize (0 ),
2525 m_tableMaxSize (0 ),
26- m_alloc (_u(" WebAssemblyModule" ), scriptContext->GetThreadContext ()->GetPageAllocator(), Js::Throw::OutOfMemory),
2726 m_indirectfuncs (nullptr ),
2827 m_exports (nullptr ),
2928 m_exportCount (0 ),
@@ -37,12 +36,13 @@ WebAssemblyModule::WebAssemblyModule(Js::ScriptContext* scriptContext, const byt
3736 m_binaryBufferLength (binaryBufferLength),
3837 m_customSections (nullptr )
3938{
39+ m_alloc = HeapNew (ArenaAllocator, _u (" WebAssemblyModule" ), scriptContext->GetThreadContext ()->GetPageAllocator (), Js::Throw::OutOfMemory);
4040 // the first elm is the number of Vars in front of I32; makes for a nicer offset computation
4141 memset (m_globalCounts, 0 , sizeof (uint) * Wasm::WasmTypes::Limit);
4242 m_functionsInfo = RecyclerNew (scriptContext->GetRecycler (), WasmFunctionInfosList, scriptContext->GetRecycler ());
43- m_imports = Anew (& m_alloc, WasmImportsList, & m_alloc);
44- m_globals = Anew (& m_alloc, WasmGlobalsList, & m_alloc);
45- m_reader = Anew (& m_alloc, Wasm::WasmBinaryReader, & m_alloc, this , binaryBuffer, binaryBufferLength);
43+ m_imports = Anew (m_alloc, WasmImportsList, m_alloc);
44+ m_globals = Anew (m_alloc, WasmGlobalsList, m_alloc);
45+ m_reader = Anew (m_alloc, Wasm::WasmBinaryReader, m_alloc, this , binaryBuffer, binaryBufferLength);
4646}
4747
4848/* static */
@@ -428,7 +428,7 @@ WebAssemblyModule::AddWasmFunctionInfo(Wasm::WasmSignature* sig)
428428{
429429 uint32 functionId = GetWasmFunctionCount ();
430430 // must be recycler memory, since it holds reference to the function body
431- Wasm::WasmFunctionInfo* funcInfo = RecyclerNew (GetRecycler (), Wasm::WasmFunctionInfo, & m_alloc, sig, functionId);
431+ Wasm::WasmFunctionInfo* funcInfo = RecyclerNew (GetRecycler (), Wasm::WasmFunctionInfo, m_alloc, sig, functionId);
432432 m_functionsInfo->Add (funcInfo);
433433 return funcInfo;
434434}
@@ -464,7 +464,7 @@ WebAssemblyModule::AttachCustomInOutTracingReader(Wasm::WasmFunctionInfo* func,
464464 throw Wasm::WasmCompilationException (_u (" InOut tracing reader signature mismatch" ));
465465 }
466466 // Create the custom reader to generate the import thunk
467- Wasm::WasmCustomReader* customReader = Anew (& m_alloc, Wasm::WasmCustomReader, & m_alloc);
467+ Wasm::WasmCustomReader* customReader = Anew (m_alloc, Wasm::WasmCustomReader, m_alloc);
468468 // Print the function name we are calling
469469 {
470470 Wasm::WasmNode nameNode;
@@ -543,7 +543,7 @@ WebAssemblyModule::AttachCustomInOutTracingReader(Wasm::WasmFunctionInfo* func,
543543void
544544WebAssemblyModule::AllocateFunctionExports (uint32 entries)
545545{
546- m_exports = AnewArrayZ (& m_alloc, Wasm::WasmExport, entries);
546+ m_exports = AnewArrayZ (m_alloc, Wasm::WasmExport, entries);
547547 m_exportCount = entries;
548548}
549549
@@ -581,7 +581,7 @@ WebAssemblyModule::AddFunctionImport(uint32 sigId, const char16* modName, uint32
581581 }
582582
583583 // Store the information about the import
584- Wasm::WasmImport* importInfo = Anew (& m_alloc, Wasm::WasmImport);
584+ Wasm::WasmImport* importInfo = Anew (m_alloc, Wasm::WasmImport);
585585 importInfo->kind = Wasm::ExternalKinds::Function;
586586 importInfo->modNameLen = modNameLen;
587587 importInfo->modName = modName;
@@ -592,7 +592,7 @@ WebAssemblyModule::AddFunctionImport(uint32 sigId, const char16* modName, uint32
592592 Wasm::WasmSignature* signature = GetSignature (sigId);
593593 Wasm::WasmFunctionInfo* funcInfo = AddWasmFunctionInfo (signature);
594594 // Create the custom reader to generate the import thunk
595- Wasm::WasmCustomReader* customReader = Anew (& m_alloc, Wasm::WasmCustomReader, & m_alloc);
595+ Wasm::WasmCustomReader* customReader = Anew (m_alloc, Wasm::WasmCustomReader, m_alloc);
596596 for (uint32 iParam = 0 ; iParam < (uint32)signature->GetParamCount (); iParam++)
597597 {
598598 Wasm::WasmNode node;
@@ -641,7 +641,7 @@ WebAssemblyModule::GetImport(uint32 i) const
641641void
642642WebAssemblyModule::AddGlobalImport (const char16* modName, uint32 modNameLen, const char16* importName, uint32 importNameLen)
643643{
644- Wasm::WasmImport* wi = Anew (& m_alloc, Wasm::WasmImport);
644+ Wasm::WasmImport* wi = Anew (m_alloc, Wasm::WasmImport);
645645 wi->kind = Wasm::ExternalKinds::Global;
646646 wi->importName = importName;
647647 wi->importNameLen = importNameLen;
@@ -653,7 +653,7 @@ WebAssemblyModule::AddGlobalImport(const char16* modName, uint32 modNameLen, con
653653void
654654WebAssemblyModule::AddMemoryImport (const char16* modName, uint32 modNameLen, const char16* importName, uint32 importNameLen)
655655{
656- Wasm::WasmImport* wi = Anew (& m_alloc, Wasm::WasmImport);
656+ Wasm::WasmImport* wi = Anew (m_alloc, Wasm::WasmImport);
657657 wi->kind = Wasm::ExternalKinds::Memory;
658658 wi->importName = importName;
659659 wi->importNameLen = importNameLen;
@@ -666,7 +666,7 @@ WebAssemblyModule::AddMemoryImport(const char16* modName, uint32 modNameLen, con
666666void
667667WebAssemblyModule::AddTableImport (const char16* modName, uint32 modNameLen, const char16* importName, uint32 importNameLen)
668668{
669- Wasm::WasmImport* wi = Anew (& m_alloc, Wasm::WasmImport);
669+ Wasm::WasmImport* wi = Anew (m_alloc, Wasm::WasmImport);
670670 wi->kind = Wasm::ExternalKinds::Table;
671671 wi->importName = importName;
672672 wi->importNameLen = importNameLen;
@@ -724,7 +724,7 @@ WebAssemblyModule::ValidateInitExportForOffset(const Wasm::WasmNode& initExpr) c
724724void
725725WebAssemblyModule::AddGlobal (Wasm::GlobalReferenceTypes::Type refType, Wasm::WasmTypes::WasmType type, bool isMutable, Wasm::WasmNode init)
726726{
727- Wasm::WasmGlobal* global = Anew (& m_alloc, Wasm::WasmGlobal, refType, m_globalCounts[type]++, type, isMutable, init);
727+ Wasm::WasmGlobal* global = Anew (m_alloc, Wasm::WasmGlobal, refType, m_globalCounts[type]++, type, isMutable, init);
728728 m_globals->Add (global);
729729}
730730
@@ -749,7 +749,7 @@ WebAssemblyModule::AllocateDataSegs(uint32 count)
749749{
750750 Assert (count != 0 );
751751 m_datasegCount = count;
752- m_datasegs = AnewArray (& m_alloc, Wasm::WasmDataSegment*, count);
752+ m_datasegs = AnewArray (m_alloc, Wasm::WasmDataSegment*, count);
753753}
754754
755755void
@@ -774,7 +774,7 @@ WebAssemblyModule::AllocateElementSegs(uint32 count)
774774{
775775 Assert (count != 0 );
776776 m_elementsegCount = count;
777- m_elementsegs = AnewArrayZ (& m_alloc, Wasm::WasmElementSegment*, count);
777+ m_elementsegs = AnewArrayZ (m_alloc, Wasm::WasmElementSegment*, count);
778778}
779779
780780void
@@ -834,13 +834,17 @@ WebAssemblyModule::GetModuleEnvironmentSize() const
834834void
835835WebAssemblyModule::Finalize (bool isShutdown)
836836{
837- m_alloc.Clear ();
837+ if (m_alloc)
838+ {
839+ HeapDelete (m_alloc);
840+ m_alloc = nullptr ;
841+ }
838842}
839843
840844void
841845WebAssemblyModule::Dispose (bool isShutdown)
842846{
843- Assert (m_alloc. Size () == 0 );
847+ Assert (! m_alloc);
844848}
845849
846850void
@@ -915,7 +919,7 @@ WebAssemblyModule::AddCustomSection(Wasm::CustomSection customSection)
915919{
916920 if (!m_customSections)
917921 {
918- m_customSections = Anew (& m_alloc, CustomSectionsList, & m_alloc);
922+ m_customSections = Anew (m_alloc, CustomSectionsList, m_alloc);
919923 }
920924 m_customSections->Add (customSection);
921925}
0 commit comments