Title: [201176] trunk/Source/_javascript_Core
Revision
201176
Author
[email protected]
Date
2016-05-19 13:09:47 -0700 (Thu, 19 May 2016)

Log 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:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (201175 => 201176)


--- trunk/Source/_javascript_Core/ChangeLog	2016-05-19 19:15:35 UTC (rev 201175)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-05-19 20:09:47 UTC (rev 201176)
@@ -1,3 +1,19 @@
+2016-05-19  Saam barati  <[email protected]>
+
+        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:
+
 2016-05-19  Michael Saboff  <[email protected]>
 
         Unreviewed build fix.

Modified: trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp (201175 => 201176)


--- trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp	2016-05-19 19:15:35 UTC (rev 201175)
+++ trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp	2016-05-19 20:09:47 UTC (rev 201176)
@@ -575,7 +575,8 @@
     }
 
     if (needsToUpdateArrowFunctionContext() && !codeBlock->isArrowFunction()) {
-        initializeArrowFunctionContextScopeIfNeeded();
+        bool canReuseLexicalEnvironment = isSimpleParameterList;
+        initializeArrowFunctionContextScopeIfNeeded(functionSymbolTable, canReuseLexicalEnvironment);
         emitPutThisToArrowFunctionContextScope();
         emitPutNewTargetToArrowFunctionContextScope();
         emitPutDerivedConstructorToArrowFunctionContextScope();
@@ -893,10 +894,37 @@
     }
 }
 
-void BytecodeGenerator::initializeArrowFunctionContextScopeIfNeeded()
+void BytecodeGenerator::initializeArrowFunctionContextScopeIfNeeded(SymbolTable* functionSymbolTable, bool canReuseLexicalEnvironment)
 {
     ASSERT(!m_arrowFunctionContextLexicalEnvironmentRegister);
 
+    if (canReuseLexicalEnvironment && m_lexicalEnvironmentRegister) {
+        RELEASE_ASSERT(!m_codeBlock->isArrowFunction());
+        RELEASE_ASSERT(functionSymbolTable);
+
+        m_arrowFunctionContextLexicalEnvironmentRegister = m_lexicalEnvironmentRegister;
+        
+        ScopeOffset offset;
+        
+        ConcurrentJITLocker locker(ConcurrentJITLocker::NoLockingNecessary);
+        if (isThisUsedInInnerArrowFunction()) {
+            offset = functionSymbolTable->takeNextScopeOffset(locker);
+            functionSymbolTable->set(locker, propertyNames().thisIdentifier.impl(), SymbolTableEntry(VarOffset(offset)));
+        }
+
+        if (m_codeType == FunctionCode && isNewTargetUsedInInnerArrowFunction()) {
+            offset = functionSymbolTable->takeNextScopeOffset();
+            functionSymbolTable->set(locker, propertyNames().newTargetLocalPrivateName.impl(), SymbolTableEntry(VarOffset(offset)));
+        }
+        
+        if (isConstructor() && constructorKind() == ConstructorKind::Derived && isSuperUsedInInnerArrowFunction()) {
+            offset = functionSymbolTable->takeNextScopeOffset(locker);
+            functionSymbolTable->set(locker, propertyNames().derivedConstructorPrivateName.impl(), SymbolTableEntry(VarOffset(offset)));
+        }
+
+        return;
+    }
+
     VariableEnvironment environment;
 
     if (isThisUsedInInnerArrowFunction()) {

Modified: trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h (201175 => 201176)


--- trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h	2016-05-19 19:15:35 UTC (rev 201175)
+++ trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h	2016-05-19 20:09:47 UTC (rev 201176)
@@ -858,7 +858,7 @@
         void initializeParameters(FunctionParameters&);
         void initializeVarLexicalEnvironment(int symbolTableConstantIndex, SymbolTable* functionSymbolTable, bool hasCapturedVariables);
         void initializeDefaultParameterValuesAndSetupFunctionScopeStack(FunctionParameters&, bool isSimpleParameterList, FunctionNode*, SymbolTable*, int symbolTableConstantIndex, const std::function<bool (UniquedStringImpl*)>& captures, bool shouldCreateArgumentsVariableInParameterScope);
-        void initializeArrowFunctionContextScopeIfNeeded();
+        void initializeArrowFunctionContextScopeIfNeeded(SymbolTable* functionSymbolTable = nullptr, bool canReuseLexicalEnvironment = false);
 
     public:
         JSString* addStringConstant(const Identifier&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to