Skip to content

Commit 12f05cb

Browse files
authored
Anonymous lambda should have empty function name (#1024)
1 parent b40718f commit 12f05cb

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Jint.Tests/Runtime/FunctionTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,12 @@ function test() {
9494
.SetValue("assertEqual", new Action<object, object>((a, b) => Assert.Equal(b, a)))
9595
.Execute(script);
9696
}
97+
98+
[Fact]
99+
public void AnonymousLambdaShouldHaveNameDefined()
100+
{
101+
var engine = new Engine();
102+
Assert.True(engine.Evaluate("(()=>{}).hasOwnProperty('name')").AsBoolean());
103+
}
97104
}
98105
}

Jint/Native/Function/FunctionInstance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public override void RemoveOwnProperty(JsValue property)
213213

214214
internal void SetFunctionName(JsValue name, string prefix = null, bool force = false)
215215
{
216-
if (!force && _nameDescriptor != null && !UnwrapJsValue(_nameDescriptor).IsUndefined())
216+
if (!force && _nameDescriptor != null && UnwrapJsValue(_nameDescriptor) != JsString.Empty)
217217
{
218218
return;
219219
}

Jint/Runtime/Interpreter/Expressions/JintArrowFunctionExpression.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Esprima.Ast;
2+
using Jint.Native;
23
using Jint.Native.Function;
34

45
namespace Jint.Runtime.Interpreter.Expressions
@@ -25,6 +26,11 @@ protected override ExpressionResult EvaluateInternal(EvaluationContext context)
2526
FunctionThisMode.Lexical,
2627
proto: engine.Realm.Intrinsics.Function.PrototypeObject);
2728

29+
if (_function.Name is null)
30+
{
31+
closure.SetFunctionName(JsString.Empty);
32+
}
33+
2834
return NormalCompletion(closure);
2935
}
3036
}

0 commit comments

Comments
 (0)