@@ -48,17 +48,18 @@ Element::List& Element::list() {
48
48
}
49
49
50
50
Element* Element::operator [](unsigned i) {
51
+ if (!isList ()) throw ParseException (" expected list" , line, col);
51
52
if (i >= list ().size ()) throw ParseException (" expected more elements in list" , line, col);
52
53
return list ()[i];
53
54
}
54
55
55
56
IString Element::str () {
56
- element_assert (!isList_ );
57
+ if (! isStr ()) throw ParseException ( " expected string " , line, col );
57
58
return str_;
58
59
}
59
60
60
61
const char * Element::c_str () {
61
- element_assert (!isList_ );
62
+ if (! isStr ()) throw ParseException ( " expected string " , line, col );
62
63
return str_.str ;
63
64
}
64
65
@@ -207,7 +208,8 @@ Element* SExpressionParser::parseString() {
207
208
}
208
209
209
210
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" );
211
213
if (module .size () == 1 ) return ;
212
214
Index i = 1 ;
213
215
if (module [i]->dollared ()) {
@@ -579,7 +581,6 @@ WasmType SExpressionWasmBuilder::stringToWasmType(const char* str, bool allowErr
579
581
}
580
582
581
583
Expression* SExpressionWasmBuilder::parseExpression (Element& s) {
582
- assert (s.isList ());
583
584
IString id = s[0 ]->str ();
584
585
const char *str = id.str ;
585
586
const char *dot = strchr (str, ' .' );
0 commit comments