From 968d2c0889e761a29dd2c85663bc57d8643860bf Mon Sep 17 00:00:00 2001 From: raskad <32105367+raskad@users.noreply.github.com> Date: Sun, 6 Nov 2022 18:49:31 +0100 Subject: [PATCH 1/2] Add early error for `yield` in `GeneratorExpression` parameters --- boa_engine/src/string/mod.rs | 1 - .../parser/expression/primary/generator_expression/mod.rs | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/boa_engine/src/string/mod.rs b/boa_engine/src/string/mod.rs index 71f5dfb723f..2b6ea514eb8 100644 --- a/boa_engine/src/string/mod.rs +++ b/boa_engine/src/string/mod.rs @@ -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. diff --git a/boa_parser/src/parser/expression/primary/generator_expression/mod.rs b/boa_parser/src/parser/expression/primary/generator_expression/mod.rs index de336a44292..8a2dc0faa13 100644 --- a/boa_parser/src/parser/expression/primary/generator_expression/mod.rs +++ b/boa_parser/src/parser/expression/primary/generator_expression/mod.rs @@ -130,6 +130,14 @@ where params_start_position, )?; + // It is a Syntax Error if FormalParameters Contains YieldExpression is true. + if contains(¶ms, 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) { From ddac6f0dc5ccbf08391d1f0d0e184efe16856be5 Mon Sep 17 00:00:00 2001 From: raskad <32105367+raskad@users.noreply.github.com> Date: Mon, 7 Nov 2022 20:17:14 +0100 Subject: [PATCH 2/2] Update spec links and text for generator expression parsing --- .../expression/primary/generator_expression/mod.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/boa_parser/src/parser/expression/primary/generator_expression/mod.rs b/boa_parser/src/parser/expression/primary/generator_expression/mod.rs index 8a2dc0faa13..5a12db96823 100644 --- a/boa_parser/src/parser/expression/primary/generator_expression/mod.rs +++ b/boa_parser/src/parser/expression/primary/generator_expression/mod.rs @@ -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( @@ -103,8 +104,9 @@ 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(), @@ -112,8 +114,9 @@ where ))); } - // 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(), @@ -122,8 +125,8 @@ 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(¶ms), &top_level_lexically_declared_names(&body), @@ -131,6 +134,7 @@ where )?; // It is a Syntax Error if FormalParameters Contains YieldExpression is true. + // https://tc39.es/ecma262/#sec-generator-function-definitions-static-semantics-early-errors if contains(¶ms, ContainsSymbol::YieldExpression) { return Err(Error::lex(LexError::Syntax( "generator expression cannot contain yield expression in parameters".into(),