Ignore:
Timestamp:
Nov 24, 2015, 5:43:14 PM (10 years ago)
Author:
[email protected]
Message:

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

Patch by Caitlin Potter <[email protected]> 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):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.