diff --git a/Jint.Tests/Runtime/EngineTests.cs b/Jint.Tests/Runtime/EngineTests.cs index d13bf3f209..ffe3914775 100644 --- a/Jint.Tests/Runtime/EngineTests.cs +++ b/Jint.Tests/Runtime/EngineTests.cs @@ -597,6 +597,21 @@ public void EvalFunctionParseAndExecuteCode() "); } + [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 @@ public bool TryConvert(object value, Type type, IFormatProvider formatProvider, throw new NotImplementedException(); } } -} \ No newline at end of file +} diff --git a/Jint/Native/Function/EvalFunction.cs b/Jint/Native/Function/EvalFunction.cs index 54424df454..9dbbf72254 100644 --- a/Jint/Native/Function/EvalFunction.cs +++ b/Jint/Native/Function/EvalFunction.cs @@ -217,5 +217,15 @@ protected override object VisitMetaProperty(MetaProperty metaProperty) _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; + } } }