Ignore:
Timestamp:
Jun 18, 2015, 5:35:32 AM (10 years ago)
Author:
[email protected]
Message:

[ES6] support default values in deconstruction parameter nodes
https://bugs.webkit.org/show_bug.cgi?id=142679

Reviewed by Darin Adler.

Source/JavaScriptCore:

ES6 destructuring allows destructuring properties to assign
default values. A link to the spec:
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-destructuring-binding-patterns

This patch implements default values for all places where deconstruction
is allowed besides function parameters. This is because function
parameters are parsed in a separate parser arena than the function
body itself and ExpresionNode's which are default values for
deconstruction parameters will be deallocated by the time we parse the body
of the function. I have opened a bug to address this problem:
https://bugs.webkit.org/show_bug.cgi?id=145995

  • bytecompiler/NodesCodegen.cpp:

(JSC::DeconstructionPatternNode::~DeconstructionPatternNode):
(JSC::assignDefaultValueIfUndefined):
(JSC::ArrayPatternNode::bindValue):
(JSC::ArrayPatternNode::emitDirectBinding):
(JSC::ArrayPatternNode::toString):
(JSC::ArrayPatternNode::collectBoundIdentifiers):
(JSC::ObjectPatternNode::bindValue):

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::appendArrayPatternSkipEntry):
(JSC::ASTBuilder::appendArrayPatternEntry):
(JSC::ASTBuilder::createObjectPattern):
(JSC::ASTBuilder::appendObjectPatternEntry):
(JSC::ASTBuilder::createBindingLocation):

  • parser/Nodes.h:

(JSC::ArrayPatternNode::appendIndex):
(JSC::ObjectPatternNode::appendEntry):
(JSC::ObjectPatternNode::Entry::Entry): Deleted.

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseDeconstructionPattern):
(JSC::Parser<LexerType>::parseDefaultValueForDeconstructionPattern):
(JSC::Parser<LexerType>::parseConstDeclarationList):

  • parser/Parser.h:
  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::operatorStackPop):

LayoutTests:

  • js/destructuring-assignment-default-values-expected.txt: Added.
  • js/destructuring-assignment-default-values.html: Added.
  • js/script-tests/destructuring-assignment-default-values.js: Added.

(assert):
(test1):
(arr):
(test2):
(test3):
(test4):
(test5):
(test6):
(test7):
(test8):
(shouldThrow):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/SyntaxChecker.h

    r184640 r185699  
    309309    {
    310310    }
    311     void appendArrayPatternEntry(ArrayPattern, const JSTokenLocation&, DeconstructionPattern)
     311    void appendArrayPatternEntry(ArrayPattern, const JSTokenLocation&, DeconstructionPattern, int)
    312312    {
    313313    }
     
    316316        return ObjectDeconstruction;
    317317    }
    318     void appendObjectPatternEntry(ArrayPattern, const JSTokenLocation&, bool, const Identifier&, DeconstructionPattern)
     318    void appendObjectPatternEntry(ArrayPattern, const JSTokenLocation&, bool, const Identifier&, DeconstructionPattern, int)
    319319    {
    320320    }
Note: See TracChangeset for help on using the changeset viewer.