Skip to content

Commit b856925

Browse files
authored
text format parsing fixes (#1002)
1 parent c72d10b commit b856925

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/wasm/wasm-s-parser.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,18 @@ Element::List& Element::list() {
4848
}
4949

5050
Element* Element::operator[](unsigned i) {
51+
if (!isList()) throw ParseException("expected list", line, col);
5152
if (i >= list().size()) throw ParseException("expected more elements in list", line, col);
5253
return list()[i];
5354
}
5455

5556
IString Element::str() {
56-
element_assert(!isList_);
57+
if (!isStr()) throw ParseException("expected string", line, col);
5758
return str_;
5859
}
5960

6061
const char* Element::c_str() {
61-
element_assert(!isList_);
62+
if (!isStr()) throw ParseException("expected string", line, col);
6263
return str_.str;
6364
}
6465

@@ -207,7 +208,8 @@ Element* SExpressionParser::parseString() {
207208
}
208209

209210
SExpressionWasmBuilder::SExpressionWasmBuilder(Module& wasm, Element& module, Name* moduleName) : wasm(wasm), allocator(wasm.allocator), globalCounter(0) {
210-
assert(module[0]->str() == MODULE);
211+
if (module.size() == 0) throw ParseException("empty toplevel, expected module");
212+
if (module[0]->str() != MODULE) throw ParseException("toplevel does not start with module");
211213
if (module.size() == 1) return;
212214
Index i = 1;
213215
if (module[i]->dollared()) {
@@ -579,7 +581,6 @@ WasmType SExpressionWasmBuilder::stringToWasmType(const char* str, bool allowErr
579581
}
580582

581583
Expression* SExpressionWasmBuilder::parseExpression(Element& s) {
582-
assert(s.isList());
583584
IString id = s[0]->str();
584585
const char *str = id.str;
585586
const char *dot = strchr(str, '.');

0 commit comments

Comments
 (0)