Explorar o código

Destructuring declaration should not produce value (#6330)

Without this we had problem when we are producing returns from the global function when
they are marked as fscrReturnExpression, like in eval case
Fixed this in MustProduceValue function to skip that statement.
Fixes OS : 23989602
Akrosh Gandhi %!s(int64=5) %!d(string=hai) anos
pai
achega
bd79dba434
Modificáronse 2 ficheiros con 14 adicións e 0 borrados
  1. 6 0
      lib/Runtime/ByteCode/ByteCodeGenerator.cpp
  2. 8 0
      test/es6/destructuring_bugs.js

+ 6 - 0
lib/Runtime/ByteCode/ByteCodeGenerator.cpp

@@ -577,6 +577,12 @@ bool MustProduceValue(ParseNode *pnode, const Js::ScriptContext *const scriptCon
 {
     // Determine whether the current statement is guaranteed to produce a value.
 
+    if (pnode->IsPatternDeclaration())
+    {
+        // The pattern declaration are as var declaration they don't produce a value.
+        return false;
+    }
+
     if (IsExpressionStatement(pnode, scriptContext))
     {
         // These are trivially true.

+ 8 - 0
test/es6/destructuring_bugs.js

@@ -529,6 +529,14 @@ var tests = [
         };
         test1();
     }
+  },
+  {
+    name: "OS: 23989602, Destructuring declaration should not produce any value",
+    body: function () {
+        assert.areEqual(undefined, eval("var {x} = {};"));
+        assert.areEqual(undefined, eval("{ var {x} = {}; }"));
+        assert.areEqual(undefined, eval("{ var [] = []; }"));
+    }
   }
 ];