@@ -751,7 +751,7 @@ void WasmBinaryReader::ReadTableSection()
751751 // Allocate maximum length for now until resizing supported
752752 initialLength = maximumLength;
753753 }
754- m_module->AllocateTable (initialLength);
754+ m_module->SetTableSize (initialLength);
755755 m_module->CalculateEquivalentSignatures ();
756756 TRACE_WASM_DECODER (_u (" Indirect table: %u entries" ), initialLength);
757757 }
@@ -762,30 +762,26 @@ WasmBinaryReader::ReadElementSection()
762762{
763763 uint32 length = 0 ;
764764 uint32 count = LEB128 (length);
765+ if (count != 0 )
766+ {
767+ m_module->AllocateElementSegs (count);
768+ }
769+ TRACE_WASM_DECODER (_u (" Indirect table element: %u entries" ), count);
765770
766771 for (uint32 i = 0 ; i < count; ++i)
767772 {
768- uint32 index = LEB128 (length);
773+ uint32 index = LEB128 (length); // Table id
769774 if (index != 0 )
770775 {
771- ThrowDecodingError (_u (" Invalid table index %d" ), index);
772- }
773-
774- WasmNode initExpr = ReadInitExpr ();
775- if (initExpr.op != wbI32Const)
776- {
777- ThrowDecodingError (_u (" Only int32.const supported for element offset" ));
776+ ThrowDecodingError (_u (" Invalid table index %d" ), index); // MVP limitation
778777 }
779778
780- uint32 offset = initExpr. cnst . i32 ;
779+ WasmNode initExpr = ReadInitExpr (); // Offset Init
781780 uint32 numElem = LEB128 (length);
782- uint32 end = UInt32Math::Add (offset, numElem);
783- if (end > m_module->GetTableSize ())
784- {
785- ThrowDecodingError (_u (" Out of bounds element in Table[%d][%d], max index: %d" ), index, end - 1 , m_module->GetTableSize () - 1 );
786- }
787781
788- for (uint32 iElem = offset; iElem < end; ++iElem)
782+ WasmElementSegment *eSeg = Anew (m_alloc, WasmElementSegment, m_alloc, index, initExpr, numElem);
783+
784+ for (uint32 iElem = 0 ; iElem < numElem; ++iElem)
789785 {
790786 uint32 elem = LEB128 (length);
791787 FunctionIndexTypes::Type funcType = m_module->GetFunctionIndexType (elem);
@@ -797,8 +793,9 @@ WasmBinaryReader::ReadElementSection()
797793 {
798794 ThrowDecodingError (_u (" Import functions in the table NYI" ));
799795 }
800- m_module-> SetTableValue (elem, iElem );
796+ eSeg-> AddElement (elem, *m_module );
801797 }
798+ m_module->SetTableValues (eSeg, i);
802799 }
803800}
804801
@@ -821,10 +818,7 @@ WasmBinaryReader::ReadDataSegments()
821818 }
822819 TRACE_WASM_DECODER (_u (" Data Segment #%u" ), i);
823820 WasmNode initExpr = ReadInitExpr ();
824- if (initExpr.op != wbI32Const && initExpr.op != wbGetGlobal)
825- {
826- ThrowDecodingError (_u (" Only i32.const supported for data segment offset" ));
827- }
821+
828822 // UINT32 offset = initExpr.cnst.i32;
829823 UINT32 dataByteLen = LEB128 (len);
830824 WasmDataSegment *dseg = Anew (m_alloc, WasmDataSegment, m_alloc, initExpr, dataByteLen, m_pc);
0 commit comments