Title: [202602] trunk/Source/_javascript_Core
Revision
202602
Author
sbar...@apple.com
Date
2016-06-28 19:06:22 -0700 (Tue, 28 Jun 2016)

Log Message

Assertion failure or crash when accessing let-variable in TDZ with eval with a function in it that returns let variable
https://bugs.webkit.org/show_bug.cgi?id=158796
<rdar://problem/26984659>

Reviewed by Michael Saboff.

There was a bug where some functions inside of an eval were
omitting a necessary TDZ check. This obviously leads to bad
things because a variable under TDZ is the null pointer.
The eval's bytecode was generated with the correct TDZ set, but 
it created all its functions before pushing that TDZ set onto
the stack. That's a mistake. Those functions need to be created with
that TDZ set. The solution is simple, the TDZ set that the eval
is created with needs to be pushed onto the TDZ stack before
the eval creates any functions.

* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::BytecodeGenerator):
* tests/stress/variable-under-tdz-eval-tricky.js: Added.
(assert):
(throw.new.Error):
(assert.try.underTDZ):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (202601 => 202602)


--- trunk/Source/_javascript_Core/ChangeLog	2016-06-29 01:52:14 UTC (rev 202601)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-06-29 02:06:22 UTC (rev 202602)
@@ -1,3 +1,28 @@
+2016-06-28  Saam Barati  <sbar...@apple.com>
+
+        Assertion failure or crash when accessing let-variable in TDZ with eval with a function in it that returns let variable
+        https://bugs.webkit.org/show_bug.cgi?id=158796
+        <rdar://problem/26984659>
+
+        Reviewed by Michael Saboff.
+
+        There was a bug where some functions inside of an eval were
+        omitting a necessary TDZ check. This obviously leads to bad
+        things because a variable under TDZ is the null pointer.
+        The eval's bytecode was generated with the correct TDZ set, but 
+        it created all its functions before pushing that TDZ set onto
+        the stack. That's a mistake. Those functions need to be created with
+        that TDZ set. The solution is simple, the TDZ set that the eval
+        is created with needs to be pushed onto the TDZ stack before
+        the eval creates any functions.
+
+        * bytecompiler/BytecodeGenerator.cpp:
+        (JSC::BytecodeGenerator::BytecodeGenerator):
+        * tests/stress/variable-under-tdz-eval-tricky.js: Added.
+        (assert):
+        (throw.new.Error):
+        (assert.try.underTDZ):
+
 2016-06-28  Michael Saboff  <msab...@apple.com>
 
         REGRESSION (r200946): Improper backtracking from last alternative in sticky patterns

Modified: trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp (202601 => 202602)


--- trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp	2016-06-29 01:52:14 UTC (rev 202601)
+++ trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp	2016-06-29 02:06:22 UTC (rev 202602)
@@ -619,6 +619,8 @@
 
     m_codeBlock->setNumParameters(1);
 
+    pushTDZVariables(*parentScopeTDZVariables, TDZCheckOptimization::DoNotOptimize);
+
     emitEnter();
 
     allocateAndEmitScope();
@@ -641,8 +643,6 @@
     if (evalNode->usesSuperCall() || evalNode->usesNewTarget())
         m_newTargetRegister = addVar();
 
-    pushTDZVariables(*parentScopeTDZVariables, TDZCheckOptimization::DoNotOptimize);
-    
     if (codeBlock->isArrowFunctionContext() && (evalNode->usesThis() || evalNode->usesSuperProperty()))
         emitLoadThisFromArrowFunctionLexicalEnvironment();
 

Added: trunk/Source/_javascript_Core/tests/stress/variable-under-tdz-eval-tricky.js (0 => 202602)


--- trunk/Source/_javascript_Core/tests/stress/variable-under-tdz-eval-tricky.js	                        (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/variable-under-tdz-eval-tricky.js	2016-06-29 02:06:22 UTC (rev 202602)
@@ -0,0 +1,60 @@
+function assert(b) {
+    if (!b)
+        throw new Error("Bad!")
+}
+
+
+{
+    let threw = false;
+    try {
+        let underTDZ = {
+            prop: eval("function pleaseTDZMe(){ return underTDZ; }; pleaseTDZMe();")
+        };
+    } catch(e) {
+        threw = e instanceof ReferenceError;
+    }
+    assert(threw);
+}
+
+{
+    let threw = false;
+    try {
+        const underTDZ = {
+            prop: eval("function pleaseTDZMe(){ return underTDZ; }; pleaseTDZMe();")
+        };
+    } catch(e) {
+        threw = e instanceof ReferenceError;
+    }
+    assert(threw);
+}
+
+{
+    let threw = false;
+    try {
+        class underTDZ extends eval("function pleaseTDZMe() { return underTDZ; }; pleaseTDZMe()") { };
+    } catch(e) {
+        threw = e instanceof ReferenceError;
+    }
+    assert(threw);
+}
+
+{ 
+    let threw = false;
+    try {
+        let b = {a: eval("function b(){ return b; }"), b: (1, eval)("(b())")};
+    } catch(e) {
+        threw = e instanceof ReferenceError;
+    }
+    assert(threw);
+}
+
+{ 
+    let threw = false;
+    try {
+        let {b} = {a: eval("function b(){ return b; }"), b: (1, eval)("print(b())")};
+    } catch(e) {
+        threw = e instanceof ReferenceError;
+    }
+    assert(threw);
+}
+
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to