Skip to content

Commit 63ef394

Browse files
committed
Fix stackoverflow
1 parent 1fd4183 commit 63ef394

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Jint.Tests/Runtime/ArrayTests.cs

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ public void ArrayPrototypeToStringWithObject()
3939
Assert.Equal("[object Object]", result);
4040
}
4141

42+
[Fact]
43+
public void ArrayPrototypeToStringSelfReference()
44+
{
45+
var result = _engine.Evaluate("Array.prototype.toString.call((c = [1, 2, 3, 4], c[1] = c, c))").AsString();
46+
47+
Assert.Equal("1,,3,4", result);
48+
}
49+
4250
[Fact]
4351
public void EmptyStringKey()
4452
{

Jint/Native/Array/ArrayPrototype.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1273,14 +1273,14 @@ private JsValue Join(JsValue thisObject, JsValue[] arguments)
12731273
return JsString.Empty;
12741274
}
12751275

1276-
static string StringFromJsValue(JsValue value)
1276+
static string StringFromJsValue(JsValue value, JsValue thisObject)
12771277
{
1278-
return value.IsNullOrUndefined()
1278+
return value.IsNullOrUndefined() || thisObject == value
12791279
? ""
12801280
: TypeConverter.ToString(value);
12811281
}
12821282

1283-
var s = StringFromJsValue(o.Get(0));
1283+
var s = StringFromJsValue(o.Get(0), thisObject);
12841284
if (len == 1)
12851285
{
12861286
return s;
@@ -1294,7 +1294,7 @@ static string StringFromJsValue(JsValue value)
12941294
{
12951295
sb.Append(sep);
12961296
}
1297-
sb.Append(StringFromJsValue(o.Get(k)));
1297+
sb.Append(StringFromJsValue(o.Get(k), thisObject));
12981298
}
12991299

13001300
return sb.ToString();

0 commit comments

Comments
 (0)