RESOLVED FIXED 235085
[JSC] Implement support for class static initialization blocks
https://bugs.webkit.org/show_bug.cgi?id=235085
Summary [JSC] Implement support for class static initialization blocks
Devin Rousso
Reported 2022-01-11 15:11:10 PST
Attachments
Patch (50.68 KB, patch)
2022-09-27 21:49 PDT, Yijia Huang
ews-feeder: commit-queue-
Patch (51.48 KB, patch)
2022-09-28 10:05 PDT, Yijia Huang
no flags
Patch (52.17 KB, patch)
2022-09-28 11:02 PDT, Yijia Huang
ews-feeder: commit-queue-
Radar WebKit Bug Importer
Comment 1 2022-01-11 15:11:27 PST
Rob Palmer
Comment 2 2022-09-07 00:32:34 PDT
This feature went to Stage 4 one year ago (August 2021) and is now part of ES2022. The consequence of not implementing this feature is that many users of the feature are forced to transpile/downlevel their code to ES2021. This over-downlevelling has the unfortunate side-effect of causing all private fields to be stored in WeakMaps, which tend to be much slower than native private fields.
Mark Lam
Comment 3 2022-09-23 11:35:23 PDT
*** Bug 244280 has been marked as a duplicate of this bug. ***
Caitlin Potter (:caitp)
Comment 4 2022-09-25 21:22:06 PDT
FYI, Serakeri has been working on this offline
Mark Lam
Comment 5 2022-09-25 21:58:37 PDT
(In reply to Caitlin Potter (:caitp) from comment #4) > FYI, Serakeri has been working on this offline Yijia has also been working on this for a while. Perhaps we should sync up and avoid duplicating work.
Yijia Huang
Comment 6 2022-09-27 21:49:52 PDT
Yusuke Suzuki
Comment 7 2022-09-27 22:26:48 PDT
@Caitlin, Yijia's patch is now uploaded for review / merge.
Yusuke Suzuki
Comment 8 2022-09-27 22:50:04 PDT
Comment on attachment 462669 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=462669&action=review > Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:1259 > + RegisterID* ret; Use `RefPtr<RegisterID>`. > Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:4994 > + RegisterID* res = generator.emitNewFunctionExpression(generator.finalDestination(dst), this); Use `RefPtr<RegisterID>`. > Source/JavaScriptCore/parser/ASTBuilder.h:133 > + ExpressionNode* makeFunctionCallNode(const JSTokenLocation&, ExpressionNode* func, bool previousBaseWasSuper, ArgumentsNode* args, const JSTextPosition& divotStart, const JSTextPosition& divot, const JSTextPosition& divotEnd, size_t callOrApplyChildDepth, bool isOptionalCall, bool isStaticClassBlockFunctionCall = false); Avoid using `bool` for parameter since it is hard to know what it means from the callsite. Use enum instead. > Source/JavaScriptCore/parser/ASTBuilder.h:428 > + ExpressionNode* createFunctionExpr(const JSTokenLocation& location, const ParserFunctionInfo<ASTBuilder>& functionInfo, bool isStaticBlockFunction = false) Avoid using `bool` for parameter since it is hard to know what it means from the callsite. Use enum instead. > Source/JavaScriptCore/parser/ASTBuilder.h:1424 > +ExpressionNode* ASTBuilder::makeFunctionCallNode(const JSTokenLocation& location, ExpressionNode* func, bool previousBaseWasSuper, ArgumentsNode* args, const JSTextPosition& divotStart, const JSTextPosition& divot, const JSTextPosition& divotEnd, size_t callOrApplyChildDepth, bool isOptionalCall, bool isStaticBlockFunctionCall) Avoid using `bool` for parameter since it is hard to know what it means from the callsite. Use enum instead. > Source/JavaScriptCore/parser/NodeConstructors.h:412 > + inline FunctionCallValueNode::FunctionCallValueNode(const JSTokenLocation& location, ExpressionNode* expr, ArgumentsNode* args, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd, const bool isStaticBlockFunctionCall) Avoid using `bool` for parameter since it is hard to know what it means from the callsite. Use enum instead. > Source/JavaScriptCore/parser/NodeConstructors.h:1034 > + inline FuncExprNode::FuncExprNode(const JSTokenLocation& location, const Identifier& ident, FunctionMetadataNode* metadata, const SourceCode& source, bool isStaticBlockFunction) Avoid using `bool` for parameter since it is hard to know what it means from the callsite. Use enum instead. > Source/JavaScriptCore/parser/Nodes.h:991 > + FunctionCallValueNode(const JSTokenLocation&, ExpressionNode*, ArgumentsNode*, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd, bool isStatic = false); Avoid using `bool` for parameter since it is hard to know what it means from the callsite. Use enum instead. > Source/JavaScriptCore/parser/Nodes.h:2343 > + FuncExprNode(const JSTokenLocation&, const Identifier&, FunctionMetadataNode*, const SourceCode&, bool isStaticBlock = false); Avoid using `bool` for parameter since it is hard to know what it means from the callsite. Use enum instead. > Source/JavaScriptCore/parser/Parser.cpp:1899 > +template <class TreeBuilder> TreeStatement Parser<LexerType>::parseBlockStatement(TreeBuilder& context, bool isCatchBlock, bool isStaticBlock) Avoid using `bool` for parameter since it is hard to know what it means from the callsite. Use enum instead. > Source/JavaScriptCore/parser/Parser.h:1763 > + template <class TreeBuilder> TreeStatement parseBlockStatement(TreeBuilder&, bool isCatchBlock = false, bool isStaticBlock = false); Avoid using `bool` for parameter since it is hard to know what it means from the callsite. Use enum instead. > Source/JavaScriptCore/parser/SyntaxChecker.h:151 > + ExpressionType makeFunctionCallNode(const JSTokenLocation&, ExpressionType, bool, int, int, int, int, size_t, bool, bool = false) { return CallExpr; } Avoid using `bool` for parameter since it is hard to know what it means from the callsite. Use enum instead. > Source/JavaScriptCore/parser/SyntaxChecker.h:198 > + ExpressionType createFunctionExpr(const JSTokenLocation&, const ParserFunctionInfo<SyntaxChecker>&, bool = false) { return FunctionExpr; } Avoid using `bool` for parameter since it is hard to know what it means from the callsite. Use enum instead. > JSTests/stress/class-static-block.js:1 > +function assert(b) { Enable test262 too to ensure that they are correctly implemented. See JSTests/test262/config.yaml to enable it for this feature.
Yijia Huang
Comment 9 2022-09-28 10:05:29 PDT
Yijia Huang
Comment 10 2022-09-28 11:02:48 PDT
Yijia Huang
Comment 11 2022-09-28 14:26:56 PDT
Mark Lam
Comment 12 2022-09-28 15:42:42 PDT
Comment on attachment 462688 [details] Patch Taking this bugzilla patch out of review. A PR has been posted on WebKit Github. Will continue reviewing there.
Darin Adler
Comment 13 2022-09-30 09:21:03 PDT
Comment on attachment 462688 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=462688&action=review > Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:4994 > + RefPtr<RegisterID> homeObject = emitHomeObjectForCallee(generator); > + RefPtr<RegisterID> res = generator.emitNewFunctionExpression(generator.finalDestination(dst), this); Should be able to write just RefPtr here rather than RefPtr<RegisterID>. Not sure if there are different traditions in this code, but typically in WebKit we prefer words, like result, rather than fragments, like res. > Source/JavaScriptCore/parser/NodeConstructors.h:256 > + , m_expression(nullptr) > + , m_assign(nullptr) These could be initialized in the class definition instead of the constructor. > Source/JavaScriptCore/parser/NodeConstructors.h:260 > + , m_isOverriddenByDuplicate(false) This could be initialized in the class definition instead of the constructor. > Source/JavaScriptCore/parser/NodeConstructors.h:1042 > + , m_isStaticBlockFunction(false) This could be initialized in the class definition instead of the constructor. > Source/JavaScriptCore/parser/Nodes.h:1002 > ExpressionNode* m_expr; > ArgumentsNode* m_args; > + bool m_isStaticBlockFunctionCall; I suggest we initialize these to nullptr and false here in the class definition. > Source/JavaScriptCore/parser/Nodes.h:2354 > + bool m_isStaticBlockFunction; I suggest we initialize this to false here in the class definition. > Source/JavaScriptCore/parser/Parser.cpp:3101 > + case OPENBRACE: { No braces needed here. > Source/JavaScriptCore/parser/Parser.cpp:3318 > + case OPENBRACE: { > + break; > + } No braces needed here.
Yijia Huang
Comment 14 2022-09-30 09:27:40 PDT
(In reply to Darin Adler from comment #13) Thanks for your review, Darin. We've already moved our review to the GitHub PR https://github.com/WebKit/WebKit/pull/4372.
EWS
Comment 15 2022-10-05 08:36:13 PDT
Committed 255173@main (c33391001b54): <https://commits.webkit.org/255173@main> Reviewed commits have been landed. Closing PR #4372 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.