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] - Add early error for yield in GeneratorExpression parameters #2413

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
1 change: 0 additions & 1 deletion boa_engine/src/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,6 @@ impl ToStringEscaped for [u16] {
mod tests {
use super::utf16;
use super::{JsString, JsStringPtrKind};
use std::mem::size_of;

impl JsString {
/// Gets the number of `JsString`s which point to this allocation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ where
),
};

// Early Error: If BindingIdentifier is present and the source code matching BindingIdentifier is strict mode code,
// If BindingIdentifier is present and the source text matched by BindingIdentifier is strict mode code,
// it is a Syntax Error if the StringValue of BindingIdentifier is "eval" or "arguments".
// https://tc39.es/ecma262/#sec-generator-function-definitions-static-semantics-early-errors
if let Some(name) = name {
if cursor.strict_mode() && [Sym::EVAL, Sym::ARGUMENTS].contains(&name.sym()) {
return Err(Error::lex(LexError::Syntax(
Expand All @@ -103,17 +104,19 @@ where

cursor.expect(Punctuator::CloseBlock, "generator expression", interner)?;

// Early Error: If the source code matching FormalParameters is strict mode code,
// 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() {
return Err(Error::lex(LexError::Syntax(
"Duplicate parameter name not allowed in this context".into(),
params_start_position,
)));
}

// Early Error: It is a Syntax Error if FunctionBodyContainsUseStrict of GeneratorBody is true
// It is a Syntax Error if FunctionBodyContainsUseStrict of GeneratorBody is true
// and IsSimpleParameterList of FormalParameters is false.
// https://tc39.es/ecma262/#sec-generator-function-definitions-static-semantics-early-errors
if body.strict() && !params.is_simple() {
return Err(Error::lex(LexError::Syntax(
"Illegal 'use strict' directive in function with non-simple parameter list".into(),
Expand All @@ -122,14 +125,23 @@ where
}

// It is a Syntax Error if any element of the BoundNames of FormalParameters
// also occurs in the LexicallyDeclaredNames of FunctionBody.
// https://tc39.es/ecma262/#sec-function-definitions-static-semantics-early-errors
// also occurs in the LexicallyDeclaredNames of GeneratorBody.
// https://tc39.es/ecma262/#sec-generator-function-definitions-static-semantics-early-errors
name_in_lexically_declared_names(
&bound_names(&params),
&top_level_lexically_declared_names(&body),
params_start_position,
)?;

// It is a Syntax Error if FormalParameters Contains YieldExpression is true.
Copy link
Member

@jasonwilliams jasonwilliams Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// https://tc39.es/ecma262/#sec-generator-function-definitions-static-semantics-early-errors

I think the above comment is also pointing to function definitions not generator function definitions which is slightly different.

// https://tc39.es/ecma262/#sec-generator-function-definitions-static-semantics-early-errors
if contains(&params, ContainsSymbol::YieldExpression) {
return Err(Error::lex(LexError::Syntax(
"generator expression cannot contain yield expression in parameters".into(),
params_start_position,
)));
}

let function = Generator::new(name, params, body, has_binding_identifier);

if contains(&function, ContainsSymbol::Super) {
Expand Down