Title: [115217] trunk/Source/_javascript_Core
Revision
115217
Author
msab...@apple.com
Date
2012-04-25 09:11:29 -0700 (Wed, 25 Apr 2012)

Log Message

Closure in try {} with catch captures all locals from the enclosing function
https://bugs.webkit.org/show_bug.cgi?id=84804

Reviewed by Oliver Hunt.

Changed the capturing of local variables from capturing when eval is used,
within a "with" or within a "catch" to be just when an eval is used.
Renamed the function returning that we should capture from
getCapturedVariables() to usesEval(), since that what it noew returns.
Needed to fix the "with" code to only range check when the activation
has actually been torn off.  Added m_isTornOff to JSActivation to
track this.

* parser/Parser.h:
(JSC::Scope::usesEval):
(JSC::Scope::getCapturedVariables):
* runtime/JSActivation.cpp:
(JSC::JSActivation::JSActivation):
(JSC::JSActivation::symbolTableGet):
(JSC::JSActivation::symbolTablePut):
* runtime/JSActivation.h:
(JSActivation):
(JSC::JSActivation::tearOff):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (115216 => 115217)


--- trunk/Source/_javascript_Core/ChangeLog	2012-04-25 15:51:45 UTC (rev 115216)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-04-25 16:11:29 UTC (rev 115217)
@@ -1,3 +1,29 @@
+2012-04-25  Michael Saboff  <msab...@apple.com>
+
+        Closure in try {} with catch captures all locals from the enclosing function
+        https://bugs.webkit.org/show_bug.cgi?id=84804
+
+        Reviewed by Oliver Hunt.
+
+        Changed the capturing of local variables from capturing when eval is used,
+        within a "with" or within a "catch" to be just when an eval is used.
+        Renamed the function returning that we should capture from
+        getCapturedVariables() to usesEval(), since that what it noew returns.
+        Needed to fix the "with" code to only range check when the activation
+        has actually been torn off.  Added m_isTornOff to JSActivation to
+        track this.
+
+        * parser/Parser.h:
+        (JSC::Scope::usesEval):
+        (JSC::Scope::getCapturedVariables):
+        * runtime/JSActivation.cpp:
+        (JSC::JSActivation::JSActivation):
+        (JSC::JSActivation::symbolTableGet):
+        (JSC::JSActivation::symbolTablePut):
+        * runtime/JSActivation.h:
+        (JSActivation):
+        (JSC::JSActivation::tearOff):
+
 2012-04-24  Mark Hahnenberg  <mhahnenb...@apple.com>
 
         GC Activity Callback timer should be based on how much has been allocated since the last collection

Modified: trunk/Source/_javascript_Core/parser/Parser.h (115216 => 115217)


--- trunk/Source/_javascript_Core/parser/Parser.h	2012-04-25 15:51:45 UTC (rev 115216)
+++ trunk/Source/_javascript_Core/parser/Parser.h	2012-04-25 16:11:29 UTC (rev 115217)
@@ -162,7 +162,7 @@
     ALWAYS_INLINE ScopeFlags usesFlags() const { return m_scopeFlags & AllScopeUsesFlags; }
     ALWAYS_INLINE void setFlags(ScopeFlags scopeFlags) { m_scopeFlags |= scopeFlags; }
 
-    ALWAYS_INLINE bool needsFullActivation() const { return m_scopeFlags & (UsesEvalFlag | UsesWithFlag | UsesCatchFlag); }
+    ALWAYS_INLINE bool usesEval() const { return m_scopeFlags & UsesEvalFlag; }
     ALWAYS_INLINE bool strictMode() const { return m_scopeFlags & StrictModeFlag; }
     ALWAYS_INLINE bool shadowsArguments() const { return m_scopeFlags & ShadowsArgumentsFlag; }
     ALWAYS_INLINE bool isFunction() const { return m_scopeFlags & FunctionModeFlag; }
@@ -269,7 +269,7 @@
 
     void getCapturedVariables(IdentifierSet& capturedVariables)
     {
-        if (needsFullActivation()) {
+        if (usesEval()) {
             capturedVariables.swap(m_declaredVariables);
             return;
         }

Modified: trunk/Source/_javascript_Core/runtime/JSActivation.cpp (115216 => 115217)


--- trunk/Source/_javascript_Core/runtime/JSActivation.cpp	2012-04-25 15:51:45 UTC (rev 115216)
+++ trunk/Source/_javascript_Core/runtime/JSActivation.cpp	2012-04-25 16:11:29 UTC (rev 115217)
@@ -45,6 +45,7 @@
     : Base(callFrame->globalData(), callFrame->globalData().activationStructure.get(), functionExecutable->symbolTable(), callFrame->registers())
     , m_numCapturedArgs(max(callFrame->argumentCount(), functionExecutable->parameterCount()))
     , m_numCapturedVars(functionExecutable->capturedVariableCount())
+    , m_isTornOff(false)
     , m_requiresDynamicChecks(functionExecutable->usesEval() && !functionExecutable->isStrictMode())
     , m_argumentsRegister(functionExecutable->generatedBytecode().argumentsRegister())
 {
@@ -94,7 +95,7 @@
     SymbolTableEntry entry = symbolTable().inlineGet(propertyName.impl());
     if (entry.isNull())
         return false;
-    if (entry.getIndex() >= m_numCapturedVars)
+    if (m_isTornOff && entry.getIndex() >= m_numCapturedVars)
         return false;
 
     slot.setValue(registerAt(entry.getIndex()).get());
@@ -114,7 +115,7 @@
             throwTypeError(exec, StrictModeReadonlyPropertyWriteError);
         return true;
     }
-    if (entry.getIndex() >= m_numCapturedVars)
+    if (m_isTornOff && entry.getIndex() >= m_numCapturedVars)
         return false;
 
     registerAt(entry.getIndex()).set(globalData, this, value);

Modified: trunk/Source/_javascript_Core/runtime/JSActivation.h (115216 => 115217)


--- trunk/Source/_javascript_Core/runtime/JSActivation.h	2012-04-25 15:51:45 UTC (rev 115216)
+++ trunk/Source/_javascript_Core/runtime/JSActivation.h	2012-04-25 16:11:29 UTC (rev 115217)
@@ -92,7 +92,8 @@
         NEVER_INLINE PropertySlot::GetValueFunc getArgumentsGetter();
 
         int m_numCapturedArgs;
-        int m_numCapturedVars : 31;
+        int m_numCapturedVars : 30;
+        bool m_isTornOff : 1;
         bool m_requiresDynamicChecks : 1;
         int m_argumentsRegister;
     };
@@ -133,6 +134,7 @@
             registers[i].set(globalData, this, m_registers[i].get());
 
         setRegisters(registers, registerArray.release());
+        m_isTornOff = true;
     }
 
 } // namespace JSC
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to