Ignore:
Timestamp:
Aug 17, 2015, 3:24:20 PM (10 years ago)
Author:
[email protected]
Message:

[ES6] Implement ES6 arrow function syntax. Arrow function specific features. Lexical bind of this
https://bugs.webkit.org/show_bug.cgi?id=144956

Source/JavaScriptCore:

Patch by Aleksandr Skachkov <[email protected]> on 2015-08-17
Reviewed by Saam Barati.

Added support of ES6 arrow function specific feature, lexical bind of this and no constructor. http://wiki.ecmascript.org/doku.php?id=harmony:arrow_function_syntax
In patch were implemented the following cases:

this - variable |this| is point to the |this| of the function where arrow function is declared. Lexical bind of |this|
constructor - the using of the command |new| for arrow function leads to runtime error
call(), apply(), bind() - methods can only pass in arguments, but has no effect on |this|

  • CMakeLists.txt:
  • JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
  • JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • bytecode/BytecodeList.json:
  • bytecode/BytecodeUseDef.h:

(JSC::computeUsesForBytecodeOffset):
(JSC::computeDefsForBytecodeOffset):

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::dumpBytecode):

  • bytecode/ExecutableInfo.h:

(JSC::ExecutableInfo::ExecutableInfo):
(JSC::ExecutableInfo::isArrowFunction):

  • bytecode/UnlinkedCodeBlock.cpp:

(JSC::UnlinkedCodeBlock::UnlinkedCodeBlock):

  • bytecode/UnlinkedCodeBlock.h:

(JSC::UnlinkedCodeBlock::isArrowFunction):

  • bytecode/UnlinkedFunctionExecutable.cpp:

(JSC::generateFunctionCodeBlock):
(JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable):
(JSC::UnlinkedFunctionExecutable::codeBlockFor):

  • bytecode/UnlinkedFunctionExecutable.h:
  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::emitNewFunctionCommon):
(JSC::BytecodeGenerator::emitNewFunctionExpression):
(JSC::BytecodeGenerator::emitNewArrowFunctionExpression):
(JSC::BytecodeGenerator::emitLoadArrowFunctionThis):

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

(JSC::ArrowFuncExprNode::emitBytecode):

  • dfg/DFGAbstractInterpreterInlines.h:

(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):

  • dfg/DFGByteCodeParser.cpp:

(JSC::DFG::ByteCodeParser::parseBlock):

  • dfg/DFGCapabilities.cpp:

(JSC::DFG::capabilityLevel):

  • dfg/DFGClobberize.h:

(JSC::DFG::clobberize):

  • dfg/DFGDoesGC.cpp:

(JSC::DFG::doesGC):

  • dfg/DFGFixupPhase.cpp:

(JSC::DFG::FixupPhase::fixupNode):

  • dfg/DFGNode.h:

(JSC::DFG::Node::convertToPhantomNewFunction):
(JSC::DFG::Node::hasCellOperand):
(JSC::DFG::Node::isFunctionAllocation):

  • dfg/DFGNodeType.h:
  • dfg/DFGObjectAllocationSinkingPhase.cpp:
  • dfg/DFGPredictionPropagationPhase.cpp:

(JSC::DFG::PredictionPropagationPhase::propagate):

  • dfg/DFGPromotedHeapLocation.cpp:

(WTF::printInternal):

  • dfg/DFGPromotedHeapLocation.h:
  • dfg/DFGSafeToExecute.h:

(JSC::DFG::safeToExecute):

  • dfg/DFGSpeculativeJIT.cpp:

(JSC::DFG::SpeculativeJIT::compileLoadArrowFunctionThis):
(JSC::DFG::SpeculativeJIT::compileNewFunctionCommon):
(JSC::DFG::SpeculativeJIT::compileNewFunction):

  • dfg/DFGSpeculativeJIT.h:

(JSC::DFG::SpeculativeJIT::callOperation):

  • dfg/DFGSpeculativeJIT32_64.cpp:

(JSC::DFG::SpeculativeJIT::compile):

  • dfg/DFGSpeculativeJIT64.cpp:

(JSC::DFG::SpeculativeJIT::compile):

  • dfg/DFGStoreBarrierInsertionPhase.cpp:
  • dfg/DFGStructureRegistrationPhase.cpp:

(JSC::DFG::StructureRegistrationPhase::run):

  • ftl/FTLAbstractHeapRepository.cpp:
  • ftl/FTLAbstractHeapRepository.h:
  • ftl/FTLCapabilities.cpp:

(JSC::FTL::canCompile):

  • ftl/FTLIntrinsicRepository.h:
  • ftl/FTLLowerDFGToLLVM.cpp:

(JSC::FTL::DFG::LowerDFGToLLVM::compileNode):
(JSC::FTL::DFG::LowerDFGToLLVM::compileNewFunction):
(JSC::FTL::DFG::LowerDFGToLLVM::compileLoadArrowFunctionThis):

  • ftl/FTLOperations.cpp:

(JSC::FTL::operationMaterializeObjectInOSR):

  • interpreter/Interpreter.cpp:
  • interpreter/Interpreter.h:
  • jit/CCallHelpers.h:

(JSC::CCallHelpers::setupArgumentsWithExecState): Added 3 arguments version for windows build.

  • jit/JIT.cpp:

(JSC::JIT::privateCompileMainPass):

  • jit/JIT.h:
  • jit/JITInlines.h:

(JSC::JIT::callOperation):

  • jit/JITOpcodes.cpp:

(JSC::JIT::emit_op_load_arrowfunction_this):
(JSC::JIT::emit_op_new_func_exp):
(JSC::JIT::emitNewFuncExprCommon):
(JSC::JIT::emit_op_new_arrow_func_exp):

  • jit/JITOpcodes32_64.cpp:

(JSC::JIT::emit_op_load_arrowfunction_this):

  • jit/JITOperations.cpp:
  • jit/JITOperations.h:
  • llint/LLIntOffsetsExtractor.cpp:
  • llint/LLIntSlowPaths.cpp:

(JSC::LLInt::LLINT_SLOW_PATH_DECL):
(JSC::LLInt::setUpCall):

  • llint/LLIntSlowPaths.h:
  • llint/LowLevelInterpreter.asm:
  • llint/LowLevelInterpreter32_64.asm:
  • llint/LowLevelInterpreter64.asm:
  • parser/ASTBuilder.h:

(JSC::ASTBuilder::createFunctionMetadata):
(JSC::ASTBuilder::createArrowFunctionExpr):

  • parser/NodeConstructors.h:

(JSC::BaseFuncExprNode::BaseFuncExprNode):
(JSC::FuncExprNode::FuncExprNode):
(JSC::ArrowFuncExprNode::ArrowFuncExprNode):

  • parser/Nodes.cpp:

(JSC::FunctionMetadataNode::FunctionMetadataNode):

  • parser/Nodes.h:

(JSC::ExpressionNode::isArrowFuncExprNode):

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseFunctionBody):
(JSC::Parser<LexerType>::parseFunctionInfo):

  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::createFunctionMetadata):

  • runtime/Executable.cpp:

(JSC::ScriptExecutable::newCodeBlockFor):

  • runtime/Executable.h:
  • runtime/JSArrowFunction.cpp: Added.

(JSC::JSArrowFunction::destroy):
(JSC::JSArrowFunction::create):
(JSC::JSArrowFunction::JSArrowFunction):
(JSC::JSArrowFunction::createWithInvalidatedReallocationWatchpoint):
(JSC::JSArrowFunction::visitChildren):
(JSC::JSArrowFunction::getConstructData):

  • runtime/JSArrowFunction.h: Added.

(JSC::JSArrowFunction::allocationSize):
(JSC::JSArrowFunction::createImpl):
(JSC::JSArrowFunction::boundThis):
(JSC::JSArrowFunction::createStructure):
(JSC::JSArrowFunction::offsetOfThisValue):

  • runtime/JSFunction.h:
  • runtime/JSFunctionInlines.h:

(JSC::JSFunction::JSFunction):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildren):

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::arrowFunctionStructure):

  • tests/stress/arrowfunction-activation-sink-osrexit-default-value-tdz-error.js: Added.
  • tests/stress/arrowfunction-activation-sink-osrexit-default-value.js: Added.
  • tests/stress/arrowfunction-activation-sink-osrexit.js: Added.
  • tests/stress/arrowfunction-activation-sink.js: Added.
  • tests/stress/arrowfunction-bound.js: Added.
  • tests/stress/arrowfunction-call.js: Added.
  • tests/stress/arrowfunction-constructor.js: Added.
  • tests/stress/arrowfunction-lexical-bind-this-1.js: Added.
  • tests/stress/arrowfunction-lexical-bind-this-2.js: Added.
  • tests/stress/arrowfunction-lexical-bind-this-3.js: Added.
  • tests/stress/arrowfunction-lexical-bind-this-4.js: Added.
  • tests/stress/arrowfunction-lexical-bind-this-5.js: Added.
  • tests/stress/arrowfunction-lexical-bind-this-6.js: Added.
  • tests/stress/arrowfunction-lexical-this-activation-sink-osrexit.js: Added.
  • tests/stress/arrowfunction-lexical-this-activation-sink.js: Added.
  • tests/stress/arrowfunction-lexical-this-sinking-no-double-allocate.js: Added.
  • tests/stress/arrowfunction-lexical-this-sinking-osrexit.js: Added.
  • tests/stress/arrowfunction-lexical-this-sinking-put.js: Added.
  • tests/stress/arrowfunction-others.js: Added.
  • tests/stress/arrowfunction-run-10-1.js: Added.
  • tests/stress/arrowfunction-run-10-2.js: Added.
  • tests/stress/arrowfunction-run-10000-1.js: Added.
  • tests/stress/arrowfunction-run-10000-2.js: Added.
  • tests/stress/arrowfunction-sinking-no-double-allocate.js: Added.
  • tests/stress/arrowfunction-sinking-osrexit.js: Added.
  • tests/stress/arrowfunction-sinking-put.js: Added.
  • tests/stress/arrowfunction-tdz.js: Added.
  • tests/stress/arrowfunction-typeof.js: Added.

LayoutTests:

Patch by Skachkov Oleksandr <[email protected]> on 2015-08-17
Reviewed by Saam Barati.

  • js/arrowfunction-bind-expected.txt: Added.
  • js/arrowfunction-bind.html: Added.
  • js/arrowfunction-call-expected.txt: Added.
  • js/arrowfunction-call.html: Added.
  • js/arrowfunction-constructor-expected.txt: Added.
  • js/arrowfunction-constructor.html: Added.
  • js/arrowfunction-lexical-bind-this-expected.txt: Added.
  • js/arrowfunction-lexical-bind-this.html: Added.
  • js/arrowfunction-others-expected.txt: Added.
  • js/arrowfunction-others.html: Added.
  • js/arrowfunction-tdz-expected.txt: Added.
  • js/arrowfunction-tdz.html: Added.
  • js/arrowfunction-typeof-expected.txt: Added.
  • js/arrowfunction-typeof.html: Added.
  • js/regress/arrowfunction-call-expected.txt: Added.
  • js/regress/arrowfunction-call.html: Added.
  • js/regress/script-tests/arrowfunction-call.js: Added.
  • js/regress/script-tests/function-call.js: Added.
  • js/script-tests/arrowfunction-bind.js: Added.
  • js/script-tests/arrowfunction-call.js: Added.
  • js/script-tests/arrowfunction-constructor.js: Added.
  • js/script-tests/arrowfunction-lexical-bind-this.js: Added.
  • js/script-tests/arrowfunction-others.js: Added.
  • js/script-tests/arrowfunction-tdz.js: Added.
  • js/script-tests/arrowfunction-typeof.js: Added.
File:
1 edited

Legend:

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

    r188498 r188545  
    362362        unsigned startColumn, unsigned endColumn, int functionKeywordStart,
    363363        int functionNameStart, int parametersStart, bool inStrictContext,
    364         ConstructorKind constructorKind, unsigned parameterCount, SourceParseMode mode)
     364        ConstructorKind constructorKind, unsigned parameterCount, SourceParseMode mode, bool isArrowFunction)
    365365    {
    366366        return new (m_parserArena) FunctionMetadataNode(
    367367            m_parserArena, startLocation, endLocation, startColumn, endColumn,
    368368            functionKeywordStart, functionNameStart, parametersStart,
    369             inStrictContext, constructorKind, parameterCount, mode);
     369            inStrictContext, constructorKind, parameterCount, mode, isArrowFunction);
    370370    }
    371371
    372372    ExpressionNode* createArrowFunctionExpr(const JSTokenLocation& location, const ParserFunctionInfo<ASTBuilder>& functionInfo)
    373373    {
     374        usesThis();
    374375        SourceCode source = m_sourceCode->subExpression(functionInfo.startOffset, functionInfo.endOffset, functionInfo.startLine, functionInfo.bodyStartColumn);
    375 
    376         FuncExprNode* result = new (m_parserArena) FuncExprNode(location, *functionInfo.name, functionInfo.body, source);
     376        ArrowFuncExprNode* result = new (m_parserArena) ArrowFuncExprNode(location, *functionInfo.name, functionInfo.body, source);
    377377        functionInfo.body->setLoc(functionInfo.startLine, functionInfo.endLine, location.startOffset, location.lineStartOffset);
    378378        return result;
Note: See TracChangeset for help on using the changeset viewer.