Ignore:
Timestamp:
Mar 9, 2017, 6:00:33 PM (8 years ago)
Author:
[email protected]
Message:

[ESnext] Implement Object Rest - Implementing Object Rest Destructuring
https://bugs.webkit.org/show_bug.cgi?id=167962

Patch by Caio Lima <Caio Lima> on 2017-03-09
Reviewed by Keith Miller.

JSTests:

  • stress/object-rest-deconstruct.js: Added.

(let.assert):
(let.assertPropDescriptor):
(catch):
(get 3):
(foo):
(let.src.get y):
(let.src.set y):
(let.gen):

Source/JavaScriptCore:

Object Rest/Spread Destructing proposal is in stage 3[1] and this
Patch is a prototype implementation of it. A simple change over the
parser was necessary to support the new '...' token on Object Pattern
destruction rule. In the bytecode generator side, We changed the
bytecode generated on ObjectPatternNode::bindValue to store in an
array identifiers of already destructed properties, following spec draft
section[2], and then pass it as excludedNames to CopyDataProperties.
The rest destruction the calls copyDataProperties to perform the
copy of rest properties in rhs.

We also implemented CopyDataProperties as private JS global operation
on builtins/GlobalOperations.js following it's specification on [3].
It is implemented using Set object to verify if a property is on
excludedNames to keep this algorithm with O(n + m) complexity, where n

number of source's own properties and m = excludedNames.length.

As a requirement to use JSSets as constants, a change in
CodeBlock::create API was necessary, because JSSet creation can throws OOM
exception. Now, CodeBlock::finishCreation returns false if an
execption is throwed by
CodeBlock::setConstantIdentifierSetRegisters and then we return
nullptr to ScriptExecutable::newCodeBlockFor. It is responsible to
check if CodeBlock was constructed properly and then, throw OOM
exception to the correct scope.

[1] - https://github.com/sebmarkbage/ecmascript-rest-spread
[2] - http://sebmarkbage.github.io/ecmascript-rest-spread/#Rest-RuntimeSemantics-PropertyDestructuringAssignmentEvaluation
[3] - http://sebmarkbage.github.io/ecmascript-rest-spread/#AbstractOperations-CopyDataProperties

  • builtins/BuiltinNames.h:
  • builtins/GlobalOperations.js:

(globalPrivate.copyDataProperties):

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::finishCreation):
(JSC::CodeBlock::setConstantIdentifierSetRegisters):

  • bytecode/CodeBlock.h:
  • bytecode/EvalCodeBlock.h:

(JSC::EvalCodeBlock::create):

  • bytecode/FunctionCodeBlock.h:

(JSC::FunctionCodeBlock::create):

  • bytecode/ModuleProgramCodeBlock.h:

(JSC::ModuleProgramCodeBlock::create):

  • bytecode/ProgramCodeBlock.h:

(JSC::ProgramCodeBlock::create):

  • bytecode/UnlinkedCodeBlock.h:

(JSC::UnlinkedCodeBlock::addSetConstant):
(JSC::UnlinkedCodeBlock::constantIdentifierSets):

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::emitLoad):

  • bytecompiler/BytecodeGenerator.h:
  • bytecompiler/NodesCodegen.cpp:

(JSC::ObjectPatternNode::bindValue):

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::appendObjectPatternEntry):
(JSC::ASTBuilder::appendObjectPatternRestEntry):
(JSC::ASTBuilder::setContainsObjectRestElement):

  • parser/Nodes.h:

(JSC::ObjectPatternNode::appendEntry):
(JSC::ObjectPatternNode::setContainsRestElement):

  • parser/Parser.cpp:

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

  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::operatorStackPop):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::privateToObject):

  • runtime/JSGlobalObjectFunctions.h:
  • runtime/ScriptExecutable.cpp:

(JSC::ScriptExecutable::newCodeBlockFor):

Source/WTF:

  • wtf/HashSet.h:

(WTF::=):

LayoutTests:

  • js/parser-syntax-check-expected.txt:
  • js/script-tests/parser-syntax-check.js:
File:
1 edited

Legend:

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

    r211319 r213697  
    353353    {
    354354    }
     355    void appendObjectPatternRestEntry(ObjectPattern, const JSTokenLocation&, DestructuringPattern)
     356    {
     357    }
     358    void setContainsObjectRestElement(ObjectPattern, bool)
     359    {
     360    }
    355361
    356362    DestructuringPattern createBindingLocation(const JSTokenLocation&, const Identifier&, const JSTextPosition&, const JSTextPosition&, AssignmentContext)
Note: See TracChangeset for help on using the changeset viewer.