Implement support for class static initialization blocks … #1615
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://bugswebkit.org/show_bug.cgi?id=235085 rdar://99056882
Reviewed by Yusuke Suzuki.
Class static initialization block is a new feature of a class to perform additional static initialization during class definition evaluation.
TC39 Spec: https://tc39.es/proposal-class-static-block/
TC39 Proposal: https://github.com/tc39/proposal-class-static-block
MDN Web Doc: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Class_static_initialization_blocks
In this patch, static blocks are implemented as functions which are evaluated along with the initialization of static class fields during class definition evaluation. This can be further optimized by inlining static block functions to the field initialization.
(A):
(assert.C):
(assert.B):
(assert.D):
(assert.A):
(assert.A.friendA.prototype.getX):
(assert.A.friendA.prototype.setX):
(assert.A.prototype.getX):
(assert.inner):
(catch.C.prototype.async inner):
(catch.C):
(catch):
(async inner.C.prototype.async inner):
(async inner.C):
(async inner):
(C.inner):
(C):
(await.C.inner):
(await.C):
(await):
(arguments.C.inner):
(arguments.C):
(arguments):
(JSC::FunctionCallValueNode::emitBytecode):
(JSC::FuncExprNode::emitBytecode):
(JSC::ASTBuilder::createProperty):
(JSC::ASTBuilder::makeFunctionCallNode):
(JSC::FunctionCallValueNode::FunctionCallValueNode): (JSC::FuncExprNode::FuncExprNode):
(JSC::Parser::parseVariableDeclarationList): (JSC::Parser::parseBreakStatement):
(JSC::Parser::parseContinueStatement):
(JSC::Parser::parseReturnStatement):
(JSC::Parser::parseTryStatement):
(JSC::Parser::parseBlockStatement):
(JSC::stringArticleForFunctionMode):
(JSC::stringForFunctionMode):
(JSC::Parser::parseFunctionParameters): (JSC::Parser::parseFunctionInfo):
(JSC::Parser::parseClass):
(JSC::Parser::parseClassFieldInitializerSourceElements): (JSC::Parser::parseAssignmentExpression): (JSC::Parser::parsePrimaryExpression):
(JSC::Parser::parseMemberExpression):
(JSC::Parser::parseUnaryExpression):
(JSC::Scope::setIsStaticBlockScope):
(JSC::Scope::isStaticBlockScope):
(JSC::Parser::canUseIdentifierAwait):
(JSC::Parser::disallowedIdentifierAwaitReason):
(JSC::Parser::findClosetFunctionScope):
(JSC::Parser::findClosetAsyncFunctionScope):
(JSC::Parser::findScopeUntilStaticBlock):
(JSC::isMethodParseMode):
(JSC::SyntaxChecker::createFunctionExpr):
(JSC::SyntaxChecker::createProperty):
Canonical link: https://commits.webkit.org/255173@main
Pull Request Template
File a Bug
All changes should be associated with a bug. The WebKit project is currently using Bugzilla as our bug tracker. Note that multiple changes may be associated with a single bug.
Provided Tooling
The WebKit Project strongly recommends contributors use
Tools/Scripts/git-webkitto generate pull requests. See Setup and Contributing Code for how to do this.Template
If a contributor wishes to file a pull request manually, the template is below. Manually-filed pull requests should contain their commit message as the pull request description, and their commit message should be formatted like the template below.
Additionally, the pull request should be mentioned on Bugzilla, labels applied to the pull request matching the component and version of the Bugzilla associated with the pull request and the pull request assigned to its author.