Changeset 215977 in webkit


Ignore:
Timestamp:
Apr 29, 2017, 2:25:50 PM (8 years ago)
Author:
gskachkov@gmail.com
Message:

Deep nesting is leading to ReferenceError for hoisted function
https://bugs.webkit.org/show_bug.cgi?id=171456

Reviewed by Yusuke Suzuki.

Current patch fix error that appears during hoisting of the function
in block scope. Error happens only when exist some deep scope that lead
to increase scope stack, after which list of the hosted candidates do not
copied to updated scope stack.

Source/JavaScriptCore:

  • parser/Parser.h:

(JSC::Scope::Scope):

LayoutTests:

  • js/function-declaration-statement-expected.txt:
  • js/script-tests/function-declaration-statement.js:

(deepNesting.foo):
(deepNesting):
(deepNestingForFunctionDeclaration.foo):
(deepNestingForFunctionDeclaration):
(eval.deepNestingInEval.foo):
(eval.deepNestingInEval):
(eval.deepNestingForFunctionDeclarationInEval.foo):
(eval.deepNestingForFunctionDeclarationInEval):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r215976 r215977  
     12017-04-29  Oleksandr Skachkov  <gskachkov@gmail.com>
     2
     3        Deep nesting is leading to ReferenceError for hoisted function
     4        https://bugs.webkit.org/show_bug.cgi?id=171456
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * js/function-declaration-statement-expected.txt:
     9        * js/script-tests/function-declaration-statement.js:
     10        (deepNesting.foo):
     11        (deepNesting):
     12        (deepNestingForFunctionDeclaration.foo):
     13        (deepNestingForFunctionDeclaration):
     14        (eval.deepNestingInEval.foo):
     15        (eval.deepNestingInEval):
     16        (eval.deepNestingForFunctionDeclarationInEval.foo):
     17        (eval.deepNestingForFunctionDeclarationInEval):
     18
    1192017-04-28  Zalan Bujtas  <zalan@apple.com>
    220
  • trunk/LayoutTests/js/function-declaration-statement-expected.txt

    r198989 r215977  
    77PASS ifElseTest() is true
    88PASS labelTest() is true
     9PASS deepNesting() is 'abc'
     10PASS deepNestingForFunctionDeclaration() is 'abc'
     11PASS deepNestingInEval() is 'abc'
     12PASS deepNestingForFunctionDeclarationInEval() is 'abc'
    913PASS successfullyParsed is true
    1014
  • trunk/LayoutTests/js/script-tests/function-declaration-statement.js

    r198989 r215977  
    4848
    4949shouldBeTrue("labelTest()");
     50
     51
     52function deepNesting () {
     53    var y = '';
     54    {
     55        function foo() { return 'abc'; }
     56    }
     57    if (true) {
     58        {
     59            {
     60                {
     61                    {
     62                        {
     63                           {
     64                                {
     65                                    {
     66                                        {
     67                                            {
     68                                                let x = 'abc';
     69                                                y = x;
     70                                            }
     71                                        }
     72                                    }
     73                                }
     74                            }
     75                        }
     76                    }
     77                }
     78            }
     79        }
     80    }
     81    return foo();
     82};
     83
     84shouldBe("deepNesting()", "'abc'");
     85
     86function deepNestingForFunctionDeclaration () {
     87    var y = '';
     88    {
     89        {
     90            {
     91                {
     92                    {
     93                        {
     94                            {
     95                                {
     96                                    {
     97                                        {
     98                                            {
     99                                                {
     100                                                    {
     101                                                        {
     102                                                            function foo() { return 'abc'; }
     103                                                        }
     104                                                    }
     105                                                }
     106                                            }
     107                                        }
     108                                    }
     109                                }
     110                            }
     111                        }
     112                    }
     113                }
     114            }
     115        }
     116    }
     117    if (true) {
     118        {
     119            {
     120                {
     121                    {
     122                        {
     123                           {
     124                                {
     125                                    {
     126                                        {
     127                                            {
     128                                                let x = 'abc';
     129                                                y = x;
     130                                            }
     131                                        }
     132                                    }
     133                                }
     134                            }
     135                        }
     136                    }
     137                }
     138            }
     139        }
     140    }
     141    return foo();
     142};
     143
     144shouldBe("deepNestingForFunctionDeclaration()", "'abc'");
     145
     146eval(`function deepNestingInEval () {
     147    var y = '';
     148    {
     149        function foo() { return 'abc'; }
     150    }
     151    if (true) {
     152        {
     153            {
     154                {
     155                    {
     156                        {
     157                           {
     158                                {
     159                                    {
     160                                        {
     161                                            {
     162                                                let x = 'abc';
     163                                                y = x;
     164                                            }
     165                                        }
     166                                    }
     167                                }
     168                            }
     169                        }
     170                    }
     171                }
     172            }
     173        }
     174    }
     175    return foo();
     176};`);
     177
     178
     179shouldBe("deepNestingInEval()", "'abc'");
     180
     181eval(`function deepNestingForFunctionDeclarationInEval () {
     182    var y = '';
     183    {
     184        {
     185            {
     186                {
     187                    {
     188                        {
     189                            {
     190                                {
     191                                    {
     192                                        {
     193                                            {
     194                                                {
     195                                                    {
     196                                                        {
     197                                                            function foo() { return 'abc'; }
     198                                                        }
     199                                                    }
     200                                                }
     201                                            }
     202                                        }
     203                                    }
     204                                }
     205                            }
     206                        }
     207                    }
     208                }
     209            }
     210        }
     211    }
     212    if (true) {
     213        {
     214            {
     215                {
     216                    {
     217                        {
     218                           {
     219                                {
     220                                    {
     221                                        {
     222                                            {
     223                                                let x = 'abc';
     224                                                y = x;
     225                                            }
     226                                        }
     227                                    }
     228                                }
     229                            }
     230                        }
     231                    }
     232                }
     233            }
     234        }
     235    }
     236    return foo();
     237};`);
     238
     239shouldBe("deepNestingForFunctionDeclarationInEval()", "'abc'");
  • trunk/Source/JavaScriptCore/ChangeLog

    r215972 r215977  
     12017-04-29  Oleksandr Skachkov  <gskachkov@gmail.com>
     2
     3        Deep nesting is leading to ReferenceError for hoisted function
     4        https://bugs.webkit.org/show_bug.cgi?id=171456
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Current patch fix error that appears during hoisting of the function
     9        in block scope. Error happens only when exist some deep scope that lead
     10        to increase scope stack, after which list of the hosted candidates do not
     11        copied to updated scope stack.
     12
     13        * parser/Parser.h:
     14        (JSC::Scope::Scope):
     15
    1162017-04-29  Yusuke Suzuki  <utatane.tea@gmail.com>
    217
  • trunk/Source/JavaScriptCore/parser/Parser.h

    r215779 r215977  
    189189    }
    190190
    191     Scope(Scope&& other)
    192         : m_vm(other.m_vm)
    193         , m_shadowsArguments(other.m_shadowsArguments)
    194         , m_usesEval(other.m_usesEval)
    195         , m_needsFullActivation(other.m_needsFullActivation)
    196         , m_hasDirectSuper(other.m_hasDirectSuper)
    197         , m_needsSuperBinding(other.m_needsSuperBinding)
    198         , m_allowsVarDeclarations(other.m_allowsVarDeclarations)
    199         , m_allowsLexicalDeclarations(other.m_allowsLexicalDeclarations)
    200         , m_strictMode(other.m_strictMode)
    201         , m_isFunction(other.m_isFunction)
    202         , m_isGenerator(other.m_isGenerator)
    203         , m_isGeneratorBoundary(other.m_isGeneratorBoundary)
    204         , m_isArrowFunction(other.m_isArrowFunction)
    205         , m_isArrowFunctionBoundary(other.m_isArrowFunctionBoundary)
    206         , m_isAsyncFunction(other.m_isAsyncFunction)
    207         , m_isAsyncFunctionBoundary(other.m_isAsyncFunctionBoundary)
    208         , m_isLexicalScope(other.m_isLexicalScope)
    209         , m_isGlobalCodeScope(other.m_isGlobalCodeScope)
    210         , m_isFunctionBoundary(other.m_isFunctionBoundary)
    211         , m_isValidStrictMode(other.m_isValidStrictMode)
    212         , m_hasArguments(other.m_hasArguments)
    213         , m_isEvalContext(other.m_isEvalContext)
    214         , m_hasNonSimpleParameterList(other.m_hasNonSimpleParameterList)
    215         , m_constructorKind(other.m_constructorKind)
    216         , m_expectedSuperBinding(other.m_expectedSuperBinding)
    217         , m_loopDepth(other.m_loopDepth)
    218         , m_switchDepth(other.m_switchDepth)
    219         , m_innerArrowFunctionFeatures(other.m_innerArrowFunctionFeatures)
    220         , m_labels(WTFMove(other.m_labels))
    221         , m_declaredParameters(WTFMove(other.m_declaredParameters))
    222         , m_declaredVariables(WTFMove(other.m_declaredVariables))
    223         , m_lexicalVariables(WTFMove(other.m_lexicalVariables))
    224         , m_usedVariables(WTFMove(other.m_usedVariables))
    225         , m_closedVariableCandidates(WTFMove(other.m_closedVariableCandidates))
    226         , m_functionDeclarations(WTFMove(other.m_functionDeclarations))
    227     {
    228     }
     191    Scope(Scope&&) = default;
    229192
    230193    void startSwitch() { m_switchDepth++; }
Note: See TracChangeset for help on using the changeset viewer.