-
-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed: Calling Array.prototype.toString() with anything other than a …
…real Array object throws a NullReferenceException (#641)
- Loading branch information
1 parent
8adbbbc
commit 531037a
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using Jint.Runtime; | ||
using Xunit; | ||
|
||
namespace Jint.Tests.Runtime | ||
{ | ||
public class ArrayTests | ||
{ | ||
private readonly Engine _engine; | ||
|
||
public ArrayTests() | ||
{ | ||
_engine = new Engine() | ||
.SetValue("log", new Action<object>(Console.WriteLine)) | ||
.SetValue("assert", new Action<bool>(Assert.True)) | ||
.SetValue("equal", new Action<object, object>(Assert.Equal)); | ||
} | ||
|
||
private void RunTest(string source) | ||
{ | ||
_engine.Execute(source); | ||
} | ||
|
||
|
||
[Fact] | ||
public void ArrayPrototypeToStringWithArray() | ||
{ | ||
var result = _engine.Execute("Array.prototype.toString.call([1,2,3]);").GetCompletionValue().AsString(); | ||
|
||
Assert.Equal("1,2,3", result); | ||
} | ||
|
||
[Fact] | ||
public void ArrayPrototypeToStringWithNumber() | ||
{ | ||
var result = _engine.Execute("Array.prototype.toString.call(1);").GetCompletionValue().AsString(); | ||
|
||
Assert.Equal("[object Number]", result); | ||
} | ||
|
||
[Fact] | ||
public void ArrayPrototypeToStringWithObject() | ||
{ | ||
var result = _engine.Execute("Array.prototype.toString.call({});").GetCompletionValue().AsString(); | ||
|
||
Assert.Equal("[object Object]", result); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters