Implement prefixed-destructuring assignment
https://bugs.webkit.org/show_bug.cgi?id=121930
Reviewed by Mark Hahnenberg.
Source/JavaScriptCore:
This is mostly simple - the semantics of deconstruction are already
present in the language, so most of the complexity (if you call it
that) is addition of new AST nodes, and parsing the syntax.
In order to get correct semantics for the parameter lists, FunctionParameters
now needs to store refcounted references to the parameter patterns.
There's also a little work to ensure that variable creation and assignment
occurs in the correct order while the BytecodeGenerator is being constructed.
- bytecode/UnlinkedCodeBlock.cpp:
(JSC::UnlinkedFunctionExecutable::paramString):
- bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::BytecodeGenerator):
- bytecompiler/BytecodeGenerator.h:
(JSC::BytecodeGenerator::emitExpressionInfo):
- bytecompiler/NodesCodegen.cpp:
(JSC::ForInNode::emitBytecode):
(JSC::DeconstructingAssignmentNode::emitBytecode):
(JSC::DeconstructionPatternNode::~DeconstructionPatternNode):
(JSC::ArrayPatternNode::emitBytecode):
(JSC::ArrayPatternNode::emitDirectBinding):
(JSC::ArrayPatternNode::toString):
(JSC::ArrayPatternNode::collectBoundIdentifiers):
(JSC::ObjectPatternNode::toString):
(JSC::ObjectPatternNode::emitBytecode):
(JSC::ObjectPatternNode::collectBoundIdentifiers):
(JSC::BindingNode::emitBytecode):
(JSC::BindingNode::toString):
(JSC::BindingNode::collectBoundIdentifiers):
(JSC::ASTBuilder::createFormalParameterList):
(JSC::ASTBuilder::createForInLoop):
(JSC::ASTBuilder::addVar):
(JSC::ASTBuilder::createDeconstructingAssignment):
(JSC::ASTBuilder::createArrayPattern):
(JSC::ASTBuilder::appendArrayPatternSkipEntry):
(JSC::ASTBuilder::appendArrayPatternEntry):
(JSC::ASTBuilder::createObjectPattern):
(JSC::ASTBuilder::appendObjectPatternEntry):
(JSC::ASTBuilder::createBindingLocation):
- parser/NodeConstructors.h:
(JSC::CommaNode::CommaNode):
(JSC::ParameterNode::ParameterNode):
(JSC::ForInNode::ForInNode):
(JSC::DeconstructionPatternNode::DeconstructionPatternNode):
(JSC::ArrayPatternNode::ArrayPatternNode):
(JSC::ArrayPatternNode::create):
(JSC::ObjectPatternNode::ObjectPatternNode):
(JSC::ObjectPatternNode::create):
(JSC::BindingNode::create):
(JSC::BindingNode::BindingNode):
(JSC::DeconstructingAssignmentNode::DeconstructingAssignmentNode):
(JSC::FunctionParameters::create):
(JSC::FunctionParameters::FunctionParameters):
(JSC::FunctionParameters::~FunctionParameters):
(JSC::ExpressionNode::isDeconstructionNode):
(JSC::ArrayNode::elements):
(JSC::CommaNode::append):
(JSC::ParameterNode::pattern):
(JSC::FunctionParameters::at):
(JSC::FunctionParameters::patterns):
(JSC::DeconstructionPatternNode::isBindingNode):
(JSC::DeconstructionPatternNode::emitDirectBinding):
(JSC::ArrayPatternNode::appendIndex):
(JSC::ObjectPatternNode::appendEntry):
(JSC::ObjectPatternNode::Entry::Entry):
(JSC::BindingNode::boundProperty):
(JSC::BindingNode::isBindingNode):
(JSC::DeconstructingAssignmentNode::bindings):
(JSC::DeconstructingAssignmentNode::isLocation):
(JSC::DeconstructingAssignmentNode::isDeconstructionNode):
(JSC::::Parser):
(JSC::::parseVarDeclaration):
(JSC::::parseVarDeclarationList):
(JSC::::createBindingPattern):
(JSC::::parseDeconstructionPattern):
(JSC::::parseForStatement):
(JSC::::parseFormalParameters):
(JSC::::parseAssignmentExpression):
(JSC::Scope::declareBoundParameter):
(JSC::Parser::declareBoundParameter):
(JSC::SyntaxChecker::createFormalParameterList):
(JSC::SyntaxChecker::addVar):
(JSC::SyntaxChecker::operatorStackPop):
(JSC::escapeStringToBuilder):
LayoutTests:
Add enw tests, and update old ones.
- js/destructuring-assignment-expected.txt: Added.
- js/destructuring-assignment.html: Added.
- js/mozilla/strict/13.1-expected.txt:
- js/mozilla/strict/regress-532254-expected.txt:
- js/mozilla/strict/script-tests/13.1.js:
- js/regress/destructuring-arguments-expected.txt: Added.
- js/regress/destructuring-arguments-length-expected.txt: Added.
- js/regress/destructuring-arguments-length.html: Added.
- js/regress/destructuring-arguments.html: Added.
- js/regress/destructuring-swap-expected.txt: Added.
- js/regress/destructuring-swap.html: Added.
- js/regress/script-tests/destructuring-arguments-length.js: Added.
(foo):
- js/regress/script-tests/destructuring-arguments.js: Added.
(foo):
- js/regress/script-tests/destructuring-swap.js: Added.
(foo):
- js/script-tests/destructuring-assignment.js: Added.
(testDestructuring):
(testDeconstructArgs):
(testDeconstructArgLength):