mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:37:45 +00:00
LibWasm: Use TRY in Module::parse
This commit is contained in:
parent
97d15e9b8f
commit
8a9d4246f1
1 changed files with 39 additions and 104 deletions
|
@ -1251,110 +1251,45 @@ ParseResult<Module> Module::parse(InputStream& stream)
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (section_id) {
|
switch (section_id) {
|
||||||
case CustomSection::section_id: {
|
case CustomSection::section_id:
|
||||||
if (auto section = CustomSection::parse(section_stream); !section.is_error()) {
|
sections.append(TRY(CustomSection::parse(section_stream)));
|
||||||
sections.append(section.release_value());
|
continue;
|
||||||
continue;
|
case TypeSection::section_id:
|
||||||
} else {
|
sections.append(TRY(TypeSection::parse(section_stream)));
|
||||||
return section.error();
|
continue;
|
||||||
}
|
case ImportSection::section_id:
|
||||||
}
|
sections.append(TRY(ImportSection::parse(section_stream)));
|
||||||
case TypeSection::section_id: {
|
continue;
|
||||||
if (auto section = TypeSection::parse(section_stream); !section.is_error()) {
|
case FunctionSection::section_id:
|
||||||
sections.append(section.release_value());
|
sections.append(TRY(FunctionSection::parse(section_stream)));
|
||||||
continue;
|
continue;
|
||||||
} else {
|
case TableSection::section_id:
|
||||||
return section.error();
|
sections.append(TRY(TableSection::parse(section_stream)));
|
||||||
}
|
continue;
|
||||||
}
|
case MemorySection::section_id:
|
||||||
case ImportSection::section_id: {
|
sections.append(TRY(MemorySection::parse(section_stream)));
|
||||||
if (auto section = ImportSection::parse(section_stream); !section.is_error()) {
|
continue;
|
||||||
sections.append(section.release_value());
|
case GlobalSection::section_id:
|
||||||
continue;
|
sections.append(TRY(GlobalSection::parse(section_stream)));
|
||||||
} else {
|
continue;
|
||||||
return section.error();
|
case ExportSection::section_id:
|
||||||
}
|
sections.append(TRY(ExportSection::parse(section_stream)));
|
||||||
}
|
continue;
|
||||||
case FunctionSection::section_id: {
|
case StartSection::section_id:
|
||||||
if (auto section = FunctionSection::parse(section_stream); !section.is_error()) {
|
sections.append(TRY(StartSection::parse(section_stream)));
|
||||||
sections.append(section.release_value());
|
continue;
|
||||||
continue;
|
case ElementSection::section_id:
|
||||||
} else {
|
sections.append(TRY(ElementSection::parse(section_stream)));
|
||||||
return section.error();
|
continue;
|
||||||
}
|
case CodeSection::section_id:
|
||||||
}
|
sections.append(TRY(CodeSection::parse(section_stream)));
|
||||||
case TableSection::section_id: {
|
continue;
|
||||||
if (auto section = TableSection::parse(section_stream); !section.is_error()) {
|
case DataSection::section_id:
|
||||||
sections.append(section.release_value());
|
sections.append(TRY(DataSection::parse(section_stream)));
|
||||||
continue;
|
continue;
|
||||||
} else {
|
case DataCountSection::section_id:
|
||||||
return section.error();
|
sections.append(TRY(DataCountSection::parse(section_stream)));
|
||||||
}
|
continue;
|
||||||
}
|
|
||||||
case MemorySection::section_id: {
|
|
||||||
if (auto section = MemorySection::parse(section_stream); !section.is_error()) {
|
|
||||||
sections.append(section.release_value());
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
return section.error();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case GlobalSection::section_id: {
|
|
||||||
if (auto section = GlobalSection::parse(section_stream); !section.is_error()) {
|
|
||||||
sections.append(section.release_value());
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
return section.error();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case ExportSection::section_id: {
|
|
||||||
if (auto section = ExportSection::parse(section_stream); !section.is_error()) {
|
|
||||||
sections.append(section.release_value());
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
return section.error();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case StartSection::section_id: {
|
|
||||||
if (auto section = StartSection::parse(section_stream); !section.is_error()) {
|
|
||||||
sections.append(section.release_value());
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
return section.error();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case ElementSection::section_id: {
|
|
||||||
if (auto section = ElementSection::parse(section_stream); !section.is_error()) {
|
|
||||||
sections.append(section.release_value());
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
return section.error();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case CodeSection::section_id: {
|
|
||||||
if (auto section = CodeSection::parse(section_stream); !section.is_error()) {
|
|
||||||
sections.append(section.release_value());
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
return section.error();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case DataSection::section_id: {
|
|
||||||
if (auto section = DataSection::parse(section_stream); !section.is_error()) {
|
|
||||||
sections.append(section.release_value());
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
return section.error();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case DataCountSection::section_id: {
|
|
||||||
if (auto section = DataCountSection::parse(section_stream); !section.is_error()) {
|
|
||||||
sections.append(section.release_value());
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
return section.error();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return with_eof_check(stream, ParseError::InvalidIndex);
|
return with_eof_check(stream, ParseError::InvalidIndex);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue