@@ -23,7 +23,6 @@ WebAssemblyModule::WebAssemblyModule(Js::ScriptContext* scriptContext, const byt
23
23
m_memoryMaxSize (0 ),
24
24
m_tableInitSize (0 ),
25
25
m_tableMaxSize (0 ),
26
- m_alloc (_u(" WebAssemblyModule" ), scriptContext->GetThreadContext ()->GetPageAllocator(), Js::Throw::OutOfMemory),
27
26
m_indirectfuncs (nullptr ),
28
27
m_exports (nullptr ),
29
28
m_exportCount (0 ),
@@ -37,12 +36,13 @@ WebAssemblyModule::WebAssemblyModule(Js::ScriptContext* scriptContext, const byt
37
36
m_binaryBufferLength (binaryBufferLength),
38
37
m_customSections (nullptr )
39
38
{
39
+ m_alloc = HeapNew (ArenaAllocator, _u (" WebAssemblyModule" ), scriptContext->GetThreadContext ()->GetPageAllocator (), Js::Throw::OutOfMemory);
40
40
// the first elm is the number of Vars in front of I32; makes for a nicer offset computation
41
41
memset (m_globalCounts, 0 , sizeof (uint) * Wasm::WasmTypes::Limit);
42
42
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);
46
46
}
47
47
48
48
/* static */
@@ -428,7 +428,7 @@ WebAssemblyModule::AddWasmFunctionInfo(Wasm::WasmSignature* sig)
428
428
{
429
429
uint32 functionId = GetWasmFunctionCount ();
430
430
// 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);
432
432
m_functionsInfo->Add (funcInfo);
433
433
return funcInfo;
434
434
}
@@ -464,7 +464,7 @@ WebAssemblyModule::AttachCustomInOutTracingReader(Wasm::WasmFunctionInfo* func,
464
464
throw Wasm::WasmCompilationException (_u (" InOut tracing reader signature mismatch" ));
465
465
}
466
466
// 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);
468
468
// Print the function name we are calling
469
469
{
470
470
Wasm::WasmNode nameNode;
@@ -543,7 +543,7 @@ WebAssemblyModule::AttachCustomInOutTracingReader(Wasm::WasmFunctionInfo* func,
543
543
void
544
544
WebAssemblyModule::AllocateFunctionExports (uint32 entries)
545
545
{
546
- m_exports = AnewArrayZ (& m_alloc, Wasm::WasmExport, entries);
546
+ m_exports = AnewArrayZ (m_alloc, Wasm::WasmExport, entries);
547
547
m_exportCount = entries;
548
548
}
549
549
@@ -581,7 +581,7 @@ WebAssemblyModule::AddFunctionImport(uint32 sigId, const char16* modName, uint32
581
581
}
582
582
583
583
// Store the information about the import
584
- Wasm::WasmImport* importInfo = Anew (& m_alloc, Wasm::WasmImport);
584
+ Wasm::WasmImport* importInfo = Anew (m_alloc, Wasm::WasmImport);
585
585
importInfo->kind = Wasm::ExternalKinds::Function;
586
586
importInfo->modNameLen = modNameLen;
587
587
importInfo->modName = modName;
@@ -592,7 +592,7 @@ WebAssemblyModule::AddFunctionImport(uint32 sigId, const char16* modName, uint32
592
592
Wasm::WasmSignature* signature = GetSignature (sigId);
593
593
Wasm::WasmFunctionInfo* funcInfo = AddWasmFunctionInfo (signature);
594
594
// 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);
596
596
for (uint32 iParam = 0 ; iParam < (uint32)signature->GetParamCount (); iParam++)
597
597
{
598
598
Wasm::WasmNode node;
@@ -641,7 +641,7 @@ WebAssemblyModule::GetImport(uint32 i) const
641
641
void
642
642
WebAssemblyModule::AddGlobalImport (const char16* modName, uint32 modNameLen, const char16* importName, uint32 importNameLen)
643
643
{
644
- Wasm::WasmImport* wi = Anew (& m_alloc, Wasm::WasmImport);
644
+ Wasm::WasmImport* wi = Anew (m_alloc, Wasm::WasmImport);
645
645
wi->kind = Wasm::ExternalKinds::Global;
646
646
wi->importName = importName;
647
647
wi->importNameLen = importNameLen;
@@ -653,7 +653,7 @@ WebAssemblyModule::AddGlobalImport(const char16* modName, uint32 modNameLen, con
653
653
void
654
654
WebAssemblyModule::AddMemoryImport (const char16* modName, uint32 modNameLen, const char16* importName, uint32 importNameLen)
655
655
{
656
- Wasm::WasmImport* wi = Anew (& m_alloc, Wasm::WasmImport);
656
+ Wasm::WasmImport* wi = Anew (m_alloc, Wasm::WasmImport);
657
657
wi->kind = Wasm::ExternalKinds::Memory;
658
658
wi->importName = importName;
659
659
wi->importNameLen = importNameLen;
@@ -666,7 +666,7 @@ WebAssemblyModule::AddMemoryImport(const char16* modName, uint32 modNameLen, con
666
666
void
667
667
WebAssemblyModule::AddTableImport (const char16* modName, uint32 modNameLen, const char16* importName, uint32 importNameLen)
668
668
{
669
- Wasm::WasmImport* wi = Anew (& m_alloc, Wasm::WasmImport);
669
+ Wasm::WasmImport* wi = Anew (m_alloc, Wasm::WasmImport);
670
670
wi->kind = Wasm::ExternalKinds::Table;
671
671
wi->importName = importName;
672
672
wi->importNameLen = importNameLen;
@@ -724,7 +724,7 @@ WebAssemblyModule::ValidateInitExportForOffset(const Wasm::WasmNode& initExpr) c
724
724
void
725
725
WebAssemblyModule::AddGlobal (Wasm::GlobalReferenceTypes::Type refType, Wasm::WasmTypes::WasmType type, bool isMutable, Wasm::WasmNode init)
726
726
{
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);
728
728
m_globals->Add (global);
729
729
}
730
730
@@ -749,7 +749,7 @@ WebAssemblyModule::AllocateDataSegs(uint32 count)
749
749
{
750
750
Assert (count != 0 );
751
751
m_datasegCount = count;
752
- m_datasegs = AnewArray (& m_alloc, Wasm::WasmDataSegment*, count);
752
+ m_datasegs = AnewArray (m_alloc, Wasm::WasmDataSegment*, count);
753
753
}
754
754
755
755
void
@@ -774,7 +774,7 @@ WebAssemblyModule::AllocateElementSegs(uint32 count)
774
774
{
775
775
Assert (count != 0 );
776
776
m_elementsegCount = count;
777
- m_elementsegs = AnewArrayZ (& m_alloc, Wasm::WasmElementSegment*, count);
777
+ m_elementsegs = AnewArrayZ (m_alloc, Wasm::WasmElementSegment*, count);
778
778
}
779
779
780
780
void
@@ -834,13 +834,17 @@ WebAssemblyModule::GetModuleEnvironmentSize() const
834
834
void
835
835
WebAssemblyModule::Finalize (bool isShutdown)
836
836
{
837
- m_alloc.Clear ();
837
+ if (m_alloc)
838
+ {
839
+ HeapDelete (m_alloc);
840
+ m_alloc = nullptr ;
841
+ }
838
842
}
839
843
840
844
void
841
845
WebAssemblyModule::Dispose (bool isShutdown)
842
846
{
843
- Assert (m_alloc. Size () == 0 );
847
+ Assert (! m_alloc);
844
848
}
845
849
846
850
void
@@ -915,7 +919,7 @@ WebAssemblyModule::AddCustomSection(Wasm::CustomSection customSection)
915
919
{
916
920
if (!m_customSections)
917
921
{
918
- m_customSections = Anew (& m_alloc, CustomSectionsList, & m_alloc);
922
+ m_customSections = Anew (m_alloc, CustomSectionsList, m_alloc);
919
923
}
920
924
m_customSections->Add (customSection);
921
925
}
0 commit comments