Changeset 201176 in webkit


Ignore:
Timestamp:
May 19, 2016, 1:09:47 PM (9 years ago)
Author:
sbarati@apple.com
Message:

arrow function lexical environment should reuse the same environment as the function's lexical environment where possible
https://bugs.webkit.org/show_bug.cgi?id=157908

Reviewed by Filip Pizlo.

We can safely combine these two environment when we have
a simple parameter list (no default parameters, no destructring parameters).

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::initializeDefaultParameterValuesAndSetupFunctionScopeStack):
(JSC::BytecodeGenerator::initializeArrowFunctionContextScopeIfNeeded):

  • bytecompiler/BytecodeGenerator.h:
Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r201172 r201176  
     12016-05-19  Saam barati  <sbarati@apple.com>
     2
     3        arrow function lexical environment should reuse the same environment as the function's lexical environment where possible
     4        https://bugs.webkit.org/show_bug.cgi?id=157908
     5
     6        Reviewed by Filip Pizlo.
     7
     8        We can safely combine these two environment when we have
     9        a simple parameter list (no default parameters, no destructring parameters).
     10
     11        * bytecompiler/BytecodeGenerator.cpp:
     12        (JSC::BytecodeGenerator::BytecodeGenerator):
     13        (JSC::BytecodeGenerator::initializeDefaultParameterValuesAndSetupFunctionScopeStack):
     14        (JSC::BytecodeGenerator::initializeArrowFunctionContextScopeIfNeeded):
     15        * bytecompiler/BytecodeGenerator.h:
     16
    1172016-05-19  Michael Saboff  <msaboff@apple.com>
    218
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r201122 r201176  
    576576
    577577    if (needsToUpdateArrowFunctionContext() && !codeBlock->isArrowFunction()) {
    578         initializeArrowFunctionContextScopeIfNeeded();
     578        bool canReuseLexicalEnvironment = isSimpleParameterList;
     579        initializeArrowFunctionContextScopeIfNeeded(functionSymbolTable, canReuseLexicalEnvironment);
    579580        emitPutThisToArrowFunctionContextScope();
    580581        emitPutNewTargetToArrowFunctionContextScope();
     
    894895}
    895896
    896 void BytecodeGenerator::initializeArrowFunctionContextScopeIfNeeded()
     897void BytecodeGenerator::initializeArrowFunctionContextScopeIfNeeded(SymbolTable* functionSymbolTable, bool canReuseLexicalEnvironment)
    897898{
    898899    ASSERT(!m_arrowFunctionContextLexicalEnvironmentRegister);
     900
     901    if (canReuseLexicalEnvironment && m_lexicalEnvironmentRegister) {
     902        RELEASE_ASSERT(!m_codeBlock->isArrowFunction());
     903        RELEASE_ASSERT(functionSymbolTable);
     904
     905        m_arrowFunctionContextLexicalEnvironmentRegister = m_lexicalEnvironmentRegister;
     906       
     907        ScopeOffset offset;
     908       
     909        ConcurrentJITLocker locker(ConcurrentJITLocker::NoLockingNecessary);
     910        if (isThisUsedInInnerArrowFunction()) {
     911            offset = functionSymbolTable->takeNextScopeOffset(locker);
     912            functionSymbolTable->set(locker, propertyNames().thisIdentifier.impl(), SymbolTableEntry(VarOffset(offset)));
     913        }
     914
     915        if (m_codeType == FunctionCode && isNewTargetUsedInInnerArrowFunction()) {
     916            offset = functionSymbolTable->takeNextScopeOffset();
     917            functionSymbolTable->set(locker, propertyNames().newTargetLocalPrivateName.impl(), SymbolTableEntry(VarOffset(offset)));
     918        }
     919       
     920        if (isConstructor() && constructorKind() == ConstructorKind::Derived && isSuperUsedInInnerArrowFunction()) {
     921            offset = functionSymbolTable->takeNextScopeOffset(locker);
     922            functionSymbolTable->set(locker, propertyNames().derivedConstructorPrivateName.impl(), SymbolTableEntry(VarOffset(offset)));
     923        }
     924
     925        return;
     926    }
    899927
    900928    VariableEnvironment environment;
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h

    r201122 r201176  
    859859        void initializeVarLexicalEnvironment(int symbolTableConstantIndex, SymbolTable* functionSymbolTable, bool hasCapturedVariables);
    860860        void initializeDefaultParameterValuesAndSetupFunctionScopeStack(FunctionParameters&, bool isSimpleParameterList, FunctionNode*, SymbolTable*, int symbolTableConstantIndex, const std::function<bool (UniquedStringImpl*)>& captures, bool shouldCreateArgumentsVariableInParameterScope);
    861         void initializeArrowFunctionContextScopeIfNeeded();
     861        void initializeArrowFunctionContextScopeIfNeeded(SymbolTable* functionSymbolTable = nullptr, bool canReuseLexicalEnvironment = false);
    862862
    863863    public:
Note: See TracChangeset for help on using the changeset viewer.