Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Fixed #1768 #1820

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions boa/src/syntax/parser/cursor/buffered_lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const MAX_PEEK_SKIP: usize = 3;
/// The fixed size of the buffer used for storing values that are peeked ahead.
///
/// The size is calculated for a worst case scenario, where we want to peek `MAX_PEEK_SKIP` tokens
/// skipping line terminators:
/// skipping line terminators, and the stream ends just after:
/// ```text
/// [\n, B, \n, C, \n, D, \n, E, \n, F]
/// 0 0 1 1 2 2 3 3 4 4
/// [\n, B, \n, C, \n, D, \n, E, \n, F, None]
/// 0 0 1 1 2 2 3 3 4 4 5
/// ```
const PEEK_BUF_SIZE: usize = (MAX_PEEK_SKIP + 1) * 2;
const PEEK_BUF_SIZE: usize = (MAX_PEEK_SKIP + 1) * 2 + 1;

#[derive(Debug)]
pub(super) struct BufferedLexer<R> {
Expand All @@ -49,6 +49,7 @@ where
None::<Token>,
None::<Token>,
None::<Token>,
None::<Token>,
],
read_index: 0,
write_index: 0,
Expand Down
8 changes: 8 additions & 0 deletions boa/src/syntax/parser/cursor/buffered_lexer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,11 @@ fn skip_peeked_terminators() {
// End of stream
assert!(cur.peek(2, true, &mut interner).unwrap().is_none());
}

#[test]
fn issue_1768() {
let mut cur = BufferedLexer::from(&b"\n(\nx\n)\n"[..]);
let mut interner = Interner::default();

assert!(cur.peek(3, true, &mut interner).unwrap().is_none());
}
5 changes: 3 additions & 2 deletions boa/src/syntax/parser/expression/assignment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ where
.map(Node::ArrowFunctionDecl);
}
TokenKind::Punctuator(Punctuator::CloseParen) => {
// Need to check if the token after the close paren is an arrow, if so then this is an ArrowFunction
// otherwise it is an expression of the form (b).
// Need to check if the token after the close paren is an
// arrow, if so then this is an ArrowFunction otherwise it
// is an expression of the form (b).
if let Some(t) = cursor.peek(3, interner)? {
if t.kind() == &TokenKind::Punctuator(Punctuator::Arrow)
{
Expand Down