Title: [93487] trunk
Revision
93487
Author
[email protected]
Date
2011-08-20 22:21:50 -0700 (Sat, 20 Aug 2011)

Log Message

_javascript_Core bytecompiler does not compute scope depth correctly
in the case of constant declarations
https://bugs.webkit.org/show_bug.cgi?id=66572

Source/_javascript_Core:

Patch by Filip Pizlo <[email protected]> on 2011-08-20
Reviewed by Oliver Hunt.

Changed the handling of const to add the dynamic scope depth.

* bytecompiler/NodesCodegen.cpp:
(JSC::ConstDeclNode::emitCodeSingle):

LayoutTests:

Patch by Filip Pizlo <[email protected]> on 2011-08-20
Reviewed by Oliver Hunt.

Added tests that reproduce the failure.

* fast/js/const-expected.txt:
* fast/js/resources/const.js:
(tryCatch1):
(tryCatch2):
(with1):
(with2):

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (93486 => 93487)


--- trunk/LayoutTests/ChangeLog	2011-08-21 05:14:07 UTC (rev 93486)
+++ trunk/LayoutTests/ChangeLog	2011-08-21 05:21:50 UTC (rev 93487)
@@ -1,3 +1,20 @@
+2011-08-20  Filip Pizlo  <[email protected]>
+
+        _javascript_Core bytecompiler does not compute scope depth correctly
+        in the case of constant declarations
+        https://bugs.webkit.org/show_bug.cgi?id=66572
+
+        Reviewed by Oliver Hunt.
+        
+        Added tests that reproduce the failure.
+
+        * fast/js/const-expected.txt:
+        * fast/js/resources/const.js:
+        (tryCatch1):
+        (tryCatch2):
+        (with1):
+        (with2):
+
 2011-08-20  Tom Zakrajsek  <[email protected]>
 
         instanceof HTMLSourceElement Fails

Modified: trunk/LayoutTests/fast/js/const-expected.txt (93486 => 93487)


--- trunk/LayoutTests/fast/js/const-expected.txt	2011-08-21 05:14:07 UTC (rev 93486)
+++ trunk/LayoutTests/fast/js/const-expected.txt	2011-08-21 05:21:50 UTC (rev 93487)
@@ -51,6 +51,10 @@
 PASS const a; is undefined
 PASS bodyId is document.getElementById('bodyId')
 PASS ranConstInitialiser is true
+PASS tryCatch1Result is 5
+PASS tryCatch2Result is 5
+PASS with1Result is 5
+PASS with2Result is 5
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/js/resources/const.js (93486 => 93487)


--- trunk/LayoutTests/fast/js/resources/const.js	2011-08-21 05:14:07 UTC (rev 93486)
+++ trunk/LayoutTests/fast/js/resources/const.js	2011-08-21 05:21:50 UTC (rev 93487)
@@ -117,4 +117,50 @@
 const bodyId = (ranConstInitialiser = true, "Const initialiser overwrote existing property");
 shouldBe("bodyId", "document.getElementById('bodyId')");
 shouldBeTrue("ranConstInitialiser");
+
+// Make sure that dynamic scopes (catch, with) don't break const declarations
+function tryCatch1() {
+    var bar;
+    eval("try {\
+        stuff();\
+    } catch (e) {\
+        print(\"here.\");\
+        const bar = 5;\
+    }");
+    return bar;
+}
+
+function tryCatch2() {
+    var bar;
+    try {
+        stuff();
+    } catch (e) {
+        print("here.");
+        const bar = 5;
+    }
+    return bar;
+}
+
+tryCatch1Result = tryCatch1();
+shouldBe("tryCatch1Result", "5");
+tryCatch2Result = tryCatch2();
+shouldBe("tryCatch2Result", "5");
+
+function with1() {
+    var bar;
+    eval("with({foo:42}) const bar = 5;");
+    return bar;
+}
+
+function with2() {
+    var bar;
+    with({foo:42}) const bar = 5;
+    return bar;
+}
+
+with1Result = with1();
+shouldBe("with1Result", "5");
+with2Result = with2();
+shouldBe("with2Result", "5");
+
 var successfullyParsed = true;

Modified: trunk/Source/_javascript_Core/ChangeLog (93486 => 93487)


--- trunk/Source/_javascript_Core/ChangeLog	2011-08-21 05:14:07 UTC (rev 93486)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-08-21 05:21:50 UTC (rev 93487)
@@ -1,3 +1,16 @@
+2011-08-20  Filip Pizlo  <[email protected]>
+
+        _javascript_Core bytecompiler does not compute scope depth correctly
+        in the case of constant declarations
+        https://bugs.webkit.org/show_bug.cgi?id=66572
+
+        Reviewed by Oliver Hunt.
+        
+        Changed the handling of const to add the dynamic scope depth.
+
+        * bytecompiler/NodesCodegen.cpp:
+        (JSC::ConstDeclNode::emitCodeSingle):
+
 2011-08-19  Daniel Bates  <[email protected]>
 
         Only #include <signal.h> and require SA_RESTART when building with JSC_MULTIPLE_THREADS

Modified: trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp (93486 => 93487)


--- trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp	2011-08-21 05:14:07 UTC (rev 93486)
+++ trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp	2011-08-21 05:21:50 UTC (rev 93487)
@@ -1308,7 +1308,7 @@
         if (entry.isNull())
             continue;
 
-        return generator.emitPutScopedVar(depth, entry.getIndex(), value.get(), currentVariableObject->isGlobalObject() ? currentVariableObject : 0);
+        return generator.emitPutScopedVar(generator.scopeDepth() + depth, entry.getIndex(), value.get(), currentVariableObject->isGlobalObject() ? currentVariableObject : 0);
     }
 
     if (generator.codeType() != EvalCode)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to