⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 179873 in webkit


Ignore:
Timestamp:
Feb 10, 2015, 11:01:41 AM (12 years ago)
Author:
saambarati1@gmail.com
Message:

Parser::parseVarDeclarationList gets the wrong JSToken for the last identifier
https://bugs.webkit.org/show_bug.cgi?id=141272

Reviewed by Oliver Hunt.

This patch fixes a bug where the wrong text location would be
assigned to a variable declaration inside a ForIn/ForOf loop.
It also fixes a bug in the type profiler where the type profiler
emits the wrong text offset for a ForIn loop's variable declarator
when it's not a pattern node.

  • bytecompiler/NodesCodegen.cpp:

(JSC::ForInNode::emitLoopHeader):

  • parser/Parser.cpp:

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

  • tests/typeProfiler/loop.js:

(testForIn):
(testForOf):

Location:
trunk/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r179865 r179873  
     12015-02-10  Saam Barati  <saambarati1@gmail.com>
     2
     3        Parser::parseVarDeclarationList gets the wrong JSToken for the last identifier
     4        https://bugs.webkit.org/show_bug.cgi?id=141272
     5
     6        Reviewed by Oliver Hunt.
     7
     8        This patch fixes a bug where the wrong text location would be
     9        assigned to a variable declaration inside a ForIn/ForOf loop.
     10        It also fixes a bug in the type profiler where the type profiler
     11        emits the wrong text offset for a ForIn loop's variable declarator
     12        when it's not a pattern node.
     13
     14        * bytecompiler/NodesCodegen.cpp:
     15        (JSC::ForInNode::emitLoopHeader):
     16        * parser/Parser.cpp:
     17        (JSC::Parser<LexerType>::parseVarDeclarationList):
     18        * tests/typeProfiler/loop.js:
     19        (testForIn):
     20        (testForOf):
     21
    1222015-02-09  Saam Barati  <saambarati1@gmail.com>
    223
  • trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp

    r179865 r179873  
    20772077        generator.emitMove(local.get(), propertyName);
    20782078        if (generator.vm()->typeProfiler())
    2079             generator.emitTypeProfilerExpressionInfo(m_lexpr->position(), JSTextPosition(-1, m_lexpr->position().offset + ident.length(), -1));
     2079            generator.emitTypeProfilerExpressionInfo(simpleBinding->divotStart(), simpleBinding->divotEnd());
    20802080        return;
    20812081    }
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r179682 r179873  
    453453    TreeExpression tail = 0;
    454454    const Identifier* lastIdent;
     455    JSToken lastIdentToken;
    455456    do {
    456457        lastIdent = 0;
     
    467468            const Identifier* name = m_token.m_data.ident;
    468469            lastIdent = name;
     470            lastIdentToken = m_token;
    469471            next();
    470472            hasInitializer = match(EQUAL);
     
    507509    } while (match(COMMA));
    508510    if (lastIdent)
    509         lastPattern = createBindingPattern(context, DeconstructToVariables, *lastIdent, 0, m_token);
     511        lastPattern = createBindingPattern(context, DeconstructToVariables, *lastIdent, 0, lastIdentToken);
    510512    return head;
    511513}
  • trunk/Source/JavaScriptCore/tests/typeProfiler/loop.js

    r179865 r179873  
    22
    33function testForIn(x) {
    4     // FIXME: add support for the following statement types: "for (var arg of expr)" and "for (var arg in expr)"
    5     // https://bugs.webkit.org/show_bug.cgi?id=141241
    6      
     4    for (var arg1 in x)
     5        x;
     6
    77    for (arg2 in x)
    88        x;
    99
    10     for ({x: arg3} in x)
     10    for ({x: arg3} in x)
     11        x;
     12
     13    for (var {x: arg4} in x)
    1114        x;
    1215}
    1316
    1417function testForOf(x) {
     18    for (var arg1 of x)
     19        x;
     20
    1521    for (arg2 of x)
    1622        x;
     
    1824    for ({x: arg3} of x)
    1925        x;
     26    for (var {x: arg4} of x)
     27        x;
    2028}
    2129
    2230testForIn([1])
    23 var types = findTypeForExpression(testForIn, "arg2");
     31var types = findTypeForExpression(testForIn, "arg1");
     32assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.String) !== -1, "Primitive type names should contain 'String'");
     33types = findTypeForExpression(testForIn, "arg2");
    2434assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.String) !== -1, "Primitive type names should contain 'String'");
    2535types = findTypeForExpression(testForIn, "arg3");
    2636assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Undefined) !== -1, "Primitive type names should contain 'Undefined'");
     37types = findTypeForExpression(testForIn, "arg4");
     38assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Undefined) !== -1, "Primitive type names should contain 'Undefined'");
    2739
    2840testForOf([1])
     41types = findTypeForExpression(testForOf, "arg1");
     42assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Integer) !== -1, "Primitive type names should contain 'Integer'");
    2943types = findTypeForExpression(testForOf, "arg2");
    3044assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Integer) !== -1, "Primitive type names should contain 'Integer'");
    3145types = findTypeForExpression(testForOf, "arg3");
    3246assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Undefined) !== -1, "Primitive type names should contain 'Undefined'");
     47types = findTypeForExpression(testForOf, "arg4");
     48assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Undefined) !== -1, "Primitive type names should contain 'Undefined'");
    3349testForOf([{x:29}])
     50types = findTypeForExpression(testForOf, "arg1");
     51assert(types.instructionTypeSet.structures[0].fields.indexOf("x") !== -1, "variable 'arg1' should have field 'x'");
    3452types = findTypeForExpression(testForOf, "arg2");
    35 assert(types.instructionTypeSet.structures[0].fields.indexOf("x") !== -1, "variable 'arg1' should have field 'x'");
     53assert(types.instructionTypeSet.structures[0].fields.indexOf("x") !== -1, "variable 'arg2' should have field 'x'");
    3654types = findTypeForExpression(testForOf, "arg3");
    3755assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Integer) !== -1, "Primitive type names should contain 'Integer'");
     56types = findTypeForExpression(testForOf, "arg4");
     57assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Integer) !== -1, "Primitive type names should contain 'Integer'");
Note: See TracChangeset for help on using the changeset viewer.