Skip to content

Commit

Permalink
Rename strict_mode to strict
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Apr 13, 2023
1 parent f8a491d commit 3ed574c
Show file tree
Hide file tree
Showing 23 changed files with 99 additions and 101 deletions.
10 changes: 5 additions & 5 deletions boa_parser/src/lexer/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl StringLiteral {
cursor: &mut Cursor<R>,
start_pos: Position,
terminator: StringTerminator,
is_strict_mode: bool,
strict: bool,
) -> Result<(Vec<u16>, Span, Option<EscapeSequence>), Error>
where
R: Read,
Expand All @@ -139,7 +139,7 @@ impl StringLiteral {
Self::take_escape_sequence_or_line_continuation(
cursor,
ch_start_pos,
is_strict_mode,
strict,
false,
)?
{
Expand Down Expand Up @@ -167,7 +167,7 @@ impl StringLiteral {
pub(super) fn take_escape_sequence_or_line_continuation<R>(
cursor: &mut Cursor<R>,
start_pos: Position,
is_strict_mode: bool,
strict: bool,
is_template_literal: bool,
) -> Result<Option<(u32, Option<EscapeSequence>)>, Error>
where
Expand Down Expand Up @@ -208,7 +208,7 @@ impl StringLiteral {
"\\8 and \\9 are not allowed in template literal",
start_pos,
));
} else if is_strict_mode {
} else if strict {
return Err(Error::syntax(
"\\8 and \\9 are not allowed in strict mode",
start_pos,
Expand All @@ -224,7 +224,7 @@ impl StringLiteral {
));
}

if is_strict_mode {
if strict {
return Err(Error::syntax(
"octal escape sequences are not allowed in strict mode",
start_pos,
Expand Down
6 changes: 3 additions & 3 deletions boa_parser/src/parser/cursor/buffered_lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ where
.map_err(Error::from)
}

pub(super) const fn strict_mode(&self) -> bool {
pub(super) const fn strict(&self) -> bool {
self.lexer.strict()
}

pub(super) fn set_strict_mode(&mut self, strict_mode: bool) {
self.lexer.set_strict(strict_mode);
pub(super) fn set_strict(&mut self, strict: bool) {
self.lexer.set_strict(strict);
}

pub(super) const fn module(&self) -> bool {
Expand Down
8 changes: 4 additions & 4 deletions boa_parser/src/parser/cursor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ where
}

/// Gets the current strict mode for the cursor.
pub(super) const fn strict_mode(&self) -> bool {
self.buffered_lexer.strict_mode()
pub(super) const fn strict(&self) -> bool {
self.buffered_lexer.strict()
}

/// Sets the strict mode to strict or non-strict.
pub(super) fn set_strict_mode(&mut self, strict_mode: bool) {
self.buffered_lexer.set_strict_mode(strict_mode);
pub(super) fn set_strict(&mut self, strict: bool) {
self.buffered_lexer.set_strict(strict);
}

/// Returns if the cursor is currently in an arrow function declaration.
Expand Down
5 changes: 2 additions & 3 deletions boa_parser/src/parser/expression/assignment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ where
cursor.advance(interner);
cursor.set_goal(InputElement::RegExp);

if let Some(target) = AssignTarget::from_expression(&lhs, cursor.strict_mode())
{
if let Some(target) = AssignTarget::from_expression(&lhs, cursor.strict()) {
if let AssignTarget::Identifier(ident) = target {
self.name = Some(ident);
}
Expand All @@ -257,7 +256,7 @@ where
TokenKind::Punctuator(p) if p.as_assign_op().is_some() => {
cursor.advance(interner);
if let Some(target) =
AssignTarget::from_expression_simple(&lhs, cursor.strict_mode())
AssignTarget::from_expression_simple(&lhs, cursor.strict())
{
let assignop = p.as_assign_op().expect("assignop disappeared");
if assignop == AssignOp::BoolAnd
Expand Down
4 changes: 2 additions & 2 deletions boa_parser/src/parser/expression/identifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ where
let span = cursor.peek(0, interner).or_abrupt()?.span();
let ident = Identifier.parse(cursor, interner)?;
match ident.sym() {
Sym::ARGUMENTS | Sym::EVAL if cursor.strict_mode() => {
Sym::ARGUMENTS | Sym::EVAL if cursor.strict() => {
let name = interner
.resolve_expect(ident.sym())
.utf8()
Expand Down Expand Up @@ -178,7 +178,7 @@ where
}
};

if cursor.strict_mode() && ident.is_strict_reserved_identifier() {
if cursor.strict() && ident.is_strict_reserved_identifier() {
return Err(Error::unexpected(
interner
.resolve_expect(ident)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ where

// Early Error: If the source code matching FormalParameters is strict mode code,
// the Early Error rules for UniqueFormalParameters : FormalParameters are applied.
if (cursor.strict_mode() || body.strict()) && params.has_duplicates() {
if (cursor.strict() || body.strict()) && params.has_duplicates() {
return Err(Error::lex(LexError::Syntax(
"Duplicate parameter name not allowed in this context".into(),
params_start_position,
Expand All @@ -116,7 +116,7 @@ where
// Early Error: If BindingIdentifier is present and the source code matching BindingIdentifier is strict mode code,
// it is a Syntax Error if the StringValue of BindingIdentifier is "eval" or "arguments".
if let Some(name) = name {
if (cursor.strict_mode() || body.strict())
if (cursor.strict() || body.strict())
&& [Sym::EVAL, Sym::ARGUMENTS].contains(&name.sym())
{
return Err(Error::lex(LexError::Syntax(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ where

// Early Error: If the source code matching FormalParameters is strict mode code,
// the Early Error rules for UniqueFormalParameters : FormalParameters are applied.
if (cursor.strict_mode() || body.strict()) && params.has_duplicates() {
if (cursor.strict() || body.strict()) && params.has_duplicates() {
return Err(Error::lex(LexError::Syntax(
"Duplicate parameter name not allowed in this context".into(),
params_start_position,
Expand All @@ -154,7 +154,7 @@ where
// Early Error: If BindingIdentifier is present and the source code matching BindingIdentifier is strict mode code,
// it is a Syntax Error if the StringValue of BindingIdentifier is "eval" or "arguments".
if let Some(name) = name {
if (cursor.strict_mode() || body.strict())
if (cursor.strict() || body.strict())
&& [Sym::EVAL, Sym::ARGUMENTS].contains(&name.sym())
{
return Err(Error::lex(LexError::Syntax(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ where

fn parse(self, cursor: &mut Cursor<R>, interner: &mut Interner) -> ParseResult<Self::Output> {
let _timer = Profiler::global().start_event("ClassExpression", "Parsing");
let strict = cursor.strict_mode();
cursor.set_strict_mode(true);
let strict = cursor.strict();
cursor.set_strict(true);

let mut has_binding_identifier = false;
let token = cursor.peek(0, interner).or_abrupt()?;
Expand All @@ -62,7 +62,7 @@ where
}
_ => self.name,
};
cursor.set_strict_mode(strict);
cursor.set_strict(strict);

ClassTail::new(
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ where

// Early Error: If the source code matching FormalParameters is strict mode code,
// the Early Error rules for UniqueFormalParameters : FormalParameters are applied.
if (cursor.strict_mode() || body.strict()) && params.has_duplicates() {
if (cursor.strict() || body.strict()) && params.has_duplicates() {
return Err(Error::lex(LexError::Syntax(
"Duplicate parameter name not allowed in this context".into(),
params_start_position,
Expand All @@ -111,7 +111,7 @@ where
// Early Error: If BindingIdentifier is present and the source code matching BindingIdentifier is strict mode code,
// it is a Syntax Error if the StringValue of BindingIdentifier is "eval" or "arguments".
if let Some(name) = name {
if (cursor.strict_mode() || body.strict())
if (cursor.strict() || body.strict())
&& [Sym::EVAL, Sym::ARGUMENTS].contains(&name.sym())
{
return Err(Error::lex(LexError::Syntax(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ where
// If the source text matched by FormalParameters is strict mode code,
// the Early Error rules for UniqueFormalParameters : FormalParameters are applied.
// https://tc39.es/ecma262/#sec-generator-function-definitions-static-semantics-early-errors
if (cursor.strict_mode() || body.strict()) && params.has_duplicates() {
if (cursor.strict() || body.strict()) && params.has_duplicates() {
return Err(Error::lex(LexError::Syntax(
"Duplicate parameter name not allowed in this context".into(),
params_start_position,
Expand All @@ -119,7 +119,7 @@ where
// Early Error: If BindingIdentifier is present and the source code matching BindingIdentifier is strict mode code,
// it is a Syntax Error if the StringValue of BindingIdentifier is "eval" or "arguments".
if let Some(name) = name {
if (cursor.strict_mode() || body.strict())
if (cursor.strict() || body.strict())
&& [Sym::EVAL, Sym::ARGUMENTS].contains(&name.sym())
{
return Err(Error::lex(LexError::Syntax(
Expand Down
2 changes: 1 addition & 1 deletion boa_parser/src/parser/expression/primary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ where
expression_to_formal_parameters(
&node,
&mut parameters,
cursor.strict_mode(),
cursor.strict(),
start_span,
)?;
}
Expand Down
2 changes: 1 addition & 1 deletion boa_parser/src/parser/expression/unary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ where
let target = self.parse(cursor, interner)?;

match target.flatten() {
Expression::Identifier(_) if cursor.strict_mode() => {
Expression::Identifier(_) if cursor.strict() => {
return Err(Error::lex(LexError::Syntax(
"cannot delete variables in strict mode".into(),
token_start,
Expand Down
8 changes: 4 additions & 4 deletions boa_parser/src/parser/expression/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ where
.parse(cursor, interner)?;

// https://tc39.es/ecma262/#sec-update-expressions-static-semantics-early-errors
return (as_simple(&target, position, cursor.strict_mode())?).map_or_else(
return (as_simple(&target, position, cursor.strict())?).map_or_else(
|| {
Err(Error::lex(LexError::Syntax(
"Invalid left-hand side in assignment".into(),
Expand All @@ -125,7 +125,7 @@ where
.parse(cursor, interner)?;

// https://tc39.es/ecma262/#sec-update-expressions-static-semantics-early-errors
return (as_simple(&target, position, cursor.strict_mode())?).map_or_else(
return (as_simple(&target, position, cursor.strict())?).map_or_else(
|| {
Err(Error::lex(LexError::Syntax(
"Invalid left-hand side in assignment".into(),
Expand Down Expand Up @@ -154,7 +154,7 @@ where
.expect("Punctuator::Inc token disappeared");

// https://tc39.es/ecma262/#sec-update-expressions-static-semantics-early-errors
return (as_simple(&lhs, position, cursor.strict_mode())?).map_or_else(
return (as_simple(&lhs, position, cursor.strict())?).map_or_else(
|| {
Err(Error::lex(LexError::Syntax(
"Invalid left-hand side in assignment".into(),
Expand All @@ -170,7 +170,7 @@ where
.expect("Punctuator::Dec token disappeared");

// https://tc39.es/ecma262/#sec-update-expressions-static-semantics-early-errors
return (as_simple(&lhs, position, cursor.strict_mode())?).map_or_else(
return (as_simple(&lhs, position, cursor.strict())?).map_or_else(
|| {
Err(Error::lex(LexError::Syntax(
"Invalid left-hand side in assignment".into(),
Expand Down
6 changes: 3 additions & 3 deletions boa_parser/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl<R> Parser<'_, R> {
where
R: Read,
{
self.cursor.set_strict_mode(true);
self.cursor.set_strict(true);
}

/// Set the parser JSON mode to true.
Expand Down Expand Up @@ -246,8 +246,8 @@ where
type Output = StatementList;

fn parse(self, cursor: &mut Cursor<R>, interner: &mut Interner) -> ParseResult<Self::Output> {
let statement_list = ScriptBody::new(true, cursor.strict_mode(), self.direct_eval)
.parse(cursor, interner)?;
let statement_list =
ScriptBody::new(true, cursor.strict(), self.direct_eval).parse(cursor, interner)?;

// It is a Syntax Error if the LexicallyDeclaredNames of ScriptBody contains any duplicate entries.
let mut lexical_names = FxHashSet::default();
Expand Down
2 changes: 1 addition & 1 deletion boa_parser/src/parser/statement/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ where
let mut lexical_names = FxHashMap::default();
for (name, is_fn) in lexically_declared_names_legacy(&statement_list) {
if let Some(is_fn_previous) = lexical_names.insert(name, is_fn) {
match (cursor.strict_mode(), is_fn, is_fn_previous) {
match (cursor.strict(), is_fn, is_fn_previous) {
(false, true, true) => {}
_ => {
return Err(Error::general(
Expand Down
Loading

0 comments on commit 3ed574c

Please sign in to comment.