Skip to content

Commit

Permalink
Fixed #1768
Browse files Browse the repository at this point in the history
  • Loading branch information
Razican committed Feb 5, 2022
1 parent b34d581 commit 83fd796
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 6 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 Expand Up @@ -152,6 +153,7 @@ where
self.read_index, self.write_index,
"we reached the read index with the write index"
);

debug_assert!(
self.read_index < PEEK_BUF_SIZE,
"read index went out of bounds"
Expand Down
12 changes: 10 additions & 2 deletions boa/src/syntax/parser/expression/assignment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,13 @@ where
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).
if let Some(t) = cursor.peek(3, interner)? {
if t.kind() == &TokenKind::Punctuator(Punctuator::Arrow)
#[allow(clippy::match_same_arms)]
match cursor.peek(3, interner) {
Ok(Some(t))
if t.kind()
== &TokenKind::Punctuator(
Punctuator::Arrow,
) =>
{
return ArrowFunction::new(
self.allow_in,
Expand All @@ -166,6 +171,9 @@ where
.parse(cursor, interner)
.map(Node::ArrowFunctionDecl);
}
Err(ParseError::AbruptEnd) => {}
Err(e) => return Err(e),
_ => {}
}
}
_ => {}
Expand Down

0 comments on commit 83fd796

Please sign in to comment.