@@ -818,11 +818,6 @@ void WasmBinaryBuilder::read() {
818818 break ;
819819 case BinaryConsts::Section::Global: {
820820 readGlobals ();
821- // imports can read global imports, so we run getGlobalName and create
822- // the mapping but after we read globals, we need to add the internal
823- // globals too, so do that here
824- mappedGlobals.clear (); // wipe the mapping
825- getGlobalName (-1 ); // force rebuild
826821 break ;
827822 }
828823 case BinaryConsts::Section::Data:
@@ -1202,11 +1197,18 @@ void WasmBinaryBuilder::readSignatures() {
12021197 }
12031198}
12041199
1205- Name WasmBinaryBuilder::getFunctionIndexName (Index i ) {
1206- if (i >= wasm.functions .size ()) {
1200+ Name WasmBinaryBuilder::getFunctionName (Index index ) {
1201+ if (index >= wasm.functions .size ()) {
12071202 throwError (" invalid function index" );
12081203 }
1209- return wasm.functions [i]->name ;
1204+ return wasm.functions [index]->name ;
1205+ }
1206+
1207+ Name WasmBinaryBuilder::getGlobalName (Index index) {
1208+ if (index >= wasm.globals .size ()) {
1209+ throwError (" invalid global index" );
1210+ }
1211+ return wasm.globals [index]->name ;
12101212}
12111213
12121214void WasmBinaryBuilder::getResizableLimits (Address& initial,
@@ -1807,25 +1809,6 @@ Expression* WasmBinaryBuilder::popNonVoidExpression() {
18071809 return block;
18081810}
18091811
1810- Name WasmBinaryBuilder::getGlobalName (Index index) {
1811- if (!mappedGlobals.size ()) {
1812- // Create name => index mapping.
1813- auto add = [&](Global* curr) {
1814- auto index = mappedGlobals.size ();
1815- mappedGlobals[index] = curr->name ;
1816- };
1817- ModuleUtils::iterImportedGlobals (wasm, add);
1818- ModuleUtils::iterDefinedGlobals (wasm, add);
1819- }
1820- if (index == Index (-1 )) {
1821- return Name (" null" ); // just a force-rebuild
1822- }
1823- if (mappedGlobals.count (index) == 0 ) {
1824- throwError (" bad global index" );
1825- }
1826- return mappedGlobals[index];
1827- }
1828-
18291812void WasmBinaryBuilder::validateBinary () {
18301813 if (hasDataCount && wasm.memory .segments .size () != dataCount) {
18311814 throwError (" Number of segments does not agree with DataCount section" );
@@ -1840,14 +1823,14 @@ void WasmBinaryBuilder::processFunctions() {
18401823 // now that we have names for each function, apply things
18411824
18421825 if (startIndex != static_cast <Index>(-1 )) {
1843- wasm.start = getFunctionIndexName (startIndex);
1826+ wasm.start = getFunctionName (startIndex);
18441827 }
18451828
18461829 for (auto * curr : exportOrder) {
18471830 auto index = exportIndexes[curr];
18481831 switch (curr->kind ) {
18491832 case ExternalKind::Function: {
1850- curr->value = getFunctionIndexName (index);
1833+ curr->value = getFunctionName (index);
18511834 break ;
18521835 }
18531836 case ExternalKind::Table:
@@ -1869,15 +1852,15 @@ void WasmBinaryBuilder::processFunctions() {
18691852 size_t index = iter.first ;
18701853 auto & calls = iter.second ;
18711854 for (auto * call : calls) {
1872- call->target = getFunctionIndexName (index);
1855+ call->target = getFunctionName (index);
18731856 }
18741857 }
18751858
18761859 for (auto & pair : functionTable) {
18771860 auto i = pair.first ;
18781861 auto & indexes = pair.second ;
18791862 for (auto j : indexes) {
1880- wasm.table .segments [i].data .push_back (getFunctionIndexName (j));
1863+ wasm.table .segments [i].data .push_back (getFunctionName (j));
18811864 }
18821865 }
18831866
0 commit comments