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

Allow arguments and eval in the return position of strict functions #1836

Closed
wants to merge 2 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
4 changes: 1 addition & 3 deletions boa/src/syntax/lexer/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use core::convert::TryFrom;
use std::io::Read;
use std::str;

const STRICT_FORBIDDEN_IDENTIFIERS: [&str; 11] = [
"eval",
"arguments",
const STRICT_FORBIDDEN_IDENTIFIERS: [&str; 9] = [
"implements",
"interface",
"let",
Expand Down
11 changes: 9 additions & 2 deletions boa/src/syntax/parser/statement/declaration/lexical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
},
Keyword, Punctuator,
},
lexer::TokenKind,
lexer::{Error as LexError, TokenKind},
parser::{
cursor::{Cursor, SemicolonResult},
expression::Initializer,
Expand All @@ -27,6 +27,7 @@ use crate::{
BoaProfiler, Interner,
};

use boa_interner::Sym;
use std::io::Read;

/// Parses a lexical declaration.
Expand Down Expand Up @@ -259,6 +260,7 @@ where
let _timer = BoaProfiler::global().start_event("LexicalBinding", "Parsing");

let peek_token = cursor.peek(0, interner)?.ok_or(ParseError::AbruptEnd)?;
let token_pos = peek_token.span().start();

match peek_token.kind() {
TokenKind::Punctuator(Punctuator::OpenBlock) => {
Expand Down Expand Up @@ -318,7 +320,12 @@ where
} else {
None
};

if cursor.strict_mode() && (ident == Sym::EVAL || ident == Sym::ARGUMENTS) {
return Err(ParseError::lex(LexError::Syntax(
"Unexpected eval or arguments in strict mode".into(),
token_pos,
)));
}
Ok(Declaration::new_with_identifier(ident, init))
}
}
Expand Down
10 changes: 9 additions & 1 deletion boa/src/syntax/parser/statement/variable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
node::{Declaration, DeclarationList},
Keyword, Punctuator,
},
lexer::TokenKind,
lexer::{Error as LexError, TokenKind},
parser::statement::{ArrayBindingPattern, ObjectBindingPattern},
parser::{
cursor::{Cursor, SemicolonResult},
Expand All @@ -17,6 +17,7 @@ use crate::{
},
BoaProfiler, Interner,
};
use boa_interner::Sym;
use std::io::Read;

/// Variable statement parsing.
Expand Down Expand Up @@ -181,6 +182,7 @@ where
interner: &mut Interner,
) -> Result<Self::Output, ParseError> {
let peek_token = cursor.peek(0, interner)?.ok_or(ParseError::AbruptEnd)?;
let token_pos = peek_token.span().start();

match peek_token.kind() {
TokenKind::Punctuator(Punctuator::OpenBlock) => {
Expand Down Expand Up @@ -240,6 +242,12 @@ where
} else {
None
};
if cursor.strict_mode() && (ident == Sym::EVAL || ident == Sym::ARGUMENTS) {
return Err(ParseError::lex(LexError::Syntax(
"Unexpected eval or arguments in strict mode".into(),
token_pos,
)));
}

Ok(Declaration::new_with_identifier(ident, init))
}
Expand Down