Changeset 172717 in webkit


Ignore:
Timestamp:
Aug 18, 2014 12:11:41 PM (10 years ago)
Author:
commit-queue@webkit.org
Message:

The parser should generate AST nodes the var declarations with no initializers
https://bugs.webkit.org/show_bug.cgi?id=135545

Patch by Saam Barati <sbarati@apple.com> on 2014-08-18
Reviewed by Geoffrey Garen.

Currently, JSC's parser ignores variable declarations
that have no assignment initializer value because all
variables are implicitly assigned to undefined. But,
type profiling needs an AST node to be generated for these
empty variable declarations because it needs to be able to
profile their text locations and to see that their type
is undefined.

  • bytecompiler/NodesCodegen.cpp:

(JSC::EmptyVarExpression::emitBytecode):

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::createVarStatement):
(JSC::ASTBuilder::createEmptyVarExpression):

  • parser/NodeConstructors.h:

(JSC::EmptyVarExpression::EmptyVarExpression):

  • parser/Nodes.h:
  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseVarDeclarationList):

  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::createEmptyVarExpression):

Location:
trunk/Source/JavaScriptCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r172707 r172717  
     12014-08-18  Saam Barati  <sbarati@apple.com>
     2
     3        The parser should generate AST nodes the var declarations with no initializers
     4        https://bugs.webkit.org/show_bug.cgi?id=135545
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Currently, JSC's parser ignores variable declarations
     9        that have no assignment initializer value because all
     10        variables are implicitly assigned to undefined. But,
     11        type profiling needs an AST node to be generated for these
     12        empty variable declarations because it needs to be able to
     13        profile their text locations and to see that their type
     14        is undefined.
     15
     16        * bytecompiler/NodesCodegen.cpp:
     17        (JSC::EmptyVarExpression::emitBytecode):
     18        * parser/ASTBuilder.h:
     19        (JSC::ASTBuilder::createVarStatement):
     20        (JSC::ASTBuilder::createEmptyVarExpression):
     21        * parser/NodeConstructors.h:
     22        (JSC::EmptyVarExpression::EmptyVarExpression):
     23        * parser/Nodes.h:
     24        * parser/Parser.cpp:
     25        (JSC::Parser<LexerType>::parseVarDeclarationList):
     26        * parser/SyntaxChecker.h:
     27        (JSC::SyntaxChecker::createEmptyVarExpression):
     28
    1292014-08-18  Diego Pino Garcia  <dpino@igalia.com>
    230
  • trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp

    r172614 r172717  
    17831783}
    17841784
     1785// ------------------------------ EmptyVarExpression ----------------------------
     1786
     1787RegisterID* EmptyVarExpression::emitBytecode(BytecodeGenerator& generator, RegisterID*)
     1788{
     1789    if (!generator.isProfilingTypesWithHighFidelity())
     1790        return nullptr;
     1791
     1792    if (Local local = generator.local(m_ident))
     1793        generator.emitProfileTypesWithHighFidelity(local.get(), ProfileTypesBytecodeHasGlobalID, nullptr);
     1794    else {
     1795        RefPtr<RegisterID> scope = generator.emitResolveScope(generator.newTemporary(), m_ident);
     1796        RefPtr<RegisterID> value = generator.emitGetFromScope(generator.newTemporary(), scope.get(), m_ident, DoNotThrowIfNotFound);
     1797        generator.emitProfileTypesWithHighFidelity(value.get(), ProfileTypesBytecodeGetFromScope, &m_ident);
     1798    }
     1799
     1800    generator.emitHighFidelityTypeProfilingExpressionInfo(position(), JSTextPosition(-1, position().offset + m_ident.length(), -1));
     1801
     1802    // It's safe to return null here because this node will always be a child node of VarStatementNode which ignores our return value.
     1803    return nullptr;
     1804}
     1805
    17851806// ------------------------------ IfElseNode ---------------------------------------
    17861807
  • trunk/Source/JavaScriptCore/parser/ASTBuilder.h

    r168107 r172717  
    417417    {
    418418        StatementNode* result;
    419         if (!expr)
    420             result = new (m_vm) EmptyStatementNode(location);
    421         else
    422             result = new (m_vm) VarStatementNode(location, expr);
     419        result = new (m_vm) VarStatementNode(location, expr);
    423420        result->setLoc(start, end, location.startOffset, location.lineStartOffset);
    424421        return result;
     422    }
     423
     424    ExpressionNode* createEmptyVarExpression(const JSTokenLocation& location, const Identifier& identifier)
     425    {
     426        return new (m_vm) EmptyVarExpression(location, identifier);
    425427    }
    426428
  • trunk/Source/JavaScriptCore/parser/NodeConstructors.h

    r163321 r172717  
    656656    {
    657657    }
     658
     659    inline EmptyVarExpression::EmptyVarExpression(const JSTokenLocation& location, const Identifier& ident)
     660        : ExpressionNode(location)
     661        , m_ident(ident)
     662    {
     663    }
    658664   
    659665    inline IfElseNode::IfElseNode(const JSTokenLocation& location, ExpressionNode* condition, StatementNode* ifBlock, StatementNode* elseBlock)
  • trunk/Source/JavaScriptCore/parser/Nodes.h

    r172176 r172717  
    12131213    };
    12141214
     1215    class EmptyVarExpression : public ExpressionNode {
     1216    public:
     1217        EmptyVarExpression(const JSTokenLocation&, const Identifier&);
     1218
     1219    private:
     1220        virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override;
     1221
     1222        const Identifier& m_ident;
     1223    };
     1224
     1225
    12151226    class IfElseNode : public StatementNode {
    12161227    public:
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r172381 r172717  
    459459        if (match(IDENT)) {
    460460            JSTextPosition varStart = tokenStartPosition();
     461            JSTokenLocation varStartLocation(tokenLocation());
    461462            identStart = varStart;
    462463            const Identifier* name = m_token.m_data.ident;
     
    476477               
    477478                node = context.createAssignResolve(location, *name, initializer, varStart, varDivot, lastTokenEndPosition());
    478             }
     479            } else
     480                node = context.createEmptyVarExpression(varStartLocation, *name);
    479481        } else {
    480482            lastIdent = 0;
     
    491493        }
    492494       
    493         if (hasInitializer) {
    494             if (!varDecls)
    495                 varDecls = node;
    496             else
    497                 varDecls = context.combineCommaNodes(location, varDecls, node);
    498         }
     495        if (!varDecls)
     496            varDecls = node;
     497        else
     498            varDecls = context.combineCommaNodes(location, varDecls, node);
    499499    } while (match(COMMA));
    500500    if (lastIdent)
  • trunk/Source/JavaScriptCore/parser/SyntaxChecker.h

    r168107 r172717  
    159159    ExpressionType createConditionalExpr(const JSTokenLocation&, ExpressionType, ExpressionType, ExpressionType) { return ConditionalExpr; }
    160160    ExpressionType createAssignResolve(const JSTokenLocation&, const Identifier&, ExpressionType, int, int, int) { return AssignmentExpr; }
     161    ExpressionType createEmptyVarExpression(const JSTokenLocation&, const Identifier&) { return AssignmentExpr; }
    161162    ExpressionType createFunctionExpr(const JSTokenLocation&, const Identifier*, int, int, int, int, int, int, int) { return FunctionExpr; }
    162163    int createFunctionBody(const JSTokenLocation&, const JSTokenLocation&, int, int, bool) { return FunctionBodyResult; }
Note: See TracChangeset for help on using the changeset viewer.