Changeset 192768 in webkit


Ignore:
Timestamp:
Nov 24, 2015 5:43:14 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

[JSC] support Computed Property Names in destructuring Patterns
https://bugs.webkit.org/show_bug.cgi?id=151494

Patch by Caitlin Potter <caitp@igalia.com> on 2015-11-24
Reviewed by Saam Barati.

Add support for computed property names in destructuring BindingPatterns
and AssignmentPatterns.

Productions BindingProperty(1) and AssignmentProperty(2) allow for any valid
PropertName(3), including ComputedPropertyName(4)

1: http://tc39.github.io/ecma262/#prod-BindingProperty
2: http://tc39.github.io/ecma262/#prod-AssignmentProperty
3: http://tc39.github.io/ecma262/#prod-PropertyName
4: http://tc39.github.io/ecma262/#prod-ComputedPropertyName

  • bytecompiler/NodesCodegen.cpp:

(JSC::ObjectPatternNode::bindValue):

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::appendObjectPatternEntry):

  • parser/Nodes.h:

(JSC::ObjectPatternNode::appendEntry):

  • parser/Parser.cpp:

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

  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::operatorStackPop):

  • tests/es6.yaml:
  • tests/es6/destructuring_assignment_computed_properties.js: Added.

(test):
(test.computeName):
(test.loadValue):
(test.out.get a):
(test.out.set a):
(test.out.get b):
(test.out.set b):
(test.out.get c):
(test.out.set c):
(test.get var):

Location:
trunk/Source/JavaScriptCore
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r192766 r192768  
     12015-11-24  Caitlin Potter  <caitp@igalia.com>
     2
     3        [JSC] support Computed Property Names in destructuring Patterns
     4        https://bugs.webkit.org/show_bug.cgi?id=151494
     5
     6        Reviewed by Saam Barati.
     7
     8        Add support for computed property names in destructuring BindingPatterns
     9        and AssignmentPatterns.
     10
     11        Productions BindingProperty(1) and AssignmentProperty(2) allow for any valid
     12        PropertName(3), including ComputedPropertyName(4)
     13
     14        1: http://tc39.github.io/ecma262/#prod-BindingProperty
     15        2: http://tc39.github.io/ecma262/#prod-AssignmentProperty
     16        3: http://tc39.github.io/ecma262/#prod-PropertyName
     17        4: http://tc39.github.io/ecma262/#prod-ComputedPropertyName
     18
     19        * bytecompiler/NodesCodegen.cpp:
     20        (JSC::ObjectPatternNode::bindValue):
     21        * parser/ASTBuilder.h:
     22        (JSC::ASTBuilder::appendObjectPatternEntry):
     23        * parser/Nodes.h:
     24        (JSC::ObjectPatternNode::appendEntry):
     25        * parser/Parser.cpp:
     26        (JSC::Parser<LexerType>::parseDestructuringPattern):
     27        * parser/SyntaxChecker.h:
     28        (JSC::SyntaxChecker::operatorStackPop):
     29        * tests/es6.yaml:
     30        * tests/es6/destructuring_assignment_computed_properties.js: Added.
     31        (test):
     32        (test.computeName):
     33        (test.loadValue):
     34        (test.out.get a):
     35        (test.out.set a):
     36        (test.out.get b):
     37        (test.out.set b):
     38        (test.out.get c):
     39        (test.out.set c):
     40        (test.get var):
     41
    1422015-11-24  Commit Queue  <commit-queue@webkit.org>
    243
  • trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp

    r192671 r192768  
    33413341        auto& target = m_targetPatterns[i];
    33423342        RefPtr<RegisterID> temp = generator.newTemporary();
    3343         generator.emitGetById(temp.get(), rhs, target.propertyName);
     3343        if (!target.propertyExpression)
     3344            generator.emitGetById(temp.get(), rhs, target.propertyName);
     3345        else {
     3346            RefPtr<RegisterID> propertyName = generator.emitNode(target.propertyExpression);
     3347            generator.emitGetByVal(temp.get(), rhs, propertyName.get());
     3348        }
     3349
    33443350        if (target.defaultValue)
    33453351            assignDefaultValueIfUndefined(generator, temp.get(), target.defaultValue);
  • trunk/Source/JavaScriptCore/parser/ASTBuilder.h

    r192671 r192768  
    852852        node->appendEntry(location, identifier, wasString, pattern, defaultValue);
    853853    }
    854    
     854
     855    void appendObjectPatternEntry(ObjectPattern node, const JSTokenLocation& location, ExpressionNode* propertyExpression, DestructuringPattern pattern, ExpressionNode* defaultValue)
     856    {
     857        node->appendEntry(location, propertyExpression, pattern, defaultValue);
     858    }
     859
    855860    BindingPattern createBindingLocation(const JSTokenLocation&, const Identifier& boundProperty, const JSTextPosition& start, const JSTextPosition& end, AssignmentContext context)
    856861    {
  • trunk/Source/JavaScriptCore/parser/Nodes.h

    r192671 r192768  
    20182018        void appendEntry(const JSTokenLocation&, const Identifier& identifier, bool wasString, DestructuringPatternNode* pattern, ExpressionNode* defaultValue)
    20192019        {
    2020             m_targetPatterns.append(Entry{ identifier, wasString, pattern, defaultValue });
     2020            m_targetPatterns.append(Entry{ identifier, nullptr, wasString, pattern, defaultValue });
     2021        }
     2022
     2023        void appendEntry(const JSTokenLocation&, ExpressionNode* propertyExpression, DestructuringPatternNode* pattern, ExpressionNode* defaultValue)
     2024        {
     2025            m_targetPatterns.append(Entry{ Identifier(), propertyExpression, false, pattern, defaultValue });
    20212026        }
    20222027
     
    20272032        struct Entry {
    20282033            const Identifier& propertyName;
     2034            ExpressionNode* propertyExpression;
    20292035            bool wasString;
    20302036            DestructuringPatternNode* pattern;
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r192695 r192768  
    862862
    863863            const Identifier* propertyName = nullptr;
     864            TreeExpression propertyExpression = 0;
    864865            TreeDestructuringPattern innerPattern = 0;
    865866            JSTokenLocation location = m_token.m_location;
     
    883884                    propertyName = m_token.m_data.ident;
    884885                    wasString = true;
     886                    break;
     887                case OPENBRACKET:
     888                    next();
     889                    propertyExpression = parseAssignmentExpression(context);
     890                    failIfFalse(propertyExpression, "Cannot parse computed property name");
     891                    matchOrFail(CLOSEBRACKET, "Expected ']' to end end a computed property name");
    885892                    break;
    886893                default:
     
    909916            failIfFalse(innerPattern, "Cannot parse this destructuring pattern");
    910917            TreeExpression defaultValue = parseDefaultValueForDestructuringPattern(context);
    911             ASSERT(propertyName);
    912             context.appendObjectPatternEntry(objectPattern, location, wasString, *propertyName, innerPattern, defaultValue);
     918            if (propertyExpression)
     919                context.appendObjectPatternEntry(objectPattern, location, propertyExpression, innerPattern, defaultValue);
     920            else {
     921                ASSERT(propertyName);
     922                context.appendObjectPatternEntry(objectPattern, location, wasString, *propertyName, innerPattern, defaultValue);
     923            }
    913924        } while (consume(COMMA));
    914925
  • trunk/Source/JavaScriptCore/parser/SyntaxChecker.h

    r192671 r192768  
    344344    {
    345345    }
     346    void appendObjectPatternEntry(ArrayPattern, const JSTokenLocation&, Expression, DestructuringPattern, Expression)
     347    {
     348    }
     349
    346350    DestructuringPattern createBindingLocation(const JSTokenLocation&, const Identifier&, const JSTextPosition&, const JSTextPosition&, AssignmentContext)
    347351    {
  • trunk/Source/JavaScriptCore/tests/es6.yaml

    r192671 r192768  
    217217- path: es6/destructuring_assignment_non_simple_target.js
    218218  cmd: runES6 :normal
     219- path: es6/destructuring_assignment_computed_properties.js
     220  cmd: runES6 :normal
     221- path: es6/destructuring_assignment_computed_property_simple.js
     222  cmd: runES6 :normal
     223- path: es6/destructuring_assignment_computed_property_default.js
     224  cmd: runES6 :normal
    219225- path: es6/destructuring_initializer_scoping.js
    220226  cmd: runES6 :normal
     
    746752  cmd: runES6 :fail
    747753- path: es6/destructuring_computed_properties.js
    748   cmd: runES6 :fail
     754  cmd: runES6 :normal
    749755- path: es6/destructuring_defaults_in_parameters_separate_scope.js
    750756  cmd: runES6 :fail
Note: See TracChangeset for help on using the changeset viewer.