-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Classes are haunted: yield
and await
probably shouldn't be allowed in field initializers
#3333
Comments
The maximally consistent interpretation is to say that initializer RHSes are basically new function bodies and therefore should unset the |
Agreed. I think these should all be [~Yield, +Await, ~Return] with Early Error ban for |
While we're at it... can we also ban syntactically class C {
#secrets;
[this.#secrets] = 42;
static [this.#secrets] = 42;
}; or class C {
static #secrets;
[this.#secrets] = 42;
static [this.#secrets] = 42;
}; Maybe this should be in a different issue though. Right now I think they're all a runtime error (Although, until recently it was a crash in JSC). |
@kmiller68 Babel relies on it being syntactically valid to compile decorators, and banning it would break it: |
https://bugs.webkit.org/show_bug.cgi?id=276438 rdar://119044881 Reviewed by NOBODY (OOPS!). The language spec doesn't explictly disallow yield and await expressions in class field initializers, however it implicitly does given that the expression is effectively evaluated as if it's inside a method. Additionally, the consensus seems to be that these expressions should not be allowed, see: tc39/ecma262#3333 The yield and await expressions are now handled differently, but similar to how they are each handled in other contexts. This also seems to be the least disruptive way to handle existing scripts, as well as consistent with other engines: yield: raise syntax error await: parse as an identifier Also adding a new test that generates and verifies scripts containing a class with a field initializer containing yield and await, where the class is either not nested or nested inside generator or async functions to verify the behavior of various combinations. * Source/JavaScriptCore/parser/Parser.cpp: (JSC::Parser<LexerType>::parseYieldExpression): (JSC::Parser<LexerType>::parseAwaitExpression): (JSC::Parser<LexerType>::parsePrimaryExpression): (JSC::Parser<LexerType>::parseUnaryExpression):
https://bugs.webkit.org/show_bug.cgi?id=276438 rdar://119044881 Reviewed by Yusuke Suzuki. The language spec doesn't explictly disallow yield and await expressions in class field initializers, however it implicitly does given that the expression is effectively evaluated as if it's inside a method. Additionally, the consensus seems to be that these expressions should not be allowed, see: tc39/ecma262#3333 The yield and await expressions are now handled differently, but similar to how they are each handled in other contexts. This also seems to be the least disruptive way to handle existing scripts, as well as consistent with other engines: yield: raise syntax error await: parse as an identifier Also adding a new test that generates and verifies scripts containing a class with a field initializer containing yield and await, where the class is either not nested or nested inside generator or async functions to verify the behavior of various combinations. * Source/JavaScriptCore/parser/Parser.cpp: (JSC::Parser<LexerType>::parseYieldExpression): (JSC::Parser<LexerType>::parseAwaitExpression): (JSC::Parser<LexerType>::parsePrimaryExpression): (JSC::Parser<LexerType>::parseUnaryExpression): Canonical link: https://commits.webkit.org/280837@main
https://bugs.webkit.org/show_bug.cgi?id=276438 rdar://119044881 Reviewed by Yusuke Suzuki. The language spec doesn't explictly disallow yield and await expressions in class field initializers, however it implicitly does given that the expression is effectively evaluated as if it's inside a method. Additionally, the consensus seems to be that these expressions should not be allowed, see: tc39/ecma262#3333 The yield and await expressions are now handled differently, but similar to how they are each handled in other contexts. This also seems to be the least disruptive way to handle existing scripts, as well as consistent with other engines: yield: raise syntax error await: parse as an identifier Also adding a new test that generates and verifies scripts containing a class with a field initializer containing yield and await, where the class is either not nested or nested inside generator or async functions to verify the behavior of various combinations. * Source/JavaScriptCore/parser/Parser.cpp: (JSC::Parser<LexerType>::parseYieldExpression): (JSC::Parser<LexerType>::parseAwaitExpression): (JSC::Parser<LexerType>::parsePrimaryExpression): (JSC::Parser<LexerType>::parseUnaryExpression): Canonical link: https://commits.webkit.org/280837@main
https://bugs.webkit.org/show_bug.cgi?id=278589 rdar://132338331 Reviewed by NOBODY (OOPS!). The language spec doesn't explictly disallow yield and await expressions in class field initializers, however it implicitly does given that the expression is effectively evaluated as if it's inside a method. Additionally, the consensus seems to be that these expressions should not be allowed, see: tc39/ecma262#3333 The yield and await expressions are now handled differently, but similar to how they are each handled in other contexts. This also seems to be the least disruptive way to handle existing scripts, as well as consistent with other engines: yield: raise syntax error await: parse as an identifier Also adding a new test that generates and verifies scripts containing a class with a field initializer containing yield and await, where the class is either not nested or nested inside generator or async functions to verify the behavior of various combinations. * JSTests/stress/yield-await-class-field-initializer-expr.js: Added. (genTestCases): (genTestScript.append): (genTestScript): (expected): (testNegativeCases): (testPositiveCases.assertEq): (testPositiveCases.yieldFn0): * Source/JavaScriptCore/parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionBody): (JSC::Parser<LexerType>::parseClass): (JSC::Parser<LexerType>::parseYieldExpression): (JSC::Parser<LexerType>::parseAwaitExpression): (JSC::Parser<LexerType>::parsePrimaryExpression): (JSC::Parser<LexerType>::parseUnaryExpression): * Source/JavaScriptCore/parser/Parser.h:
https://bugs.webkit.org/show_bug.cgi?id=278589 rdar://132338331 Reviewed by NOBODY (OOPS!). The language spec doesn't explictly disallow yield and await expressions in class field initializers, however it implicitly does given that the expression is effectively evaluated as if it's inside a method. Additionally, the consensus seems to be that these expressions should not be allowed, see: tc39/ecma262#3333 The yield and await expressions are now handled differently, but similar to how they are each handled in other contexts. This also seems to be the least disruptive way to handle existing scripts, as well as consistent with other engines: yield: raise syntax error await: parse as an identifier Also adding a new test that generates and verifies scripts containing a class with a field initializer containing yield and await, where the class is either not nested or nested inside generator or async functions to verify the behavior of various combinations. * JSTests/stress/yield-await-class-field-initializer-expr.js: Added. (genTestCases): (genTestScript.append): (genTestScript): (expected): (testNegativeCases): (testPositiveCases.assertEq): (testPositiveCases.yieldFn0): * Source/JavaScriptCore/parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionBody): (JSC::Parser<LexerType>::parseClass): (JSC::Parser<LexerType>::parseYieldExpression): (JSC::Parser<LexerType>::parseAwaitExpression): (JSC::Parser<LexerType>::parsePrimaryExpression): (JSC::Parser<LexerType>::parseUnaryExpression): * Source/JavaScriptCore/parser/Parser.h:
https://bugs.webkit.org/show_bug.cgi?id=278589 rdar://132338331 Reviewed by NOBODY (OOPS!). The language spec doesn't explictly disallow yield and await expressions in class field initializers, however it implicitly does given that the expression is effectively evaluated as if it's inside a method. Additionally, the consensus seems to be that these expressions should not be allowed, see: tc39/ecma262#3333 The yield and await expressions are now handled differently, but similar to how they are each handled in other contexts. This also seems to be the least disruptive way to handle existing scripts, as well as consistent with other engines: yield: raise syntax error await: parse as an identifier Also adding a new test that generates and verifies scripts containing a class with a field initializer containing yield and await, where the class is either not nested or nested inside generator or async functions to verify the behavior of various combinations. * JSTests/stress/yield-await-class-field-initializer-expr.js: Added. (genTestCases): (genTestScript.append): (genTestScript): (expected): (testNegativeCases): (testPositiveCases.assertEq): (testPositiveCases.yieldFn0): * Source/JavaScriptCore/parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionBody): (JSC::Parser<LexerType>::parseClass): (JSC::Parser<LexerType>::parseYieldExpression): (JSC::Parser<LexerType>::parseAwaitExpression): (JSC::Parser<LexerType>::parsePrimaryExpression): (JSC::Parser<LexerType>::parseUnaryExpression): * Source/JavaScriptCore/parser/Parser.h:
https://bugs.webkit.org/show_bug.cgi?id=278589 rdar://132338331 Reviewed by NOBODY (OOPS!). The language spec doesn't explictly disallow yield and await expressions in class field initializers, however it implicitly does given that the expression is effectively evaluated as if it's inside a method. Additionally, the consensus seems to be that these expressions should not be allowed, see: tc39/ecma262#3333 The yield and await expressions are now handled differently, but similar to how they are each handled in other contexts. This also seems to be the least disruptive way to handle existing scripts, as well as consistent with other engines: yield: raise syntax error await: parse as an identifier However, if the field initializer expression is an async function expression, then 'await' is allowed within that expression. Also adding a new test that generates and verifies scripts containing a class with a field initializer containing yield and await, where the class is either not nested or nested inside generator or async functions to verify the behavior of various combinations. * JSTests/stress/yield-await-class-field-initializer-expr.js: Added. (genTestCases): (genTestScript.append): (genTestScript): (expected): (testNegativeCases): (testPositiveCases.assertEq): (testPositiveCases.yieldFn0): * Source/JavaScriptCore/parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionBody): (JSC::Parser<LexerType>::parseClass): (JSC::Parser<LexerType>::parseYieldExpression): (JSC::Parser<LexerType>::parseAwaitExpression): (JSC::Parser<LexerType>::parsePrimaryExpression): (JSC::Parser<LexerType>::parseUnaryExpression): * Source/JavaScriptCore/parser/Parser.h:
https://bugs.webkit.org/show_bug.cgi?id=278589 rdar://132338331 Reviewed by Yusuke Suzuki. The language spec doesn't explictly disallow yield and await expressions in class field initializers, however it implicitly does given that the expression is effectively evaluated as if it's inside a method. Additionally, the consensus seems to be that these expressions should not be allowed, see: tc39/ecma262#3333 The yield and await expressions are now handled differently, but similar to how they are each handled in other contexts. This also seems to be the least disruptive way to handle existing scripts, as well as consistent with other engines: yield: raise syntax error await: parse as an identifier However, if the field initializer expression is an async function expression, then 'await' is allowed within that expression. Also adding a new test that generates and verifies scripts containing a class with a field initializer containing yield and await, where the class is either not nested or nested inside generator or async functions to verify the behavior of various combinations. * JSTests/stress/yield-await-class-field-initializer-expr.js: Added. (genTestCases): (genTestScript.append): (genTestScript): (expected): (testNegativeCases): (testPositiveCases.assertEq): (testPositiveCases.yieldFn0): * Source/JavaScriptCore/parser/Parser.cpp: (JSC::Parser<LexerType>::parseFunctionBody): (JSC::Parser<LexerType>::parseClass): (JSC::Parser<LexerType>::parseYieldExpression): (JSC::Parser<LexerType>::parseAwaitExpression): (JSC::Parser<LexerType>::parsePrimaryExpression): (JSC::Parser<LexerType>::parseUnaryExpression): * Source/JavaScriptCore/parser/Parser.h: Canonical link: https://commits.webkit.org/282819@main
FieldDefinition passes along [?Yield, ?Await], which means the RHS of field initializers inside async functions and generators allow
yield
andawait
expressions to be parsed.Suspending in the middle of construction of a class instance is super cursed!
It is arguably sensible for
static
initializers, but even that seems gross.Behavior diverges among browser implementations. JSC parses both
yield
andawait
expressions in initializers, and SpiderMonkey and V8 rejectyield
andawait
expressions.The text was updated successfully, but these errors were encountered: