Changeset 38747 in webkit


Ignore:
Timestamp:
Nov 24, 2008 11:23:44 PM (15 years ago)
Author:
cwzwarich@webkit.org
Message:

2008-11-24 Cameron Zwarich <zwarich@apple.com>

Reviewed by Geoff Garen.

Bug 13790: Function declarations are not treated as statements (used to affect starcraft2.com)
<https://bugs.webkit.org/show_bug.cgi?id=13790>

Modify the parser to treat function declarations as statements,
simplifying the grammar in the process. Technically, according to the
grammar in the ECMA spec, function declarations are not statements and
can not be used everywhere that statements can, but it is not worth the
possibility compatibility issues just to stick to the spec in this case.

JavaScriptCore:

  • parser/Grammar.y:
  • parser/Nodes.cpp: (JSC::FuncDeclNode::emitBytecode): Avoid returning ignoredResult() as a result, because it causes a crash in DoWhileNode::emitBytecode().

LayoutTests:

  • fast/js/function-declaration-statement-expected.txt: Added.
  • fast/js/function-declaration-statement.html: Added.
  • fast/js/resources/function-declaration-statement.js: Added.
Location:
trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r38745 r38747  
     12008-11-24  Cameron Zwarich  <zwarich@apple.com>
     2
     3        Reviewed by Geoff Garen.
     4
     5        Bug 13790: Function declarations are not treated as statements (used to affect starcraft2.com)
     6        <https://bugs.webkit.org/show_bug.cgi?id=13790>
     7
     8        Modify the parser to treat function declarations as statements,
     9        simplifying the grammar in the process. Technically, according to the
     10        grammar in the ECMA spec, function declarations are not statements and
     11        can not be used everywhere that statements can, but it is not worth the
     12        possibility compatibility issues just to stick to the spec in this case.
     13
     14        * parser/Grammar.y:
     15        * parser/Nodes.cpp:
     16        (JSC::FuncDeclNode::emitBytecode): Avoid returning ignoredResult()
     17        as a result, because it causes a crash in DoWhileNode::emitBytecode().
     18
    1192008-11-24  Geoffrey Garen  <ggaren@apple.com>
    220
  • trunk/JavaScriptCore/parser/Grammar.y

    r38649 r38747  
    261261%type <statementNode>   ThrowStatement TryStatement
    262262%type <statementNode>   DebuggerStatement
    263 %type <statementNode>   SourceElement
    264263
    265264%type <expressionNode>  Initializer InitializerNoIn
    266 %type <funcDeclNode>    FunctionDeclaration
     265%type <statementNode>   FunctionDeclaration
    267266%type <funcExprNode>    FunctionExpr
    268267%type <functionBodyNode>  FunctionBody
     
    797796  | VariableStatement
    798797  | ConstStatement
     798  | FunctionDeclaration
    799799  | EmptyStatement
    800800  | ExprStatement
     
    11691169
    11701170FunctionDeclaration:
    1171     FUNCTION IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeInfo(new FuncDeclNode(GLOBAL_DATA, *$2, $6, LEXER->sourceCode($5, $7, @5.first_line)), ((*$2 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | ClosureFeature, 0); DBG($6, @5, @7); }
     1171    FUNCTION IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeDeclarationInfo<StatementNode*>(new FuncDeclNode(GLOBAL_DATA, *$2, $6, LEXER->sourceCode($5, $7, @5.first_line)), 0, new ParserRefCountedData<DeclarationStacks::FunctionStack>(GLOBAL_DATA), ((*$2 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | ClosureFeature, 0); DBG($6, @5, @7); $$.m_funcDeclarations->data.append(static_cast<FuncDeclNode*>($$.m_node)); }
    11721172  | FUNCTION IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE
    11731173      {
    1174           $$ = createNodeInfo(new FuncDeclNode(GLOBAL_DATA, *$2, $7, LEXER->sourceCode($6, $8, @6.first_line), $4.m_node.head), ((*$2 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $4.m_features | ClosureFeature, 0);
     1174          $$ = createNodeDeclarationInfo<StatementNode*>(new FuncDeclNode(GLOBAL_DATA, *$2, $7, LEXER->sourceCode($6, $8, @6.first_line), $4.m_node.head), 0, new ParserRefCountedData<DeclarationStacks::FunctionStack>(GLOBAL_DATA), ((*$2 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $4.m_features | ClosureFeature, 0);
    11751175          if ($4.m_features & ArgumentsFeature)
    11761176              $7->setUsesArguments();
    1177           DBG($7, @6, @8);
     1177          DBG($7, @6, @8);
     1178          $$.m_funcDeclarations->data.append(static_cast<FuncDeclNode*>($$.m_node));
    11781179      }
    11791180;
     
    12191220
    12201221SourceElements:
    1221     SourceElement                       { $$.m_node = new SourceElements(GLOBAL_DATA);
     1222    Statement                           { $$.m_node = new SourceElements(GLOBAL_DATA);
    12221223                                          $$.m_node->append($1.m_node);
    12231224                                          $$.m_varDeclarations = $1.m_varDeclarations;
     
    12261227                                          $$.m_numConstants = $1.m_numConstants;
    12271228                                        }
    1228   | SourceElements SourceElement        { $$.m_node->append($2.m_node);
     1229  | SourceElements Statement            { $$.m_node->append($2.m_node);
    12291230                                          $$.m_varDeclarations = mergeDeclarationLists($1.m_varDeclarations, $2.m_varDeclarations);
    12301231                                          $$.m_funcDeclarations = mergeDeclarationLists($1.m_funcDeclarations, $2.m_funcDeclarations);
     
    12321233                                          $$.m_numConstants = $1.m_numConstants + $2.m_numConstants;
    12331234                                        }
    1234 ;
    1235 
    1236 SourceElement:
    1237     FunctionDeclaration                 { $$ = createNodeDeclarationInfo<StatementNode*>($1.m_node, 0, new ParserRefCountedData<DeclarationStacks::FunctionStack>(GLOBAL_DATA), $1.m_features, 0); $$.m_funcDeclarations->data.append($1.m_node); }
    1238   | Statement                           { $$ = $1; }
    12391235;
    12401236 
     
    16271623  | VariableStatement_NoNode
    16281624  | ConstStatement_NoNode
     1625  | FunctionDeclaration_NoNode
    16291626  | EmptyStatement_NoNode
    16301627  | ExprStatement_NoNode
     
    18211818
    18221819SourceElements_NoNode:
    1823     SourceElement_NoNode
    1824   | SourceElements_NoNode SourceElement_NoNode
    1825 ;
    1826 
    1827 SourceElement_NoNode:
    1828     FunctionDeclaration_NoNode
    1829   | Statement_NoNode
     1820    Statement_NoNode
     1821  | SourceElements_NoNode Statement_NoNode
    18301822;
    18311823
  • trunk/JavaScriptCore/parser/Nodes.cpp

    r38635 r38747  
    26332633RegisterID* FuncDeclNode::emitBytecode(BytecodeGenerator&, RegisterID* dst)
    26342634{
     2635    if (dst == ignoredResult())
     2636        dst = 0;
    26352637    return dst;
    26362638}
  • trunk/LayoutTests/ChangeLog

    r38736 r38747  
     12008-11-24  Cameron Zwarich  <zwarich@apple.com>
     2
     3        Reviewed by Geoff Garen.
     4
     5        Add tests for bug 13790: Function declarations are not treated as statements (used to affect starcraft2.com)
     6        <https://bugs.webkit.org/show_bug.cgi?id=13790>
     7
     8        * fast/js/function-declaration-statement-expected.txt: Added.
     9        * fast/js/function-declaration-statement.html: Added.
     10        * fast/js/resources/function-declaration-statement.js: Added.
     11
    1122008-11-24  Nikolas Zimmermann  <nikolas.zimmermann@torchmobile.com>
    213
Note: See TracChangeset for help on using the changeset viewer.