فهرست منبع

eval syntax checks should not descend into function declarations (#2123)


---------

Co-authored-by: Rolf Grossmann <[email protected]>
Rolf Grossmann 1 ماه پیش
والد
کامیت
9957b5ba15
2فایلهای تغییر یافته به همراه26 افزوده شده و 1 حذف شده
  1. 16 1
      Jint.Tests/Runtime/EngineTests.cs
  2. 10 0
      Jint/Native/Function/EvalFunction.cs

+ 16 - 1
Jint.Tests/Runtime/EngineTests.cs

@@ -597,6 +597,21 @@ public partial class EngineTests : IDisposable
             ");
     }
 
+    [Fact]
+    public void EvalFunctionWithTargetNewParse()
+    {
+        RunTest(@"
+                const code = `function MyClass() {
+                   if (!new.target) throw new Error('Use MyClass as constructor!');
+                }`;
+                eval(code);
+                const code2 = `var x = function () {
+                   if (!new.target) throw new Error('Use as constructor!');
+                }`;
+                eval(code2);
+            ");
+    }
+
     [Fact]
     public void ForInStatement()
     {
@@ -3098,4 +3113,4 @@ x.test = {
             throw new NotImplementedException();
         }
     }
-}
+}

+ 10 - 0
Jint/Native/Function/EvalFunction.cs

@@ -217,5 +217,15 @@ public sealed class EvalFunction : Function
             _containsSuperCall |= callExpression.Callee.Type == NodeType.Super;
             return base.VisitCallExpression(callExpression);
         }
+
+        protected override object? VisitFunctionDeclaration(FunctionDeclaration node)
+        {
+            return node;
+        }
+
+        protected override object? VisitFunctionExpression(FunctionExpression node)
+        {
+            return node;
+        }
     }
 }