Skip to content

Commit a7d3f18

Browse files
authored
Handle strings when skipping function bodies (#8614)
Explicitly parse strings in the logic for mostly skipping function bodies in the first parser phase. This avoids parentheses inside strings causing the parser to skip too much or too little of the input.
1 parent 4301eae commit a7d3f18

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/parser/context-decls.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ bool ParseDeclsCtx::skipFunctionBody() {
329329
}
330330
continue;
331331
}
332+
// Avoid confusion due to parens inside strings by skipping strings as a
333+
// unit.
334+
if (in.takeString()) {
335+
continue;
336+
}
332337
in.take(1);
333338
in.advance();
334339
}

test/lit/wat-kitchen-sink.wast

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5259,4 +5259,11 @@
52595259
)
52605260
)
52615261
)
5262+
5263+
(func $paren-in-string
5264+
;; We should not be tripped up by an extra close parenthesis inside a string.
5265+
(drop
5266+
(string.const ")")
5267+
)
5268+
)
52625269
)

0 commit comments

Comments
 (0)