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

[JSC] ForStatement should call CreatePerIterationEnvironment before first iteration #19403

Commits on Oct 23, 2023

  1. [JSC] ForStatement should call CreatePerIterationEnvironment before f…

    …irst iteration
    
    https://bugs.webkit.org/show_bug.cgi?id=189799
    <rdar://problem/44730906>
    
    Reviewed by Justin Michaud.
    
    This change implements step 2 of ForBodyEvaluation [1], but only if loop initializer contains a function
    that captures a variable from outer scope (so-called closure), to preserve performance of the common case.
    
    Emitting prepareLexicalScopeForNextForLoopIteration() unconditionally would otherwise slow down any `for`
    loop with body statement containing a closure (which is a quite common) by 10-20%.
    
    Before this patch, a closure inside `for` loop initializer was created with parent scope of the first
    iteration, rather than a separate lexical scope, ending up capturing incorrect loop counter value.
    
    Aligns JSC with V8 and SpiderMonkey.
    
    [1]: https://tc39.es/ecma262/#sec-forbodyevaluation
    
    * JSTests/stress/regress-189799.js: Added.
    * JSTests/test262/expectations.yaml: Mark 2 tests as passing.
    * Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:
    (JSC::ForNode::emitBytecode):
    * Source/JavaScriptCore/parser/ASTBuilder.h:
    (JSC::ASTBuilder::createForLoop):
    * Source/JavaScriptCore/parser/NodeConstructors.h:
    (JSC::ForNode::ForNode):
    * Source/JavaScriptCore/parser/Nodes.h:
    * Source/JavaScriptCore/parser/Parser.cpp:
    (JSC::Parser<LexerType>::parseForStatement):
    * Source/JavaScriptCore/parser/SyntaxChecker.h:
    (JSC::SyntaxChecker::createForLoop):
    
    Canonical link: https://commits.webkit.org/269653@main
    Alexey Shvayka committed Oct 23, 2023
    Configuration menu
    Copy the full SHA
    f32cd0f View commit details
    Browse the repository at this point in the history